mirror of
https://github.com/vector-im/element-call.git
synced 2026-02-08 04:19:11 +00:00
improve widget tests
(this we might want to cherry pick in its own PR)
This commit is contained in:
@@ -11,7 +11,6 @@ import { createRoomWidgetClient, EventType } from "matrix-js-sdk";
|
||||
import { getUrlParams } from "./UrlParams";
|
||||
import { initializeWidget, widget } from "./widget";
|
||||
import { Config } from "./config/Config";
|
||||
import { ElementCallReactionEventType } from "./reactions";
|
||||
|
||||
vi.mock("matrix-js-sdk", { spy: true });
|
||||
const createRoomWidgetClientSpy = vi.mocked(createRoomWidgetClient);
|
||||
@@ -35,7 +34,7 @@ vi.mock("./UrlParams", () => ({
|
||||
})),
|
||||
}));
|
||||
|
||||
initializeWidget();
|
||||
initializeWidget("ANYRTCAPP");
|
||||
describe("widget", () => {
|
||||
beforeAll(() => {});
|
||||
|
||||
@@ -52,48 +51,39 @@ describe("widget", () => {
|
||||
expect(widget).toBeDefined();
|
||||
expect(configInitSpy).toHaveBeenCalled();
|
||||
const sendEvent = [
|
||||
EventType.CallNotify, // Sent as a deprecated fallback
|
||||
EventType.RTCNotification,
|
||||
"org.matrix.msc4075.call.notify", // Sent as a deprecated fallback
|
||||
"org.matrix.msc4075.rtc.notification",
|
||||
];
|
||||
const sendRecvEvent = [
|
||||
"org.matrix.rageshake_request",
|
||||
EventType.CallEncryptionKeysPrefix,
|
||||
EventType.Reaction,
|
||||
EventType.RoomRedaction,
|
||||
ElementCallReactionEventType,
|
||||
EventType.RTCDecline,
|
||||
EventType.RTCMembership,
|
||||
"io.element.call.encryption_keys",
|
||||
"m.reaction",
|
||||
"m.room.redaction",
|
||||
"io.element.call.reaction",
|
||||
"org.matrix.msc4310.rtc.decline",
|
||||
"org.matrix.msc4143.rtc.member",
|
||||
];
|
||||
|
||||
const sendState = [
|
||||
"myYser", // Legacy call membership events
|
||||
`_myYser_AAAAA_m.call`, // Session membership events
|
||||
`myYser_AAAAA_m.call`, // The above with no leading underscore, for room versions whose auth rules allow it
|
||||
].map((stateKey) => ({
|
||||
eventType: EventType.GroupCallMemberPrefix,
|
||||
stateKey,
|
||||
}));
|
||||
{ eventType: "org.matrix.msc3401.call.member", stateKey: "myYser" }, // Legacy call membership events
|
||||
{
|
||||
eventType: "org.matrix.msc3401.call.member",
|
||||
stateKey: `_myYser_AAAAA_ANYRTCAPP`,
|
||||
}, // Session membership events
|
||||
{
|
||||
eventType: "org.matrix.msc3401.call.member",
|
||||
stateKey: `myYser_AAAAA_ANYRTCAPP`,
|
||||
}, // The above with no leading underscore, for room versions whose auth rules allow it
|
||||
];
|
||||
const receiveState = [
|
||||
{ eventType: EventType.RoomCreate },
|
||||
{ eventType: EventType.RoomName },
|
||||
{ eventType: EventType.RoomMember },
|
||||
{ eventType: EventType.RoomEncryption },
|
||||
{ eventType: EventType.GroupCallMemberPrefix },
|
||||
{ eventType: "m.room.create" },
|
||||
{ eventType: "m.room.name" },
|
||||
{ eventType: "m.room.member" },
|
||||
{ eventType: "m.room.encryption" },
|
||||
{ eventType: "org.matrix.msc3401.call.member" },
|
||||
];
|
||||
|
||||
const sendRecvToDevice = [
|
||||
EventType.CallInvite,
|
||||
EventType.CallCandidates,
|
||||
EventType.CallAnswer,
|
||||
EventType.CallHangup,
|
||||
EventType.CallReject,
|
||||
EventType.CallSelectAnswer,
|
||||
EventType.CallNegotiate,
|
||||
EventType.CallSDPStreamMetadataChanged,
|
||||
EventType.CallSDPStreamMetadataChangedPrefix,
|
||||
EventType.CallReplaces,
|
||||
EventType.CallEncryptionKeysPrefix,
|
||||
];
|
||||
const sendRecvToDevice = ["io.element.call.encryption_keys"];
|
||||
|
||||
expect(createRoomWidgetClientSpy.mock.calls[0][1]).toStrictEqual({
|
||||
sendEvent: [...sendEvent, ...sendRecvEvent],
|
||||
|
||||
@@ -68,7 +68,7 @@ export let widget: WidgetHelpers | null;
|
||||
*/
|
||||
// this needs to be a seperate call and cannot be done on import to allow us to spy on methods in here before
|
||||
// execution.
|
||||
export const initializeWidget = (): void => {
|
||||
export const initializeWidget = (rtcApplication: string = "m.call"): void => {
|
||||
try {
|
||||
const {
|
||||
widgetId,
|
||||
@@ -128,8 +128,8 @@ export const initializeWidget = (): void => {
|
||||
|
||||
const sendState = [
|
||||
userId, // Legacy call membership events
|
||||
`_${userId}_${deviceId}_m.call`, // Session membership events
|
||||
`${userId}_${deviceId}_m.call`, // The above with no leading underscore, for room versions whose auth rules allow it
|
||||
`_${userId}_${deviceId}_${rtcApplication}`, // Session membership events
|
||||
`${userId}_${deviceId}_${rtcApplication}`, // The above with no leading underscore, for room versions whose auth rules allow it
|
||||
].map((stateKey) => ({
|
||||
eventType: EventType.GroupCallMemberPrefix,
|
||||
stateKey,
|
||||
@@ -142,19 +142,7 @@ export const initializeWidget = (): void => {
|
||||
{ eventType: EventType.GroupCallMemberPrefix },
|
||||
];
|
||||
|
||||
const sendRecvToDevice = [
|
||||
EventType.CallInvite,
|
||||
EventType.CallCandidates,
|
||||
EventType.CallAnswer,
|
||||
EventType.CallHangup,
|
||||
EventType.CallReject,
|
||||
EventType.CallSelectAnswer,
|
||||
EventType.CallNegotiate,
|
||||
EventType.CallSDPStreamMetadataChanged,
|
||||
EventType.CallSDPStreamMetadataChangedPrefix,
|
||||
EventType.CallReplaces,
|
||||
EventType.CallEncryptionKeysPrefix,
|
||||
];
|
||||
const sendRecvToDevice = [EventType.CallEncryptionKeysPrefix];
|
||||
|
||||
const client = createRoomWidgetClient(
|
||||
api,
|
||||
|
||||
Reference in New Issue
Block a user