Skip to content

Commit e12a779

Browse files
setchyadufr
authored andcommitted
refactor: simplify notification html url logic (gitify-app#793)
* refactor: simplify html url * fix: add test coverage
1 parent 3121483 commit e12a779

File tree

6 files changed

+420
-215
lines changed

6 files changed

+420
-215
lines changed

src/__mocks__/mock-state.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { Appearance, AuthState, SettingsState } from '../types';
2-
import { mockedUser } from './mockedData';
2+
import { mockedUser, mockedEnterpriseAccounts } from './mockedData';
33

44
export const mockAccounts: AuthState = {
55
token: 'token-123-456',
6-
enterpriseAccounts: [
7-
{
8-
token: 'token-gitify-123-456',
9-
hostname: 'github.gitify.io',
10-
},
11-
],
6+
enterpriseAccounts: mockedEnterpriseAccounts,
127
user: mockedUser,
138
};
149

src/__mocks__/mockedData.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,108 @@ export const mockedGraphQLResponse: GraphQLSearch = {
383383
},
384384
},
385385
},
386+
{
387+
node: {
388+
viewerSubscription: 'IGNORED',
389+
title: '1.16.0',
390+
url: 'https://github.com/manosim/notifications-test/discussions/612',
391+
comments: {
392+
edges: [
393+
{
394+
node: {
395+
databaseId: 2215656,
396+
createdAt: '2022-02-20T18:33:39Z',
397+
replies: {
398+
edges: [],
399+
},
400+
},
401+
},
402+
{
403+
node: {
404+
databaseId: 2217789,
405+
createdAt: '2022-02-21T03:30:42Z',
406+
replies: {
407+
edges: [],
408+
},
409+
},
410+
},
411+
{
412+
node: {
413+
databaseId: 2223243,
414+
createdAt: '2022-02-21T18:26:27Z',
415+
replies: {
416+
edges: [
417+
{
418+
node: {
419+
databaseId: 2232922,
420+
createdAt: '2022-02-23T00:57:58Z',
421+
},
422+
},
423+
],
424+
},
425+
},
426+
},
427+
{
428+
node: {
429+
databaseId: 2232921,
430+
createdAt: '2022-02-23T00:57:49Z',
431+
replies: {
432+
edges: [],
433+
},
434+
},
435+
},
436+
{
437+
node: {
438+
databaseId: 2258799,
439+
createdAt: '2022-02-27T01:22:20Z',
440+
replies: {
441+
edges: [
442+
{
443+
node: {
444+
databaseId: 2300902,
445+
createdAt: '2022-03-05T17:43:52Z',
446+
},
447+
},
448+
],
449+
},
450+
},
451+
},
452+
{
453+
node: {
454+
databaseId: 2297637,
455+
createdAt: '2022-03-04T20:39:44Z',
456+
replies: {
457+
edges: [
458+
{
459+
node: {
460+
databaseId: 2300893,
461+
createdAt: '2022-03-05T17:41:04Z',
462+
},
463+
},
464+
],
465+
},
466+
},
467+
},
468+
{
469+
node: {
470+
databaseId: 2299763,
471+
createdAt: '2022-03-05T11:05:42Z',
472+
replies: {
473+
edges: [
474+
{
475+
node: {
476+
databaseId: 2300895,
477+
createdAt: '2022-03-05T17:41:44Z',
478+
},
479+
},
480+
],
481+
},
482+
},
483+
},
484+
],
485+
},
486+
},
487+
},
386488
],
387489
},
388490
},

src/components/NotificationRow.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import * as TestRenderer from 'react-test-renderer';
33
import { fireEvent, render } from '@testing-library/react';
44

5-
const { shell } = require('electron');
5+
import * as helpers from '../utils/helpers';
66

77
import { AppContext } from '../context/App';
88
import { mockedSingleNotification } from '../__mocks__/mockedData';
@@ -11,7 +11,7 @@ import { mockAccounts, mockSettings } from '../__mocks__/mock-state';
1111

1212
describe('components/Notification.js', () => {
1313
beforeEach(() => {
14-
jest.spyOn(shell, 'openExternal');
14+
jest.spyOn(helpers, 'openInBrowser');
1515
});
1616

1717
afterEach(() => {
@@ -51,7 +51,7 @@ describe('components/Notification.js', () => {
5151
);
5252

5353
fireEvent.click(getByRole('main'));
54-
expect(shell.openExternal).toHaveBeenCalledTimes(1);
54+
expect(helpers.openInBrowser).toHaveBeenCalledTimes(1);
5555
expect(removeNotificationFromState).toHaveBeenCalledTimes(1);
5656
});
5757

@@ -76,7 +76,7 @@ describe('components/Notification.js', () => {
7676
);
7777

7878
fireEvent.click(getByRole('main'));
79-
expect(shell.openExternal).toHaveBeenCalledTimes(1);
79+
expect(helpers.openInBrowser).toHaveBeenCalledTimes(1);
8080
expect(markNotificationDone).toHaveBeenCalledTimes(1);
8181
});
8282

0 commit comments

Comments
 (0)