Fix flakiness of cypress crypto tests (#8731)
This commit is contained in:
parent
e11dbae89b
commit
23cc1aff73
1 changed files with 14 additions and 10 deletions
|
@ -19,13 +19,17 @@ limitations under the License.
|
||||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
import { SynapseInstance } from "../../plugins/synapsedocker";
|
import { SynapseInstance } from "../../plugins/synapsedocker";
|
||||||
|
|
||||||
function waitForEncryption(cli: MatrixClient, roomId: string, win: Cypress.AUTWindow, resolve: () => void) {
|
function waitForEncryption(cli: MatrixClient, roomId: string, win: Cypress.AUTWindow): Promise<void> {
|
||||||
cli.crypto.cryptoStore.getEndToEndRooms(null, (result) => {
|
return new Promise<void>(resolve => {
|
||||||
if (result[roomId]) {
|
const onEvent = () => {
|
||||||
resolve();
|
cli.crypto.cryptoStore.getEndToEndRooms(null, (result) => {
|
||||||
} else {
|
if (result[roomId]) {
|
||||||
cli.once(win.matrixcs.RoomStateEvent.Update, () => waitForEncryption(cli, roomId, win, resolve));
|
cli.off(win.matrixcs.ClientEvent.Event, onEvent);
|
||||||
}
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
cli.on(win.matrixcs.ClientEvent.Event, onEvent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,15 +65,15 @@ describe("Cryptography", () => {
|
||||||
cy.window(),
|
cy.window(),
|
||||||
]).then(([bot, roomId, win]) => {
|
]).then(([bot, roomId, win]) => {
|
||||||
cy.inviteUser(roomId, bot.getUserId());
|
cy.inviteUser(roomId, bot.getUserId());
|
||||||
cy.visit("/#/room/" + roomId);
|
|
||||||
cy.wrap(
|
cy.wrap(
|
||||||
new Promise<void>(resolve =>
|
waitForEncryption(
|
||||||
waitForEncryption(bot, roomId, win, resolve),
|
bot, roomId, win,
|
||||||
).then(() => bot.sendMessage(roomId, {
|
).then(() => bot.sendMessage(roomId, {
|
||||||
body: "Top secret message",
|
body: "Top secret message",
|
||||||
msgtype: "m.text",
|
msgtype: "m.text",
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
cy.visit("/#/room/" + roomId);
|
||||||
});
|
});
|
||||||
|
|
||||||
cy.get(".mx_RoomView_body .mx_cryptoEvent").should("contain", "Encryption enabled");
|
cy.get(".mx_RoomView_body .mx_cryptoEvent").should("contain", "Encryption enabled");
|
||||||
|
|
Loading…
Reference in a new issue