You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
Add thread notification with server assistance (MSC3773) (#9400)
Co-authored-by: Janne Mareike Koschinski <janne@kuschku.de>
This commit is contained in:
@ -16,10 +16,15 @@ limitations under the License.
|
||||
|
||||
import { mocked } from 'jest-mock';
|
||||
import { ConditionKind, PushRuleActionName, TweakName } from "matrix-js-sdk/src/@types/PushRules";
|
||||
import { NotificationCountType, Room } from 'matrix-js-sdk/src/models/room';
|
||||
|
||||
import { stubClient } from "./test-utils";
|
||||
import { mkEvent, stubClient } from "./test-utils";
|
||||
import { MatrixClientPeg } from "../src/MatrixClientPeg";
|
||||
import { getRoomNotifsState, RoomNotifState } from "../src/RoomNotifs";
|
||||
import {
|
||||
getRoomNotifsState,
|
||||
RoomNotifState,
|
||||
getUnreadNotificationCount,
|
||||
} from "../src/RoomNotifs";
|
||||
|
||||
describe("RoomNotifs test", () => {
|
||||
beforeEach(() => {
|
||||
@ -83,4 +88,74 @@ describe("RoomNotifs test", () => {
|
||||
});
|
||||
expect(getRoomNotifsState("!roomId:server")).toBe(RoomNotifState.AllMessagesLoud);
|
||||
});
|
||||
|
||||
describe("getUnreadNotificationCount", () => {
|
||||
const ROOM_ID = "!roomId:example.org";
|
||||
const THREAD_ID = "$threadId";
|
||||
|
||||
let cli;
|
||||
let room: Room;
|
||||
beforeEach(() => {
|
||||
cli = MatrixClientPeg.get();
|
||||
room = new Room(ROOM_ID, cli, cli.getUserId());
|
||||
});
|
||||
|
||||
it("counts room notification type", () => {
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(0);
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(0);
|
||||
});
|
||||
|
||||
it("counts notifications type", () => {
|
||||
room.setUnreadNotificationCount(NotificationCountType.Total, 2);
|
||||
room.setUnreadNotificationCount(NotificationCountType.Highlight, 1);
|
||||
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(2);
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(1);
|
||||
});
|
||||
|
||||
it("counts predecessor highlight", () => {
|
||||
room.setUnreadNotificationCount(NotificationCountType.Total, 2);
|
||||
room.setUnreadNotificationCount(NotificationCountType.Highlight, 1);
|
||||
|
||||
const OLD_ROOM_ID = "!oldRoomId:example.org";
|
||||
const oldRoom = new Room(OLD_ROOM_ID, cli, cli.getUserId());
|
||||
oldRoom.setUnreadNotificationCount(NotificationCountType.Total, 10);
|
||||
oldRoom.setUnreadNotificationCount(NotificationCountType.Highlight, 6);
|
||||
|
||||
cli.getRoom.mockReset().mockReturnValue(oldRoom);
|
||||
|
||||
const predecessorEvent = mkEvent({
|
||||
event: true,
|
||||
type: "m.room.create",
|
||||
room: ROOM_ID,
|
||||
user: cli.getUserId(),
|
||||
content: {
|
||||
creator: cli.getUserId(),
|
||||
room_version: "5",
|
||||
predecessor: {
|
||||
room_id: OLD_ROOM_ID,
|
||||
event_id: "$someevent",
|
||||
},
|
||||
},
|
||||
ts: Date.now(),
|
||||
});
|
||||
room.addLiveEvents([predecessorEvent]);
|
||||
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Total)).toBe(8);
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight)).toBe(7);
|
||||
});
|
||||
|
||||
it("counts thread notification type", () => {
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Total, THREAD_ID)).toBe(0);
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, THREAD_ID)).toBe(0);
|
||||
});
|
||||
|
||||
it("counts notifications type", () => {
|
||||
room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total, 2);
|
||||
room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight, 1);
|
||||
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Total, THREAD_ID)).toBe(2);
|
||||
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, THREAD_ID)).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user