Skip to content
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

fix: discussions-url #538

Merged
merged 9 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ temp/

dist/
build/
.vscode/settings.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"react-transition-group": "^4.4.1",
"tailwindcss": "^2.0.2",
"ts-loader": "^9.4.2",
"typescript": "^4.1.3"
"typescript": "^4.6.2"
},
"devDependencies": {
"@testing-library/react": "^11.2.2",
Expand Down
30 changes: 15 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 19 additions & 11 deletions src/__mocks__/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,35 @@ window.localStorage = {

window.alert = jest.fn();

const browserWindow = {
loadURL: jest.fn(),
webContents: {
let instance;

class BrowserWindow {
constructor() {
if (!instance) {
instance = this;
}
return instance;
}
loadURL = jest.fn();
webContents = {
on: () => {},
session: {
clearStorageData: jest.fn(),
},
},
on: () => {},
close: jest.fn(),
hide: jest.fn(),
destroy: jest.fn(),
};
};
on() {}
close = jest.fn();
hide = jest.fn();
destroy = jest.fn();
}

const dialog = {
showErrorBox: jest.fn(),
};

module.exports = {
remote: {
BrowserWindow: () => browserWindow,
BrowserWindow: BrowserWindow,
dialog: dialog,
process: {
platform: 'darwin',
Expand All @@ -57,7 +65,7 @@ module.exports = {
getLoginItemSettings: jest.fn(),
setLoginItemSettings: () => {},
},
getCurrentWindow: jest.fn(() => browserWindow),
getCurrentWindow: jest.fn(() => instance || new BrowserWindow()),
},
ipcRenderer: {
send: jest.fn(),
Expand Down
115 changes: 114 additions & 1 deletion src/__mocks__/mockedData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountNotifications, EnterpriseAccount } from '../types';
import { Notification, Repository, User } from '../typesGithub';
import { Notification, Repository, User, GraphQLSearch } from '../typesGithub';

export const mockedEnterpriseAccounts: EnterpriseAccount[] = [
{
Expand Down Expand Up @@ -274,3 +274,116 @@ export const mockedSingleAccountNotifications: AccountNotifications[] = [
notifications: [mockedSingleNotification],
},
];

export const mockedGraphQLResponse: GraphQLSearch = {
data: {
data: {
search: {
edges: [
{
node: {
viewerSubscription: 'SUBSCRIBED',
title: '1.16.0',
url: 'https://github.com/manosim/notifications-test/discussions/612',
comments: {
edges: [
{
node: {
databaseId: 2215656,
createdAt: '2022-02-20T18:33:39Z',
replies: {
edges: [],
},
},
},
{
node: {
databaseId: 2217789,
createdAt: '2022-02-21T03:30:42Z',
replies: {
edges: [],
},
},
},
{
node: {
databaseId: 2223243,
createdAt: '2022-02-21T18:26:27Z',
replies: {
edges: [
{
node: {
databaseId: 2232922,
createdAt: '2022-02-23T00:57:58Z',
},
},
],
},
},
},
{
node: {
databaseId: 2232921,
createdAt: '2022-02-23T00:57:49Z',
replies: {
edges: [],
},
},
},
{
node: {
databaseId: 2258799,
createdAt: '2022-02-27T01:22:20Z',
replies: {
edges: [
{
node: {
databaseId: 2300902,
createdAt: '2022-03-05T17:43:52Z',
},
},
],
},
},
},
{
node: {
databaseId: 2297637,
createdAt: '2022-03-04T20:39:44Z',
replies: {
edges: [
{
node: {
databaseId: 2300893,
createdAt: '2022-03-05T17:41:04Z',
},
},
],
},
},
},
{
node: {
databaseId: 2299763,
createdAt: '2022-03-05T11:05:42Z',
replies: {
edges: [
{
node: {
databaseId: 2300895,
createdAt: '2022-03-05T17:41:44Z',
},
},
],
},
},
},
],
},
},
},
],
},
},
},
};
23 changes: 7 additions & 16 deletions src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const { shell } = require('electron');

import React, { useCallback, useContext } from 'react';
import { formatDistanceToNow, parseISO } from 'date-fns';
import { CheckIcon, MuteIcon } from '@primer/octicons-react';

import { formatReason, getNotificationTypeIcon } from '../utils/github-api';
import { generateGitHubWebUrl } from '../utils/helpers';
import { openInBrowser } from '../utils/helpers';
import { Notification } from '../typesGithub';
import { AppContext } from '../context/App';

Expand All @@ -18,8 +16,8 @@ export const NotificationRow: React.FC<IProps> = ({
notification,
hostname,
}) => {
const { settings, accounts } = useContext(AppContext);
const { markNotification, unsubscribeNotification } = useContext(AppContext);
const { settings, accounts, markNotification, unsubscribeNotification } =
useContext(AppContext);

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

const openBrowser = useCallback(() => {
// Some Notification types from GitHub are missing urls in their subjects.
if (notification.subject.url) {
const url = generateGitHubWebUrl(
notification.subject.url,
notification.id,
accounts.user?.id
);
shell.openExternal(url);
}
}, [notification]);
const openBrowser = useCallback(
() => openInBrowser(notification, accounts),
[notification]
);

const unsubscribe = (event: React.MouseEvent<HTMLElement>) => {
// Don't trigger onClick of parent element.
Expand Down
7 changes: 1 addition & 6 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ export const useNotifications = (): NotificationsState => {
]
: [...enterpriseNotifications];

triggerNativeNotifications(
notifications,
data,
settings,
accounts.user
);
triggerNativeNotifications(notifications, data, settings, accounts);
setNotifications(data);
setIsFetching(false);
})
Expand Down
2 changes: 1 addition & 1 deletion src/routes/__snapshots__/LoginWithToken.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports[`routes/LoginWithToken.js renders correctly 1`] = `
<span
className="underline font-extrabold text-yellow-500"
>
read:user, notifications
read:user, notifications, repo

</span>
scopes.
Expand Down
Loading