Skip to content

Commit 5c848c7

Browse files
afonsojramossetchy
andauthored
feat: add 'Show read notifications' setting (#2488)
Co-authored-by: Adam Setch <adam.setch@outlook.com>
1 parent 12603f2 commit 5c848c7

31 files changed

Lines changed: 1921 additions & 782 deletions

src/renderer/__helpers__/jest.setup.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ import '@testing-library/jest-dom';
77
*/
88
import '@primer/react/test-helpers';
99

10+
/**
11+
* Custom snapshot serializer to normalize React auto-generated IDs.
12+
* This makes snapshots stable regardless of test execution order.
13+
* React's useId() generates IDs like "_r_X_" where X changes based on
14+
* how many components have rendered before.
15+
*/
16+
expect.addSnapshotSerializer({
17+
test: (val) => typeof val === 'string' && /_r_[a-z0-9]+_/.test(val),
18+
serialize: (val: string) => {
19+
return `"${val.replace(/_r_[a-z0-9]+_/g, '_r_ID_')}"`;
20+
},
21+
});
22+
1023
/**
1124
* Gitify context bridge API
1225
*/

src/renderer/__helpers__/test-utils.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,41 @@ export function AppContextProvider({
2222
children,
2323
value = {},
2424
}: AppContextProviderProps) {
25-
const defaultValue: Partial<AppContextState> = useMemo(() => {
25+
const defaultValue: AppContextState = useMemo(() => {
2626
return {
2727
auth: mockAuth,
2828
settings: mockSettings,
2929
isLoggedIn: true,
3030

3131
notifications: [],
32+
notificationCount: 0,
33+
unreadNotificationCount: 0,
34+
hasNotifications: false,
35+
hasUnreadNotifications: false,
3236

3337
status: 'success',
3438
globalError: null,
3539

40+
// Default mock implementations for all required methods
41+
loginWithGitHubApp: jest.fn(),
42+
loginWithOAuthApp: jest.fn(),
43+
loginWithPersonalAccessToken: jest.fn(),
44+
logoutFromAccount: jest.fn(),
45+
46+
fetchNotifications: jest.fn(),
47+
removeAccountNotifications: jest.fn(),
48+
49+
markNotificationsAsRead: jest.fn(),
50+
markNotificationsAsDone: jest.fn(),
51+
unsubscribeNotification: jest.fn(),
52+
53+
clearFilters: jest.fn(),
54+
resetSettings: jest.fn(),
55+
updateSetting: jest.fn(),
56+
updateFilter: jest.fn(),
57+
3658
...value,
37-
} as Partial<AppContextState>;
59+
} as AppContextState;
3860
}, [value]);
3961

4062
return (

src/renderer/__mocks__/state-mocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const mockNotificationSettings: NotificationSettingsState = {
4343
showPills: true,
4444
showNumber: true,
4545
participating: false,
46+
fetchReadNotifications: false,
4647
markAsDoneOnOpen: false,
4748
markAsDoneOnUnsubscribe: false,
4849
delayNotificationState: false,

src/renderer/components/Sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const Sidebar: FC = () => {
3737
status,
3838
settings,
3939
auth,
40-
unreadNotificationCount,
40+
notificationCount,
4141
hasUnreadNotifications,
4242
updateSetting,
4343
} = useAppContext();
@@ -92,7 +92,7 @@ export const Sidebar: FC = () => {
9292
<IconButton
9393
aria-label="Notifications"
9494
data-testid="sidebar-notifications"
95-
description={`${unreadNotificationCount} unread notifications ↗`}
95+
description={`${notificationCount} ${settings.fetchReadNotifications ? 'notifications' : 'unread notifications'} ↗`}
9696
icon={BellIcon}
9797
onClick={() => openGitHubNotifications(primaryAccountHostname)}
9898
size="small"

0 commit comments

Comments
 (0)