Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/renderer/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const mockNotificationSettings: NotificationSettingsState = {
showPills: true,
showNumber: true,
participating: false,
showReadNotifications: false,
markAsDoneOnOpen: false,
markAsDoneOnUnsubscribe: false,
delayNotificationState: false,
Expand Down
18 changes: 18 additions & 0 deletions src/renderer/components/notifications/NotificationRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => {
expect(markNotificationsAsReadMock).toHaveBeenCalledTimes(1);
});

it('should hide mark as read button when notification is already read', async () => {
const readNotification = {
...mockSingleNotification,
unread: false,
};

const props = {
notification: readNotification,
account: mockGitHubCloudAccount,
};

renderWithAppContext(<NotificationRow {...props} />);

expect(
screen.queryByTestId('notification-mark-as-read'),
).not.toBeInTheDocument();
});

it('should mark notifications as done', async () => {
const markNotificationsAsDoneMock = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const NotificationRow: FC<NotificationRowProps> = ({

<HoverButton
action={actionMarkAsRead}
enabled={!isNotificationRead}
icon={ReadIcon}
label="Mark as read"
testid="notification-mark-as-read"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/renderer/components/settings/NotificationSettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => {
);
});

it('should toggle the showReadNotifications checkbox', async () => {
await act(async () => {
renderWithAppContext(<NotificationSettings />, {
updateSetting: updateSettingMock,
});
});

await userEvent.click(screen.getByTestId('checkbox-showReadNotifications'));

expect(updateSettingMock).toHaveBeenCalledTimes(1);
expect(updateSettingMock).toHaveBeenCalledWith(
'showReadNotifications',
true,
);
});

it('should toggle the markAsDoneOnOpen checkbox', async () => {
await act(async () => {
renderWithAppContext(<NotificationSettings />, {
Expand Down
25 changes: 25 additions & 0 deletions src/renderer/components/settings/NotificationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,31 @@ export const NotificationSettings: FC = () => {
}
/>

<Checkbox
checked={settings.showReadNotifications}
label="Show read notifications"
name="showReadNotifications"
onChange={(evt) =>
updateSetting('showReadNotifications', evt.target.checked)
}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>
When <Text as="u">checked</Text>, {APPLICATION.NAME} will fetch
and display both read and unread notifications.
</Text>
<Text>
When <Text as="u">unchecked</Text>, {APPLICATION.NAME} will only
fetch and display unread notifications.
</Text>
<Text className="text-gitify-caution">
⚠️ Enabling this setting will increase API usage and may cause
rate limiting for users with many notifications.
</Text>
</Stack>
}
/>

<Checkbox
checked={settings.markAsDoneOnOpen}
label="Mark as done on open"
Expand Down
1 change: 1 addition & 0 deletions src/renderer/context/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const defaultNotificationSettings: NotificationSettingsState = {
showPills: true,
showNumber: true,
participating: false,
showReadNotifications: false,
markAsDoneOnOpen: false,
markAsDoneOnUnsubscribe: false,
delayNotificationState: false,
Expand Down
61 changes: 55 additions & 6 deletions src/renderer/routes/__snapshots__/Settings.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface NotificationSettingsState {
showPills: boolean;
showNumber: boolean;
participating: boolean;
showReadNotifications: boolean;
markAsDoneOnOpen: boolean;
markAsDoneOnUnsubscribe: boolean;
delayNotificationState: boolean;
Expand Down
38 changes: 38 additions & 0 deletions src/renderer/utils/api/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,44 @@ describe('renderer/utils/api/client.ts', () => {
data: {},
});
});

it('should include all=true when showReadNotifications is enabled', async () => {
const mockSettings: Partial<SettingsState> = {
participating: false,
showReadNotifications: true,
};

await listNotificationsForAuthenticatedUser(
mockGitHubCloudAccount,
mockSettings as SettingsState,
);

expect(axios).toHaveBeenCalledWith({
url: 'https://api.github.com/notifications?participating=false&all=true',
headers: mockNonCachedAuthHeaders,
method: 'GET',
data: {},
});
});

it('should not include all parameter when showReadNotifications is disabled', async () => {
const mockSettings: Partial<SettingsState> = {
participating: false,
showReadNotifications: false,
};

await listNotificationsForAuthenticatedUser(
mockGitHubCloudAccount,
mockSettings as SettingsState,
);

expect(axios).toHaveBeenCalledWith({
url: 'https://api.github.com/notifications?participating=false',
headers: mockNonCachedAuthHeaders,
method: 'GET',
data: {},
});
});
});

it('markNotificationThreadAsRead - should mark notification thread as read', async () => {
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/utils/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export function listNotificationsForAuthenticatedUser(
url.pathname += 'notifications';
url.searchParams.append('participating', String(settings.participating));

if (settings.showReadNotifications) {
url.searchParams.append('all', 'true');
}

return apiRequestAuth(
url.toString() as Link,
'GET',
Expand Down
Loading
Loading