You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
Device manager - eagerly create m.local_notification_settings
events (#9353)
* eagerly save m.local_notification_settings events * unskip test * create local notification settings after first non-cached sync
This commit is contained in:
@ -20,6 +20,8 @@ import { mocked } from "jest-mock";
|
||||
import {
|
||||
localNotificationsAreSilenced,
|
||||
getLocalNotificationAccountDataEventType,
|
||||
createLocalNotificationSettingsIfNeeded,
|
||||
deviceNotificationSettingsKeys,
|
||||
} from "../../src/utils/notifications";
|
||||
import SettingsStore from "../../src/settings/SettingsStore";
|
||||
import { getMockClientWithEventEmitter } from "../test-utils/client";
|
||||
@ -46,6 +48,38 @@ describe('notifications', () => {
|
||||
mocked(SettingsStore).getValue.mockReturnValue(false);
|
||||
});
|
||||
|
||||
describe('createLocalNotification', () => {
|
||||
it('creates account data event', async () => {
|
||||
await createLocalNotificationSettingsIfNeeded(mockClient);
|
||||
const event = mockClient.getAccountData(accountDataEventKey);
|
||||
expect(event?.getContent().is_silenced).toBe(true);
|
||||
});
|
||||
|
||||
it.each(deviceNotificationSettingsKeys)(
|
||||
'unsilenced for existing sessions when %s setting is truthy',
|
||||
async (settingKey) => {
|
||||
mocked(SettingsStore)
|
||||
.getValue
|
||||
.mockImplementation((key) => {
|
||||
return key === settingKey;
|
||||
});
|
||||
|
||||
await createLocalNotificationSettingsIfNeeded(mockClient);
|
||||
const event = mockClient.getAccountData(accountDataEventKey);
|
||||
expect(event?.getContent().is_silenced).toBe(false);
|
||||
});
|
||||
|
||||
it("does not override an existing account event data", async () => {
|
||||
mockClient.setAccountData(accountDataEventKey, {
|
||||
is_silenced: false,
|
||||
});
|
||||
|
||||
await createLocalNotificationSettingsIfNeeded(mockClient);
|
||||
const event = mockClient.getAccountData(accountDataEventKey);
|
||||
expect(event?.getContent().is_silenced).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('localNotificationsAreSilenced', () => {
|
||||
it('defaults to true when no setting exists', () => {
|
||||
expect(localNotificationsAreSilenced(mockClient)).toBeTruthy();
|
||||
|
Reference in New Issue
Block a user