2022-01-06 10:47:03 +01:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import React from "react";
|
2022-09-28 19:13:09 +02:00
|
|
|
import {
|
|
|
|
IPushRule,
|
|
|
|
IPushRules,
|
|
|
|
RuleId,
|
|
|
|
IPusher,
|
|
|
|
LOCAL_NOTIFICATION_SETTINGS_PREFIX,
|
|
|
|
MatrixEvent,
|
2022-11-15 11:27:13 +01:00
|
|
|
Room,
|
|
|
|
NotificationCountType,
|
2022-12-12 12:24:14 +01:00
|
|
|
} from "matrix-js-sdk/src/matrix";
|
|
|
|
import { IThreepid, ThreepidMedium } from "matrix-js-sdk/src/@types/threepids";
|
|
|
|
import { act } from "react-dom/test-utils";
|
|
|
|
import { fireEvent, getByTestId, render, screen, waitFor } from "@testing-library/react";
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import Notifications from "../../../../src/components/views/settings/Notifications";
|
2022-01-06 10:47:03 +01:00
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
2022-12-12 12:24:14 +01:00
|
|
|
import { StandardActions } from "../../../../src/notifications/StandardActions";
|
2023-01-11 12:33:06 +01:00
|
|
|
import { getMockClientWithEventEmitter, mkMessage, mockClientMethodsUser } from "../../../test-utils";
|
2022-01-06 10:47:03 +01:00
|
|
|
|
|
|
|
// don't pollute test output with error logs from mock rejections
|
|
|
|
jest.mock("matrix-js-sdk/src/logger");
|
|
|
|
|
2022-05-10 15:13:02 +02:00
|
|
|
// Avoid indirectly importing any eagerly created stores that would require extra setup
|
|
|
|
jest.mock("../../../../src/Notifier");
|
2022-01-06 10:47:03 +01:00
|
|
|
|
|
|
|
const masterRule = {
|
|
|
|
actions: ["dont_notify"],
|
|
|
|
conditions: [],
|
|
|
|
default: true,
|
|
|
|
enabled: false,
|
|
|
|
rule_id: RuleId.Master,
|
|
|
|
};
|
|
|
|
// eslint-disable-next-line max-len
|
2022-12-12 12:24:14 +01:00
|
|
|
const oneToOneRule = {
|
|
|
|
conditions: [
|
|
|
|
{ kind: "room_member_count", is: "2" },
|
|
|
|
{ kind: "event_match", key: "type", pattern: "m.room.message" },
|
|
|
|
],
|
|
|
|
actions: ["notify", { set_tweak: "highlight", value: false }],
|
|
|
|
rule_id: ".m.rule.room_one_to_one",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
2022-01-06 10:47:03 +01:00
|
|
|
// eslint-disable-next-line max-len
|
2022-12-12 12:24:14 +01:00
|
|
|
const encryptedOneToOneRule = {
|
|
|
|
conditions: [
|
|
|
|
{ kind: "room_member_count", is: "2" },
|
|
|
|
{ kind: "event_match", key: "type", pattern: "m.room.encrypted" },
|
|
|
|
],
|
|
|
|
actions: ["notify", { set_tweak: "sound", value: "default" }, { set_tweak: "highlight", value: false }],
|
|
|
|
rule_id: ".m.rule.encrypted_room_one_to_one",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
2022-01-06 10:47:03 +01:00
|
|
|
// eslint-disable-next-line max-len
|
2022-12-12 12:24:14 +01:00
|
|
|
const encryptedGroupRule = {
|
|
|
|
conditions: [{ kind: "event_match", key: "type", pattern: "m.room.encrypted" }],
|
|
|
|
actions: ["dont_notify"],
|
|
|
|
rule_id: ".m.rule.encrypted",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
} as IPushRule;
|
2022-01-06 10:47:03 +01:00
|
|
|
// eslint-disable-next-line max-len
|
2022-12-12 12:24:14 +01:00
|
|
|
const pushRules: IPushRules = {
|
|
|
|
global: {
|
|
|
|
underride: [
|
|
|
|
{
|
|
|
|
conditions: [{ kind: "event_match", key: "type", pattern: "m.call.invite" }],
|
|
|
|
actions: ["notify", { set_tweak: "sound", value: "ring" }, { set_tweak: "highlight", value: false }],
|
|
|
|
rule_id: ".m.rule.call",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
oneToOneRule,
|
|
|
|
encryptedOneToOneRule,
|
|
|
|
{
|
|
|
|
conditions: [{ kind: "event_match", key: "type", pattern: "m.room.message" }],
|
|
|
|
actions: ["notify", { set_tweak: "sound", value: "default" }, { set_tweak: "highlight", value: false }],
|
|
|
|
rule_id: ".m.rule.message",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
encryptedGroupRule,
|
|
|
|
{
|
|
|
|
conditions: [
|
|
|
|
{ kind: "event_match", key: "type", pattern: "im.vector.modular.widgets" },
|
|
|
|
{ kind: "event_match", key: "content.type", pattern: "jitsi" },
|
|
|
|
{ kind: "event_match", key: "state_key", pattern: "*" },
|
|
|
|
],
|
|
|
|
actions: ["notify", { set_tweak: "highlight", value: false }],
|
|
|
|
rule_id: ".im.vector.jitsi",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
sender: [],
|
|
|
|
room: [{ actions: ["dont_notify"], rule_id: "!zJPyWqpMorfCcWObge:matrix.org", default: false, enabled: true }],
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
actions: ["notify", { set_tweak: "highlight", value: false }],
|
|
|
|
pattern: "banana",
|
|
|
|
rule_id: "banana",
|
|
|
|
default: false,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actions: ["notify", { set_tweak: "sound", value: "default" }, { set_tweak: "highlight" }],
|
|
|
|
pattern: "kadev1",
|
|
|
|
rule_id: ".m.rule.contains_user_name",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
override: [
|
|
|
|
{ conditions: [], actions: ["dont_notify"], rule_id: ".m.rule.master", default: true, enabled: false },
|
|
|
|
{
|
|
|
|
conditions: [{ kind: "event_match", key: "content.msgtype", pattern: "m.notice" }],
|
|
|
|
actions: ["dont_notify"],
|
|
|
|
rule_id: ".m.rule.suppress_notices",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [
|
|
|
|
{ kind: "event_match", key: "type", pattern: "m.room.member" },
|
|
|
|
{ kind: "event_match", key: "content.membership", pattern: "invite" },
|
|
|
|
{ kind: "event_match", key: "state_key", pattern: "@kadev1:matrix.org" },
|
|
|
|
],
|
|
|
|
actions: ["notify", { set_tweak: "sound", value: "default" }, { set_tweak: "highlight", value: false }],
|
|
|
|
rule_id: ".m.rule.invite_for_me",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [{ kind: "event_match", key: "type", pattern: "m.room.member" }],
|
|
|
|
actions: ["dont_notify"],
|
|
|
|
rule_id: ".m.rule.member_event",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [{ kind: "contains_display_name" }],
|
|
|
|
actions: ["notify", { set_tweak: "sound", value: "default" }, { set_tweak: "highlight" }],
|
|
|
|
rule_id: ".m.rule.contains_display_name",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [
|
|
|
|
{ kind: "event_match", key: "content.body", pattern: "@room" },
|
|
|
|
{ kind: "sender_notification_permission", key: "room" },
|
|
|
|
],
|
|
|
|
actions: ["notify", { set_tweak: "highlight", value: true }],
|
|
|
|
rule_id: ".m.rule.roomnotif",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [
|
|
|
|
{ kind: "event_match", key: "type", pattern: "m.room.tombstone" },
|
|
|
|
{ kind: "event_match", key: "state_key", pattern: "" },
|
|
|
|
],
|
|
|
|
actions: ["notify", { set_tweak: "highlight", value: true }],
|
|
|
|
rule_id: ".m.rule.tombstone",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
conditions: [{ kind: "event_match", key: "type", pattern: "m.reaction" }],
|
|
|
|
actions: ["dont_notify"],
|
|
|
|
rule_id: ".m.rule.reaction",
|
|
|
|
default: true,
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
device: {},
|
|
|
|
} as IPushRules;
|
|
|
|
|
|
|
|
const flushPromises = async () => await new Promise((resolve) => window.setTimeout(resolve));
|
|
|
|
|
|
|
|
describe("<Notifications />", () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
const getComponent = () => render(<Notifications />);
|
2022-01-06 10:47:03 +01:00
|
|
|
|
|
|
|
// get component, wait for async data and force a render
|
|
|
|
const getComponentAndWait = async () => {
|
|
|
|
const component = getComponent();
|
|
|
|
await flushPromises();
|
|
|
|
return component;
|
|
|
|
};
|
|
|
|
|
2022-03-22 11:32:35 +01:00
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
2023-01-11 12:33:06 +01:00
|
|
|
...mockClientMethodsUser(),
|
2022-02-02 13:02:17 +01:00
|
|
|
getPushRules: jest.fn(),
|
|
|
|
getPushers: jest.fn(),
|
|
|
|
getThreePids: jest.fn(),
|
|
|
|
setPusher: jest.fn(),
|
|
|
|
setPushRuleEnabled: jest.fn(),
|
|
|
|
setPushRuleActions: jest.fn(),
|
|
|
|
getRooms: jest.fn().mockReturnValue([]),
|
2022-12-12 12:24:14 +01:00
|
|
|
getAccountData: jest.fn().mockImplementation((eventType) => {
|
2022-09-28 19:13:09 +02:00
|
|
|
if (eventType.startsWith(LOCAL_NOTIFICATION_SETTINGS_PREFIX.name)) {
|
|
|
|
return new MatrixEvent({
|
|
|
|
type: eventType,
|
|
|
|
content: {
|
|
|
|
is_silenced: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
setAccountData: jest.fn(),
|
2022-11-15 11:27:13 +01:00
|
|
|
sendReadReceipt: jest.fn(),
|
2023-01-30 13:20:11 +01:00
|
|
|
supportsThreads: jest.fn().mockReturnValue(true),
|
2023-02-09 13:46:17 +01:00
|
|
|
isInitialSyncComplete: jest.fn().mockReturnValue(false),
|
2022-03-22 11:32:35 +01:00
|
|
|
});
|
2022-01-06 10:47:03 +01:00
|
|
|
mockClient.getPushRules.mockResolvedValue(pushRules);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockClient.getPushRules.mockClear().mockResolvedValue(pushRules);
|
|
|
|
mockClient.getPushers.mockClear().mockResolvedValue({ pushers: [] });
|
|
|
|
mockClient.getThreePids.mockClear().mockResolvedValue({ threepids: [] });
|
|
|
|
mockClient.setPusher.mockClear().mockResolvedValue({});
|
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("renders spinner while loading", async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
getComponent();
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(screen.getByTestId("spinner")).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("renders error message when fetching push rules fails", async () => {
|
2022-02-02 13:02:17 +01:00
|
|
|
mockClient.getPushRules.mockRejectedValue({});
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(screen.getByTestId("error-message")).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
2022-12-12 12:24:14 +01:00
|
|
|
it("renders error message when fetching pushers fails", async () => {
|
2022-02-02 13:02:17 +01:00
|
|
|
mockClient.getPushers.mockRejectedValue({});
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(screen.getByTestId("error-message")).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
2022-12-12 12:24:14 +01:00
|
|
|
it("renders error message when fetching threepids fails", async () => {
|
2022-02-02 13:02:17 +01:00
|
|
|
mockClient.getThreePids.mockRejectedValue({});
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(screen.getByTestId("error-message")).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
describe("main notification switches", () => {
|
|
|
|
it("renders only enable notifications switch when notifications are disabled", async () => {
|
2022-01-06 10:47:03 +01:00
|
|
|
const disableNotificationsPushRules = {
|
|
|
|
global: {
|
|
|
|
...pushRules.global,
|
|
|
|
override: [{ ...masterRule, enabled: true }],
|
|
|
|
},
|
2022-03-22 11:32:35 +01:00
|
|
|
} as unknown as IPushRules;
|
2022-01-06 10:47:03 +01:00
|
|
|
mockClient.getPushRules.mockClear().mockResolvedValue(disableNotificationsPushRules);
|
2022-11-15 11:27:13 +01:00
|
|
|
const { container } = await getComponentAndWait();
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-11-15 11:27:13 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
2022-12-12 12:24:14 +01:00
|
|
|
it("renders switches correctly", async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-12-12 12:24:14 +01: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 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
describe("email switches", () => {
|
|
|
|
const testEmail = "tester@test.com";
|
2022-01-06 10:47:03 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
mockClient.getThreePids.mockResolvedValue({
|
|
|
|
threepids: [
|
|
|
|
// should render switch bc pushKey and address match
|
|
|
|
{
|
|
|
|
medium: ThreepidMedium.Email,
|
|
|
|
address: testEmail,
|
2022-03-22 11:32:35 +01:00
|
|
|
} as unknown as IThreepid,
|
2022-01-06 10:47:03 +01:00
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("renders email switches correctly when email 3pids exist", async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(screen.getByTestId("notif-email-switch")).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("renders email switches correctly when notifications are on for email", async () => {
|
2022-03-22 11:32:35 +01:00
|
|
|
mockClient.getPushers.mockResolvedValue({
|
2022-12-12 12:24:14 +01:00
|
|
|
pushers: [{ kind: "email", pushkey: testEmail } as unknown as IPusher],
|
2022-03-22 11:32:35 +01:00
|
|
|
});
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
const emailSwitch = screen.getByTestId("notif-email-switch");
|
2022-11-15 11:27:13 +01:00
|
|
|
expect(emailSwitch.querySelector('[aria-checked="true"]')).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("enables email notification when toggling on", async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
const emailToggle = screen.getByTestId("notif-email-switch").querySelector('div[role="switch"]');
|
2022-01-06 10:47:03 +01:00
|
|
|
|
|
|
|
await act(async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
fireEvent.click(emailToggle);
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01: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,
|
|
|
|
}),
|
|
|
|
);
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("displays error when pusher update fails", async () => {
|
2022-02-02 13:02:17 +01:00
|
|
|
mockClient.setPusher.mockRejectedValue({});
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
const emailToggle = screen.getByTestId("notif-email-switch").querySelector('div[role="switch"]');
|
2022-01-06 10:47:03 +01:00
|
|
|
|
|
|
|
await act(async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
fireEvent.click(emailToggle);
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// force render
|
|
|
|
await flushPromises();
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(screen.getByTestId("error-message")).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("enables email notification when toggling off", async () => {
|
|
|
|
const testPusher = { kind: "email", pushkey: "tester@test.com" } as unknown as IPusher;
|
2022-01-06 10:47:03 +01:00
|
|
|
mockClient.getPushers.mockResolvedValue({ pushers: [testPusher] });
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
const emailToggle = screen.getByTestId("notif-email-switch").querySelector('div[role="switch"]');
|
2022-01-06 10:47:03 +01:00
|
|
|
|
|
|
|
await act(async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
fireEvent.click(emailToggle);
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(mockClient.setPusher).toHaveBeenCalledWith({
|
2022-12-12 12:24:14 +01:00
|
|
|
...testPusher,
|
|
|
|
kind: null,
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("toggles and sets settings correctly", async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
|
|
|
let audioNotifsToggle;
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-05-10 15:13:02 +02:00
|
|
|
const update = () => {
|
2022-12-12 12:24:14 +01:00
|
|
|
audioNotifsToggle = screen
|
|
|
|
.getByTestId("notif-setting-audioNotificationsEnabled")
|
2022-11-15 11:27:13 +01:00
|
|
|
.querySelector('div[role="switch"]');
|
2022-05-10 15:13:02 +02:00
|
|
|
};
|
|
|
|
update();
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-11-15 11:27:13 +01:00
|
|
|
expect(audioNotifsToggle.getAttribute("aria-checked")).toEqual("true");
|
2022-05-10 15:13:02 +02:00
|
|
|
expect(SettingsStore.getValue("audioNotificationsEnabled")).toEqual(true);
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
act(() => {
|
|
|
|
fireEvent.click(audioNotifsToggle);
|
|
|
|
});
|
2022-05-10 15:13:02 +02:00
|
|
|
update();
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-11-15 11:27:13 +01:00
|
|
|
expect(audioNotifsToggle.getAttribute("aria-checked")).toEqual("false");
|
2022-05-10 15:13:02 +02:00
|
|
|
expect(SettingsStore.getValue("audioNotificationsEnabled")).toEqual(false);
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
describe("individual notification level settings", () => {
|
|
|
|
it("renders categories correctly", async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-12-12 12:24:14 +01: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 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("renders radios correctly", async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-12-12 12:24:14 +01:00
|
|
|
const section = "vector_global";
|
2022-01-06 10:47:03 +01:00
|
|
|
|
2022-11-15 11:27:13 +01:00
|
|
|
const globalSection = screen.getByTestId(`notif-section-${section}`);
|
2022-01-06 18:52:06 +01:00
|
|
|
// 4 notification rules with class 'global'
|
2022-12-12 12:24:14 +01:00
|
|
|
expect(globalSection.querySelectorAll("fieldset").length).toEqual(4);
|
2022-01-06 10:47:03 +01:00
|
|
|
// oneToOneRule is set to 'on'
|
2022-11-15 11:27:13 +01:00
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
|
|
|
expect(oneToOneRuleElement.querySelector("[aria-label='On']")).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
// encryptedOneToOneRule is set to 'loud'
|
2022-11-15 11:27:13 +01:00
|
|
|
const encryptedOneToOneElement = screen.getByTestId(section + encryptedOneToOneRule.rule_id);
|
|
|
|
expect(encryptedOneToOneElement.querySelector("[aria-label='Noisy']")).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
// encryptedGroupRule is set to 'off'
|
2022-11-15 11:27:13 +01:00
|
|
|
const encryptedGroupElement = screen.getByTestId(section + encryptedGroupRule.rule_id);
|
|
|
|
expect(encryptedGroupElement.querySelector("[aria-label='Off']")).toBeInTheDocument();
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("updates notification level when changed", async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
await getComponentAndWait();
|
2022-12-12 12:24:14 +01:00
|
|
|
const section = "vector_global";
|
2022-01-06 10:47:03 +01:00
|
|
|
|
|
|
|
// oneToOneRule is set to 'on'
|
|
|
|
// and is kind: 'underride'
|
2022-11-15 11:27:13 +01:00
|
|
|
const oneToOneRuleElement = screen.getByTestId(section + oneToOneRule.rule_id);
|
2022-01-06 10:47:03 +01:00
|
|
|
|
|
|
|
await act(async () => {
|
2022-11-15 11:27:13 +01:00
|
|
|
const offToggle = oneToOneRuleElement.querySelector('input[type="radio"]');
|
|
|
|
fireEvent.click(offToggle);
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(mockClient.setPushRuleEnabled).toHaveBeenCalledWith(
|
2022-12-12 12:24:14 +01:00
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
oneToOneRule.rule_id,
|
|
|
|
true,
|
|
|
|
);
|
2022-01-06 10:47:03 +01:00
|
|
|
|
|
|
|
// actions for '.m.rule.room_one_to_one' state is ACTION_DONT_NOTIFY
|
|
|
|
expect(mockClient.setPushRuleActions).toHaveBeenCalledWith(
|
2022-12-12 12:24:14 +01:00
|
|
|
"global",
|
|
|
|
"underride",
|
|
|
|
oneToOneRule.rule_id,
|
|
|
|
StandardActions.ACTION_DONT_NOTIFY,
|
|
|
|
);
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|
|
|
|
});
|
2022-11-15 11:27:13 +01: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,
|
|
|
|
});
|
|
|
|
room.addLiveEvents([message]);
|
|
|
|
room.setUnreadNotificationCount(NotificationCountType.Total, 1);
|
|
|
|
|
|
|
|
const { container } = await getComponentAndWait();
|
|
|
|
const clearNotificationEl = getByTestId(container, "clear-notifications");
|
|
|
|
|
|
|
|
fireEvent.click(clearNotificationEl);
|
|
|
|
|
|
|
|
expect(clearNotificationEl.className).toContain("mx_AccessibleButton_disabled");
|
|
|
|
expect(mockClient.sendReadReceipt).toHaveBeenCalled();
|
|
|
|
|
|
|
|
await waitFor(() => {
|
2022-12-22 14:18:38 +01:00
|
|
|
expect(clearNotificationEl).not.toBeInTheDocument();
|
2022-11-15 11:27:13 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-01-06 10:47:03 +01:00
|
|
|
});
|