Skip to content

Commit fb7f57a

Browse files
committed
fix: notification read state for delayNotificationState
Signed-off-by: Adam Setch <[email protected]>
1 parent c8641c9 commit fb7f57a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/renderer/hooks/useNotifications.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ describe('renderer/hooks/useNotifications.ts', () => {
2727
// by nock. So, configure axios to use the node adapter.
2828
axios.defaults.adapter = 'http';
2929
rendererLogErrorSpy.mockReset();
30+
31+
// Reset mock notification state between tests since it's mutated
32+
mockSingleNotification.unread = true;
3033
});
3134

3235
const id = mockSingleNotification.id;
@@ -367,6 +370,32 @@ describe('renderer/hooks/useNotifications.ts', () => {
367370
});
368371

369372
expect(result.current.notifications.length).toBe(0);
373+
expect(mockSingleNotification.unread).toBeTruthy();
374+
});
375+
376+
it('should mark notifications as read with success - delayNotificationState', async () => {
377+
nock('https://api.github.com/')
378+
.patch(`/notifications/threads/${id}`)
379+
.reply(200);
380+
381+
const { result } = renderHook(() => useNotifications());
382+
383+
act(() => {
384+
result.current.markNotificationsAsRead(
385+
{
386+
...mockState,
387+
settings: { ...mockState.settings, delayNotificationState: true },
388+
},
389+
[mockSingleNotification],
390+
);
391+
});
392+
393+
await waitFor(() => {
394+
expect(result.current.status).toBe('success');
395+
});
396+
397+
expect(result.current.notifications.length).toBe(0);
398+
expect(mockSingleNotification.unread).toBeFalsy();
370399
});
371400

372401
it('should mark notifications as read with failure', async () => {
@@ -410,6 +439,32 @@ describe('renderer/hooks/useNotifications.ts', () => {
410439
});
411440

412441
expect(result.current.notifications.length).toBe(0);
442+
expect(mockSingleNotification.unread).toBeTruthy();
443+
});
444+
445+
it('should mark notifications as done with success - delayNotificationState', async () => {
446+
nock('https://api.github.com/')
447+
.delete(`/notifications/threads/${id}`)
448+
.reply(200);
449+
450+
const { result } = renderHook(() => useNotifications());
451+
452+
act(() => {
453+
result.current.markNotificationsAsDone(
454+
{
455+
...mockState,
456+
settings: { ...mockState.settings, delayNotificationState: true },
457+
},
458+
[mockSingleNotification],
459+
);
460+
});
461+
462+
await waitFor(() => {
463+
expect(result.current.status).toBe('success');
464+
});
465+
466+
expect(result.current.notifications.length).toBe(0);
467+
expect(mockSingleNotification.unread).toBeFalsy();
413468
});
414469

415470
it('should mark notifications as done with failure', async () => {

0 commit comments

Comments
 (0)