2022-01-06 09:47:03 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-05-05 08:13:50 +00:00
|
|
|
Copyright 2022, 2023 The Matrix.org Foundation C.I.C.
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-01-06 09:47:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2022-09-28 17:13:09 +00:00
|
|
|
import {
|
|
|
|
IPushRule,
|
|
|
|
IPushRules,
|
|
|
|
RuleId,
|
|
|
|
IPusher,
|
|
|
|
LOCAL_NOTIFICATION_SETTINGS_PREFIX,
|
|
|
|
MatrixEvent,
|
2022-11-15 10:27:13 +00:00
|
|
|
Room,
|
2023-02-13 11:39:16 +00:00
|
|
|
PushRuleActionName,
|
2023-03-02 05:33:19 +00:00
|
|
|
TweakName,
|
|
|
|
ConditionKind,
|
|
|
|
IPushRuleCondition,
|
2023-05-05 08:13:50 +00:00
|
|
|
PushRuleKind,
|
2023-08-23 09:04:25 +00:00
|
|
|
IThreepid,
|
|
|
|
ThreepidMedium,
|
2022-09-28 17:13:09 +00:00
|
|
|
} from "matrix-js-sdk/src/matrix";
|
2023-04-21 09:48:48 +00:00
|
|
|
import { randomString } from "matrix-js-sdk/src/randomstring";
|
2024-08-06 17:22:02 +00:00
|
|
|
import {
|
|
|
|
act,
|
|
|
|
fireEvent,
|
|
|
|
getByTestId,
|
|
|
|
render,
|
|
|
|
screen,
|
|
|
|
waitFor,
|
|
|
|
waitForElementToBeRemoved,
|
|
|
|
within,
|
2024-10-14 16:11:58 +00:00
|
|
|
} from "jest-matrix-react";
|
2023-04-21 09:48:48 +00:00
|
|
|
import { mocked } from "jest-mock";
|
2023-05-05 08:13:50 +00:00
|
|
|
import userEvent from "@testing-library/user-event";
|
2022-01-06 09:47:03 +00:00
|
|
|
|
|
|
|
import Notifications from "../../../../src/components/views/settings/Notifications";
|
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
|
|
|
import { StandardActions } from "../../../../src/notifications/StandardActions";
|
2023-05-05 08:13:50 +00:00
|
|
|
import { clearAllModals, getMockClientWithEventEmitter, mkMessage, mockClientMethodsUser } from "../../../test-utils";
|
2022-01-06 09:47:03 +00:00
|
|
|
|
|
|
|
// don't pollute test output with error logs from mock rejections
|
|
|
|
jest.mock("matrix-js-sdk/src/logger");
|
|
|
|
|
2022-05-10 13:13:02 +00:00
|
|
|
// Avoid indirectly importing any eagerly created stores that would require extra setup
|
|
|
|
jest.mock("../../../../src/Notifier");
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
const masterRule: IPushRule = {
|
|
|
|
actions: [PushRuleActionName.DontNotify],
|
2022-01-06 09:47:03 +00:00
|
|
|
conditions: [],
|
|
|
|
default: true,
|
|
|
|
enabled: false,
|
|
|
|
rule_id: RuleId.Master,
|
|
|
|
};
|
2023-02-13 11:39:16 +00:00
|
|
|
const oneToOneRule: IPushRule = {
|
2022-01-06 09:47:03 +00:00
|
|
|
conditions: [
|
2023-03-02 05:33:19 +00:00
|
|
|
{ kind: ConditionKind.RoomMemberCount, is: "2" },
|
|
|
|
{ kind: ConditionKind.EventMatch, key: "type", pattern: "m.room.message" },
|
2022-01-06 09:47:03 +00:00
|
|
|
],
|
2023-03-02 05:33:19 +00:00
|
|
|
actions: [PushRuleActionName.Notify, { set_tweak: TweakName.Highlight, value: false }],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".m.rule.room_one_to_one",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
2023-02-13 11:39:16 +00:00
|
|
|
const encryptedOneToOneRule: IPushRule = {
|
2022-01-06 09:47:03 +00:00
|
|
|
conditions: [
|
2023-03-02 05:33:19 +00:00
|
|
|
{ kind: ConditionKind.RoomMemberCount, is: "2" },
|
|
|
|
{ kind: ConditionKind.EventMatch, key: "type", pattern: "m.room.encrypted" },
|
|
|
|
],
|
|
|
|
actions: [
|
|
|
|
PushRuleActionName.Notify,
|
|
|
|
{ set_tweak: TweakName.Sound, value: "default" },
|
|
|
|
{ set_tweak: TweakName.Highlight, value: false },
|
2022-01-06 09:47:03 +00:00
|
|
|
],
|
|
|
|
rule_id: ".m.rule.encrypted_room_one_to_one",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
2023-03-02 05:33:19 +00:00
|
|
|
const groupRule = {
|
|
|
|
conditions: [{ kind: ConditionKind.EventMatch, key: "type", pattern: "m.room.message" }],
|
|
|
|
actions: [
|
|
|
|
PushRuleActionName.Notify,
|
|
|
|
{ set_tweak: TweakName.Sound, value: "default" },
|
|
|
|
{ set_tweak: TweakName.Highlight, value: false },
|
|
|
|
],
|
|
|
|
rule_id: ".m.rule.message",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
};
|
2023-02-13 11:39:16 +00:00
|
|
|
const encryptedGroupRule: IPushRule = {
|
2023-03-02 05:33:19 +00:00
|
|
|
conditions: [{ kind: ConditionKind.EventMatch, key: "type", pattern: "m.room.encrypted" }],
|
|
|
|
actions: [PushRuleActionName.DontNotify],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".m.rule.encrypted",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
2023-03-13 21:59:04 +00:00
|
|
|
|
|
|
|
const bananaRule = {
|
|
|
|
actions: [PushRuleActionName.Notify, { set_tweak: TweakName.Highlight, value: false }],
|
|
|
|
pattern: "banana",
|
|
|
|
rule_id: "banana",
|
|
|
|
default: false,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
|
|
|
|
2022-01-06 09:47:03 +00:00
|
|
|
const pushRules: IPushRules = {
|
|
|
|
global: {
|
|
|
|
underride: [
|
|
|
|
{
|
2023-03-02 05:33:19 +00:00
|
|
|
conditions: [{ kind: ConditionKind.EventMatch, key: "type", pattern: "m.call.invite" }],
|
|
|
|
actions: [
|
|
|
|
PushRuleActionName.Notify,
|
|
|
|
{ set_tweak: TweakName.Sound, value: "ring" },
|
|
|
|
{ set_tweak: TweakName.Highlight, value: false },
|
|
|
|
],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".m.rule.call",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
oneToOneRule,
|
|
|
|
encryptedOneToOneRule,
|
2023-03-02 05:33:19 +00:00
|
|
|
groupRule,
|
2022-01-06 09:47:03 +00:00
|
|
|
encryptedGroupRule,
|
|
|
|
{
|
|
|
|
conditions: [
|
2023-03-02 05:33:19 +00:00
|
|
|
{ kind: ConditionKind.EventMatch, key: "type", pattern: "im.vector.modular.widgets" },
|
|
|
|
{ kind: ConditionKind.EventMatch, key: "content.type", pattern: "jitsi" },
|
|
|
|
{ kind: ConditionKind.EventMatch, key: "state_key", pattern: "*" },
|
2022-01-06 09:47:03 +00:00
|
|
|
],
|
2023-03-02 05:33:19 +00:00
|
|
|
actions: [PushRuleActionName.Notify, { set_tweak: TweakName.Highlight, value: false }],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".im.vector.jitsi",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
sender: [],
|
2023-03-02 05:33:19 +00:00
|
|
|
room: [
|
|
|
|
{
|
|
|
|
actions: [PushRuleActionName.DontNotify],
|
|
|
|
rule_id: "!zJPyWqpMorfCcWObge:matrix.org",
|
|
|
|
default: false,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
],
|
2022-01-06 09:47:03 +00:00
|
|
|
content: [
|
2023-03-13 21:59:04 +00:00
|
|
|
bananaRule,
|
2022-01-06 09:47:03 +00:00
|
|
|
{
|
2023-03-02 05:33:19 +00:00
|
|
|
actions: [
|
|
|
|
PushRuleActionName.Notify,
|
|
|
|
{ set_tweak: TweakName.Sound, value: "default" },
|
|
|
|
{ set_tweak: TweakName.Highlight },
|
|
|
|
],
|
2022-01-06 09:47:03 +00:00
|
|
|
pattern: "kadev1",
|
|
|
|
rule_id: ".m.rule.contains_user_name",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
override: [
|
|
|
|
{
|
2023-03-02 05:33:19 +00:00
|
|
|
conditions: [],
|
|
|
|
actions: [PushRuleActionName.DontNotify],
|
|
|
|
rule_id: ".m.rule.master",
|
|
|
|
default: true,
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [{ kind: ConditionKind.EventMatch, key: "content.msgtype", pattern: "m.notice" }],
|
|
|
|
actions: [PushRuleActionName.DontNotify],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".m.rule.suppress_notices",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [
|
2023-03-02 05:33:19 +00:00
|
|
|
{ kind: ConditionKind.EventMatch, key: "type", pattern: "m.room.member" },
|
|
|
|
{ kind: ConditionKind.EventMatch, key: "content.membership", pattern: "invite" },
|
|
|
|
{ kind: ConditionKind.EventMatch, key: "state_key", pattern: "@kadev1:matrix.org" },
|
|
|
|
],
|
|
|
|
actions: [
|
|
|
|
PushRuleActionName.Notify,
|
|
|
|
{ set_tweak: TweakName.Sound, value: "default" },
|
|
|
|
{ set_tweak: TweakName.Highlight, value: false },
|
2022-01-06 09:47:03 +00:00
|
|
|
],
|
|
|
|
rule_id: ".m.rule.invite_for_me",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
2023-03-02 05:33:19 +00:00
|
|
|
conditions: [{ kind: ConditionKind.EventMatch, key: "type", pattern: "m.room.member" }],
|
|
|
|
actions: [PushRuleActionName.DontNotify],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".m.rule.member_event",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [{ kind: "contains_display_name" }],
|
2023-03-02 05:33:19 +00:00
|
|
|
actions: [
|
|
|
|
PushRuleActionName.Notify,
|
|
|
|
{ set_tweak: TweakName.Sound, value: "default" },
|
|
|
|
{ set_tweak: TweakName.Highlight },
|
|
|
|
],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".m.rule.contains_display_name",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [
|
2023-03-02 05:33:19 +00:00
|
|
|
{ kind: ConditionKind.EventMatch, key: "content.body", pattern: "@room" },
|
2022-01-06 09:47:03 +00:00
|
|
|
{ kind: "sender_notification_permission", key: "room" },
|
|
|
|
],
|
2023-03-02 05:33:19 +00:00
|
|
|
actions: [PushRuleActionName.Notify, { set_tweak: TweakName.Highlight, value: true }],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".m.rule.roomnotif",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [
|
2023-03-02 05:33:19 +00:00
|
|
|
{ kind: ConditionKind.EventMatch, key: "type", pattern: "m.room.tombstone" },
|
|
|
|
{ kind: ConditionKind.EventMatch, key: "state_key", pattern: "" },
|
2022-01-06 09:47:03 +00:00
|
|
|
],
|
2023-03-02 05:33:19 +00:00
|
|
|
actions: [PushRuleActionName.Notify, { set_tweak: TweakName.Highlight, value: true }],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".m.rule.tombstone",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
2023-03-02 05:33:19 +00:00
|
|
|
conditions: [{ kind: ConditionKind.EventMatch, key: "type", pattern: "m.reaction" }],
|
|
|
|
actions: [PushRuleActionName.DontNotify],
|
2022-01-06 09:47:03 +00:00
|
|
|
rule_id: ".m.rule.reaction",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
2022-12-12 11:24:14 +00:00
|
|
|
],
|
2022-01-06 09:47:03 +00:00
|
|
|
},
|
|
|
|
device: {},
|
|
|
|
} as IPushRules;
|
2022-12-12 11:24:14 +00:00
|
|
|
|
2022-11-30 11:32:56 +00:00
|
|
|
const flushPromises = async () => await new Promise((resolve) => window.setTimeout(resolve));
|
2022-12-12 11:24:14 +00:00
|
|
|
|
2022-01-06 09:47:03 +00:00
|
|
|
describe("<Notifications />", () => {
|
2022-11-15 10:27:13 +00:00
|
|
|
const getComponent = () => render(<Notifications />);
|
2022-01-06 09:47:03 +00:00
|
|
|
|
|
|
|
// get component, wait for async data and force a render
|
|
|
|
const getComponentAndWait = async () => {
|
|
|
|
const component = getComponent();
|
2024-08-06 17:22:02 +00:00
|
|
|
await waitForElementToBeRemoved(() => component.queryAllByRole("progressbar"));
|
2022-01-06 09:47:03 +00:00
|
|
|
return component;
|
|
|
|
};
|
|
|
|
|
2022-03-22 10:32:35 +00:00
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
2023-01-11 11:33:06 +00:00
|
|
|
...mockClientMethodsUser(),
|
2022-02-02 12:02:17 +00:00
|
|
|
getPushRules: jest.fn(),
|
|
|
|
getPushers: jest.fn(),
|
|
|
|
getThreePids: jest.fn(),
|
|
|
|
setPusher: jest.fn(),
|
2023-05-05 08:13:50 +00:00
|
|
|
removePusher: jest.fn(),
|
2022-02-02 12:02:17 +00:00
|
|
|
setPushRuleEnabled: jest.fn(),
|
|
|
|
setPushRuleActions: jest.fn(),
|
|
|
|
getRooms: jest.fn().mockReturnValue([]),
|
2022-09-28 17:13:09 +00:00
|
|
|
getAccountData: jest.fn().mockImplementation((eventType) => {
|
|
|
|
if (eventType.startsWith(LOCAL_NOTIFICATION_SETTINGS_PREFIX.name)) {
|
|
|
|
return new MatrixEvent({
|
|
|
|
type: eventType,
|
|
|
|
content: {
|
|
|
|
is_silenced: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
setAccountData: jest.fn(),
|
2022-11-15 10:27:13 +00:00
|
|
|
sendReadReceipt: jest.fn(),
|
2023-01-30 12:20:11 +00:00
|
|
|
supportsThreads: jest.fn().mockReturnValue(true),
|
2023-02-09 12:46:17 +00:00
|
|
|
isInitialSyncComplete: jest.fn().mockReturnValue(false),
|
2023-05-05 08:13:50 +00:00
|
|
|
addPushRule: jest.fn().mockResolvedValue({}),
|
|
|
|
deletePushRule: jest.fn().mockResolvedValue({}),
|
2022-03-22 10:32:35 +00:00
|
|
|
});
|
2022-01-06 09:47:03 +00:00
|
|
|
mockClient.getPushRules.mockResolvedValue(pushRules);
|
|
|
|
|
2023-05-05 08:13:50 +00:00
|
|
|
beforeEach(async () => {
|
2023-04-21 09:48:48 +00:00
|
|
|
let i = 0;
|
|
|
|
mocked(randomString).mockImplementation(() => {
|
|
|
|
return "testid_" + i++;
|
|
|
|
});
|
|
|
|
|
2022-01-06 09:47:03 +00:00
|
|
|
mockClient.getPushRules.mockClear().mockResolvedValue(pushRules);
|
|
|
|
mockClient.getPushers.mockClear().mockResolvedValue({ pushers: [] });
|
|
|
|
mockClient.getThreePids.mockClear().mockResolvedValue({ threepids: [] });
|
2023-05-05 08:13:50 +00:00
|
|
|
mockClient.setPusher.mockReset().mockResolvedValue({});
|
|
|
|
mockClient.removePusher.mockClear().mockResolvedValue({});
|
2023-03-13 21:59:04 +00:00
|
|
|
mockClient.setPushRuleActions.mockReset().mockResolvedValue({});
|
2023-03-02 05:33:19 +00:00
|
|
|
mockClient.pushRules = pushRules;
|
2023-05-05 08:13:50 +00:00
|
|
|
mockClient.getPushRules.mockClear().mockResolvedValue(pushRules);
|
|
|
|
mockClient.addPushRule.mockClear();
|
|
|
|
mockClient.deletePushRule.mockClear();
|
|
|
|
|
|
|
|
userEvent.setup();
|
|
|
|
|
|
|
|
await clearAllModals();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
2022-11-15 10:27:13 +00:00
|
|
|
it("renders spinner while loading", async () => {
|
|
|
|
getComponent();
|
|
|
|
expect(screen.getByTestId("spinner")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("renders error message when fetching push rules fails", async () => {
|
2022-02-02 12:02:17 +00:00
|
|
|
mockClient.getPushRules.mockRejectedValue({});
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
|
|
|
expect(screen.getByTestId("error-message")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
it("renders error message when fetching pushers fails", async () => {
|
2022-02-02 12:02:17 +00:00
|
|
|
mockClient.getPushers.mockRejectedValue({});
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
|
|
|
expect(screen.getByTestId("error-message")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
it("renders error message when fetching threepids fails", async () => {
|
2022-02-02 12:02:17 +00:00
|
|
|
mockClient.getThreePids.mockRejectedValue({});
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
|
|
|
expect(screen.getByTestId("error-message")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("main notification switches", () => {
|
|
|
|
it("renders only enable notifications switch when notifications are disabled", async () => {
|
|
|
|
const disableNotificationsPushRules = {
|
|
|
|
global: {
|
|
|
|
...pushRules.global,
|
|
|
|
override: [{ ...masterRule, enabled: true }],
|
|
|
|
},
|
2022-03-22 10:32:35 +00:00
|
|
|
} as unknown as IPushRules;
|
2022-01-06 09:47:03 +00:00
|
|
|
mockClient.getPushRules.mockClear().mockResolvedValue(disableNotificationsPushRules);
|
2022-11-15 10:27:13 +00:00
|
|
|
const { container } = await getComponentAndWait();
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2022-11-15 10:27:13 +00:00
|
|
|
expect(container).toMatchSnapshot();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
it("renders switches correctly", async () => {
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2022-11-15 10:27:13 +00:00
|
|
|
expect(screen.getByTestId("notif-master-switch")).toBeInTheDocument();
|
|
|
|
expect(screen.getByTestId("notif-device-switch")).toBeInTheDocument();
|
|
|
|
expect(screen.getByTestId("notif-setting-notificationsEnabled")).toBeInTheDocument();
|
|
|
|
expect(screen.getByTestId("notif-setting-notificationBodyEnabled")).toBeInTheDocument();
|
|
|
|
expect(screen.getByTestId("notif-setting-audioNotificationsEnabled")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("email switches", () => {
|
|
|
|
const testEmail = "tester@test.com";
|
|
|
|
beforeEach(() => {
|
|
|
|
mockClient.getThreePids.mockResolvedValue({
|
|
|
|
threepids: [
|
|
|
|
// should render switch bc pushKey and address match
|
|
|
|
{
|
|
|
|
medium: ThreepidMedium.Email,
|
|
|
|
address: testEmail,
|
2022-03-22 10:32:35 +00:00
|
|
|
} as unknown as IThreepid,
|
2022-01-06 09:47:03 +00:00
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders email switches correctly when email 3pids exist", async () => {
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
|
|
|
expect(screen.getByTestId("notif-email-switch")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("renders email switches correctly when notifications are on for email", async () => {
|
2022-03-22 10:32:35 +00:00
|
|
|
mockClient.getPushers.mockResolvedValue({
|
|
|
|
pushers: [{ kind: "email", pushkey: testEmail } as unknown as IPusher],
|
|
|
|
});
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2022-11-15 10:27:13 +00:00
|
|
|
const emailSwitch = screen.getByTestId("notif-email-switch");
|
|
|
|
expect(emailSwitch.querySelector('[aria-checked="true"]')).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("enables email notification when toggling on", async () => {
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2023-02-15 13:36:22 +00:00
|
|
|
const emailToggle = screen.getByTestId("notif-email-switch").querySelector('div[role="switch"]')!;
|
|
|
|
fireEvent.click(emailToggle);
|
2022-01-06 09:47:03 +00:00
|
|
|
|
|
|
|
expect(mockClient.setPusher).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
kind: "email",
|
|
|
|
app_id: "m.email",
|
|
|
|
pushkey: testEmail,
|
|
|
|
app_display_name: "Email Notifications",
|
|
|
|
device_display_name: testEmail,
|
|
|
|
append: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("displays error when pusher update fails", async () => {
|
2022-02-02 12:02:17 +00:00
|
|
|
mockClient.setPusher.mockRejectedValue({});
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2023-02-15 13:36:22 +00:00
|
|
|
const emailToggle = screen.getByTestId("notif-email-switch").querySelector('div[role="switch"]')!;
|
|
|
|
fireEvent.click(emailToggle);
|
2022-01-06 09:47:03 +00:00
|
|
|
|
|
|
|
// force render
|
|
|
|
await flushPromises();
|
|
|
|
|
2023-05-05 08:13:50 +00:00
|
|
|
const dialog = await screen.findByRole("dialog");
|
|
|
|
|
|
|
|
expect(
|
|
|
|
within(dialog).getByText("An error occurred whilst saving your notification preferences."),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
|
|
// dismiss the dialog
|
|
|
|
fireEvent.click(within(dialog).getByText("OK"));
|
2022-11-15 10:27:13 +00:00
|
|
|
expect(screen.getByTestId("error-message")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("enables email notification when toggling off", async () => {
|
2023-05-05 08:13:50 +00:00
|
|
|
const testPusher = {
|
|
|
|
kind: "email",
|
|
|
|
pushkey: "tester@test.com",
|
|
|
|
app_id: "testtest",
|
|
|
|
} as unknown as IPusher;
|
2022-01-06 09:47:03 +00:00
|
|
|
mockClient.getPushers.mockResolvedValue({ pushers: [testPusher] });
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2023-02-15 13:36:22 +00:00
|
|
|
const emailToggle = screen.getByTestId("notif-email-switch").querySelector('div[role="switch"]')!;
|
|
|
|
fireEvent.click(emailToggle);
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2023-05-05 08:13:50 +00:00
|
|
|
expect(mockClient.removePusher).toHaveBeenCalledWith(testPusher.pushkey, testPusher.app_id);
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-03-13 21:59:04 +00:00
|
|
|
it("toggles master switch correctly", async () => {
|
|
|
|
await getComponentAndWait();
|
|
|
|
|
|
|
|
// master switch is on
|
|
|
|
expect(screen.getByLabelText("Enable notifications for this account")).toBeChecked();
|
|
|
|
fireEvent.click(screen.getByLabelText("Enable notifications for this account"));
|
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
expect(mockClient.setPushRuleEnabled).toHaveBeenCalledWith("global", "override", ".m.rule.master", true);
|
|
|
|
});
|
|
|
|
|
2022-05-10 13:13:02 +00:00
|
|
|
it("toggles and sets settings correctly", async () => {
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
2023-02-15 13:36:22 +00:00
|
|
|
let audioNotifsToggle!: HTMLDivElement;
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2022-05-10 13:13:02 +00:00
|
|
|
const update = () => {
|
2022-11-15 10:27:13 +00:00
|
|
|
audioNotifsToggle = screen
|
|
|
|
.getByTestId("notif-setting-audioNotificationsEnabled")
|
2023-02-15 13:36:22 +00:00
|
|
|
.querySelector('div[role="switch"]')!;
|
2022-05-10 13:13:02 +00:00
|
|
|
};
|
|
|
|
update();
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2022-11-15 10:27:13 +00:00
|
|
|
expect(audioNotifsToggle.getAttribute("aria-checked")).toEqual("true");
|
2022-05-10 13:13:02 +00:00
|
|
|
expect(SettingsStore.getValue("audioNotificationsEnabled")).toEqual(true);
|
|
|
|
|
2023-02-15 13:36:22 +00:00
|
|
|
fireEvent.click(audioNotifsToggle);
|
2022-05-10 13:13:02 +00:00
|
|
|
update();
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2022-11-15 10:27:13 +00:00
|
|
|
expect(audioNotifsToggle.getAttribute("aria-checked")).toEqual("false");
|
2022-05-10 13:13:02 +00:00
|
|
|
expect(SettingsStore.getValue("audioNotificationsEnabled")).toEqual(false);
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("individual notification level settings", () => {
|
|
|
|
it("renders categories correctly", async () => {
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
2022-01-06 09:47:03 +00:00
|
|
|
|
2022-11-15 10:27:13 +00:00
|
|
|
expect(screen.getByTestId("notif-section-vector_global")).toBeInTheDocument();
|
|
|
|
expect(screen.getByTestId("notif-section-vector_mentions")).toBeInTheDocument();
|
|
|
|
expect(screen.getByTestId("notif-section-vector_other")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("renders radios correctly", async () => {
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
2022-01-06 09:47:03 +00:00
|
|
|
const section = "vector_global";
|
|
|
|
|
2022-11-15 10:27:13 +00:00
|
|
|
const globalSection = screen.getByTestId(`notif-section-${section}`);
|
2022-01-06 17:52:06 +00:00
|
|
|
// 4 notification rules with class 'global'
|
2022-11-15 10:27:13 +00:00
|
|
|
expect(globalSection.querySelectorAll("fieldset").length).toEqual(4);
|
2022-01-06 09:47:03 +00:00
|
|
|
// oneToOneRule is set to 'on'
|
2022-11-15 10:27:13 +00:00
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
|
|
|
expect(oneToOneRuleElement.querySelector("[aria-label='On']")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
// encryptedOneToOneRule is set to 'loud'
|
2022-11-15 10:27:13 +00:00
|
|
|
const encryptedOneToOneElement = screen.getByTestId(section + encryptedOneToOneRule.rule_id);
|
|
|
|
expect(encryptedOneToOneElement.querySelector("[aria-label='Noisy']")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
// encryptedGroupRule is set to 'off'
|
2022-11-15 10:27:13 +00:00
|
|
|
const encryptedGroupElement = screen.getByTestId(section + encryptedGroupRule.rule_id);
|
|
|
|
expect(encryptedGroupElement.querySelector("[aria-label='Off']")).toBeInTheDocument();
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("updates notification level when changed", async () => {
|
2022-11-15 10:27:13 +00:00
|
|
|
await getComponentAndWait();
|
2022-01-06 09:47:03 +00:00
|
|
|
const section = "vector_global";
|
|
|
|
|
|
|
|
// oneToOneRule is set to 'on'
|
|
|
|
// and is kind: 'underride'
|
2022-11-15 10:27:13 +00:00
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
2022-01-06 09:47:03 +00:00
|
|
|
|
|
|
|
await act(async () => {
|
2023-02-15 13:36:22 +00:00
|
|
|
const offToggle = oneToOneRuleElement.querySelector('input[type="radio"]')!;
|
2022-11-15 10:27:13 +00:00
|
|
|
fireEvent.click(offToggle);
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(mockClient.setPushRuleEnabled).toHaveBeenCalledWith(
|
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
oneToOneRule.rule_id,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
|
|
|
// actions for '.m.rule.room_one_to_one' state is ACTION_DONT_NOTIFY
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledWith(
|
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
oneToOneRule.rule_id,
|
|
|
|
StandardActions.ACTION_DONT_NOTIFY,
|
|
|
|
);
|
|
|
|
});
|
2023-03-02 05:33:19 +00:00
|
|
|
|
2023-03-13 21:59:04 +00:00
|
|
|
it("adds an error message when updating notification level fails", async () => {
|
|
|
|
await getComponentAndWait();
|
|
|
|
const section = "vector_global";
|
|
|
|
|
|
|
|
const error = new Error("oups");
|
|
|
|
mockClient.setPushRuleEnabled.mockRejectedValue(error);
|
|
|
|
|
|
|
|
// oneToOneRule is set to 'on'
|
|
|
|
// and is kind: 'underride'
|
|
|
|
const offToggle = screen.getByTestId(section + oneToOneRule.rule_id).querySelector('input[type="radio"]')!;
|
2024-08-06 17:22:02 +00:00
|
|
|
await act(() => {
|
|
|
|
fireEvent.click(offToggle);
|
|
|
|
});
|
2023-03-13 21:59:04 +00:00
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
// error message attached to oneToOne rule
|
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
|
|
|
// old value still shown as selected
|
|
|
|
expect(within(oneToOneRuleElement).getByLabelText("On")).toBeChecked();
|
|
|
|
expect(
|
|
|
|
within(oneToOneRuleElement).getByText(
|
|
|
|
"An error occurred when updating your notification preferences. Please try to toggle your option again.",
|
|
|
|
),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("clears error message for notification rule on retry", async () => {
|
|
|
|
await getComponentAndWait();
|
|
|
|
const section = "vector_global";
|
|
|
|
|
|
|
|
const error = new Error("oups");
|
|
|
|
mockClient.setPushRuleEnabled.mockRejectedValueOnce(error).mockResolvedValue({});
|
|
|
|
|
|
|
|
// oneToOneRule is set to 'on'
|
|
|
|
// and is kind: 'underride'
|
|
|
|
const offToggle = screen.getByTestId(section + oneToOneRule.rule_id).querySelector('input[type="radio"]')!;
|
2024-08-06 17:22:02 +00:00
|
|
|
await act(() => {
|
|
|
|
fireEvent.click(offToggle);
|
|
|
|
});
|
2023-03-13 21:59:04 +00:00
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
// error message attached to oneToOne rule
|
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
|
|
|
expect(
|
|
|
|
within(oneToOneRuleElement).getByText(
|
|
|
|
"An error occurred when updating your notification preferences. Please try to toggle your option again.",
|
|
|
|
),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
|
|
// retry
|
|
|
|
fireEvent.click(offToggle);
|
|
|
|
|
|
|
|
// error removed as soon as we start request
|
|
|
|
expect(
|
|
|
|
within(oneToOneRuleElement).queryByText(
|
|
|
|
"An error occurred when updating your notification preferences. Please try to toggle your option again.",
|
|
|
|
),
|
|
|
|
).not.toBeInTheDocument();
|
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
2024-08-06 17:22:02 +00:00
|
|
|
// no error after successful change
|
2023-03-13 21:59:04 +00:00
|
|
|
expect(
|
|
|
|
within(oneToOneRuleElement).queryByText(
|
|
|
|
"An error occurred when updating your notification preferences. Please try to toggle your option again.",
|
|
|
|
),
|
|
|
|
).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2023-03-02 05:33:19 +00:00
|
|
|
describe("synced rules", () => {
|
|
|
|
const pollStartOneToOne = {
|
|
|
|
conditions: [
|
|
|
|
{
|
|
|
|
kind: ConditionKind.RoomMemberCount,
|
|
|
|
is: "2",
|
|
|
|
} as IPushRuleCondition<ConditionKind.RoomMemberCount>,
|
|
|
|
{
|
|
|
|
kind: ConditionKind.EventMatch,
|
|
|
|
key: "type",
|
|
|
|
pattern: "org.matrix.msc3381.poll.start",
|
|
|
|
} as IPushRuleCondition<ConditionKind.EventMatch>,
|
|
|
|
],
|
|
|
|
actions: [PushRuleActionName.DontNotify],
|
|
|
|
rule_id: ".org.matrix.msc3930.rule.poll_start_one_to_one",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
|
|
|
const pollStartGroup = {
|
|
|
|
conditions: [
|
|
|
|
{
|
|
|
|
kind: ConditionKind.EventMatch,
|
|
|
|
key: "type",
|
|
|
|
pattern: "org.matrix.msc3381.poll.start",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
actions: [PushRuleActionName.Notify],
|
|
|
|
rule_id: ".org.matrix.msc3930.rule.poll_start",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
|
|
|
const pollEndOneToOne = {
|
|
|
|
conditions: [
|
|
|
|
{
|
|
|
|
kind: ConditionKind.RoomMemberCount,
|
|
|
|
is: "2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
kind: ConditionKind.EventMatch,
|
|
|
|
key: "type",
|
|
|
|
pattern: "org.matrix.msc3381.poll.end",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
actions: [
|
|
|
|
PushRuleActionName.Notify,
|
|
|
|
{ set_tweak: TweakName.Highlight, value: false },
|
|
|
|
{ set_tweak: TweakName.Sound, value: "default" },
|
|
|
|
],
|
|
|
|
rule_id: ".org.matrix.msc3930.rule.poll_end_one_to_one",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
|
|
|
|
|
|
|
const setPushRuleMock = (rules: IPushRule[] = []): void => {
|
|
|
|
const combinedRules = {
|
|
|
|
...pushRules,
|
|
|
|
global: {
|
|
|
|
...pushRules.global,
|
|
|
|
underride: [...pushRules.global.underride!, ...rules],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
mockClient.getPushRules.mockClear().mockResolvedValue(combinedRules);
|
|
|
|
mockClient.pushRules = combinedRules;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ".m.rule.room_one_to_one" and ".m.rule.message" have synced rules
|
|
|
|
it("succeeds when no synced rules exist for user", async () => {
|
|
|
|
await getComponentAndWait();
|
|
|
|
const section = "vector_global";
|
|
|
|
|
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
|
|
|
|
|
|
|
const offToggle = oneToOneRuleElement.querySelector('input[type="radio"]')!;
|
|
|
|
fireEvent.click(offToggle);
|
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
// didnt attempt to update any non-existant rules
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledTimes(1);
|
|
|
|
|
|
|
|
// no error
|
2023-03-13 21:59:04 +00:00
|
|
|
expect(
|
|
|
|
within(oneToOneRuleElement).queryByText(
|
|
|
|
"An error occurred when updating your notification preferences. Please try to toggle your option again.",
|
|
|
|
),
|
|
|
|
).not.toBeInTheDocument();
|
2023-03-02 05:33:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("updates synced rules when they exist for user", async () => {
|
|
|
|
setPushRuleMock([pollStartOneToOne, pollStartGroup]);
|
|
|
|
await getComponentAndWait();
|
|
|
|
const section = "vector_global";
|
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
|
|
|
|
|
|
|
const offToggle = oneToOneRuleElement.querySelector('input[type="radio"]')!;
|
|
|
|
fireEvent.click(offToggle);
|
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
// updated synced rule
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledWith(
|
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
oneToOneRule.rule_id,
|
|
|
|
[PushRuleActionName.DontNotify],
|
|
|
|
);
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledWith(
|
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
pollStartOneToOne.rule_id,
|
|
|
|
[PushRuleActionName.DontNotify],
|
|
|
|
);
|
|
|
|
// only called for parent rule and one existing synced rule
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledTimes(2);
|
|
|
|
|
|
|
|
// no error
|
2023-03-13 21:59:04 +00:00
|
|
|
expect(
|
|
|
|
within(oneToOneRuleElement).queryByText(
|
|
|
|
"An error occurred when updating your notification preferences. Please try to toggle your option again.",
|
|
|
|
),
|
|
|
|
).not.toBeInTheDocument();
|
2023-03-02 05:33:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("does not update synced rules when main rule update fails", async () => {
|
|
|
|
setPushRuleMock([pollStartOneToOne]);
|
|
|
|
await getComponentAndWait();
|
|
|
|
const section = "vector_global";
|
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
|
|
|
// have main rule update fail
|
|
|
|
mockClient.setPushRuleActions.mockRejectedValue("oups");
|
|
|
|
|
|
|
|
const offToggle = oneToOneRuleElement.querySelector('input[type="radio"]')!;
|
2024-08-06 17:22:02 +00:00
|
|
|
await act(() => {
|
|
|
|
fireEvent.click(offToggle);
|
|
|
|
});
|
2023-03-02 05:33:19 +00:00
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledWith(
|
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
oneToOneRule.rule_id,
|
|
|
|
[PushRuleActionName.DontNotify],
|
|
|
|
);
|
|
|
|
// only called for parent rule
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledTimes(1);
|
|
|
|
|
2023-03-13 21:59:04 +00:00
|
|
|
expect(
|
|
|
|
within(oneToOneRuleElement).getByText(
|
|
|
|
"An error occurred when updating your notification preferences. Please try to toggle your option again.",
|
|
|
|
),
|
|
|
|
).toBeInTheDocument();
|
2023-03-02 05:33:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("sets the UI toggle to rule value when no synced rule exist for the user", async () => {
|
|
|
|
setPushRuleMock([]);
|
|
|
|
await getComponentAndWait();
|
|
|
|
const section = "vector_global";
|
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
|
|
|
|
|
|
|
// loudest state of synced rules should be the toggle value
|
|
|
|
expect(oneToOneRuleElement.querySelector('input[aria-label="On"]')).toBeChecked();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets the UI toggle to the loudest synced rule value", async () => {
|
|
|
|
// oneToOneRule is set to 'On'
|
|
|
|
// pollEndOneToOne is set to 'Loud'
|
|
|
|
setPushRuleMock([pollStartOneToOne, pollEndOneToOne]);
|
|
|
|
await getComponentAndWait();
|
|
|
|
const section = "vector_global";
|
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
|
|
|
|
|
|
|
// loudest state of synced rules should be the toggle value
|
|
|
|
expect(oneToOneRuleElement.querySelector('input[aria-label="Noisy"]')).toBeChecked();
|
|
|
|
|
|
|
|
const onToggle = oneToOneRuleElement.querySelector('input[aria-label="On"]')!;
|
|
|
|
fireEvent.click(onToggle);
|
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
// called for all 3 rules
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledTimes(3);
|
|
|
|
const expectedActions = [PushRuleActionName.Notify, { set_tweak: TweakName.Highlight, value: false }];
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledWith(
|
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
oneToOneRule.rule_id,
|
|
|
|
expectedActions,
|
|
|
|
);
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledWith(
|
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
pollStartOneToOne.rule_id,
|
|
|
|
expectedActions,
|
|
|
|
);
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledWith(
|
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
pollEndOneToOne.rule_id,
|
|
|
|
expectedActions,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|
2022-11-15 10:27:13 +00:00
|
|
|
|
2023-03-13 21:59:04 +00:00
|
|
|
describe("keywords", () => {
|
|
|
|
// keywords rule is not a real rule, but controls actions on keywords content rules
|
|
|
|
const keywordsRuleId = "_keywords";
|
|
|
|
it("updates individual keywords content rules when keywords rule is toggled", async () => {
|
|
|
|
await getComponentAndWait();
|
|
|
|
const section = "vector_mentions";
|
|
|
|
|
|
|
|
fireEvent.click(within(screen.getByTestId(section + keywordsRuleId)).getByLabelText("Off"));
|
|
|
|
|
|
|
|
expect(mockClient.setPushRuleEnabled).toHaveBeenCalledWith("global", "content", bananaRule.rule_id, false);
|
|
|
|
|
|
|
|
fireEvent.click(within(screen.getByTestId(section + keywordsRuleId)).getByLabelText("Noisy"));
|
|
|
|
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledWith(
|
|
|
|
"global",
|
|
|
|
"content",
|
|
|
|
bananaRule.rule_id,
|
|
|
|
StandardActions.ACTION_HIGHLIGHT_DEFAULT_SOUND,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders an error when updating keywords fails", async () => {
|
|
|
|
await getComponentAndWait();
|
|
|
|
const section = "vector_mentions";
|
|
|
|
|
|
|
|
mockClient.setPushRuleEnabled.mockRejectedValueOnce("oups");
|
|
|
|
|
2024-08-06 17:22:02 +00:00
|
|
|
await act(() => {
|
|
|
|
fireEvent.click(within(screen.getByTestId(section + keywordsRuleId)).getByLabelText("Off"));
|
|
|
|
});
|
2023-03-13 21:59:04 +00:00
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
|
|
|
|
const rule = screen.getByTestId(section + keywordsRuleId);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
within(rule).getByText(
|
|
|
|
"An error occurred when updating your notification preferences. Please try to toggle your option again.",
|
|
|
|
),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
});
|
2023-05-05 08:13:50 +00:00
|
|
|
|
|
|
|
it("adds a new keyword", async () => {
|
|
|
|
await getComponentAndWait();
|
|
|
|
|
|
|
|
await userEvent.type(screen.getByLabelText("Keyword"), "jest");
|
|
|
|
expect(screen.getByLabelText("Keyword")).toHaveValue("jest");
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByText("Add"));
|
|
|
|
|
|
|
|
expect(mockClient.addPushRule).toHaveBeenCalledWith("global", PushRuleKind.ContentSpecific, "jest", {
|
|
|
|
actions: [PushRuleActionName.Notify, { set_tweak: "highlight", value: false }],
|
|
|
|
pattern: "jest",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("adds a new keyword with same actions as existing rules when keywords rule is off", async () => {
|
|
|
|
const offContentRule = {
|
|
|
|
...bananaRule,
|
|
|
|
enabled: false,
|
|
|
|
actions: [PushRuleActionName.Notify],
|
|
|
|
};
|
|
|
|
const pushRulesWithContentOff = {
|
|
|
|
global: {
|
|
|
|
...pushRules.global,
|
|
|
|
content: [offContentRule],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
mockClient.pushRules = pushRulesWithContentOff;
|
|
|
|
mockClient.getPushRules.mockClear().mockResolvedValue(pushRulesWithContentOff);
|
|
|
|
|
|
|
|
await getComponentAndWait();
|
|
|
|
|
|
|
|
const keywords = screen.getByTestId("vector_mentions_keywords");
|
|
|
|
|
|
|
|
expect(within(keywords).getByLabelText("Off")).toBeChecked();
|
|
|
|
|
|
|
|
await userEvent.type(screen.getByLabelText("Keyword"), "jest");
|
|
|
|
expect(screen.getByLabelText("Keyword")).toHaveValue("jest");
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByText("Add"));
|
|
|
|
|
|
|
|
expect(mockClient.addPushRule).toHaveBeenCalledWith("global", PushRuleKind.ContentSpecific, "jest", {
|
|
|
|
actions: [PushRuleActionName.Notify, { set_tweak: TweakName.Highlight, value: false }],
|
|
|
|
pattern: "jest",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("removes keyword", async () => {
|
|
|
|
await getComponentAndWait();
|
|
|
|
|
|
|
|
await userEvent.type(screen.getByLabelText("Keyword"), "jest");
|
|
|
|
|
|
|
|
const keyword = screen.getByText("banana");
|
|
|
|
|
|
|
|
fireEvent.click(within(keyword.parentElement!).getByLabelText("Remove"));
|
|
|
|
|
|
|
|
expect(mockClient.deletePushRule).toHaveBeenCalledWith("global", PushRuleKind.ContentSpecific, "banana");
|
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
});
|
2023-03-13 21:59:04 +00:00
|
|
|
});
|
|
|
|
|
2022-11-15 10:27:13 +00:00
|
|
|
describe("clear all notifications", () => {
|
|
|
|
it("clears all notifications", async () => {
|
|
|
|
const room = new Room("room123", mockClient, "@alice:example.org");
|
|
|
|
mockClient.getRooms.mockReset().mockReturnValue([room]);
|
|
|
|
|
|
|
|
const message = mkMessage({
|
|
|
|
event: true,
|
|
|
|
room: "room123",
|
|
|
|
user: "@alice:example.org",
|
|
|
|
ts: 1,
|
|
|
|
});
|
2024-02-01 17:58:57 +00:00
|
|
|
await room.addLiveEvents([message]);
|
2022-11-15 10:27:13 +00:00
|
|
|
|
|
|
|
const { container } = await getComponentAndWait();
|
|
|
|
const clearNotificationEl = getByTestId(container, "clear-notifications");
|
|
|
|
|
|
|
|
fireEvent.click(clearNotificationEl);
|
|
|
|
|
|
|
|
expect(clearNotificationEl.className).toContain("mx_AccessibleButton_disabled");
|
2024-05-02 14:53:35 +00:00
|
|
|
await waitFor(() => expect(clearNotificationEl.className).not.toContain("mx_AccessibleButton_disabled"));
|
2022-11-15 10:27:13 +00:00
|
|
|
expect(mockClient.sendReadReceipt).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2022-01-06 09:47:03 +00:00
|
|
|
});
|