Live location sharing: move test utils into utils (#8365)
* move makeRoomWithState events to test utils Signed-off-by: Kerry Archibald <kerrya@element.io> * move beacon test helpers into utils Signed-off-by: Kerry Archibald <kerrya@element.io> * remove file Signed-off-by: Kerry Archibald <kerrya@element.io> * more types Signed-off-by: Kerry Archibald <kerrya@element.io>pull/28788/head^2
parent
56cf9212d3
commit
70cdd57a5c
|
@ -22,12 +22,18 @@ import {
|
||||||
Beacon,
|
Beacon,
|
||||||
Room,
|
Room,
|
||||||
RoomMember,
|
RoomMember,
|
||||||
|
MatrixEvent,
|
||||||
getBeaconInfoIdentifier,
|
getBeaconInfoIdentifier,
|
||||||
} from 'matrix-js-sdk/src/matrix';
|
} from 'matrix-js-sdk/src/matrix';
|
||||||
|
|
||||||
import BeaconMarker from '../../../../src/components/views/beacon/BeaconMarker';
|
import BeaconMarker from '../../../../src/components/views/beacon/BeaconMarker';
|
||||||
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';
|
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';
|
||||||
import { getMockClientWithEventEmitter, makeBeaconEvent, makeBeaconInfoEvent } from '../../../test-utils';
|
import {
|
||||||
|
getMockClientWithEventEmitter,
|
||||||
|
makeBeaconEvent,
|
||||||
|
makeBeaconInfoEvent,
|
||||||
|
makeRoomWithStateEvents,
|
||||||
|
} from '../../../test-utils';
|
||||||
import { TILE_SERVER_WK_KEY } from '../../../../src/utils/WellKnownUtils';
|
import { TILE_SERVER_WK_KEY } from '../../../../src/utils/WellKnownUtils';
|
||||||
|
|
||||||
describe('<BeaconMarker />', () => {
|
describe('<BeaconMarker />', () => {
|
||||||
|
@ -53,13 +59,9 @@ describe('<BeaconMarker />', () => {
|
||||||
|
|
||||||
// make fresh rooms every time
|
// make fresh rooms every time
|
||||||
// as we update room state
|
// as we update room state
|
||||||
const makeRoomWithStateEvents = (stateEvents = []): Room => {
|
const setupRoom = (stateEvents: MatrixEvent[] = []): Room => {
|
||||||
const room1 = new Room(roomId, mockClient, aliceId);
|
const room1 = makeRoomWithStateEvents(stateEvents, { roomId, mockClient });
|
||||||
|
|
||||||
room1.currentState.setStateEvents(stateEvents);
|
|
||||||
jest.spyOn(room1, 'getMember').mockReturnValue(aliceMember);
|
jest.spyOn(room1, 'getMember').mockReturnValue(aliceMember);
|
||||||
mockClient.getRoom.mockReturnValue(room1);
|
|
||||||
|
|
||||||
return room1;
|
return room1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -97,21 +99,21 @@ describe('<BeaconMarker />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders nothing when beacon is not live', () => {
|
it('renders nothing when beacon is not live', () => {
|
||||||
const room = makeRoomWithStateEvents([notLiveEvent]);
|
const room = setupRoom([notLiveEvent]);
|
||||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(notLiveEvent));
|
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(notLiveEvent));
|
||||||
const component = getComponent({ beacon });
|
const component = getComponent({ beacon });
|
||||||
expect(component.html()).toBe(null);
|
expect(component.html()).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders nothing when beacon has no location', () => {
|
it('renders nothing when beacon has no location', () => {
|
||||||
const room = makeRoomWithStateEvents([defaultEvent]);
|
const room = setupRoom([defaultEvent]);
|
||||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||||
const component = getComponent({ beacon });
|
const component = getComponent({ beacon });
|
||||||
expect(component.html()).toBe(null);
|
expect(component.html()).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders marker when beacon has location', () => {
|
it('renders marker when beacon has location', () => {
|
||||||
const room = makeRoomWithStateEvents([defaultEvent]);
|
const room = setupRoom([defaultEvent]);
|
||||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||||
beacon.addLocations([location1]);
|
beacon.addLocations([location1]);
|
||||||
const component = getComponent({ beacon });
|
const component = getComponent({ beacon });
|
||||||
|
@ -119,7 +121,7 @@ describe('<BeaconMarker />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates with new locations', () => {
|
it('updates with new locations', () => {
|
||||||
const room = makeRoomWithStateEvents([defaultEvent]);
|
const room = setupRoom([defaultEvent]);
|
||||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||||
beacon.addLocations([location1]);
|
beacon.addLocations([location1]);
|
||||||
const component = getComponent({ beacon });
|
const component = getComponent({ beacon });
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { mount } from 'enzyme';
|
||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
import {
|
import {
|
||||||
MatrixClient,
|
MatrixClient,
|
||||||
|
MatrixEvent,
|
||||||
Room,
|
Room,
|
||||||
RoomMember,
|
RoomMember,
|
||||||
getBeaconInfoIdentifier,
|
getBeaconInfoIdentifier,
|
||||||
|
@ -30,6 +31,7 @@ import {
|
||||||
getMockClientWithEventEmitter,
|
getMockClientWithEventEmitter,
|
||||||
makeBeaconEvent,
|
makeBeaconEvent,
|
||||||
makeBeaconInfoEvent,
|
makeBeaconInfoEvent,
|
||||||
|
makeRoomWithStateEvents,
|
||||||
} from '../../../test-utils';
|
} from '../../../test-utils';
|
||||||
import { TILE_SERVER_WK_KEY } from '../../../../src/utils/WellKnownUtils';
|
import { TILE_SERVER_WK_KEY } from '../../../../src/utils/WellKnownUtils';
|
||||||
|
|
||||||
|
@ -55,12 +57,9 @@ describe('<BeaconViewDialog />', () => {
|
||||||
|
|
||||||
// make fresh rooms every time
|
// make fresh rooms every time
|
||||||
// as we update room state
|
// as we update room state
|
||||||
const makeRoomWithStateEvents = (stateEvents = []): Room => {
|
const setupRoom = (stateEvents: MatrixEvent[] = []): Room => {
|
||||||
const room1 = new Room(roomId, mockClient, aliceId);
|
const room1 = makeRoomWithStateEvents(stateEvents, { roomId, mockClient });
|
||||||
|
|
||||||
room1.currentState.setStateEvents(stateEvents);
|
|
||||||
jest.spyOn(room1, 'getMember').mockReturnValue(aliceMember);
|
jest.spyOn(room1, 'getMember').mockReturnValue(aliceMember);
|
||||||
mockClient.getRoom.mockReturnValue(room1);
|
|
||||||
|
|
||||||
return room1;
|
return room1;
|
||||||
};
|
};
|
||||||
|
@ -85,7 +84,7 @@ describe('<BeaconViewDialog />', () => {
|
||||||
mount(<BeaconViewDialog {...defaultProps} {...props} />);
|
mount(<BeaconViewDialog {...defaultProps} {...props} />);
|
||||||
|
|
||||||
it('renders a map with markers', () => {
|
it('renders a map with markers', () => {
|
||||||
const room = makeRoomWithStateEvents([defaultEvent]);
|
const room = setupRoom([defaultEvent]);
|
||||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||||
beacon.addLocations([location1]);
|
beacon.addLocations([location1]);
|
||||||
const component = getComponent();
|
const component = getComponent();
|
||||||
|
@ -97,7 +96,7 @@ describe('<BeaconViewDialog />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates markers on changes to beacons', () => {
|
it('updates markers on changes to beacons', () => {
|
||||||
const room = makeRoomWithStateEvents([defaultEvent]);
|
const room = setupRoom([defaultEvent]);
|
||||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||||
beacon.addLocations([location1]);
|
beacon.addLocations([location1]);
|
||||||
const component = getComponent();
|
const component = getComponent();
|
||||||
|
@ -122,7 +121,7 @@ describe('<BeaconViewDialog />', () => {
|
||||||
|
|
||||||
it('renders a fallback when no live beacons remain', () => {
|
it('renders a fallback when no live beacons remain', () => {
|
||||||
const onFinished = jest.fn();
|
const onFinished = jest.fn();
|
||||||
const room = makeRoomWithStateEvents([defaultEvent]);
|
const room = setupRoom([defaultEvent]);
|
||||||
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
const beacon = room.currentState.beacons.get(getBeaconInfoIdentifier(defaultEvent));
|
||||||
beacon.addLocations([location1]);
|
beacon.addLocations([location1]);
|
||||||
const component = getComponent({ onFinished });
|
const component = getComponent({ onFinished });
|
||||||
|
|
|
@ -20,12 +20,16 @@ import { act } from 'react-dom/test-utils';
|
||||||
import maplibregl from 'maplibre-gl';
|
import maplibregl from 'maplibre-gl';
|
||||||
import {
|
import {
|
||||||
BeaconEvent,
|
BeaconEvent,
|
||||||
Room,
|
|
||||||
getBeaconInfoIdentifier,
|
getBeaconInfoIdentifier,
|
||||||
} from 'matrix-js-sdk/src/matrix';
|
} from 'matrix-js-sdk/src/matrix';
|
||||||
|
|
||||||
import MBeaconBody from '../../../../src/components/views/messages/MBeaconBody';
|
import MBeaconBody from '../../../../src/components/views/messages/MBeaconBody';
|
||||||
import { getMockClientWithEventEmitter, makeBeaconEvent, makeBeaconInfoEvent } from '../../../test-utils';
|
import {
|
||||||
|
getMockClientWithEventEmitter,
|
||||||
|
makeBeaconEvent,
|
||||||
|
makeBeaconInfoEvent,
|
||||||
|
makeRoomWithStateEvents,
|
||||||
|
} from '../../../test-utils';
|
||||||
import { RoomPermalinkCreator } from '../../../../src/utils/permalinks/Permalinks';
|
import { RoomPermalinkCreator } from '../../../../src/utils/permalinks/Permalinks';
|
||||||
import { MediaEventHelper } from '../../../../src/utils/MediaEventHelper';
|
import { MediaEventHelper } from '../../../../src/utils/MediaEventHelper';
|
||||||
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';
|
import MatrixClientContext from '../../../../src/contexts/MatrixClientContext';
|
||||||
|
@ -51,17 +55,6 @@ describe('<MBeaconBody />', () => {
|
||||||
getRoom: jest.fn(),
|
getRoom: jest.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// make fresh rooms every time
|
|
||||||
// as we update room state
|
|
||||||
const makeRoomWithStateEvents = (stateEvents = []): Room => {
|
|
||||||
const room1 = new Room(roomId, mockClient, aliceId);
|
|
||||||
|
|
||||||
room1.currentState.setStateEvents(stateEvents);
|
|
||||||
mockClient.getRoom.mockReturnValue(room1);
|
|
||||||
|
|
||||||
return room1;
|
|
||||||
};
|
|
||||||
|
|
||||||
const defaultEvent = makeBeaconInfoEvent(aliceId,
|
const defaultEvent = makeBeaconInfoEvent(aliceId,
|
||||||
roomId,
|
roomId,
|
||||||
{ isLive: true },
|
{ isLive: true },
|
||||||
|
@ -96,7 +89,7 @@ describe('<MBeaconBody />', () => {
|
||||||
{ isLive: false },
|
{ isLive: false },
|
||||||
'$alice-room1-1',
|
'$alice-room1-1',
|
||||||
);
|
);
|
||||||
makeRoomWithStateEvents([beaconInfoEvent]);
|
makeRoomWithStateEvents([beaconInfoEvent], { roomId, mockClient });
|
||||||
const component = getComponent({ mxEvent: beaconInfoEvent });
|
const component = getComponent({ mxEvent: beaconInfoEvent });
|
||||||
expect(component.text()).toEqual("Live location ended");
|
expect(component.text()).toEqual("Live location ended");
|
||||||
});
|
});
|
||||||
|
@ -108,7 +101,7 @@ describe('<MBeaconBody />', () => {
|
||||||
{ isLive: true, timestamp: now - 600000, timeout: 500 },
|
{ isLive: true, timestamp: now - 600000, timeout: 500 },
|
||||||
'$alice-room1-1',
|
'$alice-room1-1',
|
||||||
);
|
);
|
||||||
makeRoomWithStateEvents([beaconInfoEvent]);
|
makeRoomWithStateEvents([beaconInfoEvent], { roomId, mockClient });
|
||||||
const component = getComponent({ mxEvent: beaconInfoEvent });
|
const component = getComponent({ mxEvent: beaconInfoEvent });
|
||||||
expect(component.text()).toEqual("Live location ended");
|
expect(component.text()).toEqual("Live location ended");
|
||||||
});
|
});
|
||||||
|
@ -120,7 +113,7 @@ describe('<MBeaconBody />', () => {
|
||||||
{ isLive: true, timestamp: now - 600000, timeout: 500 },
|
{ isLive: true, timestamp: now - 600000, timeout: 500 },
|
||||||
'$alice-room1-1',
|
'$alice-room1-1',
|
||||||
);
|
);
|
||||||
makeRoomWithStateEvents([beaconInfoEvent]);
|
makeRoomWithStateEvents([beaconInfoEvent], { roomId, mockClient });
|
||||||
const component = getComponent({ mxEvent: beaconInfoEvent });
|
const component = getComponent({ mxEvent: beaconInfoEvent });
|
||||||
act(() => {
|
act(() => {
|
||||||
component.find('.mx_MBeaconBody_map').simulate('click');
|
component.find('.mx_MBeaconBody_map').simulate('click');
|
||||||
|
@ -145,7 +138,7 @@ describe('<MBeaconBody />', () => {
|
||||||
'$alice-room1-2',
|
'$alice-room1-2',
|
||||||
);
|
);
|
||||||
|
|
||||||
makeRoomWithStateEvents([aliceBeaconInfo1, aliceBeaconInfo2]);
|
makeRoomWithStateEvents([aliceBeaconInfo1, aliceBeaconInfo2], { roomId, mockClient });
|
||||||
|
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo1 });
|
const component = getComponent({ mxEvent: aliceBeaconInfo1 });
|
||||||
// beacon1 has been superceded by beacon2
|
// beacon1 has been superceded by beacon2
|
||||||
|
@ -168,7 +161,7 @@ describe('<MBeaconBody />', () => {
|
||||||
'$alice-room1-2',
|
'$alice-room1-2',
|
||||||
);
|
);
|
||||||
|
|
||||||
const room = makeRoomWithStateEvents([aliceBeaconInfo1]);
|
const room = makeRoomWithStateEvents([aliceBeaconInfo1], { roomId, mockClient });
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo1 });
|
const component = getComponent({ mxEvent: aliceBeaconInfo1 });
|
||||||
|
|
||||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo1));
|
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo1));
|
||||||
|
@ -193,7 +186,7 @@ describe('<MBeaconBody />', () => {
|
||||||
'$alice-room1-1',
|
'$alice-room1-1',
|
||||||
);
|
);
|
||||||
|
|
||||||
const room = makeRoomWithStateEvents([aliceBeaconInfo]);
|
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||||
|
|
||||||
|
@ -226,14 +219,14 @@ describe('<MBeaconBody />', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
it('renders a live beacon without a location correctly', () => {
|
it('renders a live beacon without a location correctly', () => {
|
||||||
makeRoomWithStateEvents([aliceBeaconInfo]);
|
makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||||
|
|
||||||
expect(component.text()).toEqual("Loading live location...");
|
expect(component.text()).toEqual("Loading live location...");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does nothing on click when a beacon has no location', () => {
|
it('does nothing on click when a beacon has no location', () => {
|
||||||
makeRoomWithStateEvents([aliceBeaconInfo]);
|
makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
|
@ -244,7 +237,7 @@ describe('<MBeaconBody />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders a live beacon with a location correctly', () => {
|
it('renders a live beacon with a location correctly', () => {
|
||||||
const room = makeRoomWithStateEvents([aliceBeaconInfo]);
|
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||||
beaconInstance.addLocations([location1]);
|
beaconInstance.addLocations([location1]);
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||||
|
@ -253,7 +246,7 @@ describe('<MBeaconBody />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('opens maximised map view on click when beacon has a live location', () => {
|
it('opens maximised map view on click when beacon has a live location', () => {
|
||||||
const room = makeRoomWithStateEvents([aliceBeaconInfo]);
|
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||||
beaconInstance.addLocations([location1]);
|
beaconInstance.addLocations([location1]);
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||||
|
@ -267,7 +260,7 @@ describe('<MBeaconBody />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does nothing on click when a beacon has no location', () => {
|
it('does nothing on click when a beacon has no location', () => {
|
||||||
makeRoomWithStateEvents([aliceBeaconInfo]);
|
makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
|
@ -278,7 +271,7 @@ describe('<MBeaconBody />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders a live beacon with a location correctly', () => {
|
it('renders a live beacon with a location correctly', () => {
|
||||||
const room = makeRoomWithStateEvents([aliceBeaconInfo]);
|
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||||
beaconInstance.addLocations([location1]);
|
beaconInstance.addLocations([location1]);
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||||
|
@ -287,7 +280,7 @@ describe('<MBeaconBody />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('opens maximised map view on click when beacon has a live location', () => {
|
it('opens maximised map view on click when beacon has a live location', () => {
|
||||||
const room = makeRoomWithStateEvents([aliceBeaconInfo]);
|
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||||
beaconInstance.addLocations([location1]);
|
beaconInstance.addLocations([location1]);
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||||
|
@ -301,7 +294,7 @@ describe('<MBeaconBody />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates latest location', () => {
|
it('updates latest location', () => {
|
||||||
const room = makeRoomWithStateEvents([aliceBeaconInfo]);
|
const room = makeRoomWithStateEvents([aliceBeaconInfo], { roomId, mockClient });
|
||||||
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
const component = getComponent({ mxEvent: aliceBeaconInfo });
|
||||||
|
|
||||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(aliceBeaconInfo));
|
||||||
|
|
|
@ -16,11 +16,17 @@ limitations under the License.
|
||||||
|
|
||||||
import { MockedObject } from "jest-mock";
|
import { MockedObject } from "jest-mock";
|
||||||
import { makeBeaconInfoContent, makeBeaconContent } from "matrix-js-sdk/src/content-helpers";
|
import { makeBeaconInfoContent, makeBeaconContent } from "matrix-js-sdk/src/content-helpers";
|
||||||
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
|
import {
|
||||||
|
MatrixClient,
|
||||||
|
MatrixEvent,
|
||||||
|
Beacon,
|
||||||
|
getBeaconInfoIdentifier,
|
||||||
|
} from "matrix-js-sdk/src/matrix";
|
||||||
import { M_BEACON, M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
|
import { M_BEACON, M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
|
||||||
import { LocationAssetType } from "matrix-js-sdk/src/@types/location";
|
import { LocationAssetType } from "matrix-js-sdk/src/@types/location";
|
||||||
|
|
||||||
import { getMockGeolocationPositionError } from "./location";
|
import { getMockGeolocationPositionError } from "./location";
|
||||||
|
import { makeRoomWithStateEvents } from "./room";
|
||||||
|
|
||||||
type InfoContentProps = {
|
type InfoContentProps = {
|
||||||
timeout: number;
|
timeout: number;
|
||||||
|
@ -182,3 +188,22 @@ export const watchPositionMockImplementation = (delays: number[], errorCodes: nu
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a room with beacon events
|
||||||
|
* sets given locations on beacons
|
||||||
|
* returns beacons
|
||||||
|
*/
|
||||||
|
export const makeRoomWithBeacons = (
|
||||||
|
roomId: string,
|
||||||
|
mockClient: MockedObject<MatrixClient>,
|
||||||
|
beaconInfoEvents: MatrixEvent[],
|
||||||
|
locationEvents?: MatrixEvent[],
|
||||||
|
): Beacon[] => {
|
||||||
|
const room = makeRoomWithStateEvents(beaconInfoEvents, { roomId, mockClient });
|
||||||
|
const beacons = beaconInfoEvents.map(event => room.currentState.beacons.get(getBeaconInfoIdentifier(event)));
|
||||||
|
if (locationEvents) {
|
||||||
|
beacons.forEach(beacon => beacon.addLocations(locationEvents));
|
||||||
|
}
|
||||||
|
return beacons;
|
||||||
|
};
|
||||||
|
|
|
@ -14,8 +14,12 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { MockedObject } from "jest-mock";
|
||||||
import {
|
import {
|
||||||
|
MatrixClient,
|
||||||
|
MatrixEvent,
|
||||||
EventType,
|
EventType,
|
||||||
|
Room,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { mkEvent } from "./test-utils";
|
import { mkEvent } from "./test-utils";
|
||||||
|
@ -32,3 +36,17 @@ export const makeMembershipEvent = (
|
||||||
ts: Date.now(),
|
ts: Date.now(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a room
|
||||||
|
* sets state events on the room
|
||||||
|
* Sets client getRoom to return room
|
||||||
|
* returns room
|
||||||
|
*/
|
||||||
|
export const makeRoomWithStateEvents = (
|
||||||
|
stateEvents: MatrixEvent[] = [],
|
||||||
|
{ roomId, mockClient }: { roomId: string, mockClient: MockedObject<MatrixClient>}): Room => {
|
||||||
|
const room1 = new Room(roomId, mockClient, '@user:server.org');
|
||||||
|
room1.currentState.setStateEvents(stateEvents);
|
||||||
|
mockClient.getRoom.mockReturnValue(room1);
|
||||||
|
return room1;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue