Add intercept of config.json (#10908)

* Add intercept of `config.json`

To help make sure that we run our tests against a known config, rather than
accidentally making requests to `matrix.org`.

* Remove now-redundant stubs of matrix.org files

Now that we intercept config.json, all this stuff is redundant.

* Reinstate fixture which is actually used

Turns out this is used after all

* Add a `map_style_url`

* disable failing axe check
This commit is contained in:
Richard van der Hoff 2023-05-16 13:15:20 +01:00 committed by GitHub
parent 0d981326ac
commit 81df8a3d2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 52 additions and 91 deletions

View file

@ -21,10 +21,6 @@ import { HomeserverInstance } from "../../plugins/utils/homeserver";
describe("Login", () => { describe("Login", () => {
let homeserver: HomeserverInstance; let homeserver: HomeserverInstance;
beforeEach(() => {
cy.stubDefaultServer();
});
afterEach(() => { afterEach(() => {
cy.stopHomeserver(homeserver); cy.stopHomeserver(homeserver);
}); });
@ -44,17 +40,18 @@ describe("Login", () => {
it("logs in with an existing account and lands on the home screen", () => { it("logs in with an existing account and lands on the home screen", () => {
cy.injectAxe(); cy.injectAxe();
cy.findByRole("textbox", { name: "Username", timeout: 15000 }).should("be.visible"); // first pick the homeserver, as otherwise the user picker won't be visible
// Disabled because flaky - see https://github.com/vector-im/element-web/issues/24688
//cy.percySnapshot("Login");
cy.checkA11y();
cy.findByRole("button", { name: "Edit" }).click(); cy.findByRole("button", { name: "Edit" }).click();
cy.findByRole("textbox", { name: "Other homeserver" }).type(homeserver.baseUrl); cy.findByRole("textbox", { name: "Other homeserver" }).type(homeserver.baseUrl);
cy.findByRole("button", { name: "Continue" }).click(); cy.findByRole("button", { name: "Continue" }).click();
// wait for the dialog to go away // wait for the dialog to go away
cy.get(".mx_ServerPickerDialog").should("not.exist"); cy.get(".mx_ServerPickerDialog").should("not.exist");
cy.findByRole("textbox", { name: "Username", timeout: 15000 }).should("be.visible");
// Disabled because flaky - see https://github.com/vector-im/element-web/issues/24688
//cy.percySnapshot("Login");
cy.checkA11y();
cy.findByRole("textbox", { name: "Username" }).type(username); cy.findByRole("textbox", { name: "Username" }).type(username);
cy.findByPlaceholderText("Password").type(password); cy.findByPlaceholderText("Password").type(password);
cy.findByRole("button", { name: "Sign in" }).click(); cy.findByRole("button", { name: "Sign in" }).click();

View file

@ -22,7 +22,6 @@ describe("Registration", () => {
let homeserver: HomeserverInstance; let homeserver: HomeserverInstance;
beforeEach(() => { beforeEach(() => {
cy.stubDefaultServer();
cy.visit("/#/register"); cy.visit("/#/register");
cy.startHomeserver("consent").then((data) => { cy.startHomeserver("consent").then((data) => {
homeserver = data; homeserver = data;

View file

@ -1,48 +0,0 @@
{
"flows": [
{
"type": "m.login.sso",
"identity_providers": [
{
"id": "oidc-github",
"name": "GitHub",
"icon": "mxc://matrix.org/sVesTtrFDTpXRbYfpahuJsKP",
"brand": "github"
},
{
"id": "oidc-google",
"name": "Google",
"icon": "mxc://matrix.org/ZlnaaZNPxtUuQemvgQzlOlkz",
"brand": "google"
},
{
"id": "oidc-gitlab",
"name": "GitLab",
"icon": "mxc://matrix.org/MCVOEmFgVieKFshPxmnejWOq",
"brand": "gitlab"
},
{
"id": "oidc-facebook",
"name": "Facebook",
"icon": "mxc://matrix.org/nsyeLIgzxazZmJadflMAsAWG",
"brand": "facebook"
},
{
"id": "oidc-apple",
"name": "Apple",
"icon": "mxc://matrix.org/QQKNSOdLiMHtJhzeAObmkFiU",
"brand": "apple"
}
]
},
{
"type": "m.login.token"
},
{
"type": "m.login.password"
},
{
"type": "m.login.application_service"
}
]
}

View file

@ -1,8 +0,0 @@
{
"m.homeserver": {
"base_url": "https://matrix-client.matrix.org"
},
"m.identity_server": {
"base_url": "https://vector.im"
}
}

View file

@ -1 +0,0 @@
{}

View file

@ -59,6 +59,10 @@ Cypress.Commands.overwrite(
"color-contrast": { "color-contrast": {
enabled: false, enabled: false,
}, },
// link-in-text-block also complains due to known contrast issues
"link-in-text-block": {
enabled: false,
},
...options.rules, ...options.rules,
}, },
}, },

View file

@ -0,0 +1,41 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* Intercept requests to `config.json`, so that we can test against a known configuration.
*
* If we don't do this, we end up testing against the Element config for develop.element.io, which then means
* we make requests to the live `matrix.org`, which makes our tests dependent on matrix.org being up and responsive.
*/
const CONFIG_JSON = {
// This is deliberately quite a minimal config.json, so that we can test that the default settings
// actually work.
//
// The only thing that we really *need* (otherwise Element refuses to load) is a default homeserver.
// We point that to a guaranteed-invalid domain.
default_server_config: {
"m.homeserver": {
base_url: "https://server.invalid",
},
},
// the location tests want a map style url.
map_style_url: "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx",
};
beforeEach(() => {
cy.intercept({ method: "GET", pathname: "/config.json" }, { body: CONFIG_JSON });
});

View file

@ -20,6 +20,7 @@ import "@percy/cypress";
import "cypress-real-events"; import "cypress-real-events";
import "@testing-library/cypress/add-commands"; import "@testing-library/cypress/add-commands";
import "./config.json";
import "./homeserver"; import "./homeserver";
import "./login"; import "./login";
import "./labs"; import "./labs";

View file

@ -68,29 +68,5 @@ Cypress.Commands.add("goOnline", (): void => {
}); });
}); });
Cypress.Commands.add("stubDefaultServer", (): void => {
cy.log("Stubbing vector.im and matrix.org network calls");
// We intercept vector.im & matrix.org calls so that tests don't fail when it has issues
cy.intercept("GET", "https://vector.im/_matrix/identity/v2", {
fixture: "vector-im-identity-v2.json",
});
cy.intercept("GET", "https://matrix.org/.well-known/matrix/client", {
fixture: "matrix-org-client-well-known.json",
});
cy.intercept("GET", "https://matrix-client.matrix.org/_matrix/client/versions", {
fixture: "matrix-org-client-versions.json",
});
cy.intercept("GET", "https://matrix-client.matrix.org/_matrix/client/r0/login", {
fixture: "matrix-org-client-login.json",
});
cy.intercept("POST", "https://matrix-client.matrix.org/_matrix/client/r0/register?kind=guest", {
statusCode: 403,
body: {
errcode: "M_FORBIDDEN",
error: "Registration is not enabled on this homeserver.",
},
});
});
// Needed to make this file a module // Needed to make this file a module
export {}; export {};