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

Commit

Permalink
Add e2e tests for knocking into public knock rooms
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Aheichyk <[email protected]>
  • Loading branch information
Mikhail Aheichyk committed Oct 26, 2023
1 parent e09f190 commit 890fbaf
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 76 deletions.
37 changes: 37 additions & 0 deletions cypress/e2e/knock/create-knock-room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { JoinRule } from "matrix-js-sdk/src/matrix";

import { HomeserverInstance } from "../../plugins/utils/homeserver";
import { waitForRoom } from "../utils";
import { Filter } from "../../support/settings";

describe("Create Knock Room", () => {
let homeserver: HomeserverInstance;
Expand Down Expand Up @@ -98,4 +99,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");
});
});
});
21 changes: 20 additions & 1 deletion cypress/e2e/knock/knock-into-room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ 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 { Filter } from "../../support/settings";

describe("Knock Into Room", () => {
let homeserver: HomeserverInstance;
Expand Down Expand Up @@ -176,4 +177,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" });
});
});
});
76 changes: 1 addition & 75 deletions cypress/e2e/spotlight/spotlight.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "../../support/settings";

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
/**
* Opens the spotlight dialog
*/
openSpotlightDialog(
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
spotlightDialog(
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
spotlightFilter(
filter: Filter | null,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
spotlightSearch(
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
spotlightResults(
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
roomHeaderName(
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
Expand All @@ -60,57 +37,6 @@ declare global {
}
}

Cypress.Commands.add(
"openSpotlightDialog",
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
cy.get(".mx_RoomSearch_spotlightTrigger", options).click({ force: true });
return cy.spotlightDialog(options);
},
);

Cypress.Commands.add(
"spotlightDialog",
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
return cy.get('[role=dialog][aria-label="Search Dialog"]', options);
},
);

Cypress.Commands.add(
"spotlightFilter",
(
filter: Filter | null,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>> => {
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<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
return cy.get(".mx_SpotlightDialog_searchBox", options).findByRole("textbox", { name: "Search" });
},
);

Cypress.Commands.add(
"spotlightResults",
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
return cy.get(".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option", options);
},
);

Cypress.Commands.add(
"roomHeaderName",
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
Expand Down
80 changes: 80 additions & 0 deletions cypress/support/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ limitations under the License.
/// <reference types="cypress" />

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";

export enum Filter {
People = "people",
PublicRooms = "public_rooms",
}

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
Expand Down Expand Up @@ -102,6 +111,26 @@ declare global {
* @return {*} The value, or null if not found
*/
getSettingValue<T>(settingName: string, roomId?: string, excludeDefault?: boolean): Chainable<T>;

/**
* Opens the spotlight dialog
*/
openSpotlightDialog(
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
spotlightDialog(
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
spotlightFilter(
filter: Filter | null,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
spotlightSearch(
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
spotlightResults(
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
}
}
}
Expand Down Expand Up @@ -191,5 +220,56 @@ Cypress.Commands.add("leaveBeta", (name: string): Chainable<JQuery<HTMLElement>>
});
});

Cypress.Commands.add(
"openSpotlightDialog",
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
cy.get(".mx_RoomSearch_spotlightTrigger", options).click({ force: true });
return cy.spotlightDialog(options);
},
);

Cypress.Commands.add(
"spotlightDialog",
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
return cy.get('[role=dialog][aria-label="Search Dialog"]', options);
},
);

Cypress.Commands.add(
"spotlightFilter",
(
filter: Filter | null,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>> => {
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<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
return cy.get(".mx_SpotlightDialog_searchBox", options).findByRole("textbox", { name: "Search" });
},
);

Cypress.Commands.add(
"spotlightResults",
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
return cy.get(".mx_SpotlightDialog_section.mx_SpotlightDialog_results .mx_SpotlightDialog_option", options);
},
);

// Needed to make this file a module
export {};

0 comments on commit 890fbaf

Please sign in to comment.