Skip to content

Commit 376e138

Browse files
committed
test: refactor render with app context
Signed-off-by: Adam Setch <[email protected]>
1 parent f6b610e commit 376e138

17 files changed

+61
-53
lines changed

src/renderer/__helpers__/test-utils.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,10 @@ export function renderWithAppContext(
6767
),
6868
});
6969
}
70+
71+
/**
72+
* Ensure stable snapshots for our randomized emoji use-cases
73+
*/
74+
export function ensureStableEmojis() {
75+
global.Math.random = jest.fn(() => 0.1);
76+
}

src/renderer/__mocks__/account-mocks.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import type {
66
Hostname,
77
Token,
88
} from '../types';
9-
import {
10-
mockEnterpriseNotifications,
11-
mockGitHubNotifications,
12-
mockSingleNotification,
13-
} from '../utils/api/__mocks__/response-mocks';
149
import { mockGitifyUser } from './user-mocks';
1510

1611
export const mockPersonalAccessTokenAccount: Account = {
@@ -59,27 +54,6 @@ export const mockGitHubAppAccount: Account = {
5954
hasRequiredScopes: true,
6055
};
6156

62-
export const mockAccountNotifications: AccountNotifications[] = [
63-
{
64-
account: mockGitHubCloudAccount,
65-
notifications: mockGitHubNotifications,
66-
error: null,
67-
},
68-
{
69-
account: mockGitHubEnterpriseServerAccount,
70-
notifications: mockEnterpriseNotifications,
71-
error: null,
72-
},
73-
];
74-
75-
export const mockSingleAccountNotifications: AccountNotifications[] = [
76-
{
77-
account: mockGitHubCloudAccount,
78-
notifications: [mockSingleNotification],
79-
error: null,
80-
},
81-
];
82-
8357
export function mockAccountWithError(error: GitifyError): AccountNotifications {
8458
return {
8559
account: mockGitHubCloudAccount,

src/renderer/__mocks__/notifications-mocks.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import { Constants } from '../constants';
2-
import type { Hostname } from '../types';
2+
import type { AccountNotifications, Hostname } from '../types';
33
import type {
44
Notification,
55
Repository,
66
StateType,
77
Subject,
88
SubjectType,
99
} from '../typesGitHub';
10-
import { mockGitHubCloudAccount } from './account-mocks';
10+
import {
11+
mockEnterpriseNotifications,
12+
mockGitHubNotifications,
13+
mockSingleNotification,
14+
} from '../utils/api/__mocks__/response-mocks';
15+
import {
16+
mockGitHubCloudAccount,
17+
mockGitHubEnterpriseServerAccount,
18+
} from './account-mocks';
1119
import { mockToken } from './state-mocks';
1220
import { mockGitifyUser } from './user-mocks';
1321

@@ -55,3 +63,24 @@ export function createMockNotificationForRepoName(
5563
account: mockGitHubCloudAccount,
5664
} as Notification;
5765
}
66+
67+
export const mockAccountNotifications: AccountNotifications[] = [
68+
{
69+
account: mockGitHubCloudAccount,
70+
notifications: mockGitHubNotifications,
71+
error: null,
72+
},
73+
{
74+
account: mockGitHubEnterpriseServerAccount,
75+
notifications: mockEnterpriseNotifications,
76+
error: null,
77+
},
78+
];
79+
80+
export const mockSingleAccountNotifications: AccountNotifications[] = [
81+
{
82+
account: mockGitHubCloudAccount,
83+
notifications: [mockSingleNotification],
84+
error: null,
85+
},
86+
];

src/renderer/__mocks__/utils.ts

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

src/renderer/components/AllRead.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { act } from '@testing-library/react';
22

3-
import { renderWithAppContext } from '../__helpers__/test-utils';
3+
import {
4+
ensureStableEmojis,
5+
renderWithAppContext,
6+
} from '../__helpers__/test-utils';
47
import { mockSettings } from '../__mocks__/state-mocks';
5-
import { ensureStableEmojis } from '../__mocks__/utils';
68
import { AllRead } from './AllRead';
79

810
describe('renderer/components/AllRead.tsx', () => {

src/renderer/components/Oops.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { act } from '@testing-library/react';
22

3-
import { renderWithAppContext } from '../__helpers__/test-utils';
4-
import { ensureStableEmojis } from '../__mocks__/utils';
3+
import {
4+
ensureStableEmojis,
5+
renderWithAppContext,
6+
} from '../__helpers__/test-utils';
57
import { Oops } from './Oops';
68

79
describe('renderer/components/Oops.tsx', () => {

src/renderer/components/Sidebar.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import userEvent from '@testing-library/user-event';
33
import { MemoryRouter } from 'react-router-dom';
44

55
import { renderWithAppContext } from '../__helpers__/test-utils';
6-
import { mockAccountNotifications } from '../__mocks__/account-mocks';
6+
import { mockAccountNotifications } from '../__mocks__/notifications-mocks';
77
import * as comms from '../utils/comms';
88
import { Sidebar } from './Sidebar';
99

src/renderer/components/filters/FilterSection.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
44
import { MarkGithubIcon } from '@primer/octicons-react';
55

66
import { renderWithAppContext } from '../../__helpers__/test-utils';
7-
import { mockAccountNotifications } from '../../__mocks__/account-mocks';
7+
import { mockAccountNotifications } from '../../__mocks__/notifications-mocks';
88
import { mockSettings } from '../../__mocks__/state-mocks';
99
import { stateFilter } from '../../utils/notifications/filters';
1010
import { FilterSection } from './FilterSection';

src/renderer/components/filters/ReasonFilter.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { renderWithAppContext } from '../../__helpers__/test-utils';
2-
import { mockAccountNotifications } from '../../__mocks__/account-mocks';
2+
import { mockAccountNotifications } from '../../__mocks__/notifications-mocks';
33
import { ReasonFilter } from './ReasonFilter';
44

55
describe('renderer/components/filters/ReasonFilter.tsx', () => {

src/renderer/components/filters/StateFilter.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { renderWithAppContext } from '../../__helpers__/test-utils';
2-
import { mockAccountNotifications } from '../../__mocks__/account-mocks';
2+
import { mockAccountNotifications } from '../../__mocks__/notifications-mocks';
33
import { StateFilter } from './StateFilter';
44

55
describe('renderer/components/filters/StateFilter.tsx', () => {

0 commit comments

Comments
 (0)