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

Commit 406ffe1

Browse files
authored
Add test for useRoomThreadNotifications (#12140)
* Add test for useRoomThreadNotifications * Remove unused code
1 parent 02a8023 commit 406ffe1

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
Copyright 2024 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { renderHook } from "@testing-library/react-hooks/dom";
18+
import { MatrixClient, NotificationCountType, Room } from "matrix-js-sdk/src/matrix";
19+
20+
import { useRoomThreadNotifications } from "../../../src/hooks/room/useRoomThreadNotifications";
21+
import { stubClient } from "../../test-utils";
22+
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
23+
import { NotificationColor } from "../../../src/stores/notifications/NotificationColor";
24+
import { populateThread } from "../../test-utils/threads";
25+
26+
function render(room: Room) {
27+
return renderHook(() => useRoomThreadNotifications(room));
28+
}
29+
30+
describe("useRoomThreadNotifications", () => {
31+
let cli: MatrixClient;
32+
let room: Room;
33+
34+
beforeEach(() => {
35+
stubClient();
36+
cli = MatrixClientPeg.safeGet();
37+
cli.supportsThreads = () => true;
38+
room = new Room("!room:server", cli, cli.getSafeUserId());
39+
});
40+
41+
it("returns none if no thread in the room has notifications", async () => {
42+
const { result } = render(room);
43+
44+
expect(result.current).toBe(NotificationColor.None);
45+
});
46+
47+
it("returns red if a thread in the room has a highlight notification", async () => {
48+
room.setThreadUnreadNotificationCount("flooble", NotificationCountType.Highlight, 1);
49+
const { result } = render(room);
50+
51+
expect(result.current).toBe(NotificationColor.Red);
52+
});
53+
54+
it("returns grey if a thread in the room has a normal notification", async () => {
55+
room.setThreadUnreadNotificationCount("flooble", NotificationCountType.Total, 1);
56+
const { result } = render(room);
57+
58+
expect(result.current).toBe(NotificationColor.Grey);
59+
});
60+
61+
it("returns bold if a thread in the room unread messages", async () => {
62+
await populateThread({
63+
room,
64+
client: cli,
65+
authorId: cli.getSafeUserId(),
66+
participantUserIds: ["@alice:server.org"],
67+
});
68+
69+
const { result } = render(room);
70+
71+
expect(result.current).toBe(NotificationColor.Bold);
72+
});
73+
});

0 commit comments

Comments
 (0)