This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 827
/
Copy pathroom-header.spec.ts
282 lines (223 loc) · 10.7 KB
/
room-header.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
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.
*/
/// <reference types="cypress" />
import { IWidget } from "matrix-widget-api";
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 default buttons properly", () => {
cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room");
cy.get(".mx_RoomHeader").within(() => {
// 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");
});
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 are specified and the buttons are not compressed
// Note these assertions do not check the size of mx_RoomHeader_name button
cy.get(".mx_RoomHeader_button")
.should("have.length", 6)
.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 to emulate the narrow RoomHeader on the actual UI
});
});
it("should have buttons highlighted by being clicked", () => {
cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room");
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
}
});
cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with a highlighted button");
});
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(() => {
// 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", 7);
});
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", () => {
createVideoRoom();
cy.get(".mx_RoomHeader").findByRole("button", { name: "Chat" }).click();
// Assert that the video is rendered
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");
});
});
});
describe("with a widget", () => {
const ROOM_NAME = "Test Room with a widget";
const WIDGET_ID = "fake-widget";
const WIDGET_HTML = `
<html lang="en">
<head>
<title>Fake Widget</title>
</head>
<body>
Hello World
</body>
</html>
`;
let widgetUrl: string;
let roomId: string;
beforeEach(() => {
cy.serveHtmlFile(WIDGET_HTML).then((url) => {
widgetUrl = url;
});
cy.createRoom({ name: ROOM_NAME }).then((id) => {
roomId = id;
// setup widget via state event
cy.getClient()
.then(async (matrixClient) => {
const content: IWidget = {
id: WIDGET_ID,
creatorUserId: "somebody",
type: "widget",
name: "widget",
url: widgetUrl,
};
await matrixClient.sendStateEvent(roomId, "im.vector.modular.widgets", content, WIDGET_ID);
})
.as("widgetEventSent");
// set initial layout
cy.getClient()
.then(async (matrixClient) => {
const content = {
widgets: {
[WIDGET_ID]: {
container: "top",
index: 1,
width: 100,
height: 0,
},
},
};
await matrixClient.sendStateEvent(roomId, "io.element.widgets.layout", content, "");
})
.as("layoutEventSent");
});
cy.all([cy.get<string>("@widgetEventSent"), cy.get<string>("@layoutEventSent")]).then(() => {
// open the room
cy.viewRoomByName(ROOM_NAME);
});
});
it("should highlight the apps button", () => {
// Assert that AppsDrawer is rendered
cy.get(".mx_AppsDrawer").should("exist");
cy.get(".mx_RoomHeader").within(() => {
// Assert that "Hide Widgets" button is rendered and aria-checked is set to true
cy.findByRole("button", { name: "Hide Widgets" })
.should("exist")
.should("have.attr", "aria-checked", "true");
});
cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with apps button (highlighted)");
});
it("should support hiding a widget", () => {
cy.get(".mx_AppsDrawer").should("exist");
cy.get(".mx_RoomHeader").within(() => {
// Click the apps button to hide AppsDrawer
cy.findByRole("button", { name: "Hide Widgets" }).should("exist").click();
// Assert that "Show widgets" button is rendered and aria-checked is set to false
cy.findByRole("button", { name: "Show Widgets" })
.should("exist")
.should("have.attr", "aria-checked", "false");
});
// Assert that AppsDrawer is not rendered
cy.get(".mx_AppsDrawer").should("not.exist");
cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with apps button (not highlighted)");
});
});
});