Add mark as read option in room setting (#9798)
This commit is contained in:
parent
ce75d3381f
commit
e9224f6fce
9 changed files with 378 additions and 37 deletions
|
@ -26,6 +26,7 @@ import {
|
|||
createLocalNotificationSettingsIfNeeded,
|
||||
deviceNotificationSettingsKeys,
|
||||
clearAllNotifications,
|
||||
clearRoomNotification,
|
||||
} from "../../src/utils/notifications";
|
||||
import SettingsStore from "../../src/settings/SettingsStore";
|
||||
import { getMockClientWithEventEmitter } from "../test-utils/client";
|
||||
|
@ -107,10 +108,44 @@ describe("notifications", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("clearRoomNotification", () => {
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
let sendReadReceiptSpy: jest.SpyInstance;
|
||||
const ROOM_ID = "123";
|
||||
const USER_ID = "@bob:example.org";
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.get());
|
||||
room = new Room(ROOM_ID, client, USER_ID);
|
||||
sendReadReceiptSpy = jest.spyOn(client, "sendReadReceipt").mockResolvedValue({});
|
||||
jest.spyOn(client, "getRooms").mockReturnValue([room]);
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
|
||||
return name === "sendReadReceipts";
|
||||
});
|
||||
});
|
||||
|
||||
it("sends a request even if everything has been read", () => {
|
||||
clearRoomNotification(room, client);
|
||||
expect(sendReadReceiptSpy).not.toBeCalled();
|
||||
});
|
||||
|
||||
it("marks the room as read even if the receipt failed", async () => {
|
||||
room.setUnreadNotificationCount(NotificationCountType.Total, 5);
|
||||
sendReadReceiptSpy = jest.spyOn(client, "sendReadReceipt").mockReset().mockRejectedValue({});
|
||||
try {
|
||||
await clearRoomNotification(room, client);
|
||||
} finally {
|
||||
expect(room.getUnreadNotificationCount(NotificationCountType.Total)).toBe(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("clearAllNotifications", () => {
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
let sendReadReceiptSpy;
|
||||
let sendReadReceiptSpy: jest.SpyInstance;
|
||||
|
||||
const ROOM_ID = "123";
|
||||
const USER_ID = "@bob:example.org";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue