You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-07 21:23:00 +03:00
Apply prettier formatting
This commit is contained in:
@@ -78,12 +78,14 @@ describe("Notifier", () => {
|
||||
mockClient = getMockClientWithEventEmitter({
|
||||
...mockClientMethodsUser(userId),
|
||||
isGuest: jest.fn().mockReturnValue(false),
|
||||
getAccountData: jest.fn().mockImplementation(eventType => accountDataStore[eventType]),
|
||||
getAccountData: jest.fn().mockImplementation((eventType) => accountDataStore[eventType]),
|
||||
setAccountData: jest.fn().mockImplementation((eventType, content) => {
|
||||
accountDataStore[eventType] = content ? new MatrixEvent({
|
||||
type: eventType,
|
||||
content,
|
||||
}) : undefined;
|
||||
accountDataStore[eventType] = content
|
||||
? new MatrixEvent({
|
||||
type: eventType,
|
||||
content,
|
||||
})
|
||||
: undefined;
|
||||
}),
|
||||
decryptEventIfNeeded: jest.fn(),
|
||||
getRoom: jest.fn(),
|
||||
@@ -107,20 +109,20 @@ describe("Notifier", () => {
|
||||
|
||||
Notifier.isBodyEnabled = jest.fn().mockReturnValue(true);
|
||||
|
||||
mockClient.getRoom.mockImplementation(id => {
|
||||
mockClient.getRoom.mockImplementation((id) => {
|
||||
return id === roomId ? testRoom : new Room(id, mockClient, mockClient.getUserId());
|
||||
});
|
||||
});
|
||||
|
||||
describe('triggering notification from events', () => {
|
||||
describe("triggering notification from events", () => {
|
||||
let hasStartedNotiferBefore = false;
|
||||
|
||||
const event = new MatrixEvent({
|
||||
sender: '@alice:server.org',
|
||||
type: 'm.room.message',
|
||||
room_id: '!room:server.org',
|
||||
sender: "@alice:server.org",
|
||||
type: "m.room.message",
|
||||
room_id: "!room:server.org",
|
||||
content: {
|
||||
body: 'hey',
|
||||
body: "hey",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -142,28 +144,28 @@ describe("Notifier", () => {
|
||||
});
|
||||
|
||||
mockSettings = {
|
||||
'notificationsEnabled': true,
|
||||
'audioNotificationsEnabled': true,
|
||||
notificationsEnabled: true,
|
||||
audioNotificationsEnabled: true,
|
||||
};
|
||||
|
||||
// enable notifications by default
|
||||
jest.spyOn(SettingsStore, "getValue").mockReset().mockImplementation(
|
||||
settingName => mockSettings[settingName] ?? false,
|
||||
);
|
||||
jest.spyOn(SettingsStore, "getValue")
|
||||
.mockReset()
|
||||
.mockImplementation((settingName) => mockSettings[settingName] ?? false);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
Notifier.stop();
|
||||
});
|
||||
|
||||
it('does not create notifications before syncing has started', () => {
|
||||
it("does not create notifications before syncing has started", () => {
|
||||
emitLiveEvent(event);
|
||||
|
||||
expect(MockPlatform.displayNotification).not.toHaveBeenCalled();
|
||||
expect(MockPlatform.loudNotification).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not create notifications for own event', () => {
|
||||
it("does not create notifications for own event", () => {
|
||||
const ownEvent = new MatrixEvent({ sender: userId });
|
||||
|
||||
mockClient!.emit(ClientEvent.Sync, SyncState.Syncing, null);
|
||||
@@ -173,7 +175,7 @@ describe("Notifier", () => {
|
||||
expect(MockPlatform.loudNotification).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not create notifications for non-live events (scrollback)', () => {
|
||||
it("does not create notifications for non-live events (scrollback)", () => {
|
||||
mockClient!.emit(ClientEvent.Sync, SyncState.Syncing, null);
|
||||
mockClient!.emit(RoomEvent.Timeline, event, testRoom, false, false, {
|
||||
liveEvent: false,
|
||||
@@ -184,7 +186,7 @@ describe("Notifier", () => {
|
||||
expect(MockPlatform.loudNotification).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not create notifications for rooms which cannot be obtained via client.getRoom', () => {
|
||||
it("does not create notifications for rooms which cannot be obtained via client.getRoom", () => {
|
||||
mockClient!.emit(ClientEvent.Sync, SyncState.Syncing, null);
|
||||
mockClient.getRoom.mockReturnValue(null);
|
||||
mockClient!.emit(RoomEvent.Timeline, event, testRoom, false, false, {
|
||||
@@ -196,7 +198,7 @@ describe("Notifier", () => {
|
||||
expect(MockPlatform.loudNotification).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not create notifications when event does not have notify push action', () => {
|
||||
it("does not create notifications when event does not have notify push action", () => {
|
||||
mockClient.getPushActionsForEvent.mockReturnValue({
|
||||
notify: false,
|
||||
tweaks: {
|
||||
@@ -211,29 +213,21 @@ describe("Notifier", () => {
|
||||
expect(MockPlatform.loudNotification).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('creates desktop notification when enabled', () => {
|
||||
it("creates desktop notification when enabled", () => {
|
||||
mockClient!.emit(ClientEvent.Sync, SyncState.Syncing, null);
|
||||
emitLiveEvent(event);
|
||||
|
||||
expect(MockPlatform.displayNotification).toHaveBeenCalledWith(
|
||||
testRoom.name,
|
||||
'hey',
|
||||
null,
|
||||
testRoom,
|
||||
event,
|
||||
);
|
||||
expect(MockPlatform.displayNotification).toHaveBeenCalledWith(testRoom.name, "hey", null, testRoom, event);
|
||||
});
|
||||
|
||||
it('creates a loud notification when enabled', () => {
|
||||
it("creates a loud notification when enabled", () => {
|
||||
mockClient!.emit(ClientEvent.Sync, SyncState.Syncing, null);
|
||||
emitLiveEvent(event);
|
||||
|
||||
expect(MockPlatform.loudNotification).toHaveBeenCalledWith(
|
||||
event, testRoom,
|
||||
);
|
||||
expect(MockPlatform.loudNotification).toHaveBeenCalledWith(event, testRoom);
|
||||
});
|
||||
|
||||
it('does not create loud notification when event does not have sound tweak in push actions', () => {
|
||||
it("does not create loud notification when event does not have sound tweak in push actions", () => {
|
||||
mockClient.getPushActionsForEvent.mockReturnValue({
|
||||
notify: true,
|
||||
tweaks: {
|
||||
@@ -252,7 +246,7 @@ describe("Notifier", () => {
|
||||
});
|
||||
|
||||
describe("_displayPopupNotification", () => {
|
||||
const testCases: {event: IContent | undefined, count: number}[] = [
|
||||
const testCases: { event: IContent | undefined; count: number }[] = [
|
||||
{ event: { is_silenced: true }, count: 0 },
|
||||
{ event: { is_silenced: false }, count: 1 },
|
||||
{ event: undefined, count: 1 },
|
||||
@@ -274,7 +268,7 @@ describe("Notifier", () => {
|
||||
});
|
||||
|
||||
describe("_playAudioNotification", () => {
|
||||
const testCases: {event: IContent | undefined, count: number}[] = [
|
||||
const testCases: { event: IContent | undefined; count: number }[] = [
|
||||
{ event: { is_silenced: true }, count: 0 },
|
||||
{ event: { is_silenced: false }, count: 1 },
|
||||
{ event: undefined, count: 1 },
|
||||
@@ -330,13 +324,15 @@ describe("Notifier", () => {
|
||||
|
||||
const callEvent = callOnEvent();
|
||||
|
||||
expect(ToastStore.sharedInstance().addOrReplaceToast).toHaveBeenCalledWith(expect.objectContaining({
|
||||
key: `call_${callEvent.getStateKey()}`,
|
||||
priority: 100,
|
||||
component: IncomingCallToast,
|
||||
bodyClassName: "mx_IncomingCallToast",
|
||||
props: { callEvent },
|
||||
}));
|
||||
expect(ToastStore.sharedInstance().addOrReplaceToast).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
key: `call_${callEvent.getStateKey()}`,
|
||||
priority: 100,
|
||||
component: IncomingCallToast,
|
||||
bodyClassName: "mx_IncomingCallToast",
|
||||
props: { callEvent },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("should not show toast when group calls are not supported", () => {
|
||||
@@ -356,7 +352,7 @@ describe("Notifier", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('local notification settings', () => {
|
||||
describe("local notification settings", () => {
|
||||
const createLocalNotificationSettingsIfNeededMock = mocked(createLocalNotificationSettingsIfNeeded);
|
||||
let hasStartedNotiferBefore = false;
|
||||
beforeEach(() => {
|
||||
@@ -375,36 +371,34 @@ describe("Notifier", () => {
|
||||
Notifier.stop();
|
||||
});
|
||||
|
||||
it('does not create local notifications event after a sync error', () => {
|
||||
it("does not create local notifications event after a sync error", () => {
|
||||
mockClient.emit(ClientEvent.Sync, SyncState.Error, SyncState.Syncing);
|
||||
expect(createLocalNotificationSettingsIfNeededMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not create local notifications event after sync stops', () => {
|
||||
it("does not create local notifications event after sync stops", () => {
|
||||
mockClient.emit(ClientEvent.Sync, SyncState.Stopped, SyncState.Syncing);
|
||||
expect(createLocalNotificationSettingsIfNeededMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not create local notifications event after a cached sync', () => {
|
||||
it("does not create local notifications event after a cached sync", () => {
|
||||
mockClient.emit(ClientEvent.Sync, SyncState.Syncing, SyncState.Syncing, {
|
||||
fromCache: true,
|
||||
});
|
||||
expect(createLocalNotificationSettingsIfNeededMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('creates local notifications event after a non-cached sync', () => {
|
||||
it("creates local notifications event after a non-cached sync", () => {
|
||||
mockClient.emit(ClientEvent.Sync, SyncState.Syncing, SyncState.Syncing, {});
|
||||
expect(createLocalNotificationSettingsIfNeededMock).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('_evaluateEvent', () => {
|
||||
describe("_evaluateEvent", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId")
|
||||
.mockReturnValue(testRoom.roomId);
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(testRoom.roomId);
|
||||
|
||||
jest.spyOn(UserActivity.sharedInstance(), "userActiveRecently")
|
||||
.mockReturnValue(true);
|
||||
jest.spyOn(UserActivity.sharedInstance(), "userActiveRecently").mockReturnValue(true);
|
||||
|
||||
jest.spyOn(Modal, "hasDialogs").mockReturnValue(false);
|
||||
|
||||
@@ -457,9 +451,7 @@ describe("Notifier", () => {
|
||||
thread_id: rootEvent.getId(),
|
||||
});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBe(rootEvent.getId()),
|
||||
);
|
||||
await waitFor(() => expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBe(rootEvent.getId()));
|
||||
|
||||
Notifier._evaluateEvent(events[1]);
|
||||
expect(Notifier._displayPopupNotification).toHaveBeenCalledTimes(1);
|
||||
|
Reference in New Issue
Block a user