Merge branch 'develop' into andybalaam/stas-demydiuk-membership-type3
This commit is contained in:
commit
d7bdbee8d2
124 changed files with 2399 additions and 1052 deletions
|
@ -18,7 +18,7 @@ import { textToHtmlRainbow } from "../../src/utils/colour";
|
|||
|
||||
describe("textToHtmlRainbow", () => {
|
||||
it("correctly transform text to html without splitting the emoji in two", () => {
|
||||
expect(textToHtmlRainbow("🐻")).toBe('<font color="#ff00be">🐻</font>');
|
||||
expect(textToHtmlRainbow("🐕🦺")).toBe('<font color="#ff00be">🐕🦺</font>');
|
||||
expect(textToHtmlRainbow("🐻")).toBe('<span data-mx-color="#ff00be">🐻</span>');
|
||||
expect(textToHtmlRainbow("🐕🦺")).toBe('<span data-mx-color="#ff00be">🐕🦺</span>');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -26,6 +26,8 @@ import {
|
|||
clearRoomNotification,
|
||||
notificationLevelToIndicator,
|
||||
getThreadNotificationLevel,
|
||||
getMarkedUnreadState,
|
||||
setMarkedUnreadState,
|
||||
} from "../../src/utils/notifications";
|
||||
import SettingsStore from "../../src/settings/SettingsStore";
|
||||
import { getMockClientWithEventEmitter } from "../test-utils/client";
|
||||
|
@ -135,8 +137,8 @@ describe("notifications", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("sends a request even if everything has been read", () => {
|
||||
clearRoomNotification(room, client);
|
||||
it("sends a request even if everything has been read", async () => {
|
||||
await clearRoomNotification(room, client);
|
||||
expect(sendReadReceiptSpy).toHaveBeenCalledWith(message, ReceiptType.Read, true);
|
||||
});
|
||||
|
||||
|
@ -155,8 +157,8 @@ describe("notifications", () => {
|
|||
sendReceiptsSetting = false;
|
||||
});
|
||||
|
||||
it("should send a private read receipt", () => {
|
||||
clearRoomNotification(room, client);
|
||||
it("should send a private read receipt", async () => {
|
||||
await clearRoomNotification(room, client);
|
||||
expect(sendReadReceiptSpy).toHaveBeenCalledWith(message, ReceiptType.ReadPrivate, true);
|
||||
});
|
||||
});
|
||||
|
@ -186,7 +188,7 @@ describe("notifications", () => {
|
|||
expect(sendReadReceiptSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sends unthreaded receipt requests", () => {
|
||||
it("sends unthreaded receipt requests", async () => {
|
||||
const message = mkMessage({
|
||||
event: true,
|
||||
room: ROOM_ID,
|
||||
|
@ -196,12 +198,12 @@ describe("notifications", () => {
|
|||
room.addLiveEvents([message]);
|
||||
room.setUnreadNotificationCount(NotificationCountType.Total, 1);
|
||||
|
||||
clearAllNotifications(client);
|
||||
await clearAllNotifications(client);
|
||||
|
||||
expect(sendReadReceiptSpy).toHaveBeenCalledWith(message, ReceiptType.Read, true);
|
||||
});
|
||||
|
||||
it("sends private read receipts", () => {
|
||||
it("sends private read receipts", async () => {
|
||||
const message = mkMessage({
|
||||
event: true,
|
||||
room: ROOM_ID,
|
||||
|
@ -213,12 +215,121 @@ describe("notifications", () => {
|
|||
|
||||
jest.spyOn(SettingsStore, "getValue").mockReset().mockReturnValue(false);
|
||||
|
||||
clearAllNotifications(client);
|
||||
await clearAllNotifications(client);
|
||||
|
||||
expect(sendReadReceiptSpy).toHaveBeenCalledWith(message, ReceiptType.ReadPrivate, true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getMarkedUnreadState", () => {
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
|
||||
const ROOM_ID = "123";
|
||||
const USER_ID = "@bob:example.org";
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.safeGet());
|
||||
room = new Room(ROOM_ID, client, USER_ID);
|
||||
});
|
||||
|
||||
it("reads from stable prefix", async () => {
|
||||
room.getAccountData = jest.fn().mockImplementation((eventType: string) => {
|
||||
if (eventType === "m.marked_unread") {
|
||||
return { getContent: jest.fn().mockReturnValue({ unread: true }) };
|
||||
}
|
||||
return null;
|
||||
});
|
||||
expect(getMarkedUnreadState(room)).toBe(true);
|
||||
});
|
||||
|
||||
it("reads from unstable prefix", async () => {
|
||||
room.getAccountData = jest.fn().mockImplementation((eventType: string) => {
|
||||
if (eventType === "com.famedly.marked_unread") {
|
||||
return { getContent: jest.fn().mockReturnValue({ unread: true }) };
|
||||
}
|
||||
return null;
|
||||
});
|
||||
expect(getMarkedUnreadState(room)).toBe(true);
|
||||
});
|
||||
|
||||
it("returns undefined if neither prefix is present", async () => {
|
||||
room.getAccountData = jest.fn().mockImplementation((eventType: string) => {
|
||||
return null;
|
||||
});
|
||||
expect(getMarkedUnreadState(room)).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe("setUnreadMarker", () => {
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
|
||||
const ROOM_ID = "123";
|
||||
const USER_ID = "@bob:example.org";
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.safeGet());
|
||||
room = new Room(ROOM_ID, client, USER_ID);
|
||||
});
|
||||
|
||||
// set true, no existing event
|
||||
it("sets unread flag if event doesn't exist", async () => {
|
||||
await setMarkedUnreadState(room, client, true);
|
||||
expect(client.setRoomAccountData).toHaveBeenCalledWith(ROOM_ID, "com.famedly.marked_unread", {
|
||||
unread: true,
|
||||
});
|
||||
});
|
||||
|
||||
// set false, no existing event
|
||||
it("does nothing when clearing if flag is false", async () => {
|
||||
await setMarkedUnreadState(room, client, false);
|
||||
expect(client.setRoomAccountData).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// set true, existing event = false
|
||||
it("sets unread flag to if existing event is false", async () => {
|
||||
room.getAccountData = jest
|
||||
.fn()
|
||||
.mockReturnValue({ getContent: jest.fn().mockReturnValue({ unread: false }) });
|
||||
await setMarkedUnreadState(room, client, true);
|
||||
expect(client.setRoomAccountData).toHaveBeenCalledWith(ROOM_ID, "com.famedly.marked_unread", {
|
||||
unread: true,
|
||||
});
|
||||
});
|
||||
|
||||
// set false, existing event = false
|
||||
it("does nothing if set false and existing event is false", async () => {
|
||||
room.getAccountData = jest
|
||||
.fn()
|
||||
.mockReturnValue({ getContent: jest.fn().mockReturnValue({ unread: false }) });
|
||||
await setMarkedUnreadState(room, client, false);
|
||||
expect(client.setRoomAccountData).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// set true, existing event = true
|
||||
it("does nothing if setting true and existing event is true", async () => {
|
||||
room.getAccountData = jest
|
||||
.fn()
|
||||
.mockReturnValue({ getContent: jest.fn().mockReturnValue({ unread: true }) });
|
||||
await setMarkedUnreadState(room, client, true);
|
||||
expect(client.setRoomAccountData).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// set false, existing event = true
|
||||
it("sets flag if setting false and existing event is true", async () => {
|
||||
room.getAccountData = jest
|
||||
.fn()
|
||||
.mockReturnValue({ getContent: jest.fn().mockReturnValue({ unread: true }) });
|
||||
await setMarkedUnreadState(room, client, false);
|
||||
expect(client.setRoomAccountData).toHaveBeenCalledWith(ROOM_ID, "com.famedly.marked_unread", {
|
||||
unread: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("notificationLevelToIndicator", () => {
|
||||
it("returns undefined if notification level is None", () => {
|
||||
expect(notificationLevelToIndicator(NotificationLevel.None)).toBeUndefined();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue