Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Start adding Cypress tests for crypto #8577

Merged
merged 14 commits into from
May 30, 2022
2 changes: 2 additions & 0 deletions cypress/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

import "matrix-js-sdk/src/@types/global";
import type { MatrixClient, ClientEvent } from "matrix-js-sdk/src/client";
import type { RoomStateEvent } from "matrix-js-sdk/src/matrix";
import type { RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
import type { MatrixDispatcher } from "../src/dispatcher/dispatcher";

Expand All @@ -33,6 +34,7 @@ declare global {
MatrixClient: typeof MatrixClient;
ClientEvent: typeof ClientEvent;
RoomMemberEvent: typeof RoomMemberEvent;
RoomStateEvent: typeof RoomStateEvent;
};
}
}
Expand Down
32 changes: 19 additions & 13 deletions cypress/integration/6-crypto/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ limitations under the License.

/// <reference types="cypress" />

import { MatrixClient, RoomStateEvent } from "matrix-js-sdk/src/matrix";

import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { SynapseInstance } from "../../plugins/synapsedocker";

function waitForRoomEncryption(cli: MatrixClient, roomId: string, callback: () => void) {
// @ts-ignore - protected
if (cli.roomList.isRoomEncrypted(roomId)) {
function waitForEvent(cli: MatrixClient, event: any, check: () => boolean, callback: () => void) {
if (check()) {
callback();
} else {
cli.once(RoomStateEvent.Update, () => waitForRoomEncryption(cli, roomId, callback));
cli.once(event, () => waitForEvent(cli, event, check, callback));
}
}

Expand Down Expand Up @@ -60,13 +58,21 @@ describe("Cryptography", () => {
roomId => cy.inviteUser(roomId, bot.getUserId())
.then(() => cy.visit("/#/room/" + roomId))
.then(
() => cy.wrap(
new Promise<void>(
resolve => waitForRoomEncryption(bot, roomId, resolve),
).then(() => bot.sendMessage(roomId, {
body: "Top secret message",
msgtype: "m.text",
})),
() => cy.window().then(
win => cy.wrap(
new Promise<void>(
resolve => waitForEvent(
bot,
win.matrixcs.RoomStateEvent.Update,
// @ts-ignore - protected
() => bot.roomList.isRoomEncrypted(roomId),
resolve,
),
).then(() => bot.sendMessage(roomId, {
body: "Top secret message",
msgtype: "m.text",
})),
),
),
),
duxovni marked this conversation as resolved.
Show resolved Hide resolved
),
Expand Down