Skip to content

Commit fb0a468

Browse files
fix: discussions-url (#538)
Co-authored-by: Afonso Jorge Ramos <[email protected]>
1 parent 43b47a6 commit fb0a468

16 files changed

+454
-182
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ temp/
7373

7474
dist/
7575
build/
76+
.vscode/settings.json

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"react-transition-group": "^4.4.1",
126126
"tailwindcss": "^2.0.2",
127127
"ts-loader": "^9.4.2",
128-
"typescript": "^4.1.3"
128+
"typescript": "^4.6.2"
129129
},
130130
"devDependencies": {
131131
"@testing-library/react": "^11.2.2",

pnpm-lock.yaml

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__mocks__/electron.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,35 @@ window.localStorage = {
2727

2828
window.alert = jest.fn();
2929

30-
const browserWindow = {
31-
loadURL: jest.fn(),
32-
webContents: {
30+
let instance;
31+
32+
class BrowserWindow {
33+
constructor() {
34+
if (!instance) {
35+
instance = this;
36+
}
37+
return instance;
38+
}
39+
loadURL = jest.fn();
40+
webContents = {
3341
on: () => {},
3442
session: {
3543
clearStorageData: jest.fn(),
3644
},
37-
},
38-
on: () => {},
39-
close: jest.fn(),
40-
hide: jest.fn(),
41-
destroy: jest.fn(),
42-
};
45+
};
46+
on() {}
47+
close = jest.fn();
48+
hide = jest.fn();
49+
destroy = jest.fn();
50+
}
4351

4452
const dialog = {
4553
showErrorBox: jest.fn(),
4654
};
4755

4856
module.exports = {
4957
remote: {
50-
BrowserWindow: () => browserWindow,
58+
BrowserWindow: BrowserWindow,
5159
dialog: dialog,
5260
process: {
5361
platform: 'darwin',
@@ -57,7 +65,7 @@ module.exports = {
5765
getLoginItemSettings: jest.fn(),
5866
setLoginItemSettings: () => {},
5967
},
60-
getCurrentWindow: jest.fn(() => browserWindow),
68+
getCurrentWindow: jest.fn(() => instance || new BrowserWindow()),
6169
},
6270
ipcRenderer: {
6371
send: jest.fn(),

src/__mocks__/mockedData.ts

+114-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AccountNotifications, EnterpriseAccount } from '../types';
2-
import { Notification, Repository, User } from '../typesGithub';
2+
import { Notification, Repository, User, GraphQLSearch } from '../typesGithub';
33

44
export const mockedEnterpriseAccounts: EnterpriseAccount[] = [
55
{
@@ -274,3 +274,116 @@ export const mockedSingleAccountNotifications: AccountNotifications[] = [
274274
notifications: [mockedSingleNotification],
275275
},
276276
];
277+
278+
export const mockedGraphQLResponse: GraphQLSearch = {
279+
data: {
280+
data: {
281+
search: {
282+
edges: [
283+
{
284+
node: {
285+
viewerSubscription: 'SUBSCRIBED',
286+
title: '1.16.0',
287+
url: 'https://github.com/manosim/notifications-test/discussions/612',
288+
comments: {
289+
edges: [
290+
{
291+
node: {
292+
databaseId: 2215656,
293+
createdAt: '2022-02-20T18:33:39Z',
294+
replies: {
295+
edges: [],
296+
},
297+
},
298+
},
299+
{
300+
node: {
301+
databaseId: 2217789,
302+
createdAt: '2022-02-21T03:30:42Z',
303+
replies: {
304+
edges: [],
305+
},
306+
},
307+
},
308+
{
309+
node: {
310+
databaseId: 2223243,
311+
createdAt: '2022-02-21T18:26:27Z',
312+
replies: {
313+
edges: [
314+
{
315+
node: {
316+
databaseId: 2232922,
317+
createdAt: '2022-02-23T00:57:58Z',
318+
},
319+
},
320+
],
321+
},
322+
},
323+
},
324+
{
325+
node: {
326+
databaseId: 2232921,
327+
createdAt: '2022-02-23T00:57:49Z',
328+
replies: {
329+
edges: [],
330+
},
331+
},
332+
},
333+
{
334+
node: {
335+
databaseId: 2258799,
336+
createdAt: '2022-02-27T01:22:20Z',
337+
replies: {
338+
edges: [
339+
{
340+
node: {
341+
databaseId: 2300902,
342+
createdAt: '2022-03-05T17:43:52Z',
343+
},
344+
},
345+
],
346+
},
347+
},
348+
},
349+
{
350+
node: {
351+
databaseId: 2297637,
352+
createdAt: '2022-03-04T20:39:44Z',
353+
replies: {
354+
edges: [
355+
{
356+
node: {
357+
databaseId: 2300893,
358+
createdAt: '2022-03-05T17:41:04Z',
359+
},
360+
},
361+
],
362+
},
363+
},
364+
},
365+
{
366+
node: {
367+
databaseId: 2299763,
368+
createdAt: '2022-03-05T11:05:42Z',
369+
replies: {
370+
edges: [
371+
{
372+
node: {
373+
databaseId: 2300895,
374+
createdAt: '2022-03-05T17:41:44Z',
375+
},
376+
},
377+
],
378+
},
379+
},
380+
},
381+
],
382+
},
383+
},
384+
},
385+
],
386+
},
387+
},
388+
},
389+
};

src/components/NotificationRow.tsx

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
const { shell } = require('electron');
2-
31
import React, { useCallback, useContext } from 'react';
42
import { formatDistanceToNow, parseISO } from 'date-fns';
53
import { CheckIcon, MuteIcon } from '@primer/octicons-react';
64

75
import { formatReason, getNotificationTypeIcon } from '../utils/github-api';
8-
import { generateGitHubWebUrl } from '../utils/helpers';
6+
import { openInBrowser } from '../utils/helpers';
97
import { Notification } from '../typesGithub';
108
import { AppContext } from '../context/App';
119

@@ -18,8 +16,8 @@ export const NotificationRow: React.FC<IProps> = ({
1816
notification,
1917
hostname,
2018
}) => {
21-
const { settings, accounts } = useContext(AppContext);
22-
const { markNotification, unsubscribeNotification } = useContext(AppContext);
19+
const { settings, accounts, markNotification, unsubscribeNotification } =
20+
useContext(AppContext);
2321

2422
const pressTitle = useCallback(() => {
2523
openBrowser();
@@ -29,17 +27,10 @@ export const NotificationRow: React.FC<IProps> = ({
2927
}
3028
}, [settings]);
3129

32-
const openBrowser = useCallback(() => {
33-
// Some Notification types from GitHub are missing urls in their subjects.
34-
if (notification.subject.url) {
35-
const url = generateGitHubWebUrl(
36-
notification.subject.url,
37-
notification.id,
38-
accounts.user?.id
39-
);
40-
shell.openExternal(url);
41-
}
42-
}, [notification]);
30+
const openBrowser = useCallback(
31+
() => openInBrowser(notification, accounts),
32+
[notification]
33+
);
4334

4435
const unsubscribe = (event: React.MouseEvent<HTMLElement>) => {
4536
// Don't trigger onClick of parent element.

src/hooks/useNotifications.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@ export const useNotifications = (): NotificationsState => {
9898
]
9999
: [...enterpriseNotifications];
100100

101-
triggerNativeNotifications(
102-
notifications,
103-
data,
104-
settings,
105-
accounts.user
106-
);
101+
triggerNativeNotifications(notifications, data, settings, accounts);
107102
setNotifications(data);
108103
setIsFetching(false);
109104
})

src/routes/__snapshots__/LoginWithToken.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ exports[`routes/LoginWithToken.js renders correctly 1`] = `
8484
<span
8585
className="underline font-extrabold text-yellow-500"
8686
>
87-
read:user, notifications
87+
read:user, notifications, repo
8888
8989
</span>
9090
scopes.

0 commit comments

Comments
 (0)