You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-09 08:42:50 +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;
|
||||
};
|
||||
|
@@ -14,8 +14,12 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { MockedObject } from "jest-mock";
|
||||
import {
|
||||
MatrixClient,
|
||||
MatrixEvent,
|
||||
EventType,
|
||||
Room,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { mkEvent } from "./test-utils";
|
||||
@@ -32,3 +36,17 @@ export const makeMembershipEvent = (
|
||||
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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user