2022-05-26 09:19:00 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// <reference types="cypress" />
|
|
|
|
|
2023-08-03 12:56:30 +00:00
|
|
|
import type { MatrixClient, Preset, ICreateRoomOpts } from "matrix-js-sdk/src/matrix";
|
2023-01-10 23:29:56 +00:00
|
|
|
import { HomeserverInstance } from "../../plugins/utils/homeserver";
|
2022-05-26 09:19:00 +00:00
|
|
|
import Chainable = Cypress.Chainable;
|
|
|
|
import { UserCredentials } from "../../support/login";
|
|
|
|
|
|
|
|
function openSpaceCreateMenu(): Chainable<JQuery> {
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("button", { name: "Create a space" }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
return cy.get(".mx_SpaceCreateMenu_wrapper .mx_ContextualMenu");
|
|
|
|
}
|
|
|
|
|
|
|
|
function openSpaceContextMenu(spaceName: string): Chainable<JQuery> {
|
2022-07-25 11:46:19 +00:00
|
|
|
cy.getSpacePanelButton(spaceName).rightclick();
|
2022-05-26 09:19:00 +00:00
|
|
|
return cy.get(".mx_SpacePanel_contextMenu");
|
|
|
|
}
|
|
|
|
|
2023-02-03 08:59:21 +00:00
|
|
|
function spaceCreateOptions(spaceName: string, roomIds: string[] = []): ICreateRoomOpts {
|
2022-05-26 09:19:00 +00:00
|
|
|
return {
|
|
|
|
creation_content: {
|
|
|
|
type: "m.space",
|
|
|
|
},
|
2022-12-12 11:24:14 +00:00
|
|
|
initial_state: [
|
|
|
|
{
|
|
|
|
type: "m.room.name",
|
|
|
|
content: {
|
|
|
|
name: spaceName,
|
|
|
|
},
|
2022-05-26 09:19:00 +00:00
|
|
|
},
|
2023-02-03 08:59:21 +00:00
|
|
|
...roomIds.map(spaceChildInitialState),
|
2022-12-12 11:24:14 +00:00
|
|
|
],
|
2022-05-26 09:19:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function spaceChildInitialState(roomId: string): ICreateRoomOpts["initial_state"]["0"] {
|
|
|
|
return {
|
|
|
|
type: "m.space.child",
|
|
|
|
state_key: roomId,
|
|
|
|
content: {
|
|
|
|
via: [roomId.split(":")[1]],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("Spaces", () => {
|
2023-01-10 23:29:56 +00:00
|
|
|
let homeserver: HomeserverInstance;
|
2022-05-26 09:19:00 +00:00
|
|
|
let user: UserCredentials;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-01-10 23:29:56 +00:00
|
|
|
cy.startHomeserver("default").then((data) => {
|
|
|
|
homeserver = data;
|
2022-05-26 09:19:00 +00:00
|
|
|
|
2023-01-10 23:29:56 +00:00
|
|
|
cy.initTestUser(homeserver, "Sue").then((_user) => {
|
2022-05-26 09:19:00 +00:00
|
|
|
user = _user;
|
|
|
|
cy.mockClipboard();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2023-01-10 23:29:56 +00:00
|
|
|
cy.stopHomeserver(homeserver);
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
2023-02-02 15:25:24 +00:00
|
|
|
it("should allow user to create public space", () => {
|
2023-01-05 08:19:54 +00:00
|
|
|
openSpaceCreateMenu();
|
|
|
|
cy.get("#mx_ContextualMenu_Container").percySnapshotElement("Space create menu");
|
|
|
|
cy.get(".mx_SpaceCreateMenu_wrapper .mx_ContextualMenu").within(() => {
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to strings of "mx_SpaceCreateMenuType_public"
|
|
|
|
cy.findByRole("button", { name: /Public/ }).click();
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get('.mx_SpaceBasicSettings_avatarContainer input[type="file"]').selectFile(
|
|
|
|
"cypress/fixtures/riot.png",
|
|
|
|
{ force: true },
|
|
|
|
);
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("textbox", { name: "Name" }).type("Let's have a Riot");
|
|
|
|
cy.findByRole("textbox", { name: "Address" }).should("have.value", "lets-have-a-riot");
|
|
|
|
cy.findByRole("textbox", { name: "Description" }).type("This is a space to reminisce Riot.im!");
|
|
|
|
cy.findByRole("button", { name: "Create" }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Create the default General & Random rooms, as well as a custom "Jokes" room
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByPlaceholderText("General").should("exist");
|
|
|
|
cy.findByPlaceholderText("Random").should("exist");
|
|
|
|
cy.findByPlaceholderText("Support").type("Jokes");
|
|
|
|
cy.findByRole("button", { name: "Continue" }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
|
|
|
|
// Copy matrix.to link
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to strings of "mx_SpacePublicShare_shareButton"
|
|
|
|
cy.findByRole("button", { name: /Share invite link/ }).realClick();
|
2022-05-26 09:19:00 +00:00
|
|
|
cy.getClipboardText().should("eq", "https://matrix.to/#/#lets-have-a-riot:localhost");
|
|
|
|
|
|
|
|
// Go to space home
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("button", { name: "Go to my first room" }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
|
|
|
|
// Assert rooms exist in the room list
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("treeitem", { name: "General" }).should("exist");
|
|
|
|
cy.findByRole("treeitem", { name: "Random" }).should("exist");
|
|
|
|
cy.findByRole("treeitem", { name: "Jokes" }).should("exist");
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should allow user to create private space", () => {
|
|
|
|
openSpaceCreateMenu().within(() => {
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to strings of "mx_SpaceCreateMenuType_private"
|
|
|
|
cy.findByRole("button", { name: /Private/ }).click();
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.get('.mx_SpaceBasicSettings_avatarContainer input[type="file"]').selectFile(
|
|
|
|
"cypress/fixtures/riot.png",
|
|
|
|
{ force: true },
|
|
|
|
);
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("textbox", { name: "Name" }).type("This is not a Riot");
|
|
|
|
cy.findByRole("textbox", { name: "Address" }).should("not.exist");
|
|
|
|
cy.findByRole("textbox", { name: "Description" }).type("This is a private space of mourning Riot.im...");
|
|
|
|
cy.findByRole("button", { name: "Create" }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to strings of "mx_SpaceRoomView_privateScope_meAndMyTeammatesButton"
|
|
|
|
cy.findByRole("button", { name: /Me and my teammates/ }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
|
|
|
|
// Create the default General & Random rooms, as well as a custom "Projects" room
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByPlaceholderText("General").should("exist");
|
|
|
|
cy.findByPlaceholderText("Random").should("exist");
|
|
|
|
cy.findByPlaceholderText("Support").type("Projects");
|
|
|
|
cy.findByRole("button", { name: "Continue" }).click();
|
|
|
|
|
2023-06-05 21:11:12 +00:00
|
|
|
cy.get(".mx_SpaceRoomView h1").findByText("Invite your teammates");
|
2023-05-29 21:13:52 +00:00
|
|
|
cy.get(".mx_SpaceRoomView").percySnapshotElement("Space - 'Invite your teammates' dialog");
|
2023-06-05 21:11:12 +00:00
|
|
|
cy.findByRole("button", { name: "Skip for now" }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
|
|
|
|
// Assert rooms exist in the room list
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("treeitem", { name: "General" }).should("exist");
|
|
|
|
cy.findByRole("treeitem", { name: "Random" }).should("exist");
|
|
|
|
cy.findByRole("treeitem", { name: "Projects" }).should("exist");
|
2022-05-26 09:19:00 +00:00
|
|
|
|
|
|
|
// Assert rooms exist in the space explorer
|
2022-10-18 16:07:23 +00:00
|
|
|
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "General").should("exist");
|
|
|
|
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "Random").should("exist");
|
|
|
|
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "Projects").should("exist");
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should allow user to create just-me space", () => {
|
|
|
|
cy.createRoom({
|
|
|
|
name: "Sample Room",
|
|
|
|
});
|
|
|
|
|
|
|
|
openSpaceCreateMenu().within(() => {
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to strings of "mx_SpaceCreateMenuType_private"
|
|
|
|
cy.findByRole("button", { name: /Private/ }).click();
|
|
|
|
|
2023-02-02 10:22:19 +00:00
|
|
|
cy.get('.mx_SpaceBasicSettings_avatarContainer input[type="file"]').selectFile(
|
|
|
|
"cypress/fixtures/riot.png",
|
|
|
|
{ force: true },
|
|
|
|
);
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("textbox", { name: "Address" }).should("not.exist");
|
|
|
|
cy.findByRole("textbox", { name: "Description" }).type("This is a personal space to mourn Riot.im...");
|
|
|
|
cy.findByRole("textbox", { name: "Name" }).type("This is my Riot{enter}");
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to of strings of "mx_SpaceRoomView_privateScope_justMeButton"
|
|
|
|
cy.findByRole("button", { name: /Just me/ }).click();
|
|
|
|
|
|
|
|
cy.findByText("Sample Room").click({ force: true }); // force click as checkbox size is zero
|
2022-05-26 09:19:00 +00:00
|
|
|
|
2023-04-20 21:36:44 +00:00
|
|
|
// Temporal implementation as multiple elements with the role "button" and name "Add" are found
|
|
|
|
cy.get(".mx_AddExistingToSpace_footer").within(() => {
|
|
|
|
cy.findByRole("button", { name: "Add" }).click();
|
|
|
|
});
|
2022-05-26 09:19:00 +00:00
|
|
|
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.get(".mx_SpaceHierarchy_list").within(() => {
|
|
|
|
// Regex pattern due to the strings of "mx_SpaceHierarchy_roomTile_joined"
|
|
|
|
cy.findByRole("treeitem", { name: /Sample Room/ }).should("exist");
|
|
|
|
});
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should allow user to invite another to a space", () => {
|
|
|
|
let bot: MatrixClient;
|
2023-01-10 23:29:56 +00:00
|
|
|
cy.getBot(homeserver, { displayName: "BotBob" }).then((_bot) => {
|
2022-05-26 09:19:00 +00:00
|
|
|
bot = _bot;
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.createSpace({
|
|
|
|
visibility: "public" as any,
|
|
|
|
room_alias_name: "space",
|
|
|
|
}).as("spaceId");
|
|
|
|
|
|
|
|
openSpaceContextMenu("#space:localhost").within(() => {
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("menuitem", { name: "Invite" }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
cy.get(".mx_SpacePublicShare").within(() => {
|
|
|
|
// Copy link first
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to strings of "mx_SpacePublicShare_shareButton"
|
|
|
|
cy.findByRole("button", { name: /Share invite link/ })
|
|
|
|
.focus()
|
|
|
|
.realClick();
|
2022-05-26 09:19:00 +00:00
|
|
|
cy.getClipboardText().should("eq", "https://matrix.to/#/#space:localhost");
|
|
|
|
// Start Matrix invite flow
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to strings of "mx_SpacePublicShare_inviteButton"
|
|
|
|
cy.findByRole("button", { name: /Invite people/ }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
cy.get(".mx_InviteDialog_other").within(() => {
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("textbox").type(bot.getUserId());
|
|
|
|
cy.findByRole("button", { name: "Invite" }).click();
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
cy.get(".mx_InviteDialog_other").should("not.exist");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should show space invites at the top of the space panel", () => {
|
|
|
|
cy.createSpace({
|
|
|
|
name: "My Space",
|
|
|
|
});
|
2022-07-25 11:46:19 +00:00
|
|
|
cy.getSpacePanelButton("My Space").should("exist");
|
2022-05-26 09:19:00 +00:00
|
|
|
|
2023-01-10 23:29:56 +00:00
|
|
|
cy.getBot(homeserver, { displayName: "BotBob" }).then({ timeout: 10000 }, async (bot) => {
|
2022-05-26 09:19:00 +00:00
|
|
|
const { room_id: roomId } = await bot.createRoom(spaceCreateOptions("Space Space"));
|
|
|
|
await bot.invite(roomId, user.userId);
|
|
|
|
});
|
|
|
|
// Assert that `Space Space` is above `My Space` due to it being an invite
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.getSpacePanelButton("Space Space")
|
|
|
|
.should("exist")
|
|
|
|
.parent()
|
|
|
|
.next()
|
2023-04-20 21:36:44 +00:00
|
|
|
.findByRole("button", { name: "My Space" })
|
2022-12-12 11:24:14 +00:00
|
|
|
.should("exist");
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should include rooms in space home", () => {
|
|
|
|
cy.createRoom({
|
|
|
|
name: "Music",
|
|
|
|
}).as("roomId1");
|
|
|
|
cy.createRoom({
|
|
|
|
name: "Gaming",
|
|
|
|
}).as("roomId2");
|
|
|
|
|
|
|
|
const spaceName = "Spacey Mc. Space Space";
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.all([cy.get<string>("@roomId1"), cy.get<string>("@roomId2")]).then(([roomId1, roomId2]) => {
|
2022-05-26 09:19:00 +00:00
|
|
|
cy.createSpace({
|
|
|
|
name: spaceName,
|
2022-12-12 11:24:14 +00:00
|
|
|
initial_state: [spaceChildInitialState(roomId1), spaceChildInitialState(roomId2)],
|
2022-05-26 09:19:00 +00:00
|
|
|
}).as("spaceId");
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.get("@spaceId").then(() => {
|
2022-07-25 11:46:19 +00:00
|
|
|
cy.viewSpaceHomeByName(spaceName);
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
cy.get(".mx_SpaceRoomView .mx_SpaceHierarchy_list").within(() => {
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to strings in "mx_SpaceHierarchy_roomTile_name"
|
|
|
|
cy.findByRole("treeitem", { name: /Music/ }).findByRole("button").should("exist");
|
|
|
|
cy.findByRole("treeitem", { name: /Gaming/ })
|
|
|
|
.findByRole("button")
|
|
|
|
.should("exist");
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|
|
|
|
});
|
2022-08-10 15:29:53 +00:00
|
|
|
|
|
|
|
it("should render subspaces in the space panel only when expanded", () => {
|
|
|
|
cy.injectAxe();
|
|
|
|
|
|
|
|
cy.createSpace({
|
|
|
|
name: "Child Space",
|
|
|
|
initial_state: [],
|
2022-12-12 11:24:14 +00:00
|
|
|
}).then((spaceId) => {
|
2022-08-10 15:29:53 +00:00
|
|
|
cy.createSpace({
|
|
|
|
name: "Root Space",
|
2022-12-12 11:24:14 +00:00
|
|
|
initial_state: [spaceChildInitialState(spaceId)],
|
2022-08-10 15:29:53 +00:00
|
|
|
}).as("spaceId");
|
|
|
|
});
|
2023-04-20 21:36:44 +00:00
|
|
|
|
|
|
|
// Find collapsed Space panel
|
|
|
|
cy.findByRole("tree", { name: "Spaces" }).within(() => {
|
|
|
|
cy.findByRole("button", { name: "Root Space" }).should("exist");
|
|
|
|
cy.findByRole("button", { name: "Child Space" }).should("not.exist");
|
|
|
|
});
|
2022-08-10 15:29:53 +00:00
|
|
|
|
|
|
|
const axeOptions = {
|
|
|
|
rules: {
|
|
|
|
// Disable this check as it triggers on nested roving tab index elements which are in practice fine
|
2022-12-12 11:24:14 +00:00
|
|
|
"nested-interactive": {
|
2022-08-10 15:29:53 +00:00
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
cy.checkA11y(undefined, axeOptions);
|
|
|
|
cy.get(".mx_SpacePanel").percySnapshotElement("Space panel collapsed", { widths: [68] });
|
|
|
|
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("tree", { name: "Spaces" }).within(() => {
|
|
|
|
// This finds the expand button with the class name "mx_SpaceButton_toggleCollapse". Note there is another
|
|
|
|
// button with the same name with different class name "mx_SpacePanel_toggleCollapse".
|
|
|
|
cy.findByRole("button", { name: "Expand" }).realHover().click();
|
|
|
|
});
|
|
|
|
cy.get(".mx_SpacePanel:not(.collapsed)").should("exist"); // TODO: replace :not() selector
|
2022-08-10 15:29:53 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
cy.contains(".mx_SpaceItem", "Root Space")
|
|
|
|
.should("exist")
|
|
|
|
.contains(".mx_SpaceItem", "Child Space")
|
|
|
|
.should("exist");
|
2022-08-10 15:29:53 +00:00
|
|
|
|
|
|
|
cy.checkA11y(undefined, axeOptions);
|
|
|
|
cy.get(".mx_SpacePanel").percySnapshotElement("Space panel expanded", { widths: [258] });
|
|
|
|
});
|
2023-02-03 08:59:21 +00:00
|
|
|
|
|
|
|
it("should not soft crash when joining a room from space hierarchy which has a link in its topic", () => {
|
|
|
|
cy.getBot(homeserver, { displayName: "BotBob" }).then({ timeout: 10000 }, async (bot) => {
|
|
|
|
const { room_id: roomId } = await bot.createRoom({
|
|
|
|
preset: "public_chat" as Preset,
|
|
|
|
name: "Test Room",
|
|
|
|
topic: "This is a topic https://github.com/matrix-org/matrix-react-sdk/pull/10060 with a link",
|
|
|
|
});
|
|
|
|
const { room_id: spaceId } = await bot.createRoom(spaceCreateOptions("Test Space", [roomId]));
|
|
|
|
await bot.invite(spaceId, user.userId);
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.getSpacePanelButton("Test Space").should("exist");
|
|
|
|
cy.wait(500); // without this we can end up clicking too quickly and it ends up having no effect
|
|
|
|
cy.viewSpaceByName("Test Space");
|
2023-04-20 21:36:44 +00:00
|
|
|
cy.findByRole("button", { name: "Accept" }).click();
|
2023-02-03 08:59:21 +00:00
|
|
|
|
2023-04-20 21:36:44 +00:00
|
|
|
// Regex pattern due to strings in "mx_SpaceHierarchy_roomTile_item"
|
|
|
|
cy.findByRole("button", { name: /Test Room/ }).realHover();
|
|
|
|
cy.findByRole("button", { name: "Join" }).should("exist").realHover().click();
|
|
|
|
cy.findByRole("button", { name: "View", timeout: 5000 }).should("exist").realHover().click();
|
2023-02-03 08:59:21 +00:00
|
|
|
|
|
|
|
// Assert we get shown the new room intro, and thus not the soft crash screen
|
|
|
|
cy.get(".mx_NewRoomIntro").should("exist");
|
|
|
|
});
|
2022-05-26 09:19:00 +00:00
|
|
|
});
|