mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-15 20:54:59 +08:00
fix tests by including client field on the Room stub and stubbing getJoinedMemberCount
This commit is contained in:
parent
9d8acd1af0
commit
04c923bd75
@ -53,32 +53,6 @@ const emitPromise = (e: EventEmitter, k: string | symbol) => new Promise(r => e.
|
||||
|
||||
const testUserId = "@test:user";
|
||||
|
||||
let rooms = [];
|
||||
|
||||
const mkRoom = (roomId: string) => {
|
||||
const room = mkStubRoom(roomId);
|
||||
room.currentState.getStateEvents.mockImplementation(mockStateEventImplementation([]));
|
||||
rooms.push(room);
|
||||
return room;
|
||||
};
|
||||
|
||||
const mkSpace = (spaceId: string, children: string[] = []) => {
|
||||
const space = mkRoom(spaceId);
|
||||
space.isSpaceRoom.mockReturnValue(true);
|
||||
space.currentState.getStateEvents.mockImplementation(mockStateEventImplementation(children.map(roomId =>
|
||||
mkEvent({
|
||||
event: true,
|
||||
type: EventType.SpaceChild,
|
||||
room: spaceId,
|
||||
user: testUserId,
|
||||
skey: roomId,
|
||||
content: { via: [] },
|
||||
ts: Date.now(),
|
||||
}),
|
||||
)));
|
||||
return space;
|
||||
};
|
||||
|
||||
const getValue = jest.fn();
|
||||
SettingsStore.getValue = getValue;
|
||||
|
||||
@ -111,6 +85,32 @@ describe("SpaceStore", () => {
|
||||
const store = SpaceStore.instance;
|
||||
const client = MatrixClientPeg.get();
|
||||
|
||||
let rooms = [];
|
||||
|
||||
const mkRoom = (roomId: string) => {
|
||||
const room = mkStubRoom(roomId, roomId, client);
|
||||
room.currentState.getStateEvents.mockImplementation(mockStateEventImplementation([]));
|
||||
rooms.push(room);
|
||||
return room;
|
||||
};
|
||||
|
||||
const mkSpace = (spaceId: string, children: string[] = []) => {
|
||||
const space = mkRoom(spaceId);
|
||||
space.isSpaceRoom.mockReturnValue(true);
|
||||
space.currentState.getStateEvents.mockImplementation(mockStateEventImplementation(children.map(roomId =>
|
||||
mkEvent({
|
||||
event: true,
|
||||
type: EventType.SpaceChild,
|
||||
room: spaceId,
|
||||
user: testUserId,
|
||||
skey: roomId,
|
||||
content: { via: [] },
|
||||
ts: Date.now(),
|
||||
}),
|
||||
)));
|
||||
return space;
|
||||
};
|
||||
|
||||
const viewRoom = roomId => defaultDispatcher.dispatch({ action: "view_room", room_id: roomId }, true);
|
||||
|
||||
const run = async () => {
|
||||
|
@ -220,7 +220,7 @@ export function mkMessage(opts) {
|
||||
return mkEvent(opts);
|
||||
}
|
||||
|
||||
export function mkStubRoom(roomId = null, name) {
|
||||
export function mkStubRoom(roomId = null, name, client) {
|
||||
const stubTimeline = { getEvents: () => [] };
|
||||
return {
|
||||
roomId,
|
||||
@ -235,6 +235,7 @@ export function mkStubRoom(roomId = null, name) {
|
||||
}),
|
||||
getMembersWithMembership: jest.fn().mockReturnValue([]),
|
||||
getJoinedMembers: jest.fn().mockReturnValue([]),
|
||||
getJoinedMemberCount: jest.fn().mockReturnValue(1),
|
||||
getMembers: jest.fn().mockReturnValue([]),
|
||||
getPendingEvents: () => [],
|
||||
getLiveTimeline: () => stubTimeline,
|
||||
@ -270,6 +271,7 @@ export function mkStubRoom(roomId = null, name) {
|
||||
getAltAliases: jest.fn().mockReturnValue([]),
|
||||
timeline: [],
|
||||
getJoinRule: jest.fn().mockReturnValue("invite"),
|
||||
client,
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user