Skip to content

feat: add "Mark as done on open" setting #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 6, 2024
1 change: 1 addition & 0 deletions src/__mocks__/mock-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export const mockSettings: SettingsState = {
openAtStartup: false,
appearance: Appearance.SYSTEM,
colors: false,
markAsDoneOnOpen: false,
};
29 changes: 27 additions & 2 deletions src/components/NotificationRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('components/Notification.js', () => {
const { getByRole } = render(
<AppContext.Provider
value={{
settings: mockSettings,
settings: { ...mockSettings, markAsDoneOnOpen: false },
markNotification,
accounts: mockAccounts,
}}
Expand All @@ -54,6 +54,31 @@ describe('components/Notification.js', () => {
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(
<AppContext.Provider
value={{
settings: { ...mockSettings, markAsDoneOnOpen: true },
markNotificationDone,
accounts: mockAccounts,
}}
>
<NotificationRow {...props} />
</AppContext.Provider>,
);

fireEvent.click(getByRole('main'));
expect(shell.openExternal).toHaveBeenCalledTimes(1);
expect(markNotificationDone).toHaveBeenCalledTimes(1);
});

it('should mark a notification as read', () => {
const markNotification = jest.fn();

Expand All @@ -65,7 +90,7 @@ describe('components/Notification.js', () => {
const { getByTitle } = render(
<AppContext.Provider
value={{
settings: mockSettings,
settings: { ...mockSettings, markAsDoneOnOpen: false },
accounts: mockAccounts,
}}
>
Expand Down
4 changes: 4 additions & 0 deletions src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const NotificationRow: React.FC<IProps> = ({

const pressTitle = useCallback(() => {
openBrowser();

if (settings.markAsDoneOnOpen) {
markNotificationDone(notification.id, hostname);
}
}, [settings]);

const openBrowser = useCallback(
Expand Down
2 changes: 2 additions & 0 deletions src/context/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ describe('context/App.tsx', () => {
playSound: true,
showNotifications: true,
colors: false,
markAsDoneOnOpen: false,
},
);
});
Expand Down Expand Up @@ -328,6 +329,7 @@ describe('context/App.tsx', () => {
playSound: true,
showNotifications: true,
colors: false,
markAsDoneOnOpen: false,
},
);
});
Expand Down
1 change: 1 addition & 0 deletions src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const defaultSettings: SettingsState = {
openAtStartup: false,
appearance: Appearance.SYSTEM,
colors: false,
markAsDoneOnOpen: false,
};

interface AppContextState {
Expand Down
28 changes: 28 additions & 0 deletions src/routes/Settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<AppContext.Provider
value={{
settings: mockSettings,
accounts: mockAccounts,
updateSetting,
}}
>
<MemoryRouter>
<SettingsRoute />
</MemoryRouter>
</AppContext.Provider>,
);
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;

Expand Down
8 changes: 8 additions & 0 deletions src/routes/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ export const SettingsRoute: React.FC = () => {
updateSetting('showNotifications', evt.target.checked)
}
/>
<FieldCheckbox
name="markAsDoneOnOpen"
label="Mark as done on open"
checked={settings.markAsDoneOnOpen}
onChange={(evt) =>
updateSetting('markAsDoneOnOpen', evt.target.checked)
}
/>
{!isLinux && (
<FieldCheckbox
name="openAtStartUp"
Expand Down
23 changes: 23 additions & 0 deletions src/routes/__snapshots__/Settings.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ exports[`routes/Settings.tsx should render itself & its children 1`] = `
</label>
</div>
</div>
<div
class="flex items-start mt-1 mb-3"
>
<div
class="flex items-center h-5"
>
<input
class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded"
id="markAsDoneOnOpen"
type="checkbox"
/>
</div>
<div
class="ml-3 text-sm"
>
<label
class="font-medium text-gray-700 dark:text-gray-200"
for="markAsDoneOnOpen"
>
Mark as done on open
</label>
</div>
</div>
<div
class="flex items-start mt-1 mb-3"
>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface SettingsState {
openAtStartup: boolean;
appearance: Appearance;
colors: boolean;
markAsDoneOnOpen: boolean;
}

export enum Appearance {
Expand Down