You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
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>
This commit is contained in:
@ -16,11 +16,17 @@ limitations under the License.
|
||||
|
||||
import { MockedObject } from "jest-mock";
|
||||
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 { LocationAssetType } from "matrix-js-sdk/src/@types/location";
|
||||
|
||||
import { getMockGeolocationPositionError } from "./location";
|
||||
import { makeRoomWithStateEvents } from "./room";
|
||||
|
||||
type InfoContentProps = {
|
||||
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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user