Skip to content

Commit e8ebb68

Browse files
committed
test: add coverage for fetchReadNotifications fallback behavior
1 parent a2fd0fd commit e8ebb68

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

‎src/renderer/components/notifications/NotificationRow.test.tsx‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,32 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => {
136136
expect(markNotificationsAsDoneMock).toHaveBeenCalledTimes(1);
137137
});
138138

139+
it('should mark as read (not done) when markAsDoneOnOpen is true but fetchReadNotifications is enabled', async () => {
140+
const markNotificationsAsReadMock = jest.fn();
141+
const markNotificationsAsDoneMock = jest.fn();
142+
143+
const props = {
144+
notification: mockGitifyNotification,
145+
account: mockGitHubCloudAccount,
146+
};
147+
148+
renderWithAppContext(<NotificationRow {...props} />, {
149+
settings: {
150+
...mockSettings,
151+
markAsDoneOnOpen: true,
152+
fetchReadNotifications: true,
153+
},
154+
markNotificationsAsRead: markNotificationsAsReadMock,
155+
markNotificationsAsDone: markNotificationsAsDoneMock,
156+
});
157+
158+
await userEvent.click(screen.getByTestId('notification-row'));
159+
160+
expect(links.openNotification).toHaveBeenCalledTimes(1);
161+
expect(markNotificationsAsReadMock).toHaveBeenCalledTimes(1);
162+
expect(markNotificationsAsDoneMock).not.toHaveBeenCalled();
163+
});
164+
139165
it('should mark notifications as read', async () => {
140166
const markNotificationsAsReadMock = jest.fn();
141167

@@ -190,6 +216,24 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => {
190216
expect(markNotificationsAsDoneMock).toHaveBeenCalledTimes(1);
191217
});
192218

219+
it('should hide mark as done button when fetchReadNotifications is enabled', async () => {
220+
const props = {
221+
notification: mockGitifyNotification,
222+
account: mockGitHubCloudAccount,
223+
};
224+
225+
renderWithAppContext(<NotificationRow {...props} />, {
226+
settings: { ...mockSettings, fetchReadNotifications: true },
227+
});
228+
229+
expect(
230+
screen.queryByTestId('notification-mark-as-done'),
231+
).not.toBeInTheDocument();
232+
expect(
233+
screen.getByTestId('notification-mark-as-read'),
234+
).toBeInTheDocument();
235+
});
236+
193237
it('should unsubscribe from a notification thread', async () => {
194238
const unsubscribeNotificationMock = jest.fn();
195239

‎src/renderer/hooks/useNotifications.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,5 +585,39 @@ describe('renderer/hooks/useNotifications.ts', () => {
585585
expect(result.current.notifications.length).toBe(0);
586586
expect(rendererLogErrorSpy).toHaveBeenCalledTimes(1);
587587
});
588+
589+
it('should mark as read (not done) when markAsDoneOnUnsubscribe is true but fetchReadNotifications is enabled', async () => {
590+
// The unsubscribe endpoint call.
591+
nock('https://api.github.com/')
592+
.put(`/notifications/threads/${id}/subscription`)
593+
.reply(200);
594+
595+
// The mark read endpoint call (NOT mark done).
596+
nock('https://api.github.com/')
597+
.patch(`/notifications/threads/${id}`)
598+
.reply(200);
599+
600+
const { result } = renderHook(() => useNotifications());
601+
602+
act(() => {
603+
result.current.unsubscribeNotification(
604+
{
605+
...mockState,
606+
settings: {
607+
...mockState.settings,
608+
markAsDoneOnUnsubscribe: true,
609+
fetchReadNotifications: true,
610+
},
611+
},
612+
mockGitifyNotification,
613+
);
614+
});
615+
616+
await waitFor(() => {
617+
expect(result.current.status).toBe('success');
618+
});
619+
620+
expect(result.current.notifications.length).toBe(0);
621+
});
588622
});
589623
});

0 commit comments

Comments
 (0)