- { _t('You are sharing %(count)s live locations', { count: liveBeaconIds.length }) }
+ { _t('You are sharing your live location') }
{ stoppingInProgress ?
:
-
{ liveTimeRemaining }
+
}
', () => {
// 14.03.2022 16:15
const now = 1647270879403;
+ const MINUTE_MS = 60000;
const HOUR_MS = 3600000;
// mock the date so events are stable for snapshots etc
jest.spyOn(global.Date, 'now').mockReturnValue(now);
- const room1Beacon1 = makeBeaconInfoEvent(aliceId, room1Id, { isLive: true, timeout: HOUR_MS });
- const room2Beacon1 = makeBeaconInfoEvent(aliceId, room2Id, { isLive: true, timeout: HOUR_MS });
- const room2Beacon2 = makeBeaconInfoEvent(aliceId, room2Id, { isLive: true, timeout: HOUR_MS * 12 });
- const room3Beacon1 = makeBeaconInfoEvent(aliceId, room3Id, { isLive: true, timeout: HOUR_MS });
+ const room1Beacon1 = makeBeaconInfoEvent(aliceId, room1Id, {
+ isLive: true,
+ timeout: HOUR_MS,
+ }, '$0');
+ const room2Beacon1 = makeBeaconInfoEvent(aliceId, room2Id, { isLive: true, timeout: HOUR_MS }, '$1');
+ const room2Beacon2 = makeBeaconInfoEvent(aliceId, room2Id, { isLive: true, timeout: HOUR_MS * 12 }, '$2');
+ const room3Beacon1 = makeBeaconInfoEvent(aliceId, room3Id, { isLive: true, timeout: HOUR_MS }, '$3');
// make fresh rooms every time
// as we update room state
@@ -67,7 +71,8 @@ describe('
', () => {
const advanceDateAndTime = (ms: number) => {
// bc liveness check uses Date.now we have to advance this mock
- jest.spyOn(global.Date, 'now').mockReturnValue(now + ms);
+ jest.spyOn(global.Date, 'now').mockReturnValue(Date.now() + ms);
+
// then advance time for the interval by the same amount
jest.advanceTimersByTime(ms);
};
@@ -105,6 +110,8 @@ describe('
', () => {
jest.spyOn(global.Date, 'now').mockRestore();
});
+ const getExpiryText = wrapper => findByTestId(wrapper, 'room-live-share-expiry').text();
+
it('renders nothing when user has no live beacons at all', async () => {
await makeOwnBeaconStore();
const component = getComponent();
@@ -137,7 +144,7 @@ describe('
', () => {
const component = getComponent({ roomId: room2Id });
expect(component).toMatchSnapshot();
// later expiry displayed
- expect(findByTestId(component, 'room-live-share-expiry').text()).toEqual('12h left');
+ expect(getExpiryText(component)).toEqual('12h left');
});
it('removes itself when user stops having live beacons', async () => {
@@ -146,7 +153,9 @@ describe('
', () => {
expect(component.html()).toBeTruthy();
// time travel until room1Beacon1 is expired
- advanceDateAndTime(HOUR_MS + 1);
+ act(() => {
+ advanceDateAndTime(HOUR_MS + 1);
+ });
act(() => {
mockClient.emit(BeaconEvent.LivenessChange, false, new Beacon(room1Beacon1));
component.setProps({});
@@ -168,6 +177,29 @@ describe('
', () => {
expect(component.html()).toBeTruthy();
});
+ it('updates beacon time left periodically', () => {
+ const component = getComponent({ roomId: room1Id });
+ expect(getExpiryText(component)).toEqual('1h left');
+
+ act(() => {
+ advanceDateAndTime(MINUTE_MS * 25);
+ });
+
+ expect(getExpiryText(component)).toEqual('35m left');
+ });
+
+ it('clears expiry time interval on unmount', () => {
+ const clearIntervalSpy = jest.spyOn(global, 'clearInterval');
+ const component = getComponent({ roomId: room1Id });
+ expect(getExpiryText(component)).toEqual('1h left');
+
+ act(() => {
+ component.unmount();
+ });
+
+ expect(clearIntervalSpy).toHaveBeenCalled();
+ });
+
describe('stopping beacons', () => {
it('stops beacon on stop sharing click', () => {
const component = getComponent({ roomId: room2Id });
@@ -184,25 +216,28 @@ describe('
', () => {
it('displays again with correct state after stopping a beacon', () => {
// make sure the loading state is reset correctly after removing a beacon
- const component = getComponent({ roomId: room2Id });
+ const component = getComponent({ roomId: room1Id });
+ // stop the beacon
act(() => {
findByTestId(component, 'room-live-share-stop-sharing').at(0).simulate('click');
});
// time travel until room1Beacon1 is expired
- advanceDateAndTime(HOUR_MS + 1);
+ act(() => {
+ advanceDateAndTime(HOUR_MS + 1);
+ });
act(() => {
mockClient.emit(BeaconEvent.LivenessChange, false, new Beacon(room1Beacon1));
});
- const newLiveBeacon = makeBeaconInfoEvent(aliceId, room2Id, { isLive: true });
+ const newLiveBeacon = makeBeaconInfoEvent(aliceId, room1Id, { isLive: true });
act(() => {
mockClient.emit(BeaconEvent.New, newLiveBeacon, new Beacon(newLiveBeacon));
});
// button not disabled and expiry time shown
expect(findByTestId(component, 'room-live-share-stop-sharing').at(0).props().disabled).toBeFalsy();
- expect(findByTestId(component, 'room-live-share-expiry').text()).toEqual('11h left');
+ expect(findByTestId(component, 'room-live-share-expiry').text()).toEqual('1h left');
});
});
});
diff --git a/test/components/views/beacon/__snapshots__/RoomLiveShareWarning-test.tsx.snap b/test/components/views/beacon/__snapshots__/RoomLiveShareWarning-test.tsx.snap
index 3079670fc5..d656d57898 100644
--- a/test/components/views/beacon/__snapshots__/RoomLiveShareWarning-test.tsx.snap
+++ b/test/components/views/beacon/__snapshots__/RoomLiveShareWarning-test.tsx.snap
@@ -19,12 +19,57 @@ exports[`
when user has live beacons renders correctly w
>
You are sharing your live location
-
- 1h left
-
+
+ 1h left
+
+
when user has live beacons renders correctly w
- You are sharing 2 live locations
+ You are sharing your live location
-
- 12h left
-
+
+ 12h left
+
+