Add activity toggle for TAC (#12413)

* Add activity toggle for TAC

* Update test snapshots for new toggles

* Add test for TAC activity setting set to false

* Update snapshot for old notifications panel test too

* Fix test

* Rename setting

* Rename variables too

* Sort i18n keys

* Use functional component
This commit is contained in:
David Baker 2024-04-12 14:18:09 +01:00 committed by GitHub
parent aadb46358b
commit 14cc44e820
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 262 additions and 46 deletions

View file

@ -30,6 +30,7 @@ import { stubClient } from "../../../test-utils";
import { populateThread } from "../../../test-utils/threads";
import { NotificationLevel } from "../../../../src/stores/notifications/NotificationLevel";
import { useUnreadThreadRooms } from "../../../../src/components/views/spaces/threads-activity-centre/useUnreadThreadRooms";
import SettingsStore from "../../../../src/settings/SettingsStore";
describe("useUnreadThreadRooms", () => {
let client: MatrixClient;
@ -43,6 +44,10 @@ describe("useUnreadThreadRooms", () => {
});
});
afterEach(() => {
jest.restoreAllMocks();
});
it("has no notifications with no rooms", async () => {
const { result } = renderHook(() => useUnreadThreadRooms(false));
const { greatestNotificationLevel, rooms } = result.current;
@ -51,7 +56,7 @@ describe("useUnreadThreadRooms", () => {
expect(rooms.length).toEqual(0);
});
it("an activity notification is ignored", async () => {
it("an activity notification is ignored by default", async () => {
const notifThreadInfo = await populateThread({
room: room,
client: client,
@ -73,6 +78,30 @@ describe("useUnreadThreadRooms", () => {
expect(rooms.length).toEqual(0);
});
it("an activity notification is displayed with the setting enabled", async () => {
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
const notifThreadInfo = await populateThread({
room: room,
client: client,
authorId: "@foo:bar",
participantUserIds: ["@fee:bar"],
});
room.setThreadUnreadNotificationCount(notifThreadInfo.thread.id, NotificationCountType.Total, 0);
client.getVisibleRooms = jest.fn().mockReturnValue([room]);
const wrapper = ({ children }: { children: React.ReactNode }) => (
<MatrixClientContext.Provider value={client}>{children}</MatrixClientContext.Provider>
);
const { result } = renderHook(() => useUnreadThreadRooms(true), { wrapper });
const { greatestNotificationLevel, rooms } = result.current;
expect(greatestNotificationLevel).toBe(NotificationLevel.Activity);
expect(rooms.length).toEqual(1);
});
it("a notification and a highlight summarise to a highlight", async () => {
const notifThreadInfo = await populateThread({
room: room,