From 838064b219ea59634b8ed9c0c375845580ba7a79 Mon Sep 17 00:00:00 2001 From: Mikhail Aheichyk Date: Thu, 26 Oct 2023 15:56:20 +0300 Subject: [PATCH] Add e2e tests for knocking into public knock rooms Signed-off-by: Mikhail Aheichyk --- cypress/e2e/knock/create-knock-room.spec.ts | 38 +++++++++- cypress/e2e/knock/knock-into-room.spec.ts | 22 +++++- cypress/e2e/spotlight/spotlight.spec.ts | 76 +------------------- cypress/e2e/utils.ts | 5 ++ cypress/support/settings.ts | 80 +++++++++++++++++++++ 5 files changed, 143 insertions(+), 78 deletions(-) diff --git a/cypress/e2e/knock/create-knock-room.spec.ts b/cypress/e2e/knock/create-knock-room.spec.ts index 631d78b15de3..b7070bf437f9 100644 --- a/cypress/e2e/knock/create-knock-room.spec.ts +++ b/cypress/e2e/knock/create-knock-room.spec.ts @@ -19,7 +19,7 @@ limitations under the License. import { JoinRule } from "matrix-js-sdk/src/matrix"; import { HomeserverInstance } from "../../plugins/utils/homeserver"; -import { waitForRoom } from "../utils"; +import { waitForRoom, Filter } from "../utils"; describe("Create Knock Room", () => { let homeserver: HomeserverInstance; @@ -98,4 +98,40 @@ describe("Create Knock Room", () => { }); }); }); + + it("should create a public knock room", () => { + cy.openCreateRoomDialog().within(() => { + cy.findByRole("textbox", { name: "Name" }).type("Cybersecurity"); + cy.findByRole("button", { name: "Room visibility" }).click(); + cy.findByRole("option", { name: "Ask to join" }).click(); + cy.findByRole("checkbox", { name: "Make this room visible in the public room directory." }).click({ + force: true, + }); + + cy.findByRole("button", { name: "Create room" }).click(); + }); + + cy.get(".mx_LegacyRoomHeader").within(() => { + cy.findByText("Cybersecurity"); + }); + + cy.hash().then((urlHash) => { + const roomId = urlHash.replace("#/room/", ""); + + // Room should have a knock join rule + cy.window().then(async (win) => { + await waitForRoom(win, win.mxMatrixClientPeg.get(), roomId, (room) => { + const events = room.getLiveTimeline().getEvents(); + return events.some( + (e) => e.getType() === "m.room.join_rules" && e.getContent().join_rule === JoinRule.Knock, + ); + }); + }); + }); + + cy.openSpotlightDialog().within(() => { + cy.spotlightFilter(Filter.PublicRooms); + cy.spotlightResults().eq(0).should("contain", "Cybersecurity"); + }); + }); }); diff --git a/cypress/e2e/knock/knock-into-room.spec.ts b/cypress/e2e/knock/knock-into-room.spec.ts index d9ab8ff1f388..0680e45525d1 100644 --- a/cypress/e2e/knock/knock-into-room.spec.ts +++ b/cypress/e2e/knock/knock-into-room.spec.ts @@ -15,11 +15,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { MatrixClient } from "matrix-js-sdk/src/matrix"; +import { MatrixClient, Visibility } from "matrix-js-sdk/src/matrix"; import { HomeserverInstance } from "../../plugins/utils/homeserver"; import { UserCredentials } from "../../support/login"; -import { waitForRoom } from "../utils"; +import { waitForRoom, Filter } from "../utils"; describe("Knock Into Room", () => { let homeserver: HomeserverInstance; @@ -176,4 +176,22 @@ describe("Knock Into Room", () => { // Room should disappear from the list completely when forgotten cy.findByRole("treeitem", { name: /Cybersecurity/ }).should("not.exist"); }); + + it("should knock into the public knock room via spotlight", () => { + bot.setRoomDirectoryVisibility(roomId, Visibility.Public); + + cy.openSpotlightDialog().within(() => { + cy.spotlightFilter(Filter.PublicRooms); + cy.spotlightResults().eq(0).should("contain", "Cybersecurity"); + cy.spotlightResults().eq(0).click(); + }); + + cy.get(".mx_RoomPreviewBar").within(() => { + cy.findByRole("heading", { name: "Ask to join?" }); + cy.findByRole("textbox"); + cy.findByRole("button", { name: "Request access" }).click(); + + cy.findByRole("heading", { name: "Request to join sent" }); + }); + }); }); diff --git a/cypress/e2e/spotlight/spotlight.spec.ts b/cypress/e2e/spotlight/spotlight.spec.ts index ee5532282f6e..b6a8a3887986 100644 --- a/cypress/e2e/spotlight/spotlight.spec.ts +++ b/cypress/e2e/spotlight/spotlight.spec.ts @@ -23,35 +23,12 @@ import Loggable = Cypress.Loggable; import Timeoutable = Cypress.Timeoutable; import Withinable = Cypress.Withinable; import Shadow = Cypress.Shadow; - -enum Filter { - People = "people", - PublicRooms = "public_rooms", -} +import { Filter } from "../utils"; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Cypress { interface Chainable { - /** - * Opens the spotlight dialog - */ - openSpotlightDialog( - options?: Partial, - ): Chainable>; - spotlightDialog( - options?: Partial, - ): Chainable>; - spotlightFilter( - filter: Filter | null, - options?: Partial, - ): Chainable>; - spotlightSearch( - options?: Partial, - ): Chainable>; - spotlightResults( - options?: Partial, - ): Chainable>; roomHeaderName( options?: Partial, ): Chainable>; @@ -60,57 +37,6 @@ declare global { } } -Cypress.Commands.add( - "openSpotlightDialog", - (options?: Partial): Chainable> => { - cy.get(".mx_RoomSearch_spotlightTrigger", options).click({ force: true }); - return cy.spotlightDialog(options); - }, -); - -Cypress.Commands.add( - "spotlightDialog", - (options?: Partial): Chainable> => { - return cy.get('[role=dialog][aria-label="Search Dialog"]', options); - }, -); - -Cypress.Commands.add( - "spotlightFilter", - ( - filter: Filter | null, - options?: Partial, - ): Chainable> => { - let selector: string; - switch (filter) { - case Filter.People: - selector = "#mx_SpotlightDialog_button_startChat"; - break; - case Filter.PublicRooms: - selector = "#mx_SpotlightDialog_button_explorePublicRooms"; - break; - default: - selector = ".mx_SpotlightDialog_filter"; - break; - } - return cy.get(selector, options).click(); - }, -); - -Cypress.Commands.add( - "spotlightSearch", - (options?: Partial): Chainable> => { - return cy.get(".mx_SpotlightDialog_searchBox", options).findByRole("textbox", { name: "Search" }); - }, -); - -Cypress.Commands.add( - "spotlightResults", - (options?: Partial): Chainable> => { - return cy.get(".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option", options); - }, -); - Cypress.Commands.add( "roomHeaderName", (options?: Partial): Chainable> => { diff --git a/cypress/e2e/utils.ts b/cypress/e2e/utils.ts index 24485d6e4646..7e74723a9858 100644 --- a/cypress/e2e/utils.ts +++ b/cypress/e2e/utils.ts @@ -17,6 +17,11 @@ limitations under the License. import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; +export enum Filter { + People = "people", + PublicRooms = "public_rooms", +} + export function waitForRoom( win: Cypress.AUTWindow, matrixClient: MatrixClient, diff --git a/cypress/support/settings.ts b/cypress/support/settings.ts index d86a1649455f..93ac20c47b81 100644 --- a/cypress/support/settings.ts +++ b/cypress/support/settings.ts @@ -17,9 +17,18 @@ limitations under the License. /// import Chainable = Cypress.Chainable; +import Loggable = Cypress.Loggable; +import Timeoutable = Cypress.Timeoutable; +import Withinable = Cypress.Withinable; +import Shadow = Cypress.Shadow; import type { SettingLevel } from "../../src/settings/SettingLevel"; import type SettingsStore from "../../src/settings/SettingsStore"; +enum Filter { + People = "people", + PublicRooms = "public_rooms", +} + declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Cypress { @@ -102,6 +111,26 @@ declare global { * @return {*} The value, or null if not found */ getSettingValue(settingName: string, roomId?: string, excludeDefault?: boolean): Chainable; + + /** + * Opens the spotlight dialog + */ + openSpotlightDialog( + options?: Partial, + ): Chainable>; + spotlightDialog( + options?: Partial, + ): Chainable>; + spotlightFilter( + filter: Filter | null, + options?: Partial, + ): Chainable>; + spotlightSearch( + options?: Partial, + ): Chainable>; + spotlightResults( + options?: Partial, + ): Chainable>; } } } @@ -191,5 +220,56 @@ Cypress.Commands.add("leaveBeta", (name: string): Chainable> }); }); +Cypress.Commands.add( + "openSpotlightDialog", + (options?: Partial): Chainable> => { + cy.get(".mx_RoomSearch_spotlightTrigger", options).click({ force: true }); + return cy.spotlightDialog(options); + }, +); + +Cypress.Commands.add( + "spotlightDialog", + (options?: Partial): Chainable> => { + return cy.get('[role=dialog][aria-label="Search Dialog"]', options); + }, +); + +Cypress.Commands.add( + "spotlightFilter", + ( + filter: Filter | null, + options?: Partial, + ): Chainable> => { + let selector: string; + switch (filter) { + case Filter.People: + selector = "#mx_SpotlightDialog_button_startChat"; + break; + case Filter.PublicRooms: + selector = "#mx_SpotlightDialog_button_explorePublicRooms"; + break; + default: + selector = ".mx_SpotlightDialog_filter"; + break; + } + return cy.get(selector, options).click(); + }, +); + +Cypress.Commands.add( + "spotlightSearch", + (options?: Partial): Chainable> => { + return cy.get(".mx_SpotlightDialog_searchBox", options).findByRole("textbox", { name: "Search" }); + }, +); + +Cypress.Commands.add( + "spotlightResults", + (options?: Partial): Chainable> => { + return cy.get(".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option", options); + }, +); + // Needed to make this file a module export {};