diff --git a/src/__mocks__/mock-state.ts b/src/__mocks__/mock-state.ts index accdabd5b..310581a67 100644 --- a/src/__mocks__/mock-state.ts +++ b/src/__mocks__/mock-state.ts @@ -19,4 +19,5 @@ export const mockSettings: SettingsState = { openAtStartup: false, appearance: Appearance.SYSTEM, colors: false, + markAsDoneOnOpen: false, }; diff --git a/src/components/NotificationRow.test.tsx b/src/components/NotificationRow.test.tsx index 0359f0eef..dcd601b16 100644 --- a/src/components/NotificationRow.test.tsx +++ b/src/components/NotificationRow.test.tsx @@ -41,7 +41,7 @@ describe('components/Notification.js', () => { const { getByRole } = render( { expect(shell.openExternal).toHaveBeenCalledTimes(1); }); + it('should open a notification in browser & mark it as done', () => { + const markNotificationDone = jest.fn(); + + const props = { + notification: mockedSingleNotification, + hostname: 'github.com', + }; + + const { getByRole } = render( + + + , + ); + + fireEvent.click(getByRole('main')); + expect(shell.openExternal).toHaveBeenCalledTimes(1); + expect(markNotificationDone).toHaveBeenCalledTimes(1); + }); + it('should mark a notification as read', () => { const markNotification = jest.fn(); @@ -65,7 +90,7 @@ describe('components/Notification.js', () => { const { getByTitle } = render( diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index d8b58c72a..4a18bae7e 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -30,6 +30,10 @@ export const NotificationRow: React.FC = ({ const pressTitle = useCallback(() => { openBrowser(); + + if (settings.markAsDoneOnOpen) { + markNotificationDone(notification.id, hostname); + } }, [settings]); const openBrowser = useCallback( diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx index aea2d742c..1c788a9ea 100644 --- a/src/context/App.test.tsx +++ b/src/context/App.test.tsx @@ -291,6 +291,7 @@ describe('context/App.tsx', () => { playSound: true, showNotifications: true, colors: false, + markAsDoneOnOpen: false, }, ); }); @@ -328,6 +329,7 @@ describe('context/App.tsx', () => { playSound: true, showNotifications: true, colors: false, + markAsDoneOnOpen: false, }, ); }); diff --git a/src/context/App.tsx b/src/context/App.tsx index dbc788cd1..d009a1604 100644 --- a/src/context/App.tsx +++ b/src/context/App.tsx @@ -37,6 +37,7 @@ export const defaultSettings: SettingsState = { openAtStartup: false, appearance: Appearance.SYSTEM, colors: false, + markAsDoneOnOpen: false, }; interface AppContextState { diff --git a/src/routes/Settings.test.tsx b/src/routes/Settings.test.tsx index d82baf908..933dd2483 100644 --- a/src/routes/Settings.test.tsx +++ b/src/routes/Settings.test.tsx @@ -182,6 +182,34 @@ describe('routes/Settings.tsx', () => { expect(updateSetting).toHaveBeenCalledWith('showNotifications', false); }); + it('should toggle the markAsDoneOnOpen checkbox', async () => { + let getByLabelText; + + await act(async () => { + const { getByLabelText: getByLabelTextLocal } = render( + + + + + , + ); + getByLabelText = getByLabelTextLocal; + }); + + fireEvent.click(getByLabelText('Mark as done on open'), { + target: { checked: true }, + }); + + expect(updateSetting).toHaveBeenCalledTimes(1); + expect(updateSetting).toHaveBeenCalledWith('markAsDoneOnOpen', false); + }); + it('should toggle the openAtStartup checkbox', async () => { let getByLabelText; diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx index 433c0e4e4..78478e2f5 100644 --- a/src/routes/Settings.tsx +++ b/src/routes/Settings.tsx @@ -139,6 +139,14 @@ export const SettingsRoute: React.FC = () => { updateSetting('showNotifications', evt.target.checked) } /> + + updateSetting('markAsDoneOnOpen', evt.target.checked) + } + /> {!isLinux && ( +
+
+ +
+
+ +
+
diff --git a/src/types.ts b/src/types.ts index 8aac5134c..5925a24f7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,6 +13,7 @@ export interface SettingsState { openAtStartup: boolean; appearance: Appearance; colors: boolean; + markAsDoneOnOpen: boolean; } export enum Appearance {