Skip to content

Commit

Permalink
Merge branch 'main' into feat/state-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsojramos authored Sep 14, 2023
2 parents 2d1fdd4 + fb0a468 commit 8cffbe9
Show file tree
Hide file tree
Showing 21 changed files with 481 additions and 186 deletions.
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 @@ -275,3 +275,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',
},
},
],
},
},
},
],
},
},
},
],
},
},
},
};
22 changes: 7 additions & 15 deletions src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { shell } = require('electron');

import React, { useCallback, useContext } from 'react';
import { formatDistanceToNow, parseISO } from 'date-fns';
import { CheckIcon, MuteIcon } from '@primer/octicons-react';
Expand All @@ -10,6 +8,7 @@ import {
getNotificationTypeIconColor,
} from '../utils/github-api';
import { generateGitHubWebUrl } from '../utils/helpers';

Check failure on line 10 in src/components/NotificationRow.tsx

View workflow job for this annotation

GitHub Actions / run-unit-tests

'generateGitHubWebUrl' is declared but its value is never read.
import { openInBrowser } from '../utils/helpers';
import { Notification } from '../typesGithub';
import { AppContext } from '../context/App';

Expand All @@ -22,8 +21,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 @@ -33,17 +32,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
16 changes: 13 additions & 3 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Octicons from '@primer/octicons-react';
import { ipcRenderer, shell } from 'electron';
import React, { useCallback, useContext, useMemo } from 'react';
import { useHistory } from 'react-router-dom';
import { useHistory, useLocation } from 'react-router-dom';

import { Logo } from '../components/Logo';
import { AppContext } from '../context/App';
Expand All @@ -12,6 +12,7 @@ import { Constants } from '../utils/constants';

export const Sidebar: React.FC = () => {
const history = useHistory();
const location = useLocation();

const { isLoggedIn } = useContext(AppContext);
const { notifications, fetchNotifications } = useContext(AppContext);
Expand Down Expand Up @@ -64,15 +65,24 @@ export const Sidebar: React.FC = () => {
<>
<button
className={footerButtonClasses}
onClick={fetchNotifications}
onClick={() => {
history.replace('/');
fetchNotifications();
}}
aria-label="Refresh Notifications"
>
<IconRefresh className="w-3.5 h-3.5" />
</button>

<button
className={footerButtonClasses}
onClick={() => history.push('/settings')}
onClick={() => {
if (location.pathname.startsWith('/settings')) {
history.replace('/');
} else {
history.push('/settings');
}
}}
aria-label="Settings"
>
<IconCog className="w-4 h-4" />
Expand Down
Loading

0 comments on commit 8cffbe9

Please sign in to comment.