Skip to content

Commit e3dbb24

Browse files
authored
refactor(mocks): use consistent naming (#1142)
* refactor(mocks): use consistent naming * refactor(mocks): rename mocks
1 parent 40fa988 commit e3dbb24

19 files changed

+210
-201
lines changed

src/__mocks__/mock-state.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/__mocks__/notifications-mocks.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { AccountNotifications } from '../types';
2+
import {
3+
mockEnterpriseNotifications,
4+
mockGitHubNotifications,
5+
mockSingleNotification,
6+
} from '../utils/api/__mocks__/response-mocks';
7+
8+
export const mockAccountNotifications: AccountNotifications[] = [
9+
{
10+
hostname: 'github.com',
11+
notifications: mockGitHubNotifications,
12+
},
13+
{
14+
hostname: 'github.gitify.io',
15+
notifications: mockEnterpriseNotifications,
16+
},
17+
];
18+
19+
export const mockSingleAccountNotifications: AccountNotifications[] = [
20+
{
21+
hostname: 'github.com',
22+
notifications: [mockSingleNotification],
23+
},
24+
];

src/__mocks__/state-mocks.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
type AuthState,
3+
type EnterpriseAccount,
4+
type GitifyUser,
5+
type SettingsState,
6+
Theme,
7+
} from '../types';
8+
9+
export const mockEnterpriseAccounts: EnterpriseAccount[] = [
10+
{
11+
hostname: 'github.gitify.io',
12+
token: '1234568790',
13+
},
14+
];
15+
16+
export const mockUser: GitifyUser = {
17+
login: 'octocat',
18+
name: 'Mona Lisa Octocat',
19+
id: 123456789,
20+
};
21+
22+
export const mockAccounts: AuthState = {
23+
token: 'token-123-456',
24+
enterpriseAccounts: mockEnterpriseAccounts,
25+
user: mockUser,
26+
};
27+
28+
export const mockSettings: SettingsState = {
29+
participating: false,
30+
playSound: true,
31+
showNotifications: true,
32+
showBots: true,
33+
showNotificationsCountInTray: false,
34+
openAtStartup: false,
35+
theme: Theme.SYSTEM,
36+
detailedNotifications: true,
37+
markAsDoneOnOpen: false,
38+
showAccountHostname: false,
39+
delayNotificationState: false,
40+
};

src/components/AccountNotifications.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { render } from '@testing-library/react';
2-
import { mockedGitHubNotifications } from '../__mocks__/mockedData';
2+
import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks';
33
import { AccountNotifications } from './AccountNotifications';
44

55
jest.mock('./Repository', () => ({
@@ -10,7 +10,7 @@ describe('components/AccountNotifications.tsx', () => {
1010
it('should render itself (github.com with notifications)', () => {
1111
const props = {
1212
hostname: 'github.com',
13-
notifications: mockedGitHubNotifications,
13+
notifications: mockGitHubNotifications,
1414
showAccountHostname: true,
1515
};
1616

src/components/NotificationRow.test.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { fireEvent, render, screen } from '@testing-library/react';
22
import { shell } from 'electron';
3-
import { mockAccounts, mockSettings } from '../__mocks__/mock-state';
4-
import { mockedSingleNotification } from '../__mocks__/mockedData';
3+
import { mockAccounts, mockSettings } from '../__mocks__/state-mocks';
54
import { AppContext } from '../context/App';
65
import type { UserType } from '../typesGitHub';
6+
import { mockSingleNotification } from '../utils/api/__mocks__/response-mocks';
77
import * as helpers from '../utils/helpers';
88
import { NotificationRow } from './NotificationRow';
99

@@ -22,7 +22,7 @@ describe('components/NotificationRow.tsx', () => {
2222
.mockImplementation(() => new Date('2024').valueOf());
2323

2424
const props = {
25-
notification: mockedSingleNotification,
25+
notification: mockSingleNotification,
2626
hostname: 'github.com',
2727
};
2828

@@ -35,7 +35,7 @@ describe('components/NotificationRow.tsx', () => {
3535
.spyOn(global.Date, 'now')
3636
.mockImplementation(() => new Date('2024').valueOf());
3737

38-
const mockNotification = mockedSingleNotification;
38+
const mockNotification = mockSingleNotification;
3939
mockNotification.last_read_at = null;
4040

4141
const props = {
@@ -52,7 +52,7 @@ describe('components/NotificationRow.tsx', () => {
5252
.spyOn(global.Date, 'now')
5353
.mockImplementation(() => new Date('2024').valueOf());
5454

55-
const mockNotification = mockedSingleNotification;
55+
const mockNotification = mockSingleNotification;
5656
mockNotification.subject.user = null;
5757

5858
const props = {
@@ -70,7 +70,7 @@ describe('components/NotificationRow.tsx', () => {
7070
.spyOn(global.Date, 'now')
7171
.mockImplementation(() => new Date('2024').valueOf());
7272

73-
const mockNotification = mockedSingleNotification;
73+
const mockNotification = mockSingleNotification;
7474
mockNotification.subject.comments = null;
7575

7676
const props = {
@@ -87,7 +87,7 @@ describe('components/NotificationRow.tsx', () => {
8787
.spyOn(global.Date, 'now')
8888
.mockImplementation(() => new Date('2024').valueOf());
8989

90-
const mockNotification = mockedSingleNotification;
90+
const mockNotification = mockSingleNotification;
9191
mockNotification.subject.comments = 1;
9292

9393
const props = {
@@ -104,7 +104,7 @@ describe('components/NotificationRow.tsx', () => {
104104
.spyOn(global.Date, 'now')
105105
.mockImplementation(() => new Date('2024').valueOf());
106106

107-
const mockNotification = mockedSingleNotification;
107+
const mockNotification = mockSingleNotification;
108108
mockNotification.subject.comments = 2;
109109

110110
const props = {
@@ -122,7 +122,7 @@ describe('components/NotificationRow.tsx', () => {
122122
const removeNotificationFromState = jest.fn();
123123

124124
const props = {
125-
notification: mockedSingleNotification,
125+
notification: mockSingleNotification,
126126
hostname: 'github.com',
127127
};
128128

@@ -147,7 +147,7 @@ describe('components/NotificationRow.tsx', () => {
147147
const removeNotificationFromState = jest.fn();
148148

149149
const props = {
150-
notification: mockedSingleNotification,
150+
notification: mockSingleNotification,
151151
hostname: 'github.com',
152152
};
153153

@@ -172,7 +172,7 @@ describe('components/NotificationRow.tsx', () => {
172172
const markNotificationDone = jest.fn();
173173

174174
const props = {
175-
notification: mockedSingleNotification,
175+
notification: mockSingleNotification,
176176
hostname: 'github.com',
177177
};
178178

@@ -197,7 +197,7 @@ describe('components/NotificationRow.tsx', () => {
197197
const markNotificationRead = jest.fn();
198198

199199
const props = {
200-
notification: mockedSingleNotification,
200+
notification: mockSingleNotification,
201201
hostname: 'github.com',
202202
};
203203

@@ -222,7 +222,7 @@ describe('components/NotificationRow.tsx', () => {
222222
const markNotificationDone = jest.fn();
223223

224224
const props = {
225-
notification: mockedSingleNotification,
225+
notification: mockSingleNotification,
226226
hostname: 'github.com',
227227
};
228228

@@ -247,7 +247,7 @@ describe('components/NotificationRow.tsx', () => {
247247
const unsubscribeNotification = jest.fn();
248248

249249
const props = {
250-
notification: mockedSingleNotification,
250+
notification: mockSingleNotification,
251251
hostname: 'github.com',
252252
};
253253

@@ -265,9 +265,9 @@ describe('components/NotificationRow.tsx', () => {
265265
it('should open notification user profile', () => {
266266
const props = {
267267
notification: {
268-
...mockedSingleNotification,
268+
...mockSingleNotification,
269269
subject: {
270-
...mockedSingleNotification.subject,
270+
...mockSingleNotification.subject,
271271
user: {
272272
login: 'some-user',
273273
html_url: 'https://github.com/some-user',

src/components/Repository.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fireEvent, render, screen } from '@testing-library/react';
22
import { shell } from 'electron';
3-
import { mockedGitHubNotifications } from '../__mocks__/mockedData';
43
import { AppContext } from '../context/App';
4+
import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks';
55
import { RepositoryNotifications } from './Repository';
66

77
jest.mock('./NotificationRow', () => ({
@@ -15,7 +15,7 @@ describe('components/Repository.tsx', () => {
1515
const props = {
1616
hostname: 'github.com',
1717
repoName: 'gitify-app/notifications-test',
18-
repoNotifications: mockedGitHubNotifications,
18+
repoNotifications: mockGitHubNotifications,
1919
};
2020

2121
beforeEach(() => {

src/components/Sidebar.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { fireEvent, render, screen } from '@testing-library/react';
22
import { ipcRenderer, shell } from 'electron';
33
import { MemoryRouter } from 'react-router-dom';
4-
import { mockSettings } from '../__mocks__/mock-state';
5-
import { mockedAccountNotifications } from '../__mocks__/mockedData';
4+
import { mockAccountNotifications } from '../__mocks__/notifications-mocks';
5+
import { mockSettings } from '../__mocks__/state-mocks';
66
import { AppContext } from '../context/App';
77
import { Sidebar } from './Sidebar';
88

@@ -32,7 +32,7 @@ describe('components/Sidebar.tsx', () => {
3232
<AppContext.Provider
3333
value={{
3434
settings: mockSettings,
35-
notifications: mockedAccountNotifications,
35+
notifications: mockAccountNotifications,
3636
}}
3737
>
3838
<MemoryRouter>
@@ -46,7 +46,7 @@ describe('components/Sidebar.tsx', () => {
4646
it('should render itself & its children (logged out)', () => {
4747
const tree = render(
4848
<AppContext.Provider
49-
value={{ isLoggedIn: false, notifications: mockedAccountNotifications }}
49+
value={{ isLoggedIn: false, notifications: mockAccountNotifications }}
5050
>
5151
<MemoryRouter>
5252
<Sidebar />
@@ -131,7 +131,7 @@ describe('components/Sidebar.tsx', () => {
131131
<AppContext.Provider
132132
value={{
133133
isLoggedIn: true,
134-
notifications: mockedAccountNotifications,
134+
notifications: mockAccountNotifications,
135135
}}
136136
>
137137
<MemoryRouter>
@@ -195,7 +195,7 @@ describe('components/Sidebar.tsx', () => {
195195
<AppContext.Provider
196196
value={{
197197
isLoggedIn: true,
198-
notifications: mockedAccountNotifications,
198+
notifications: mockAccountNotifications,
199199
}}
200200
>
201201
<MemoryRouter>

src/context/App.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { act, fireEvent, render, waitFor } from '@testing-library/react';
22
import { useContext } from 'react';
3-
import { mockAccounts, mockSettings } from '../__mocks__/mock-state';
3+
4+
import { mockAccounts, mockSettings } from '../__mocks__/state-mocks';
45
import { useNotifications } from '../hooks/useNotifications';
56
import type { AuthState, SettingsState } from '../types';
67
import * as apiRequests from '../utils/api/request';

src/hooks/useNotifications.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { act, renderHook, waitFor } from '@testing-library/react';
22
import axios, { AxiosError } from 'axios';
33
import nock from 'nock';
4-
import { mockAccounts, mockSettings } from '../__mocks__/mock-state';
5-
import { mockedNotificationUser, mockedUser } from '../__mocks__/mockedData';
4+
5+
import { mockAccounts, mockSettings, mockUser } from '../__mocks__/state-mocks';
66
import type { AuthState } from '../types';
7+
import { mockNotificationUser } from '../utils/api/__mocks__/response-mocks';
78
import { Errors } from '../utils/constants';
89
import { useNotifications } from './useNotifications';
910

@@ -169,7 +170,7 @@ describe('hooks/useNotifications.ts', () => {
169170
const accounts: AuthState = {
170171
...mockAccounts,
171172
enterpriseAccounts: [],
172-
user: mockedUser,
173+
user: mockUser,
173174
};
174175

175176
const notifications = [
@@ -234,7 +235,7 @@ describe('hooks/useNotifications.ts', () => {
234235
const accounts: AuthState = {
235236
...mockAccounts,
236237
enterpriseAccounts: [],
237-
user: mockedUser,
238+
user: mockUser,
238239
};
239240

240241
const notifications = [
@@ -366,24 +367,24 @@ describe('hooks/useNotifications.ts', () => {
366367
.reply(200, {
367368
state: 'closed',
368369
merged: true,
369-
user: mockedNotificationUser,
370+
user: mockNotificationUser,
370371
});
371372
nock('https://api.github.com')
372373
.get('/repos/gitify-app/notifications-test/issues/3/comments')
373374
.reply(200, {
374-
user: mockedNotificationUser,
375+
user: mockNotificationUser,
375376
});
376377
nock('https://api.github.com')
377378
.get('/repos/gitify-app/notifications-test/pulls/4')
378379
.reply(200, {
379380
state: 'closed',
380381
merged: false,
381-
user: mockedNotificationUser,
382+
user: mockNotificationUser,
382383
});
383384
nock('https://api.github.com')
384385
.get('/repos/gitify-app/notifications-test/issues/4/comments')
385386
.reply(200, {
386-
user: mockedNotificationUser,
387+
user: mockNotificationUser,
387388
});
388389

389390
const { result } = renderHook(() => useNotifications());

src/routes/LoginWithOAuthApp.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fireEvent, render, screen } from '@testing-library/react';
22
import { ipcRenderer } from 'electron';
33
import { shell } from 'electron';
44
import { MemoryRouter } from 'react-router-dom';
5-
import { mockedEnterpriseAccounts } from '../__mocks__/mockedData';
5+
import { mockEnterpriseAccounts } from '../__mocks__/state-mocks';
66
import { AppContext } from '../context/App';
77
import type { AuthState } from '../types';
88
import { LoginWithOAuthApp, validate } from './LoginWithOAuthApp';
@@ -125,7 +125,7 @@ describe('routes/LoginWithOAuthApp.tsx', () => {
125125
<AppContext.Provider
126126
value={{
127127
accounts: {
128-
enterpriseAccounts: mockedEnterpriseAccounts,
128+
enterpriseAccounts: mockEnterpriseAccounts,
129129
user: null,
130130
},
131131
}}

0 commit comments

Comments
 (0)