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

Commit 890fbaf

Browse files
author
Mikhail Aheichyk
committed
Add e2e tests for knocking into public knock rooms
Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
1 parent e09f190 commit 890fbaf

File tree

4 files changed

+138
-76
lines changed

4 files changed

+138
-76
lines changed

cypress/e2e/knock/create-knock-room.spec.ts

+37
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { JoinRule } from "matrix-js-sdk/src/matrix";
2020

2121
import { HomeserverInstance } from "../../plugins/utils/homeserver";
2222
import { waitForRoom } from "../utils";
23+
import { Filter } from "../../support/settings";
2324

2425
describe("Create Knock Room", () => {
2526
let homeserver: HomeserverInstance;
@@ -98,4 +99,40 @@ describe("Create Knock Room", () => {
9899
});
99100
});
100101
});
102+
103+
it("should create a public knock room", () => {
104+
cy.openCreateRoomDialog().within(() => {
105+
cy.findByRole("textbox", { name: "Name" }).type("Cybersecurity");
106+
cy.findByRole("button", { name: "Room visibility" }).click();
107+
cy.findByRole("option", { name: "Ask to join" }).click();
108+
cy.findByRole("checkbox", { name: "Make this room visible in the public room directory." }).click({
109+
force: true,
110+
});
111+
112+
cy.findByRole("button", { name: "Create room" }).click();
113+
});
114+
115+
cy.get(".mx_LegacyRoomHeader").within(() => {
116+
cy.findByText("Cybersecurity");
117+
});
118+
119+
cy.hash().then((urlHash) => {
120+
const roomId = urlHash.replace("#/room/", "");
121+
122+
// Room should have a knock join rule
123+
cy.window().then(async (win) => {
124+
await waitForRoom(win, win.mxMatrixClientPeg.get(), roomId, (room) => {
125+
const events = room.getLiveTimeline().getEvents();
126+
return events.some(
127+
(e) => e.getType() === "m.room.join_rules" && e.getContent().join_rule === JoinRule.Knock,
128+
);
129+
});
130+
});
131+
});
132+
133+
cy.openSpotlightDialog().within(() => {
134+
cy.spotlightFilter(Filter.PublicRooms);
135+
cy.spotlightResults().eq(0).should("contain", "Cybersecurity");
136+
});
137+
});
101138
});

cypress/e2e/knock/knock-into-room.spec.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18-
import { MatrixClient } from "matrix-js-sdk/src/matrix";
18+
import { MatrixClient, Visibility } from "matrix-js-sdk/src/matrix";
1919

2020
import { HomeserverInstance } from "../../plugins/utils/homeserver";
2121
import { UserCredentials } from "../../support/login";
2222
import { waitForRoom } from "../utils";
23+
import { Filter } from "../../support/settings";
2324

2425
describe("Knock Into Room", () => {
2526
let homeserver: HomeserverInstance;
@@ -176,4 +177,22 @@ describe("Knock Into Room", () => {
176177
// Room should disappear from the list completely when forgotten
177178
cy.findByRole("treeitem", { name: /Cybersecurity/ }).should("not.exist");
178179
});
180+
181+
it("should knock into the public knock room via spotlight", () => {
182+
bot.setRoomDirectoryVisibility(roomId, Visibility.Public);
183+
184+
cy.openSpotlightDialog().within(() => {
185+
cy.spotlightFilter(Filter.PublicRooms);
186+
cy.spotlightResults().eq(0).should("contain", "Cybersecurity");
187+
cy.spotlightResults().eq(0).click();
188+
});
189+
190+
cy.get(".mx_RoomPreviewBar").within(() => {
191+
cy.findByRole("heading", { name: "Ask to join?" });
192+
cy.findByRole("textbox");
193+
cy.findByRole("button", { name: "Request access" }).click();
194+
195+
cy.findByRole("heading", { name: "Request to join sent" });
196+
});
197+
});
179198
});

cypress/e2e/spotlight/spotlight.spec.ts

+1-75
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,12 @@ import Loggable = Cypress.Loggable;
2323
import Timeoutable = Cypress.Timeoutable;
2424
import Withinable = Cypress.Withinable;
2525
import Shadow = Cypress.Shadow;
26-
27-
enum Filter {
28-
People = "people",
29-
PublicRooms = "public_rooms",
30-
}
26+
import { Filter } from "../../support/settings";
3127

3228
declare global {
3329
// eslint-disable-next-line @typescript-eslint/no-namespace
3430
namespace Cypress {
3531
interface Chainable {
36-
/**
37-
* Opens the spotlight dialog
38-
*/
39-
openSpotlightDialog(
40-
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
41-
): Chainable<JQuery<HTMLElement>>;
42-
spotlightDialog(
43-
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
44-
): Chainable<JQuery<HTMLElement>>;
45-
spotlightFilter(
46-
filter: Filter | null,
47-
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
48-
): Chainable<JQuery<HTMLElement>>;
49-
spotlightSearch(
50-
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
51-
): Chainable<JQuery<HTMLElement>>;
52-
spotlightResults(
53-
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
54-
): Chainable<JQuery<HTMLElement>>;
5532
roomHeaderName(
5633
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
5734
): Chainable<JQuery<HTMLElement>>;
@@ -60,57 +37,6 @@ declare global {
6037
}
6138
}
6239

63-
Cypress.Commands.add(
64-
"openSpotlightDialog",
65-
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
66-
cy.get(".mx_RoomSearch_spotlightTrigger", options).click({ force: true });
67-
return cy.spotlightDialog(options);
68-
},
69-
);
70-
71-
Cypress.Commands.add(
72-
"spotlightDialog",
73-
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
74-
return cy.get('[role=dialog][aria-label="Search Dialog"]', options);
75-
},
76-
);
77-
78-
Cypress.Commands.add(
79-
"spotlightFilter",
80-
(
81-
filter: Filter | null,
82-
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
83-
): Chainable<JQuery<HTMLElement>> => {
84-
let selector: string;
85-
switch (filter) {
86-
case Filter.People:
87-
selector = "#mx_SpotlightDialog_button_startChat";
88-
break;
89-
case Filter.PublicRooms:
90-
selector = "#mx_SpotlightDialog_button_explorePublicRooms";
91-
break;
92-
default:
93-
selector = ".mx_SpotlightDialog_filter";
94-
break;
95-
}
96-
return cy.get(selector, options).click();
97-
},
98-
);
99-
100-
Cypress.Commands.add(
101-
"spotlightSearch",
102-
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
103-
return cy.get(".mx_SpotlightDialog_searchBox", options).findByRole("textbox", { name: "Search" });
104-
},
105-
);
106-
107-
Cypress.Commands.add(
108-
"spotlightResults",
109-
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
110-
return cy.get(".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option", options);
111-
},
112-
);
113-
11440
Cypress.Commands.add(
11541
"roomHeaderName",
11642
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {

cypress/support/settings.ts

+80
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@ limitations under the License.
1717
/// <reference types="cypress" />
1818

1919
import Chainable = Cypress.Chainable;
20+
import Loggable = Cypress.Loggable;
21+
import Timeoutable = Cypress.Timeoutable;
22+
import Withinable = Cypress.Withinable;
23+
import Shadow = Cypress.Shadow;
2024
import type { SettingLevel } from "../../src/settings/SettingLevel";
2125
import type SettingsStore from "../../src/settings/SettingsStore";
2226

27+
export enum Filter {
28+
People = "people",
29+
PublicRooms = "public_rooms",
30+
}
31+
2332
declare global {
2433
// eslint-disable-next-line @typescript-eslint/no-namespace
2534
namespace Cypress {
@@ -102,6 +111,26 @@ declare global {
102111
* @return {*} The value, or null if not found
103112
*/
104113
getSettingValue<T>(settingName: string, roomId?: string, excludeDefault?: boolean): Chainable<T>;
114+
115+
/**
116+
* Opens the spotlight dialog
117+
*/
118+
openSpotlightDialog(
119+
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
120+
): Chainable<JQuery<HTMLElement>>;
121+
spotlightDialog(
122+
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
123+
): Chainable<JQuery<HTMLElement>>;
124+
spotlightFilter(
125+
filter: Filter | null,
126+
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
127+
): Chainable<JQuery<HTMLElement>>;
128+
spotlightSearch(
129+
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
130+
): Chainable<JQuery<HTMLElement>>;
131+
spotlightResults(
132+
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
133+
): Chainable<JQuery<HTMLElement>>;
105134
}
106135
}
107136
}
@@ -191,5 +220,56 @@ Cypress.Commands.add("leaveBeta", (name: string): Chainable<JQuery<HTMLElement>>
191220
});
192221
});
193222

223+
Cypress.Commands.add(
224+
"openSpotlightDialog",
225+
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
226+
cy.get(".mx_RoomSearch_spotlightTrigger", options).click({ force: true });
227+
return cy.spotlightDialog(options);
228+
},
229+
);
230+
231+
Cypress.Commands.add(
232+
"spotlightDialog",
233+
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
234+
return cy.get('[role=dialog][aria-label="Search Dialog"]', options);
235+
},
236+
);
237+
238+
Cypress.Commands.add(
239+
"spotlightFilter",
240+
(
241+
filter: Filter | null,
242+
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
243+
): Chainable<JQuery<HTMLElement>> => {
244+
let selector: string;
245+
switch (filter) {
246+
case Filter.People:
247+
selector = "#mx_SpotlightDialog_button_startChat";
248+
break;
249+
case Filter.PublicRooms:
250+
selector = "#mx_SpotlightDialog_button_explorePublicRooms";
251+
break;
252+
default:
253+
selector = ".mx_SpotlightDialog_filter";
254+
break;
255+
}
256+
return cy.get(selector, options).click();
257+
},
258+
);
259+
260+
Cypress.Commands.add(
261+
"spotlightSearch",
262+
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
263+
return cy.get(".mx_SpotlightDialog_searchBox", options).findByRole("textbox", { name: "Search" });
264+
},
265+
);
266+
267+
Cypress.Commands.add(
268+
"spotlightResults",
269+
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
270+
return cy.get(".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option", options);
271+
},
272+
);
273+
194274
// Needed to make this file a module
195275
export {};

0 commit comments

Comments
 (0)