@@ -1242,6 +1245,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = `
>
@@ -1272,6 +1276,7 @@ exports[`PreferencesUserSettingsTab should render 1`] = `
diff --git a/test/unit-tests/utils/notifications-test.ts b/test/unit-tests/utils/notifications-test.ts
index 2c603ce1b1..29810aa897 100644
--- a/test/unit-tests/utils/notifications-test.ts
+++ b/test/unit-tests/utils/notifications-test.ts
@@ -28,14 +28,13 @@ import {
getMarkedUnreadState,
setMarkedUnreadState,
} from "../../../src/utils/notifications";
-import SettingsStore from "../../../src/settings/SettingsStore";
-import { getMockClientWithEventEmitter } from "../../test-utils/client";
+import { getMockClientWithEventEmitter, mockClientMethodsServer } from "../../test-utils/client";
import { mkMessage, stubClient } from "../../test-utils/test-utils";
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
import { NotificationLevel } from "../../../src/stores/notifications/NotificationLevel";
import { SettingLevel } from "../../../src/settings/SettingLevel";
-
-jest.mock("../../../src/settings/SettingsStore");
+import MatrixClientBackedController from "../../../src/settings/controllers/MatrixClientBackedController";
+import SettingsStore from "../../../src/settings/SettingsStore";
describe("notifications", () => {
let accountDataStore: Record = {};
@@ -45,6 +44,7 @@ describe("notifications", () => {
beforeEach(() => {
jest.clearAllMocks();
mockClient = getMockClientWithEventEmitter({
+ ...mockClientMethodsServer(),
isGuest: jest.fn().mockReturnValue(false),
getAccountData: jest.fn().mockImplementation((eventType) => accountDataStore[eventType]),
setAccountData: jest.fn().mockImplementation((eventType, content) => {
@@ -53,10 +53,20 @@ describe("notifications", () => {
content,
});
}),
+ isVersionSupported: jest.fn().mockImplementation(async (v) => v === "v1.4"),
});
+
+ // Ensure unstable settings are supported, otherwise it will use the default value.
+ MatrixClientBackedController.matrixClient = mockClient;
accountDataStore = {};
accountDataEventKey = getLocalNotificationAccountDataEventType(mockClient.deviceId!);
- mocked(SettingsStore).getValue.mockReturnValue(false);
+ // Disable all notifications
+ deviceNotificationSettingsKeys.forEach((k) => SettingsStore.setValue(k, null, SettingLevel.DEVICE, false));
+ });
+
+ afterEach(() => {
+ jest.restoreAllMocks();
+ SettingsStore.reset();
});
describe("createLocalNotification", () => {
@@ -76,10 +86,15 @@ describe("notifications", () => {
it.each(deviceNotificationSettingsKeys)(
"unsilenced for existing sessions when %s setting is truthy",
async (settingKey) => {
- mocked(SettingsStore).getValue.mockImplementation((key): any => {
- return key === settingKey;
+ // We need to spy `getValue` because setting these keys requires mocking
+ // the platform to support notifications, which is out of scope for this test.
+ const origFn = SettingsStore.getValue;
+ jest.spyOn(SettingsStore, "getValue").mockImplementation((name, ...args) => {
+ if (name === settingKey) {
+ return true;
+ }
+ return origFn(name, ...args);
});
-
await createLocalNotificationSettingsIfNeeded(mockClient);
const event = mockClient.getAccountData(accountDataEventKey);
expect(event?.getContent().is_silenced).toBe(false);
@@ -117,11 +132,6 @@ describe("notifications", () => {
const ROOM_ID = "123";
const USER_ID = "@bob:example.org";
let message: MatrixEvent;
- const sendReceiptsSetting = true;
-
- afterEach(() => {
- SettingsStore.reset();
- });
beforeEach(() => {
stubClient();
@@ -136,7 +146,7 @@ describe("notifications", () => {
room.addLiveEvents([message], { addToState: true });
sendReadReceiptSpy = jest.spyOn(client, "sendReadReceipt").mockResolvedValue({});
jest.spyOn(client, "getRooms").mockReturnValue([room]);
- SettingsStore.setValue("sendReadReceipts", null, SettingLevel.ACCOUNT, sendReceiptsSetting);
+ SettingsStore.setValue("sendReadReceipts", null, SettingLevel.DEVICE, true);
});
it("sends a request even if everything has been read", async () => {
@@ -156,7 +166,7 @@ describe("notifications", () => {
describe("when sendReadReceipts setting is disabled", () => {
it("should send a private read receipt", async () => {
- SettingsStore.setValue("sendReadReceipts", null, SettingLevel.ACCOUNT, sendReceiptsSetting);
+ SettingsStore.setValue("sendReadReceipts", null, SettingLevel.DEVICE, false);
await clearRoomNotification(room, client);
expect(sendReadReceiptSpy).toHaveBeenCalledWith(message, ReceiptType.ReadPrivate, true);
});
@@ -177,11 +187,7 @@ describe("notifications", () => {
room = new Room(ROOM_ID, client, USER_ID);
sendReadReceiptSpy = jest.spyOn(client, "sendReadReceipt").mockResolvedValue({});
jest.spyOn(client, "getRooms").mockReturnValue([room]);
- SettingsStore.setValue("sendReadReceipts", null, SettingLevel.ACCOUNT, true);
- });
-
- afterEach(() => {
- SettingsStore.reset();
+ SettingsStore.setValue("sendReadReceipts", null, SettingLevel.DEVICE, true);
});
it("does not send any requests if everything has been read", () => {
@@ -214,7 +220,7 @@ describe("notifications", () => {
room.addLiveEvents([message], { addToState: true });
room.setUnreadNotificationCount(NotificationCountType.Total, 1);
- SettingsStore.setValue("sendReadReceipts", null, SettingLevel.ACCOUNT, false);
+ SettingsStore.setValue("sendReadReceipts", null, SettingLevel.DEVICE, false);
await clearAllNotifications(client);