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

Commit 8654a24

Browse files
authored
Minor cleanups to handleVerificationRequest in cypress tests (#10941)
* Remove redundant `verifier.done()` call This `done` call completes the verification process and stops it responding with further messages. It is unnecessary, *provided* the verification completes successfully, for which see matrix-org/matrix-js-sdk#3382. * Remove duplicated code in `decryption-failure` test * remove unused imports
1 parent 7d0c68a commit 8654a24

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

cypress/e2e/crypto/decryption-failure.spec.ts

+6-21
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ limitations under the License.
1515
*/
1616

1717
import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
18-
import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
1918
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
2019
import { HomeserverInstance } from "../../plugins/utils/homeserver";
2120
import { UserCredentials } from "../../support/login";
22-
import Chainable = Cypress.Chainable;
21+
import { handleVerificationRequest } from "./utils";
2322

2423
const ROOM_NAME = "Test room";
2524
const TEST_USER = "Alia";
@@ -39,24 +38,6 @@ const waitForVerificationRequest = (cli: MatrixClient): Promise<VerificationRequ
3938
});
4039
};
4140

42-
const handleVerificationRequest = (request: VerificationRequest): Chainable<EmojiMapping[]> => {
43-
return cy.wrap(
44-
new Promise<EmojiMapping[]>((resolve) => {
45-
const onShowSas = (event: ISasEvent) => {
46-
verifier.off("show_sas", onShowSas);
47-
event.confirm();
48-
resolve(event.sas.emoji);
49-
};
50-
51-
const verifier = request.beginKeyVerification("m.sas.v1");
52-
verifier.on("show_sas", onShowSas);
53-
verifier.verify();
54-
}),
55-
// extra timeout, as this sometimes takes a while
56-
{ timeout: 30_000 },
57-
);
58-
};
59-
6041
const checkTimelineNarrow = (button = true) => {
6142
cy.viewport(800, 600); // SVGA
6243
cy.get(".mx_LeftPanel_minimized").should("exist"); // Wait until the left panel is minimized
@@ -161,7 +142,11 @@ describe("Decryption Failure Bar", () => {
161142
);
162143
cy.wrap(verificationRequestPromise).then((verificationRequest: VerificationRequest) => {
163144
cy.wrap(verificationRequest.accept());
164-
handleVerificationRequest(verificationRequest).then((emojis) => {
145+
cy.wrap(
146+
handleVerificationRequest(verificationRequest),
147+
// extra timeout, as this sometimes takes a while
148+
{ timeout: 30_000 },
149+
).then((emojis: EmojiMapping[]) => {
165150
cy.get(".mx_VerificationShowSas_emojiSas_block").then((emojiBlocks) => {
166151
emojis.forEach((emoji: EmojiMapping, index: number) => {
167152
expect(emojiBlocks[index].textContent.toLowerCase()).to.eq(emoji[0] + emoji[1]);

cypress/e2e/crypto/utils.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,19 @@ export function waitForVerificationRequest(cli: MatrixClient): Promise<Verificat
3838
}
3939

4040
/**
41-
* Handle an incoming verification request
41+
* Automatically handle an incoming verification request
4242
*
4343
* Starts the key verification process, and, once it is accepted on the other side, confirms that the
4444
* emojis match.
4545
*
46-
* Returns a promise that resolves, with the emoji list, once we confirm the emojis
47-
*
4846
* @param request - incoming verification request
47+
* @returns A promise that resolves, with the emoji list, once we confirm the emojis
4948
*/
50-
export function handleVerificationRequest(request: VerificationRequest) {
49+
export function handleVerificationRequest(request: VerificationRequest): Promise<EmojiMapping[]> {
5150
return new Promise<EmojiMapping[]>((resolve) => {
5251
const onShowSas = (event: ISasEvent) => {
5352
verifier.off("show_sas", onShowSas);
5453
event.confirm();
55-
verifier.done();
5654
resolve(event.sas.emoji);
5755
};
5856

0 commit comments

Comments
 (0)