Live location sharing - send geolocation beacon events - happy path (#8127)

* geolocation utilities

Signed-off-by: Kerry Archibald <kerrya@element.io>

* messy send events

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add geolocation services

Signed-off-by: Kerry Archibald <kerrya@element.io>

* geolocation tests

Signed-off-by: Kerry Archibald <kerrya@element.io>

* debounce with backup emit every 30s

Signed-off-by: Kerry Archibald <kerrya@element.io>

* import reorder

Signed-off-by: Kerry Archibald <kerrya@element.io>

* some more working tests

Signed-off-by: Kerry Archibald <kerrya@element.io>

* complicated timeout testing

Signed-off-by: Kerry Archibald <kerrya@element.io>

* publish first location immediately

Signed-off-by: Kerry Archibald <kerrya@element.io>

* move advanceDateAndTime to utils, tidy

Signed-off-by: Kerry Archibald <kerrya@element.io>

* typos

Signed-off-by: Kerry Archibald <kerrya@element.io>

* types and lint

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry
2022-03-28 12:48:38 +02:00
committed by GitHub
parent f557ac9486
commit e9b2aea97b
6 changed files with 378 additions and 255 deletions
@@ -23,14 +23,17 @@ import '../../../skinned-sdk';
import RoomLiveShareWarning from '../../../../src/components/views/beacon/RoomLiveShareWarning';
import { OwnBeaconStore } from '../../../../src/stores/OwnBeaconStore';
import {
advanceDateAndTime,
findByTestId,
getMockClientWithEventEmitter,
makeBeaconInfoEvent,
mockGeolocation,
resetAsyncStoreWithClient,
setupAsyncStoreWithClient,
} from '../../../test-utils';
jest.useFakeTimers();
mockGeolocation();
describe('<RoomLiveShareWarning />', () => {
const aliceId = '@alice:server.org';
const room1Id = '$room1:server.org';
@@ -40,6 +43,7 @@ describe('<RoomLiveShareWarning />', () => {
getVisibleRooms: jest.fn().mockReturnValue([]),
getUserId: jest.fn().mockReturnValue(aliceId),
unstable_setLiveBeacon: jest.fn().mockResolvedValue({ event_id: '1' }),
sendEvent: jest.fn(),
});
// 14.03.2022 16:15
@@ -69,14 +73,6 @@ describe('<RoomLiveShareWarning />', () => {
return [room1, room2];
};
const advanceDateAndTime = (ms: number) => {
// bc liveness check uses Date.now we have to advance this mock
jest.spyOn(global.Date, 'now').mockReturnValue(Date.now() + ms);
// then advance time for the interval by the same amount
jest.advanceTimersByTime(ms);
};
const makeOwnBeaconStore = async () => {
const store = OwnBeaconStore.instance;
@@ -137,12 +133,16 @@ describe('<RoomLiveShareWarning />', () => {
it('renders correctly with one live beacon in room', () => {
const component = getComponent({ roomId: room1Id });
expect(component).toMatchSnapshot();
// beacons have generated ids that break snapshots
// assert on html
expect(component.html()).toMatchSnapshot();
});
it('renders correctly with two live beacons in room', () => {
const component = getComponent({ roomId: room2Id });
expect(component).toMatchSnapshot();
// beacons have generated ids that break snapshots
// assert on html
expect(component.html()).toMatchSnapshot();
// later expiry displayed
expect(getExpiryText(component)).toEqual('12h left');
});