Skip to content

Commit ebe5837

Browse files
committed
test(new room list): add tests for RoomListView
1 parent 0af7fb5 commit ebe5837

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import React from "react";
9+
import { render, screen } from "jest-matrix-react";
10+
import { mocked } from "jest-mock";
11+
12+
import { RoomListView } from "../../../../../../src/components/views/rooms/RoomListView";
13+
import { shouldShowComponent } from "../../../../../../src/customisations/helpers/UIComponents";
14+
import { MetaSpace } from "../../../../../../src/stores/spaces";
15+
16+
jest.mock("../../../../../../src/customisations/helpers/UIComponents", () => ({
17+
shouldShowComponent: jest.fn(),
18+
}));
19+
20+
describe("<RoomListView />", () => {
21+
function renderComponent() {
22+
return render(<RoomListView activeSpace={MetaSpace.Home} />);
23+
}
24+
25+
beforeEach(() => {
26+
// By default, we consider shouldShowComponent(UIComponent.FilterContainer) should return true
27+
mocked(shouldShowComponent).mockReturnValue(true);
28+
});
29+
30+
it("should render the RoomListSearch component when UIComponent.FilterContainer is at true", () => {
31+
const { asFragment } = renderComponent();
32+
expect(screen.getByRole("button", { name: "Search Ctrl K" })).toBeInTheDocument();
33+
expect(asFragment()).toMatchSnapshot();
34+
});
35+
36+
it("should not render the RoomListSearch component when UIComponent.FilterContainer is at false", () => {
37+
mocked(shouldShowComponent).mockReturnValue(false);
38+
const { asFragment } = renderComponent();
39+
40+
expect(screen.queryByRole("button", { name: "Search Ctrl K" })).toBeNull();
41+
expect(asFragment()).toMatchSnapshot();
42+
});
43+
});
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<RoomListView /> should not render the RoomListSearch component when UIComponent.FilterContainer is at false 1`] = `
4+
<DocumentFragment>
5+
<div
6+
class="mx_RoomListView"
7+
/>
8+
</DocumentFragment>
9+
`;
10+
11+
exports[`<RoomListView /> should render the RoomListSearch component when UIComponent.FilterContainer is at true 1`] = `
12+
<DocumentFragment>
13+
<div
14+
class="mx_RoomListView"
15+
>
16+
<div
17+
class="mx_RoomListSearch"
18+
role="search"
19+
>
20+
<button
21+
class="_button_i91xf_17 mx_RoomListSearch_search _has-icon_i91xf_66"
22+
data-kind="secondary"
23+
data-size="sm"
24+
role="button"
25+
tabindex="0"
26+
>
27+
<svg
28+
aria-hidden="true"
29+
fill="currentColor"
30+
height="20"
31+
viewBox="0 0 24 24"
32+
width="20"
33+
xmlns="http://www.w3.org/2000/svg"
34+
>
35+
<path
36+
d="M15.05 16.463a7.5 7.5 0 1 1 1.414-1.414l3.243 3.244a1 1 0 0 1-1.414 1.414l-3.244-3.244ZM16 10.5a5.5 5.5 0 1 0-11 0 5.5 5.5 0 0 0 11 0Z"
37+
/>
38+
</svg>
39+
<span>
40+
Search
41+
<kbd>
42+
Ctrl K
43+
</kbd>
44+
</span>
45+
</button>
46+
<button
47+
aria-label="Explore rooms"
48+
class="_button_i91xf_17 mx_RoomListSearch_explore _has-icon_i91xf_66 _icon-only_i91xf_59"
49+
data-kind="secondary"
50+
data-size="sm"
51+
role="button"
52+
tabindex="0"
53+
>
54+
<svg
55+
aria-hidden="true"
56+
fill="currentColor"
57+
height="20"
58+
viewBox="0 0 24 24"
59+
width="20"
60+
xmlns="http://www.w3.org/2000/svg"
61+
>
62+
<path
63+
d="M12 13a.968.968 0 0 1-.713-.287A.968.968 0 0 1 11 12c0-.283.096-.52.287-.713A.968.968 0 0 1 12 11c.283 0 .52.096.713.287.191.192.287.43.287.713s-.096.52-.287.713A.968.968 0 0 1 12 13Zm0 9a9.738 9.738 0 0 1-3.9-.788 10.099 10.099 0 0 1-3.175-2.137c-.9-.9-1.612-1.958-2.137-3.175A9.738 9.738 0 0 1 2 12a9.74 9.74 0 0 1 .788-3.9 10.099 10.099 0 0 1 2.137-3.175c.9-.9 1.958-1.612 3.175-2.137A9.738 9.738 0 0 1 12 2a9.74 9.74 0 0 1 3.9.788 10.098 10.098 0 0 1 3.175 2.137c.9.9 1.613 1.958 2.137 3.175A9.738 9.738 0 0 1 22 12a9.738 9.738 0 0 1-.788 3.9 10.098 10.098 0 0 1-2.137 3.175c-.9.9-1.958 1.613-3.175 2.137A9.738 9.738 0 0 1 12 22Zm0-2c2.233 0 4.125-.775 5.675-2.325C19.225 16.125 20 14.233 20 12c0-2.233-.775-4.125-2.325-5.675C16.125 4.775 14.233 4 12 4c-2.233 0-4.125.775-5.675 2.325C4.775 7.875 4 9.767 4 12c0 2.233.775 4.125 2.325 5.675C7.875 19.225 9.767 20 12 20Zm0 0c-2.233 0-4.125-.775-5.675-2.325C4.775 16.125 4 14.233 4 12c0-2.233.775-4.125 2.325-5.675C7.875 4.775 9.767 4 12 4c2.233 0 4.125.775 5.675 2.325C19.225 7.875 20 9.767 20 12c0 2.233-.775 4.125-2.325 5.675C16.125 19.225 14.233 20 12 20Zm1.675-5.85c.1-.05.192-.117.275-.2.083-.083.15-.175.2-.275l2.925-6.25c.083-.167.063-.313-.063-.438-.125-.125-.27-.145-.437-.062l-6.25 2.925c-.1.05-.192.117-.275.2-.083.083-.15.175-.2.275l-2.925 6.25c-.083.167-.063.313.063.438.124.124.27.145.437.062l6.25-2.925Z"
64+
/>
65+
</svg>
66+
</button>
67+
</div>
68+
</div>
69+
</DocumentFragment>
70+
`;

0 commit comments

Comments
 (0)