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

Commit 7d0c68a

Browse files
authored
Edit room-header.spec.ts to check apps button (#10934)
* Edit room-header.spec.ts to check apps button * Check aria-checked status instead * Edit a comment
1 parent fabfae1 commit 7d0c68a

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

cypress/e2e/room/room-header.spec.ts

+99
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ limitations under the License.
1616

1717
/// <reference types="cypress" />
1818

19+
import { IWidget } from "matrix-widget-api";
20+
1921
import { HomeserverInstance } from "../../plugins/utils/homeserver";
2022
import { SettingLevel } from "../../../src/settings/SettingLevel";
2123

@@ -190,4 +192,101 @@ describe("Room Header", () => {
190192
});
191193
});
192194
});
195+
196+
describe("with a widget", () => {
197+
const ROOM_NAME = "Test Room with a widget";
198+
const WIDGET_ID = "fake-widget";
199+
const WIDGET_HTML = `
200+
<html lang="en">
201+
<head>
202+
<title>Fake Widget</title>
203+
</head>
204+
<body>
205+
Hello World
206+
</body>
207+
</html>
208+
`;
209+
210+
let widgetUrl: string;
211+
let roomId: string;
212+
213+
beforeEach(() => {
214+
cy.serveHtmlFile(WIDGET_HTML).then((url) => {
215+
widgetUrl = url;
216+
});
217+
218+
cy.createRoom({ name: ROOM_NAME }).then((id) => {
219+
roomId = id;
220+
221+
// setup widget via state event
222+
cy.getClient()
223+
.then(async (matrixClient) => {
224+
const content: IWidget = {
225+
id: WIDGET_ID,
226+
creatorUserId: "somebody",
227+
type: "widget",
228+
name: "widget",
229+
url: widgetUrl,
230+
};
231+
await matrixClient.sendStateEvent(roomId, "im.vector.modular.widgets", content, WIDGET_ID);
232+
})
233+
.as("widgetEventSent");
234+
235+
// set initial layout
236+
cy.getClient()
237+
.then(async (matrixClient) => {
238+
const content = {
239+
widgets: {
240+
[WIDGET_ID]: {
241+
container: "top",
242+
index: 1,
243+
width: 100,
244+
height: 0,
245+
},
246+
},
247+
};
248+
await matrixClient.sendStateEvent(roomId, "io.element.widgets.layout", content, "");
249+
})
250+
.as("layoutEventSent");
251+
});
252+
253+
cy.all([cy.get<string>("@widgetEventSent"), cy.get<string>("@layoutEventSent")]).then(() => {
254+
// open the room
255+
cy.viewRoomByName(ROOM_NAME);
256+
});
257+
});
258+
259+
it("should highlight the apps button", () => {
260+
// Assert that AppsDrawer is rendered
261+
cy.get(".mx_AppsDrawer").should("exist");
262+
263+
cy.get(".mx_RoomHeader").within(() => {
264+
// Assert that "Hide Widgets" button is rendered and aria-checked is set to true
265+
cy.findByRole("button", { name: "Hide Widgets" })
266+
.should("exist")
267+
.should("have.attr", "aria-checked", "true");
268+
});
269+
270+
cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with apps button (highlighted)");
271+
});
272+
273+
it("should support hiding a widget", () => {
274+
cy.get(".mx_AppsDrawer").should("exist");
275+
276+
cy.get(".mx_RoomHeader").within(() => {
277+
// Click the apps button to hide AppsDrawer
278+
cy.findByRole("button", { name: "Hide Widgets" }).should("exist").click();
279+
280+
// Assert that "Show widgets" button is rendered and aria-checked is set to false
281+
cy.findByRole("button", { name: "Show Widgets" })
282+
.should("exist")
283+
.should("have.attr", "aria-checked", "false");
284+
});
285+
286+
// Assert that AppsDrawer is not rendered
287+
cy.get(".mx_AppsDrawer").should("not.exist");
288+
289+
cy.get(".mx_RoomHeader").percySnapshotElement("Room header - with apps button (not highlighted)");
290+
});
291+
});
193292
});

src/components/views/rooms/RoomHeader.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ export default class RoomHeader extends React.Component<IProps, IState> {
591591
})}
592592
onClick={this.props.onAppsClick}
593593
title={this.props.appsShown ? _t("Hide Widgets") : _t("Show Widgets")}
594+
aria-checked={this.props.appsShown}
594595
alignment={Alignment.Bottom}
595596
key="apps"
596597
/>,

0 commit comments

Comments
 (0)