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

Add a basic E2E test for event tiles #10306

Merged
merged 11 commits into from
Mar 17, 2023
136 changes: 136 additions & 0 deletions cypress/e2e/timeline/timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,142 @@ describe("Timeline", () => {
);
});

it("should render EventTiles on IRC layout", () => {
// Exclude timestamp and read marker from snapshots
const percyCSS = ".mx_MessageTimestamp, .mx_RoomView_myReadMarker { visibility: hidden !important; }";

sendEvent(roomId);
sendEvent(roomId); // check continuation
sendEvent(roomId); // check the last EventTile

cy.visit("/#/room/" + roomId);
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.IRC);

// Wait until configuration is finished
cy.contains(
".mx_RoomView_body .mx_GenericEventListSummary[data-layout=irc] .mx_GenericEventListSummary_summary",
"created and configured the room.",
).should("exist");

cy.get(".mx_RoomView_body[data-layout=irc]").within(() => {
// Ensure CSS declarations which cannot be detected with a screenshot test are applied as expected
cy.get(".mx_EventTile")
.should("have.css", "max-width", "100%")
.should("have.css", "clear", "both")
.should("have.css", "position", "relative");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To confirm the declarations below (except padding and font size) are kept applied:

.mx_EventTile:not([data-layout="bubble"]) {
max-width: 100%;
clear: both;
padding-top: 18px;
font-size: $font-14px;
position: relative;
}


cy.get(".mx_EventTile_continuation")
// Check that zero block padding is set
.should("have.css", "padding-block-start", "0px");

cy.get(".mx_EventTile_continuation .mx_EventTile_line").should("have.css", "clear", "both");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See:

&.mx_EventTile_continuation .mx_EventTile_line {
clear: both;
}


// Select the last event tile
cy.get(".mx_EventTile_last")
.within(() => {
// The last tile is also a continued one
cy.get(".mx_EventTile_line").should("have.css", "clear", "both");
})
// Check that zero block padding is set
.should("have.css", "padding-block-start", "0px");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

});

cy.get(".mx_MainSplit").percySnapshotElement("EventTiles on IRC layout", { percyCSS });
});

it("should render EventTiles on modern layout", () => {
// Exclude timestamp and read marker from snapshots
const percyCSS = ".mx_MessageTimestamp, .mx_RoomView_myReadMarker { visibility: hidden !important; }";

sendEvent(roomId);
sendEvent(roomId); // check continuation
sendEvent(roomId); // check the last EventTile

cy.visit("/#/room/" + roomId);
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.Group);

// Wait until configuration is finished
cy.contains(
".mx_RoomView_body .mx_GenericEventListSummary[data-layout=group] .mx_GenericEventListSummary_summary",
"created and configured the room.",
).should("exist");

cy.get(".mx_RoomView_body[data-layout=group]").within(() => {
// Ensure CSS declarations which cannot be detected with a screenshot test are applied as expected
cy.get(".mx_EventTile")
.should("have.css", "max-width", "100%")
.should("have.css", "clear", "both")
.should("have.css", "position", "relative");
Copy link
Contributor Author

Choose a reason for hiding this comment

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


// Check that block start padding of the second message is not overridden
cy.get(".mx_EventTile.mx_EventTile_continuation")
.should("have.css", "padding-block-start", "0px");

// Check that the last EventTile is rendered
cy.get(".mx_EventTile.mx_EventTile_last").should("exist");
});

cy.get(".mx_MainSplit").percySnapshotElement("EventTiles on modern layout", { percyCSS });

// Check the same thing for compact layout
cy.setSettingValue("useCompactLayout", null, SettingLevel.DEVICE, true);

cy.get(".mx_MatrixChat_useCompactLayout").within(() => {
// Ensure CSS declarations which cannot be detected with a screenshot test are applied as expected
cy.get(".mx_EventTile")
.should("have.css", "max-width", "100%")
.should("have.css", "clear", "both")
.should("have.css", "position", "relative");

// Check cascading works
cy.get(".mx_EventTile_continuation").should("have.css", "padding-block-start", "0px");

// Check that the last EventTile is rendered
cy.get(".mx_EventTile.mx_EventTile_last").should("exist");
});

cy.get(".mx_MainSplit").percySnapshotElement("EventTiles on compact modern layout", { percyCSS });
});

it("should render EventTiles on bubble layout", () => {
// Exclude timestamp and read marker from snapshots
const percyCSS = ".mx_MessageTimestamp, .mx_RoomView_myReadMarker { visibility: hidden !important; }";

sendEvent(roomId);
sendEvent(roomId); // check continuation
sendEvent(roomId); // check the last EventTile

cy.visit("/#/room/" + roomId);
cy.setSettingValue("layout", null, SettingLevel.DEVICE, Layout.Bubble);

// Wait until configuration is finished
cy.contains(
".mx_RoomView_body .mx_GenericEventListSummary[data-layout=bubble] .mx_GenericEventListSummary_summary",
"created and configured the room.",
).should("exist");

cy.get(".mx_RoomView_body[data-layout=bubble]").within(() => {
// Ensure CSS declarations which cannot be detected with a screenshot test are applied as expected
cy.get(".mx_EventTile")
.should("have.css", "max-width", "none")
.should("have.css", "clear", "both")
.should("have.css", "position", "relative");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See:

.mx_EventTile[data-layout="bubble"] {
--EventTile_bubble_line-margin-inline-start: -9px;
--EventTile_bubble_line-margin-inline-end: -12px;
--EventTile_bubble_gap-inline: 5px;
position: relative;
/* Other half of the gutter is provided by margin-bottom on the last tile
of the section */
margin-top: calc(var(--gutterSize) / 2);
margin-left: var(--EventTile_bubble-margin-inline-start);
font-size: $font-14px;

Checking default values as well.


// Check that block start padding of the second message is not overridden
cy.get(".mx_EventTile.mx_EventTile_continuation").should("have.css", "margin-block-start", "2px");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See:

&.mx_EventTile_continuation {
margin-top: 2px;
}


// Select the last bubble
cy.get(".mx_EventTile_last")
.within(() => {
// calc(var(--gutterSize) - 1px)
cy.get(".mx_EventTile_line").should("have.css", "padding-block-start", "10px");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See:

&:not(.mx_EventTile_noBubble) .mx_EventTile_line:not(.mx_EventTile_mediaLine) {
/* make the top and bottom padding 1px smaller so that we can pad
.mx_EventTile_content by 1px */
/* to avoid anti-zalgo cutting off our larger than text emojis. */
padding: calc(var(--gutterSize) - 1px);

This messy selector with the double negation should be simplified eventually.

})
.should("have.css", "margin-block-start", "2px"); // The last bubble is also a continued one
Copy link
Contributor Author

Choose a reason for hiding this comment

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

});

cy.get(".mx_MainSplit").percySnapshotElement("EventTiles on bubble layout", { percyCSS });
});

it("should set inline start padding to a hidden event line", () => {
sendEvent(roomId);
cy.visit("/#/room/" + roomId);
Expand Down