Skip to content

Commit b9ce1b6

Browse files
authored
refactor: combine mark as fns to support a list of notifications (#1560)
* refactor: combine mark as fns to support a list of notifications Signed-off-by: Adam Setch <[email protected]> * refactor: combine mark as fns to support a list of notifications Signed-off-by: Adam Setch <[email protected]> * refactor: combine mark as fns to support a list of notifications Signed-off-by: Adam Setch <[email protected]> * revert: refactor: add types Signed-off-by: Adam Setch <[email protected]> --------- Signed-off-by: Adam Setch <[email protected]>
1 parent 6efb03d commit b9ce1b6

17 files changed

+178
-575
lines changed

src/components/NotificationRow.test.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('components/NotificationRow.tsx', () => {
8282

8383
describe('notification interactions', () => {
8484
it('should open a notification in the browser - click', () => {
85-
const markNotificationRead = jest.fn();
85+
const markNotificationsAsRead = jest.fn();
8686

8787
const props = {
8888
notification: mockSingleNotification,
@@ -93,7 +93,7 @@ describe('components/NotificationRow.tsx', () => {
9393
<AppContext.Provider
9494
value={{
9595
settings: { ...mockSettings, markAsDoneOnOpen: false },
96-
markNotificationRead,
96+
markNotificationsAsRead,
9797
auth: mockAuth,
9898
}}
9999
>
@@ -103,11 +103,11 @@ describe('components/NotificationRow.tsx', () => {
103103

104104
fireEvent.click(screen.getByRole('main'));
105105
expect(links.openNotification).toHaveBeenCalledTimes(1);
106-
expect(markNotificationRead).toHaveBeenCalledTimes(1);
106+
expect(markNotificationsAsRead).toHaveBeenCalledTimes(1);
107107
});
108108

109109
it('should open a notification in the browser - delay notification setting enabled', () => {
110-
const markNotificationRead = jest.fn();
110+
const markNotificationsAsRead = jest.fn();
111111

112112
const props = {
113113
notification: mockSingleNotification,
@@ -122,7 +122,7 @@ describe('components/NotificationRow.tsx', () => {
122122
markAsDoneOnOpen: false,
123123
delayNotificationState: true,
124124
},
125-
markNotificationRead,
125+
markNotificationsAsRead,
126126
auth: mockAuth,
127127
}}
128128
>
@@ -132,11 +132,11 @@ describe('components/NotificationRow.tsx', () => {
132132

133133
fireEvent.click(screen.getByRole('main'));
134134
expect(links.openNotification).toHaveBeenCalledTimes(1);
135-
expect(markNotificationRead).toHaveBeenCalledTimes(1);
135+
expect(markNotificationsAsRead).toHaveBeenCalledTimes(1);
136136
});
137137

138138
it('should open a notification in the browser - key down', () => {
139-
const markNotificationRead = jest.fn();
139+
const markNotificationsAsRead = jest.fn();
140140

141141
const props = {
142142
notification: mockSingleNotification,
@@ -147,7 +147,7 @@ describe('components/NotificationRow.tsx', () => {
147147
<AppContext.Provider
148148
value={{
149149
settings: { ...mockSettings, markAsDoneOnOpen: false },
150-
markNotificationRead,
150+
markNotificationsAsRead,
151151
auth: mockAuth,
152152
}}
153153
>
@@ -157,11 +157,11 @@ describe('components/NotificationRow.tsx', () => {
157157

158158
fireEvent.click(screen.getByRole('main'));
159159
expect(links.openNotification).toHaveBeenCalledTimes(1);
160-
expect(markNotificationRead).toHaveBeenCalledTimes(1);
160+
expect(markNotificationsAsRead).toHaveBeenCalledTimes(1);
161161
});
162162

163163
it('should open a notification in browser & mark it as done', () => {
164-
const markNotificationDone = jest.fn();
164+
const markNotificationsAsDone = jest.fn();
165165

166166
const props = {
167167
notification: mockSingleNotification,
@@ -172,7 +172,7 @@ describe('components/NotificationRow.tsx', () => {
172172
<AppContext.Provider
173173
value={{
174174
settings: { ...mockSettings, markAsDoneOnOpen: true },
175-
markNotificationDone,
175+
markNotificationsAsDone,
176176
auth: mockAuth,
177177
}}
178178
>
@@ -182,11 +182,11 @@ describe('components/NotificationRow.tsx', () => {
182182

183183
fireEvent.click(screen.getByRole('main'));
184184
expect(links.openNotification).toHaveBeenCalledTimes(1);
185-
expect(markNotificationDone).toHaveBeenCalledTimes(1);
185+
expect(markNotificationsAsDone).toHaveBeenCalledTimes(1);
186186
});
187187

188-
it('should mark a notification as read', () => {
189-
const markNotificationRead = jest.fn();
188+
it('should mark notifications as read', () => {
189+
const markNotificationsAsRead = jest.fn();
190190

191191
const props = {
192192
notification: mockSingleNotification,
@@ -197,19 +197,19 @@ describe('components/NotificationRow.tsx', () => {
197197
<AppContext.Provider
198198
value={{
199199
settings: { ...mockSettings, markAsDoneOnOpen: false },
200-
markNotificationRead,
200+
markNotificationsAsRead,
201201
}}
202202
>
203203
<NotificationRow {...props} />
204204
</AppContext.Provider>,
205205
);
206206

207207
fireEvent.click(screen.getByTitle('Mark as read'));
208-
expect(markNotificationRead).toHaveBeenCalledTimes(1);
208+
expect(markNotificationsAsRead).toHaveBeenCalledTimes(1);
209209
});
210210

211-
it('should mark a notification as done', () => {
212-
const markNotificationDone = jest.fn();
211+
it('should mark notifications as done', () => {
212+
const markNotificationsAsDone = jest.fn();
213213

214214
const props = {
215215
notification: mockSingleNotification,
@@ -218,14 +218,14 @@ describe('components/NotificationRow.tsx', () => {
218218

219219
render(
220220
<AppContext.Provider
221-
value={{ settings: mockSettings, markNotificationDone }}
221+
value={{ settings: mockSettings, markNotificationsAsDone }}
222222
>
223223
<NotificationRow {...props} />
224224
</AppContext.Provider>,
225225
);
226226

227227
fireEvent.click(screen.getByTitle('Mark as done'));
228-
expect(markNotificationDone).toHaveBeenCalledTimes(1);
228+
expect(markNotificationsAsDone).toHaveBeenCalledTimes(1);
229229
});
230230

231231
it('should unsubscribe from a notification thread', () => {

src/components/NotificationRow.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export const NotificationRow: FC<INotificationRow> = ({
3737
}: INotificationRow) => {
3838
const {
3939
settings,
40-
markNotificationRead,
41-
markNotificationDone,
40+
markNotificationsAsRead,
41+
markNotificationsAsDone,
4242
unsubscribeNotification,
4343
} = useContext(AppContext);
4444
const [animateExit, setAnimateExit] = useState(false);
@@ -51,11 +51,16 @@ export const NotificationRow: FC<INotificationRow> = ({
5151
openNotification(notification);
5252

5353
if (settings.markAsDoneOnOpen) {
54-
markNotificationDone(notification);
54+
markNotificationsAsDone([notification]);
5555
} else {
56-
markNotificationRead(notification);
56+
markNotificationsAsRead([notification]);
5757
}
58-
}, [notification, markNotificationDone, markNotificationRead, settings]);
58+
}, [
59+
notification,
60+
markNotificationsAsRead,
61+
markNotificationsAsDone,
62+
settings,
63+
]);
5964

6065
const unsubscribeFromThread = (event: MouseEvent<HTMLElement>) => {
6166
// Don't trigger onClick of parent element.
@@ -137,7 +142,7 @@ export const NotificationRow: FC<INotificationRow> = ({
137142
onClick={() => {
138143
setAnimateExit(!settings.delayNotificationState);
139144
setShowAsRead(settings.delayNotificationState);
140-
markNotificationDone(notification);
145+
markNotificationsAsDone([notification]);
141146
}}
142147
/>
143148
)}
@@ -148,7 +153,7 @@ export const NotificationRow: FC<INotificationRow> = ({
148153
onClick={() => {
149154
setAnimateExit(!settings.delayNotificationState);
150155
setShowAsRead(settings.delayNotificationState);
151-
markNotificationRead(notification);
156+
markNotificationsAsRead([notification]);
152157
}}
153158
/>
154159
<InteractionButton

src/components/RepositoryNotifications.test.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { act, fireEvent, render, screen } from '@testing-library/react';
22
import { mockGitHubCloudAccount, mockSettings } from '../__mocks__/state-mocks';
33
import { AppContext } from '../context/App';
44
import type { Link } from '../types';
5-
import {
6-
mockGitHubNotifications,
7-
mockSingleNotification,
8-
} from '../utils/api/__mocks__/response-mocks';
5+
import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks';
96
import * as comms from '../utils/comms';
107
import { RepositoryNotifications } from './RepositoryNotifications';
118

@@ -14,8 +11,8 @@ jest.mock('./NotificationRow', () => ({
1411
}));
1512

1613
describe('components/RepositoryNotifications.tsx', () => {
17-
const markRepoNotificationsRead = jest.fn();
18-
const markRepoNotificationsDone = jest.fn();
14+
const markNotificationsAsRead = jest.fn();
15+
const markNotificationsAsDone = jest.fn();
1916

2017
const props = {
2118
account: mockGitHubCloudAccount,
@@ -58,32 +55,32 @@ describe('components/RepositoryNotifications.tsx', () => {
5855
it('should mark a repo as read', () => {
5956
render(
6057
<AppContext.Provider
61-
value={{ settings: { ...mockSettings }, markRepoNotificationsRead }}
58+
value={{ settings: { ...mockSettings }, markNotificationsAsRead }}
6259
>
6360
<RepositoryNotifications {...props} />
6461
</AppContext.Provider>,
6562
);
6663

6764
fireEvent.click(screen.getByTitle('Mark repository as read'));
6865

69-
expect(markRepoNotificationsRead).toHaveBeenCalledWith(
70-
mockSingleNotification,
66+
expect(markNotificationsAsRead).toHaveBeenCalledWith(
67+
mockGitHubNotifications,
7168
);
7269
});
7370

7471
it('should mark a repo as done', () => {
7572
render(
7673
<AppContext.Provider
77-
value={{ settings: { ...mockSettings }, markRepoNotificationsDone }}
74+
value={{ settings: { ...mockSettings }, markNotificationsAsDone }}
7875
>
7976
<RepositoryNotifications {...props} />
8077
</AppContext.Provider>,
8178
);
8279

8380
fireEvent.click(screen.getByTitle('Mark repository as done'));
8481

85-
expect(markRepoNotificationsDone).toHaveBeenCalledWith(
86-
mockSingleNotification,
82+
expect(markNotificationsAsDone).toHaveBeenCalledWith(
83+
mockGitHubNotifications,
8784
);
8885
});
8986

src/components/RepositoryNotifications.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
2626
repoName,
2727
repoNotifications,
2828
}) => {
29-
const { settings, markRepoNotificationsRead, markRepoNotificationsDone } =
29+
const { settings, markNotificationsAsRead, markNotificationsAsDone } =
3030
useContext(AppContext);
3131
const [animateExit, setAnimateExit] = useState(false);
3232
const [showAsRead, setShowAsRead] = useState(false);
@@ -91,7 +91,7 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
9191
event.stopPropagation();
9292
setAnimateExit(!settings.delayNotificationState);
9393
setShowAsRead(settings.delayNotificationState);
94-
markRepoNotificationsDone(repoNotifications[0]);
94+
markNotificationsAsDone(repoNotifications);
9595
}}
9696
/>
9797
)}
@@ -104,7 +104,7 @@ export const RepositoryNotifications: FC<IRepositoryNotifications> = ({
104104
event.stopPropagation();
105105
setAnimateExit(!settings.delayNotificationState);
106106
setShowAsRead(settings.delayNotificationState);
107-
markRepoNotificationsRead(repoNotifications[0]);
107+
markNotificationsAsRead(repoNotifications);
108108
}}
109109
/>
110110
<InteractionButton

0 commit comments

Comments
 (0)