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

Remove mx_HeaderButtons class and add a test #10713

Merged
merged 8 commits into from
May 5, 2023
Merged

Remove mx_HeaderButtons class and add a test #10713

merged 8 commits into from
May 5, 2023

Conversation

luixxiul
Copy link
Contributor

@luixxiul luixxiul commented Apr 26, 2023

Cherry-picked from #10495

This PR intends to remove mx_HeaderButtons class and add a test for the room header.

Thanks to #10628 mx_HeaderButtons class is no longer necessary as ARIA tabpanel role has been removed from the element with that class name, and it is possible to remove both the class and the style rule for it.

Here is the cropped screenshot of the DOM tree of mx_RoomHeader (mx_RoomHeader_wrapper) on this PR:

1

Please note that #10628 changed the buttons' ARIA role from tab to button and removed role="tabpanel" from the div element which had wrapped buttons with tab role, so we no longer need the wrapper. mx_RoomHeader_wrapper takes care of the placement of the all buttons inside it.

With this PR these Percy snapshots are added:

  • Room header
  • Room header - with a long room name
  • Room header - with a highlighted button
  • Room header - with a video room

Signed-off-by: Suguru Hirahara [email protected]

type: task

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

This change is marked as an internal change (Task), so will not be included in the changelog.

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 <[email protected]>
Copy link
Contributor

@alunturner alunturner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello. A few comments and some questions (mainly due to a bit of unfamiliarity on my side). The question about how to repeat a check for multiple buttons also applies to some of the later tests in this file.

Thanks for the contribution!

Comment on lines 42 to 48
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll preface this comment with saying I'm pretty new to cypress (and specifically the testing-library stuff with it).

To me, it seems that on line 40 we're already doing this test, aren't we? We're grabbing all the buttons, checking there are 7 of them, and I think checking that each thing with the role of button is visible (I could be misunderstanding how chaining a .should after a findAllBy* works though).

There may still be value in checking that we have these 7 specific buttons on the page though (ie checking the name of each button).

I've had a look to see if there's a neater way of doing this, nothing leaps out at me from the jest documentation. Perhaps something like:

const expectedButtonNames = [`Room options`...];
for (const name of expectedButtonNames) {
  cy.findByRole("button", { name}).should("be.visible");
}

Might make it a bit easier to read. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the object of this test is to ensure that just those seven (not six or eight) buttons are rendered by default. This can be achieved by combining findAllBy query with should(have.length) by counting the exact number of the all found buttons.

Each findByRole query does ensure that button whose name is specified exists, but it cannot ensure that there was not another button rendered besides them unexpectedly.

Based on your hint, b20ceec should optimize the readability and the test flow.

});

cy.get(".mx_RoomHeader").percySnapshotElement("Room header", {
widths: [300, 600], // Magic numbers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I'm unfamiliar with percy too - what are these magic numbers for? Are they the widths the snapshots are performed at? How come you chose these values?

Copy link
Contributor Author

@luixxiul luixxiul Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Values specified with widths are used to set custom widths of a snapshot of the chained element. The default values are 1024 and 1920 (both in pixel) specified here on .percy.yml.

On this case, Percy creates a snapshot of mx_RoomHeader (mind this is not the whole UI) in 300px and 600px. Similarly, this snapshot was captured in 320px and 640px, in order to emulate the narrow UI.

The custom values are indeed relevant only for Room header - with a long room name, since the object of the snapshot with overriding the default values should be to emulate the narrow UI and ensure that room name overflow is properly hidden with horizontal ellipsis. I'm going to remove unrelated widths settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with 2922c66.

Comment on lines 90 to 99
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we have a test for 7 buttons earlier on, but we only check 6 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because mx_RoomHeader_name (the room options button with dropdown menu on click) is also a button element.

This is the mx_RoomHeader_name:
1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to add a comment about it. It is indeed confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with de2dd1c


cy.get(".mx_RoomHeader").findByRole("button", { name: "Chat" }).click();

// Assert that the video is rnedered
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny typo here in rnedered

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed with d7a700d

it("should have a button highlighted by being clicked", () => {
cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room");

cy.findByRole("button", { name: "Room info" })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to test for all buttons here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently only buttons which display content on the right panel by being clicked are highlighted; Thread, Notification, and Room Info, though I am not sure if this is intended or not.

8c9eee1 should address this.

@luixxiul
Copy link
Contributor Author

Thanks for the initial review. I'm checking the code to reply to your feedback comments.

Signed-off-by: Suguru Hirahara <[email protected]>
Signed-off-by: Suguru Hirahara <[email protected]>
Signed-off-by: Suguru Hirahara <[email protected]>
Signed-off-by: Suguru Hirahara <[email protected]>
Signed-off-by: Suguru Hirahara <[email protected]>

// 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be achieved by #10495.

Copy link
Contributor

@alunturner alunturner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good to me

@alunturner alunturner added this pull request to the merge queue May 5, 2023
Merged via the queue into matrix-org:develop with commit f6f5d44 May 5, 2023
@luixxiul
Copy link
Contributor Author

luixxiul commented May 5, 2023

Thanks for the review!

@luixxiul luixxiul deleted the HeaderButtons2 branch May 5, 2023 16:06
@luixxiul
Copy link
Contributor Author

luixxiul commented May 8, 2023

@luixxiul
Copy link
Contributor Author

luixxiul commented May 8, 2023

https://percy.io/dfde73bd/matrix-react-sdk/builds/27192947/missing

This is because the snapshot was renamed to Room header - with a long room name by this PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Refactoring, enabling or disabling functionality, other engineering tasks Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants