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

Commit ad4d3f9

Browse files
authored
Move threads e2e tests over to cypress (#8501)
* Add non-consent (default) Synapse template * Add consent test * Add create room test * Stash work * Initial threads tests * fix * Delete old threads e2e tests, plan new ones * Fix typed s'more * Try something else * specify d.ts * Fix types once and for all? * Fix the consent tests * Iterate threads test harness * Fix dispatcher types * Iterate threads test * fix typing * Alternative import attempt * let it break let it break let it break * Tweak types * Stash * delint and update docs * null-guard scrollIntoView * Iterate threads test * Apply suggestions from code review
1 parent 14127c7 commit ad4d3f9

File tree

27 files changed

+810
-288
lines changed

27 files changed

+810
-288
lines changed

cypress.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"baseUrl": "http://localhost:8080",
33
"videoUploadOnPasses": false,
4-
"projectId": "ppvnzg"
4+
"projectId": "ppvnzg",
5+
"experimentalSessionAndOrigin": true,
6+
"experimentalInteractiveRunEvents": true
57
}

cypress/global.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
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.
15+
*/
16+
17+
import "matrix-js-sdk/src/@types/global";
18+
import type { MatrixClient, ClientEvent } from "matrix-js-sdk/src/client";
19+
import type { RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
20+
import type { MatrixDispatcher } from "../src/dispatcher/dispatcher";
21+
22+
declare global {
23+
// eslint-disable-next-line @typescript-eslint/no-namespace
24+
namespace Cypress {
25+
interface ApplicationWindow {
26+
mxMatrixClientPeg: {
27+
matrixClient?: MatrixClient;
28+
};
29+
mxDispatcher: MatrixDispatcher;
30+
beforeReload?: boolean; // for detecting reloads
31+
// Partial type for the matrix-js-sdk module, exported by browser-matrix
32+
matrixcs: {
33+
MatrixClient: typeof MatrixClient;
34+
ClientEvent: typeof ClientEvent;
35+
RoomMemberEvent: typeof RoomMemberEvent;
36+
};
37+
}
38+
}
39+
40+
interface Window {
41+
mxDispatcher: MatrixDispatcher; // to appease the MatrixDispatcher import
42+
}
43+
}
44+
45+
export { MatrixClient };
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
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.
15+
*/
16+
17+
/// <reference types="cypress" />
18+
19+
import { SinonStub } from "cypress/types/sinon";
20+
21+
import { SynapseInstance } from "../../plugins/synapsedocker";
22+
23+
describe("Consent", () => {
24+
let synapse: SynapseInstance;
25+
26+
beforeEach(() => {
27+
cy.startSynapse("consent").then(data => {
28+
synapse = data;
29+
30+
cy.initTestUser(synapse, "Bob");
31+
});
32+
});
33+
34+
afterEach(() => {
35+
cy.stopSynapse(synapse);
36+
});
37+
38+
it("should prompt the user to consent to terms when server deems it necessary", () => {
39+
// Attempt to create a room using the js-sdk which should return an error with `M_CONSENT_NOT_GIVEN`
40+
cy.window().then(win => {
41+
win.mxMatrixClientPeg.matrixClient.createRoom({}).catch(() => {});
42+
43+
// Stub `window.open` - clicking the primary button below will call it
44+
cy.stub(win, "open").as("windowOpen").returns({});
45+
});
46+
47+
// Accept terms & conditions
48+
cy.get(".mx_QuestionDialog").within(() => {
49+
cy.get("#mx_BaseDialog_title").contains("Terms and Conditions");
50+
cy.get(".mx_Dialog_primary").click();
51+
});
52+
53+
cy.get<SinonStub>("@windowOpen").then(stub => {
54+
const url = stub.getCall(0).args[0];
55+
56+
// Go to Synapse's consent page and accept it
57+
cy.origin(synapse.baseUrl, { args: { url } }, ({ url }) => {
58+
cy.visit(url);
59+
60+
cy.get('[type="submit"]').click();
61+
cy.get("p").contains("Danke schon");
62+
});
63+
});
64+
65+
// go back to the app
66+
cy.visit("/");
67+
// wait for the app to re-load
68+
cy.get(".mx_MatrixChat", { timeout: 15000 });
69+
70+
// attempt to perform the same action again and expect it to not fail
71+
cy.createRoom({});
72+
});
73+
});

cypress/integration/3-user-menu/user-menu.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ limitations under the License.
1919
import { SynapseInstance } from "../../plugins/synapsedocker";
2020
import type { UserCredentials } from "../../support/login";
2121

22-
describe("UserMenu", () => {
22+
describe("User Menu", () => {
2323
let synapse: SynapseInstance;
2424
let user: UserCredentials;
2525

2626
beforeEach(() => {
27-
cy.startSynapse("consent").then(data => {
27+
cy.startSynapse("default").then(data => {
2828
synapse = data;
2929

3030
cy.initTestUser(synapse, "Jeff").then(credentials => {
@@ -38,8 +38,10 @@ describe("UserMenu", () => {
3838
});
3939

4040
it("should contain our name & userId", () => {
41-
cy.get('[aria-label="User menu"]', { timeout: 15000 }).click();
42-
cy.get(".mx_UserMenu_contextMenu_displayName").should("contain", "Jeff");
43-
cy.get(".mx_UserMenu_contextMenu_userId").should("contain", user.userId);
41+
cy.get('[aria-label="User menu"]').click();
42+
cy.get(".mx_ContextualMenu").within(() => {
43+
cy.get(".mx_UserMenu_contextMenu_displayName").should("contain", "Jeff");
44+
cy.get(".mx_UserMenu_contextMenu_userId").should("contain", user.userId);
45+
});
4446
});
4547
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
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.
15+
*/
16+
17+
/// <reference types="cypress" />
18+
19+
import { SynapseInstance } from "../../plugins/synapsedocker";
20+
import Chainable = Cypress.Chainable;
21+
22+
function openCreateRoomDialog(): Chainable<JQuery<HTMLElement>> {
23+
cy.get('[aria-label="Add room"]').click();
24+
cy.get('.mx_ContextualMenu [aria-label="New room"]').click();
25+
return cy.get(".mx_CreateRoomDialog");
26+
}
27+
28+
describe("Create Room", () => {
29+
let synapse: SynapseInstance;
30+
31+
beforeEach(() => {
32+
cy.startSynapse("default").then(data => {
33+
synapse = data;
34+
35+
cy.initTestUser(synapse, "Jim");
36+
});
37+
});
38+
39+
afterEach(() => {
40+
cy.stopSynapse(synapse);
41+
});
42+
43+
it("should allow us to create a public room with name, topic & address set", () => {
44+
const name = "Test room 1";
45+
const topic = "This room is dedicated to this test and this test only!";
46+
47+
openCreateRoomDialog().within(() => {
48+
// Fill name & topic
49+
cy.get('[label="Name"]').type(name);
50+
cy.get('[label="Topic (optional)"]').type(topic);
51+
// Change room to public
52+
cy.get('[aria-label="Room visibility"]').click();
53+
cy.get("#mx_JoinRuleDropdown__public").click();
54+
// Fill room address
55+
cy.get('[label="Room address"]').type("test-room-1");
56+
// Submit
57+
cy.get(".mx_Dialog_primary").click();
58+
});
59+
60+
cy.url().should("contain", "/#/room/#test-room-1:localhost");
61+
cy.get(".mx_RoomHeader_nametext").contains(name);
62+
cy.get(".mx_RoomHeader_topic").contains(topic);
63+
});
64+
});

0 commit comments

Comments
 (0)