mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-21 00:28:08 +08:00
Factor out repeated event emitter mocks
This commit is contained in:
parent
156f1e3a10
commit
25193f467a
@ -63,58 +63,40 @@ export function withTestScheduler(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockMember(member: Partial<RoomMember>): RoomMember {
|
interface EmitterMock<T> {
|
||||||
|
on: () => T;
|
||||||
|
off: () => T;
|
||||||
|
addListener: () => T;
|
||||||
|
removeListener: () => T;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockEmitter<T>(): EmitterMock<T> {
|
||||||
return {
|
return {
|
||||||
on() {
|
on(): T {
|
||||||
return this;
|
return this as T;
|
||||||
},
|
},
|
||||||
off() {
|
off(): T {
|
||||||
return this;
|
return this as T;
|
||||||
},
|
},
|
||||||
addListener() {
|
addListener(): T {
|
||||||
return this;
|
return this as T;
|
||||||
},
|
},
|
||||||
removeListener() {
|
removeListener(): T {
|
||||||
return this;
|
return this as T;
|
||||||
},
|
},
|
||||||
...member,
|
};
|
||||||
} as RoomMember;
|
}
|
||||||
|
|
||||||
|
export function mockMember(member: Partial<RoomMember>): RoomMember {
|
||||||
|
return { ...mockEmitter(), ...member } as RoomMember;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockMatrixRoom(room: Partial<MatrixRoom>): MatrixRoom {
|
export function mockMatrixRoom(room: Partial<MatrixRoom>): MatrixRoom {
|
||||||
return {
|
return { ...mockEmitter(), ...room } as Partial<MatrixRoom> as MatrixRoom;
|
||||||
on() {
|
|
||||||
return this as MatrixRoom;
|
|
||||||
},
|
|
||||||
off() {
|
|
||||||
return this as MatrixRoom;
|
|
||||||
},
|
|
||||||
addEventListener() {
|
|
||||||
return this as MatrixRoom;
|
|
||||||
},
|
|
||||||
removeEventListener() {
|
|
||||||
return this as MatrixRoom;
|
|
||||||
},
|
|
||||||
...room,
|
|
||||||
} as Partial<MatrixRoom> as MatrixRoom;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockLivekitRoom(room: Partial<LivekitRoom>): LivekitRoom {
|
export function mockLivekitRoom(room: Partial<LivekitRoom>): LivekitRoom {
|
||||||
return {
|
return { ...mockEmitter(), ...room } as Partial<LivekitRoom> as LivekitRoom;
|
||||||
on() {
|
|
||||||
return this as LivekitRoom;
|
|
||||||
},
|
|
||||||
off() {
|
|
||||||
return this as LivekitRoom;
|
|
||||||
},
|
|
||||||
addEventListener() {
|
|
||||||
return this as LivekitRoom;
|
|
||||||
},
|
|
||||||
removeEventListener() {
|
|
||||||
return this as LivekitRoom;
|
|
||||||
},
|
|
||||||
...room,
|
|
||||||
} as Partial<LivekitRoom> as LivekitRoom;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockLocalParticipant(
|
export function mockLocalParticipant(
|
||||||
@ -124,18 +106,7 @@ export function mockLocalParticipant(
|
|||||||
isLocal: true,
|
isLocal: true,
|
||||||
getTrackPublication: () =>
|
getTrackPublication: () =>
|
||||||
({}) as Partial<LocalTrackPublication> as LocalTrackPublication,
|
({}) as Partial<LocalTrackPublication> as LocalTrackPublication,
|
||||||
on() {
|
...mockEmitter(),
|
||||||
return this as LocalParticipant;
|
|
||||||
},
|
|
||||||
off() {
|
|
||||||
return this as LocalParticipant;
|
|
||||||
},
|
|
||||||
addListener() {
|
|
||||||
return this as LocalParticipant;
|
|
||||||
},
|
|
||||||
removeListener() {
|
|
||||||
return this as LocalParticipant;
|
|
||||||
},
|
|
||||||
...participant,
|
...participant,
|
||||||
} as Partial<LocalParticipant> as LocalParticipant;
|
} as Partial<LocalParticipant> as LocalParticipant;
|
||||||
}
|
}
|
||||||
@ -165,18 +136,7 @@ export function mockRemoteParticipant(
|
|||||||
setVolume() {},
|
setVolume() {},
|
||||||
getTrackPublication: () =>
|
getTrackPublication: () =>
|
||||||
({}) as Partial<RemoteTrackPublication> as RemoteTrackPublication,
|
({}) as Partial<RemoteTrackPublication> as RemoteTrackPublication,
|
||||||
on() {
|
...mockEmitter(),
|
||||||
return this;
|
|
||||||
},
|
|
||||||
off() {
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
addListener() {
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
removeListener() {
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
...participant,
|
...participant,
|
||||||
} as RemoteParticipant;
|
} as RemoteParticipant;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user