Skip to content

Commit 6e73b90

Browse files
chore : fix cypress login test, to work with cross-signing (locally) (#660)
* Fix cypress login test, to work with cross-signing * Linter fix * Update to the latest version of axe.ts
1 parent 80f5cd6 commit 6e73b90

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

cypress/e2e/login/login.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe("Login", () => {
4141
// Will be replaced by a generated random user when we have a full docker setup
4242
const username = Cypress.env("E2E_TEST_USER_EMAIL");
4343
const password = Cypress.env("E2E_TEST_USER_PASSWORD");
44+
const securityKey = Cypress.env("E2E_TEST_USER_SECURITY_KEY");
4445

4546
beforeEach(() => {
4647
// We use a pre-existing user on dev backend. If random user was created each time, we would use :
@@ -57,12 +58,20 @@ describe("Login", () => {
5758

5859
cy.get("#mx_LoginForm_email").type(username);
5960
cy.get("#mx_LoginForm_password").type(password);
60-
cy.startMeasuring("from-submit-to-home");
6161
cy.get(".mx_Login_submit").click();
6262

63-
//TODO: does not work if account has cross signing because the screen is /#/login "Vérifier cet appareil"
63+
// Enter security key
64+
cy.get(".mx_CompleteSecurityBody .mx_AccessibleButton")
65+
.contains("Vérifier avec un Code de Récupération")
66+
.click();
67+
cy.get("#mx_securityKey").type(securityKey);
68+
cy.get(".mx_AccessSecretStorageDialog .mx_Dialog_primary").click();
69+
70+
// Success page displays. Click to continue.
71+
cy.get(".mx_E2EIcon_verified"); // check for presence of success icon
72+
cy.get(".mx_CompleteSecurityBody .mx_AccessibleButton_kind_primary").click();
73+
6474
cy.url().should("contain", "/#/home");
65-
cy.stopMeasuring("from-submit-to-home");
6675
});
6776
});
6877
});

cypress/support/axe.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
/*
2-
Copyright 2022 The Matrix.org Foundation C.I.C.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
2+
copied from matrix-react-sdk/cypress/support/axe.ts
153
*/
164

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

197
import "cypress-axe";
208
import * as axe from "axe-core";
21-
import { Options } from "cypress-axe";
229

10+
import type { Options } from "cypress-axe";
2311
import Chainable = Cypress.Chainable;
2412

2513
function terminalLog(violations: axe.Result[]): void {
@@ -67,3 +55,35 @@ Cypress.Commands.overwrite(
6755
);
6856
},
6957
);
58+
59+
// Load axe-core into the window under test.
60+
//
61+
// The injectAxe in cypress-axe attempts to load axe via an `eval`. That conflicts with our CSP
62+
// which disallows "unsafe-eval". So, replace it with an implementation that loads it via an
63+
// injected <script> element.
64+
Cypress.Commands.overwrite("injectAxe", (originalFn: Chainable["injectAxe"]): void => {
65+
Cypress.log({ name: "injectAxe" });
66+
67+
// load the minified axe source, and create an intercept to serve it up
68+
cy.readFile("node_modules/axe-core/axe.min.js", { log: false }).then((source) => {
69+
cy.intercept("/_axe", source);
70+
});
71+
72+
// inject a script tag to load it
73+
cy.get("head", { log: false }).then(
74+
(head) =>
75+
new Promise((resolve, reject) => {
76+
const script = document.createElement("script");
77+
script.type = "text/javascript";
78+
script.async = true;
79+
script.onload = resolve;
80+
script.onerror = (_e) => {
81+
// Unfortunately there does not seem to be a way to get a reason for the error.
82+
// The error event is useless.
83+
reject(new Error("Unable to load axe"));
84+
};
85+
script.src = "/_axe";
86+
head.get()[0].appendChild(script);
87+
}),
88+
);
89+
});

0 commit comments

Comments
 (0)