Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
test live share warning
Browse files Browse the repository at this point in the history
Signed-off-by: Kerry Archibald <kerrya@element.io>
  • Loading branch information
Kerry Archibald committed Mar 16, 2022
1 parent 80839b2 commit 3a6530d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/views/beacon/LeftPanelLiveShareWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const LeftPanelLiveShareWarning: React.FC<Props> = ({ isMinimized }) => {
})}
title={isMinimized ? _t('You are sharing your live location') : undefined}
>
{isMinimized ? <LiveLocationIcon height={10} /> : _t('You are sharing your live location')}
{ isMinimized ? <LiveLocationIcon height={10} /> : _t('You are sharing your live location') }
</div>;
};

Expand Down
53 changes: 48 additions & 5 deletions test/components/views/beacon/LeftPanelLiveShareWarning-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,66 @@ limitations under the License.
*/

import React from 'react';
import { mocked } from 'jest-mock';
import { mount } from 'enzyme';

import '../../../skinned-sdk';
import LeftPanelLiveShareWarning from '../../../../src/components/views/beacon/LeftPanelLiveShareWarning';
import { OwnBeaconStore, OwnBeaconStoreEvent } from '../../../../src/stores/OwnBeaconStore';
import { flushPromises } from '../../../test-utils';

jest.mock('../../../../src/stores/OwnBeaconStore', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const EventEmitter = require("events");
class MockOwnBeaconStore extends EventEmitter {
public hasLiveBeacons = jest.fn().mockReturnValue(false);
}
return {
// @ts-ignore
...jest.requireActual('../../../../src/stores/OwnBeaconStore'),
OwnBeaconStore: {
instance: new MockOwnBeaconStore() as unknown as OwnBeaconStore,
},
};
},
);

describe('<LeftPanelLiveShareWarning />', () => {
const defaultProps = {};
const getComponent = (props = {}) =>
mount(<LeftPanelLiveShareWarning {...defaultProps} {...props} />);

it('renders correctly when not minimized', () => {
it('renders nothing when user has no live beacons', () => {
const component = getComponent();
expect(component).toMatchSnapshot();
expect(component.html()).toBe(null);
});

it('renders correctly when minimized', () => {
const component = getComponent({ isMinimized: true });
expect(component).toMatchSnapshot();
describe('when user has live beacons', () => {
beforeEach(() => {
mocked(OwnBeaconStore.instance).hasLiveBeacons.mockReturnValue(true);
});
it('renders correctly when not minimized', () => {
const component = getComponent();
expect(component).toMatchSnapshot();
});

it('renders correctly when minimized', () => {
const component = getComponent({ isMinimized: true });
expect(component).toMatchSnapshot();
});

it('removes itself when user stops having live beacons', async () => {
const component = getComponent({ isMinimized: true });
// started out rendered
expect(component.html()).toBeTruthy();

mocked(OwnBeaconStore.instance).hasLiveBeacons.mockReturnValue(false);
OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.LivenessChange, false);

await flushPromises();
component.setProps({});

expect(component.html()).toBe(null);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<LeftPanelLiveShareWarning /> renders correctly when minimized 1`] = `
exports[`<LeftPanelLiveShareWarning /> when user has live beacons renders correctly when minimized 1`] = `
<LeftPanelLiveShareWarning
isMinimized={true}
/>
>
<div
className="mx_LeftPanelLiveShareWarning mx_LeftPanelLiveShareWarning__minimized"
title="You are sharing your live location"
>
<div
height={10}
/>
</div>
</LeftPanelLiveShareWarning>
`;

exports[`<LeftPanelLiveShareWarning /> renders correctly when not minimized 1`] = `<LeftPanelLiveShareWarning />`;
exports[`<LeftPanelLiveShareWarning /> when user has live beacons renders correctly when not minimized 1`] = `
<LeftPanelLiveShareWarning>
<div
className="mx_LeftPanelLiveShareWarning"
>
You are sharing your live location
</div>
</LeftPanelLiveShareWarning>
`;

0 comments on commit 3a6530d

Please sign in to comment.