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

Commit 3a6530d

Browse files
author
Kerry Archibald
committed
test live share warning
Signed-off-by: Kerry Archibald <[email protected]>
1 parent 80839b2 commit 3a6530d

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed

src/components/views/beacon/LeftPanelLiveShareWarning.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const LeftPanelLiveShareWarning: React.FC<Props> = ({ isMinimized }) => {
4343
})}
4444
title={isMinimized ? _t('You are sharing your live location') : undefined}
4545
>
46-
{isMinimized ? <LiveLocationIcon height={10} /> : _t('You are sharing your live location')}
46+
{ isMinimized ? <LiveLocationIcon height={10} /> : _t('You are sharing your live location') }
4747
</div>;
4848
};
4949

test/components/views/beacon/LeftPanelLiveShareWarning-test.tsx

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,66 @@ limitations under the License.
1515
*/
1616

1717
import React from 'react';
18+
import { mocked } from 'jest-mock';
1819
import { mount } from 'enzyme';
1920

2021
import '../../../skinned-sdk';
2122
import LeftPanelLiveShareWarning from '../../../../src/components/views/beacon/LeftPanelLiveShareWarning';
23+
import { OwnBeaconStore, OwnBeaconStoreEvent } from '../../../../src/stores/OwnBeaconStore';
24+
import { flushPromises } from '../../../test-utils';
25+
26+
jest.mock('../../../../src/stores/OwnBeaconStore', () => {
27+
// eslint-disable-next-line @typescript-eslint/no-var-requires
28+
const EventEmitter = require("events");
29+
class MockOwnBeaconStore extends EventEmitter {
30+
public hasLiveBeacons = jest.fn().mockReturnValue(false);
31+
}
32+
return {
33+
// @ts-ignore
34+
...jest.requireActual('../../../../src/stores/OwnBeaconStore'),
35+
OwnBeaconStore: {
36+
instance: new MockOwnBeaconStore() as unknown as OwnBeaconStore,
37+
},
38+
};
39+
},
40+
);
2241

2342
describe('<LeftPanelLiveShareWarning />', () => {
2443
const defaultProps = {};
2544
const getComponent = (props = {}) =>
2645
mount(<LeftPanelLiveShareWarning {...defaultProps} {...props} />);
2746

28-
it('renders correctly when not minimized', () => {
47+
it('renders nothing when user has no live beacons', () => {
2948
const component = getComponent();
30-
expect(component).toMatchSnapshot();
49+
expect(component.html()).toBe(null);
3150
});
3251

33-
it('renders correctly when minimized', () => {
34-
const component = getComponent({ isMinimized: true });
35-
expect(component).toMatchSnapshot();
52+
describe('when user has live beacons', () => {
53+
beforeEach(() => {
54+
mocked(OwnBeaconStore.instance).hasLiveBeacons.mockReturnValue(true);
55+
});
56+
it('renders correctly when not minimized', () => {
57+
const component = getComponent();
58+
expect(component).toMatchSnapshot();
59+
});
60+
61+
it('renders correctly when minimized', () => {
62+
const component = getComponent({ isMinimized: true });
63+
expect(component).toMatchSnapshot();
64+
});
65+
66+
it('removes itself when user stops having live beacons', async () => {
67+
const component = getComponent({ isMinimized: true });
68+
// started out rendered
69+
expect(component.html()).toBeTruthy();
70+
71+
mocked(OwnBeaconStore.instance).hasLiveBeacons.mockReturnValue(false);
72+
OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.LivenessChange, false);
73+
74+
await flushPromises();
75+
component.setProps({});
76+
77+
expect(component.html()).toBe(null);
78+
});
3679
});
3780
});
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`<LeftPanelLiveShareWarning /> renders correctly when minimized 1`] = `
3+
exports[`<LeftPanelLiveShareWarning /> when user has live beacons renders correctly when minimized 1`] = `
44
<LeftPanelLiveShareWarning
55
isMinimized={true}
6-
/>
6+
>
7+
<div
8+
className="mx_LeftPanelLiveShareWarning mx_LeftPanelLiveShareWarning__minimized"
9+
title="You are sharing your live location"
10+
>
11+
<div
12+
height={10}
13+
/>
14+
</div>
15+
</LeftPanelLiveShareWarning>
716
`;
817

9-
exports[`<LeftPanelLiveShareWarning /> renders correctly when not minimized 1`] = `<LeftPanelLiveShareWarning />`;
18+
exports[`<LeftPanelLiveShareWarning /> when user has live beacons renders correctly when not minimized 1`] = `
19+
<LeftPanelLiveShareWarning>
20+
<div
21+
className="mx_LeftPanelLiveShareWarning"
22+
>
23+
You are sharing your live location
24+
</div>
25+
</LeftPanelLiveShareWarning>
26+
`;

0 commit comments

Comments
 (0)