From 8af7270d02ff111e06dbf995de4d6212e9a571fd Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Tue, 25 Apr 2023 18:59:05 +0000 Subject: [PATCH 1/8] Remove `_HeaderButtons.pcss` Now that mx_HeaderButtons class is no longer necessary as ARIA "tabpanel" role has been removed from it, it is possible to remove both the class and the style rule for it. Signed-off-by: Suguru Hirahara --- cypress/e2e/create-room/create-room.spec.ts | 2 +- cypress/e2e/lazy-loading/lazy-loading.spec.ts | 2 +- res/css/_components.pcss | 1 - res/css/structures/_HeaderButtons.pcss | 19 ------------------- .../views/right_panel/HeaderButtons.tsx | 2 +- 5 files changed, 3 insertions(+), 23 deletions(-) delete mode 100644 res/css/structures/_HeaderButtons.pcss diff --git a/cypress/e2e/create-room/create-room.spec.ts b/cypress/e2e/create-room/create-room.spec.ts index 7596df087ff..6ebe770bba1 100644 --- a/cypress/e2e/create-room/create-room.spec.ts +++ b/cypress/e2e/create-room/create-room.spec.ts @@ -86,7 +86,7 @@ describe("Create Room", () => { // and the buttons are not compressed // TODO: use a same class name cy.get(".mx_RoomHeader_button").should("have.css", "height", "32px").should("have.css", "width", "32px"); - cy.get(".mx_HeaderButtons > .mx_RightPanel_headerButton") + cy.get(".mx_RoomHeader .mx_RightPanel_headerButton") .should("have.css", "height", "32px") .should("have.css", "width", "32px"); cy.get(".mx_RoomHeader").percySnapshotElement("Room header with a long room name"); diff --git a/cypress/e2e/lazy-loading/lazy-loading.spec.ts b/cypress/e2e/lazy-loading/lazy-loading.spec.ts index 6e53fc33da9..05bed5cf682 100644 --- a/cypress/e2e/lazy-loading/lazy-loading.spec.ts +++ b/cypress/e2e/lazy-loading/lazy-loading.spec.ts @@ -116,7 +116,7 @@ describe("Lazy Loading", () => { } function openMemberlist(): void { - cy.get(".mx_HeaderButtons").within(() => { + cy.get(".mx_RoomHeader").within(() => { cy.findByRole("button", { name: "Room info" }).click(); }); diff --git a/res/css/_components.pcss b/res/css/_components.pcss index 2b0cf70b9c2..a3aff0533af 100644 --- a/res/css/_components.pcss +++ b/res/css/_components.pcss @@ -63,7 +63,6 @@ @import "./structures/_FilePanel.pcss"; @import "./structures/_GenericDropdownMenu.pcss"; @import "./structures/_GenericErrorPage.pcss"; -@import "./structures/_HeaderButtons.pcss"; @import "./structures/_HomePage.pcss"; @import "./structures/_LargeLoader.pcss"; @import "./structures/_LeftPanel.pcss"; diff --git a/res/css/structures/_HeaderButtons.pcss b/res/css/structures/_HeaderButtons.pcss deleted file mode 100644 index 4a3de483762..00000000000 --- a/res/css/structures/_HeaderButtons.pcss +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 2019 New Vector Ltd - -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. -*/ - -.mx_HeaderButtons { - display: flex; -} diff --git a/src/components/views/right_panel/HeaderButtons.tsx b/src/components/views/right_panel/HeaderButtons.tsx index 9dea7cb8638..d13eb5d2d77 100644 --- a/src/components/views/right_panel/HeaderButtons.tsx +++ b/src/components/views/right_panel/HeaderButtons.tsx @@ -98,6 +98,6 @@ export default abstract class HeaderButtons

extends React.Component{this.renderButtons()}; + return this.renderButtons(); } } From 5f3b148a7fc7702c8d9a10b097955732407dbaab Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Wed, 26 Apr 2023 13:33:34 +0000 Subject: [PATCH 2/8] Tests: add `room-header.spec.ts` and edit the existing tests Signed-off-by: Suguru Hirahara --- cypress/e2e/create-room/create-room.spec.ts | 27 --- cypress/e2e/room/room-header.spec.ts | 182 ++++++++++++++++++++ 2 files changed, 182 insertions(+), 27 deletions(-) create mode 100644 cypress/e2e/room/room-header.spec.ts diff --git a/cypress/e2e/create-room/create-room.spec.ts b/cypress/e2e/create-room/create-room.spec.ts index 6ebe770bba1..d51e683abf4 100644 --- a/cypress/e2e/create-room/create-room.spec.ts +++ b/cypress/e2e/create-room/create-room.spec.ts @@ -64,31 +64,4 @@ describe("Create Room", () => { cy.findByText(topic); }); }); - - it("should create a room with a long room name, which is displayed with ellipsis", () => { - let roomId: string; - const LONG_ROOM_NAME = - "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore " + - "et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " + - "aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " + - "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " + - "officia deserunt mollit anim id est laborum."; - - cy.createRoom({ name: LONG_ROOM_NAME }).then((_roomId) => { - roomId = _roomId; - cy.visit("/#/room/" + roomId); - }); - - // Wait until the room name is set - cy.get(".mx_RoomHeader_nametext").contains("Lorem ipsum"); - - // Make sure size of buttons on RoomHeader (except .mx_RoomHeader_name) are specified - // and the buttons are not compressed - // TODO: use a same class name - cy.get(".mx_RoomHeader_button").should("have.css", "height", "32px").should("have.css", "width", "32px"); - cy.get(".mx_RoomHeader .mx_RightPanel_headerButton") - .should("have.css", "height", "32px") - .should("have.css", "width", "32px"); - cy.get(".mx_RoomHeader").percySnapshotElement("Room header with a long room name"); - }); }); diff --git a/cypress/e2e/room/room-header.spec.ts b/cypress/e2e/room/room-header.spec.ts new file mode 100644 index 00000000000..aa7e34f8c8c --- /dev/null +++ b/cypress/e2e/room/room-header.spec.ts @@ -0,0 +1,182 @@ +/* +Copyright 2023 Suguru Hirahara + +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. +*/ + +/// + +import { HomeserverInstance } from "../../plugins/utils/homeserver"; +import { SettingLevel } from "../../../src/settings/SettingLevel"; + +describe("Room Header", () => { + let homeserver: HomeserverInstance; + + beforeEach(() => { + cy.startHomeserver("default").then((data) => { + homeserver = data; + cy.initTestUser(homeserver, "Sakura"); + }); + }); + + afterEach(() => { + cy.stopHomeserver(homeserver); + }); + + it("should render seven buttons by default", () => { + cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room"); + + cy.get(".mx_RoomHeader").within(() => { + cy.findAllByRole("button").should("have.length", 7).should("be.visible"); + + cy.findByRole("button", { name: "Room options" }).should("be.visible"); + cy.findByRole("button", { name: "Voice call" }).should("be.visible"); + cy.findByRole("button", { name: "Video call" }).should("be.visible"); + cy.findByRole("button", { name: "Search" }).should("be.visible"); + cy.findByRole("button", { name: "Threads" }).should("be.visible"); + cy.findByRole("button", { name: "Notifications" }).should("be.visible"); + cy.findByRole("button", { name: "Room info" }).should("be.visible"); + }); + + cy.get(".mx_RoomHeader").percySnapshotElement("Room header", { + widths: [300, 600], // Magic numbers + }); + }); + + it("should render the pin button for pinned messages card", () => { + cy.enableLabsFeature("feature_pinning"); + + cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room"); + + cy.getComposer().type("Test message{enter}"); + + cy.get(".mx_EventTile_last").realHover().findByRole("button", { name: "Options" }).click(); + + cy.findByRole("menuitem", { name: "Pin" }).should("be.visible").click(); + + cy.get(".mx_RoomHeader").within(() => { + cy.findByRole("button", { name: "Pinned messages" }).should("be.visible"); + }); + }); + + it("should render a very long room name without collapsing the buttons", () => { + const LONG_ROOM_NAME = + "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore " + + "et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " + + "aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " + + "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " + + "officia deserunt mollit anim id est laborum."; + + cy.createRoom({ name: LONG_ROOM_NAME }).viewRoomByName(LONG_ROOM_NAME); + + cy.get(".mx_RoomHeader").within(() => { + // Wait until the room name is set + cy.get(".mx_RoomHeader_nametext").within(() => { + cy.findByText(LONG_ROOM_NAME).should("exist"); + }); + + // Assert the size of buttons on RoomHeader (except mx_RoomHeader_name) are specified + // and the buttons are not compressed + cy.get(".mx_RoomHeader_button") + .should("have.length", 3) + .should("be.visible") + .should("have.css", "height", "32px") + .should("have.css", "width", "32px"); + cy.get(".mx_RightPanel_headerButton") // TODO: use the same class name + .should("have.length", 3) + .should("be.visible") + .should("have.css", "height", "32px") + .should("have.css", "width", "32px"); + }); + + cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a long room name", { + widths: [300, 600], // Magic numbers + }); + }); + + it("should have a button highlighted by being clicked", () => { + cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room"); + + cy.findByRole("button", { name: "Room info" }) + .click() // Highlight the button + .then(($btn) => { + // Note it is not possible to get CSS values of a pseudo class with "have.css". + const color = $btn[0].ownerDocument.defaultView // get window reference from element + .getComputedStyle($btn[0], "before") // get the pseudo selector + .getPropertyValue("background-color"); // get "background-color" value + + // Assert the value is equal to $accent == hex #0dbd8b == rgba(13, 189, 139) + expect(color).to.eq("rgb(13, 189, 139)"); + }); + + cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a highlighted button", { + widths: [300, 600], // Magic numbers + }); + }); + + describe("with a video room", () => { + const createVideoRoom = () => { + // Enable video rooms. This command reloads the app + cy.setSettingValue("feature_video_rooms", null, SettingLevel.DEVICE, true); + + cy.get(".mx_LeftPanel_roomListContainer", { timeout: 20000 }) + .findByRole("button", { name: "Add room" }) + .click(); + + cy.findByRole("menuitem", { name: "New video room" }).click(); + + cy.findByRole("textbox", { name: "Name" }).type("Test video room"); + + cy.findByRole("button", { name: "Create video room" }).click(); + + cy.viewRoomByName("Test video room"); + }; + + it("should render buttons for room options, beta pill, invite, chat, and room info", () => { + createVideoRoom(); + + cy.get(".mx_RoomHeader").within(() => { + cy.findByRole("button", { name: "Room options" }).should("be.visible"); + cy.findByRole("button", { name: "Video rooms are a beta feature Click for more info" }).should( + "be.visible", + ); // Beta pill + cy.findByRole("button", { name: "Invite" }).should("be.visible"); + cy.findByRole("button", { name: "Chat" }).should("be.visible"); + cy.findByRole("button", { name: "Room info" }).should("be.visible"); + + // Assert that there is not a button except those buttons + cy.findAllByRole("button").should("have.length", 5); + }); + + cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a video room", { + widths: [300, 600], // Magic numbers + }); + }); + + it("should render a working chat button which opens the timeline on a right panel", () => { + createVideoRoom(); + + cy.get(".mx_RoomHeader").findByRole("button", { name: "Chat" }).click(); + + // Assert that the video is rnedered + cy.get(".mx_CallView video").should("exist"); + + cy.get(".mx_RightPanel .mx_TimelineCard") + .should("exist") + .within(() => { + // Assert that GELS is visible + cy.findByText("Sakura created and configured the room.").should("exist"); + }); + }); + }); +}); From 2922c66fe27ceff6fd253d4a1d842f808dd2a37a Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Fri, 28 Apr 2023 10:11:46 +0000 Subject: [PATCH 3/8] Edit snapshot widths settings Signed-off-by: Suguru Hirahara --- cypress/e2e/room/room-header.spec.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/cypress/e2e/room/room-header.spec.ts b/cypress/e2e/room/room-header.spec.ts index aa7e34f8c8c..20dd23f7d8c 100644 --- a/cypress/e2e/room/room-header.spec.ts +++ b/cypress/e2e/room/room-header.spec.ts @@ -48,9 +48,7 @@ describe("Room Header", () => { cy.findByRole("button", { name: "Room info" }).should("be.visible"); }); - cy.get(".mx_RoomHeader").percySnapshotElement("Room header", { - widths: [300, 600], // Magic numbers - }); + cy.get(".mx_RoomHeader").percySnapshotElement("Room header"); }); it("should render the pin button for pinned messages card", () => { @@ -100,7 +98,7 @@ describe("Room Header", () => { }); cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a long room name", { - widths: [300, 600], // Magic numbers + widths: [300, 600], // Magic numbers to emulate the narrow RoomHeader on the actual UI }); }); @@ -119,9 +117,7 @@ describe("Room Header", () => { expect(color).to.eq("rgb(13, 189, 139)"); }); - cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a highlighted button", { - widths: [300, 600], // Magic numbers - }); + cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a highlighted button"); }); describe("with a video room", () => { @@ -158,9 +154,7 @@ describe("Room Header", () => { cy.findAllByRole("button").should("have.length", 5); }); - cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a video room", { - widths: [300, 600], // Magic numbers - }); + cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a video room"); }); it("should render a working chat button which opens the timeline on a right panel", () => { From d7a700dca1e32c50400eb01318f91e62889062a1 Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Fri, 28 Apr 2023 10:18:02 +0000 Subject: [PATCH 4/8] Fix typo Signed-off-by: Suguru Hirahara --- cypress/e2e/room/room-header.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/e2e/room/room-header.spec.ts b/cypress/e2e/room/room-header.spec.ts index 20dd23f7d8c..56591d02295 100644 --- a/cypress/e2e/room/room-header.spec.ts +++ b/cypress/e2e/room/room-header.spec.ts @@ -162,7 +162,7 @@ describe("Room Header", () => { cy.get(".mx_RoomHeader").findByRole("button", { name: "Chat" }).click(); - // Assert that the video is rnedered + // Assert that the video is rendered cy.get(".mx_CallView video").should("exist"); cy.get(".mx_RightPanel .mx_TimelineCard") From de2dd1c4e1fc09ee5cdb92baa38fbd5172417ea2 Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Fri, 28 Apr 2023 11:27:27 +0000 Subject: [PATCH 5/8] Edit a comment Signed-off-by: Suguru Hirahara --- cypress/e2e/room/room-header.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cypress/e2e/room/room-header.spec.ts b/cypress/e2e/room/room-header.spec.ts index 56591d02295..1d338508efe 100644 --- a/cypress/e2e/room/room-header.spec.ts +++ b/cypress/e2e/room/room-header.spec.ts @@ -83,14 +83,15 @@ describe("Room Header", () => { cy.findByText(LONG_ROOM_NAME).should("exist"); }); - // Assert the size of buttons on RoomHeader (except mx_RoomHeader_name) are specified - // and the buttons are not compressed + // Assert the size of buttons on RoomHeader are specified and the buttons are not compressed + // Note these assertions do not check the size of mx_RoomHeader_name button + // TODO: merge the assertions by using the same class name cy.get(".mx_RoomHeader_button") .should("have.length", 3) .should("be.visible") .should("have.css", "height", "32px") .should("have.css", "width", "32px"); - cy.get(".mx_RightPanel_headerButton") // TODO: use the same class name + cy.get(".mx_RightPanel_headerButton") .should("have.length", 3) .should("be.visible") .should("have.css", "height", "32px") From b20ceec2e4d8c3e56321af97be2a890f650d3a28 Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Fri, 28 Apr 2023 11:51:28 +0000 Subject: [PATCH 6/8] Optimize a test to check default buttons Signed-off-by: Suguru Hirahara --- cypress/e2e/room/room-header.spec.ts | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/cypress/e2e/room/room-header.spec.ts b/cypress/e2e/room/room-header.spec.ts index 1d338508efe..38a04e0bec1 100644 --- a/cypress/e2e/room/room-header.spec.ts +++ b/cypress/e2e/room/room-header.spec.ts @@ -33,19 +33,28 @@ describe("Room Header", () => { cy.stopHomeserver(homeserver); }); - it("should render seven buttons by default", () => { + it("should render default buttons properly", () => { cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room"); cy.get(".mx_RoomHeader").within(() => { - cy.findAllByRole("button").should("have.length", 7).should("be.visible"); - - cy.findByRole("button", { name: "Room options" }).should("be.visible"); - cy.findByRole("button", { name: "Voice call" }).should("be.visible"); - cy.findByRole("button", { name: "Video call" }).should("be.visible"); - cy.findByRole("button", { name: "Search" }).should("be.visible"); - cy.findByRole("button", { name: "Threads" }).should("be.visible"); - cy.findByRole("button", { name: "Notifications" }).should("be.visible"); - cy.findByRole("button", { name: "Room info" }).should("be.visible"); + // Names (aria-label) of every button rendered on mx_RoomHeader by default + const expectedButtonNames = [ + "Room options", // The room name button next to the room avatar, which renders dropdown menu on click + "Voice call", + "Video call", + "Search", + "Threads", + "Notifications", + "Room info", + ]; + + // Assert they are found and visible + for (const name of expectedButtonNames) { + cy.findByRole("button", { name }).should("be.visible"); + } + + // Assert that just those seven buttons exist on mx_RoomHeader by default + cy.findAllByRole("button").should("have.length", 7); }); cy.get(".mx_RoomHeader").percySnapshotElement("Room header"); From 8c9eee1bbe9afa68212f767de1c208f75c93b436 Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Fri, 28 Apr 2023 12:52:22 +0000 Subject: [PATCH 7/8] Check highlighted buttons Signed-off-by: Suguru Hirahara --- cypress/e2e/room/room-header.spec.ts | 31 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/cypress/e2e/room/room-header.spec.ts b/cypress/e2e/room/room-header.spec.ts index 38a04e0bec1..c9179254cc7 100644 --- a/cypress/e2e/room/room-header.spec.ts +++ b/cypress/e2e/room/room-header.spec.ts @@ -112,20 +112,27 @@ describe("Room Header", () => { }); }); - it("should have a button highlighted by being clicked", () => { + it("should have buttons highlighted by being clicked", () => { cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room"); - cy.findByRole("button", { name: "Room info" }) - .click() // Highlight the button - .then(($btn) => { - // Note it is not possible to get CSS values of a pseudo class with "have.css". - const color = $btn[0].ownerDocument.defaultView // get window reference from element - .getComputedStyle($btn[0], "before") // get the pseudo selector - .getPropertyValue("background-color"); // get "background-color" value - - // Assert the value is equal to $accent == hex #0dbd8b == rgba(13, 189, 139) - expect(color).to.eq("rgb(13, 189, 139)"); - }); + cy.get(".mx_RoomHeader").within(() => { + // Check these buttons + const buttonsHighlighted = ["Threads", "Notifications", "Room info"]; + + for (const name of buttonsHighlighted) { + cy.findByRole("button", { name: name }) + .click() // Highlight the button + .then(($btn) => { + // Note it is not possible to get CSS values of a pseudo class with "have.css". + const color = $btn[0].ownerDocument.defaultView // get window reference from element + .getComputedStyle($btn[0], "before") // get the pseudo selector + .getPropertyValue("background-color"); // get "background-color" value + + // Assert the value is equal to $accent == hex #0dbd8b == rgba(13, 189, 139) + expect(color).to.eq("rgb(13, 189, 139)"); + }); + } + }); cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a highlighted button"); }); From 831ee06bf5998f67b03002a20a7be233dd51c50b Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Fri, 28 Apr 2023 13:04:19 +0000 Subject: [PATCH 8/8] Loop Signed-off-by: Suguru Hirahara --- cypress/e2e/room/room-header.spec.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cypress/e2e/room/room-header.spec.ts b/cypress/e2e/room/room-header.spec.ts index c9179254cc7..b4c73532d4f 100644 --- a/cypress/e2e/room/room-header.spec.ts +++ b/cypress/e2e/room/room-header.spec.ts @@ -159,13 +159,19 @@ describe("Room Header", () => { createVideoRoom(); cy.get(".mx_RoomHeader").within(() => { - cy.findByRole("button", { name: "Room options" }).should("be.visible"); - cy.findByRole("button", { name: "Video rooms are a beta feature Click for more info" }).should( - "be.visible", - ); // Beta pill - cy.findByRole("button", { name: "Invite" }).should("be.visible"); - cy.findByRole("button", { name: "Chat" }).should("be.visible"); - cy.findByRole("button", { name: "Room info" }).should("be.visible"); + // Names (aria-label) of the buttons on the video room header + const expectedButtonNames = [ + "Room options", + "Video rooms are a beta feature Click for more info", // Beta pill + "Invite", + "Chat", + "Room info", + ]; + + // Assert they are found and visible + for (const name of expectedButtonNames) { + cy.findByRole("button", { name }).should("be.visible"); + } // Assert that there is not a button except those buttons cy.findAllByRole("button").should("have.length", 5);