Skip to content

Commit 757f4c2

Browse files
committed
refactor: test mock helpers
Signed-off-by: Adam Setch <[email protected]>
1 parent 36d4be8 commit 757f4c2

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

src/renderer/__helpers__/test-utils.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { render } from '@testing-library/react';
2-
import type { ReactElement, ReactNode } from 'react';
3-
import { useMemo } from 'react';
2+
import { type ReactElement, type ReactNode, useMemo } from 'react';
43

54
import { BaseStyles, ThemeProvider } from '@primer/react';
65

76
import { mockAuth, mockSettings } from '../__mocks__/state-mocks';
8-
import type { AppContextState } from '../context/App';
9-
import { AppContext } from '../context/App';
7+
import { AppContext, type AppContextState } from '../context/App';
108

119
/**
1210
* Props for the AppContextProvider wrapper

src/renderer/__mocks__/account-mocks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ export const mockGitHubAppAccount: Account = {
5454
hasRequiredScopes: true,
5555
};
5656

57-
export function mockAccountWithError(error: GitifyError): AccountNotifications {
57+
export function createMockAccountWithError(
58+
error: GitifyError,
59+
): AccountNotifications {
5860
return {
5961
account: mockGitHubCloudAccount,
6062
notifications: [],

src/renderer/__mocks__/notifications-mocks.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ import {
1919
import { mockToken } from './state-mocks';
2020
import { mockGitifyUser } from './user-mocks';
2121

22+
export const mockAccountNotifications: AccountNotifications[] = [
23+
{
24+
account: mockGitHubCloudAccount,
25+
notifications: mockGitHubNotifications,
26+
error: null,
27+
},
28+
{
29+
account: mockGitHubEnterpriseServerAccount,
30+
notifications: mockEnterpriseNotifications,
31+
error: null,
32+
},
33+
];
34+
35+
export const mockSingleAccountNotifications: AccountNotifications[] = [
36+
{
37+
account: mockGitHubCloudAccount,
38+
notifications: [mockSingleNotification],
39+
error: null,
40+
},
41+
];
42+
2243
export function createMockSubject(mocks: {
2344
title?: string;
2445
type?: SubjectType;
@@ -63,24 +84,3 @@ export function createMockNotificationForRepoName(
6384
account: mockGitHubCloudAccount,
6485
} as Notification;
6586
}
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/utils/errors.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mockAccountWithError } from '../__mocks__/account-mocks';
1+
import { createMockAccountWithError } from '../__mocks__/account-mocks';
22
import type { AccountNotifications } from '../types';
33
import {
44
areAllAccountErrorsSame,
@@ -14,17 +14,17 @@ describe('renderer/utils/errors.ts', () => {
1414

1515
it('returns false when some accounts have no error', () => {
1616
const items: AccountNotifications[] = [
17-
mockAccountWithError(Errors.NETWORK),
18-
mockAccountWithError(null),
17+
createMockAccountWithError(Errors.NETWORK),
18+
createMockAccountWithError(null),
1919
];
2020

2121
expect(doesAllAccountsHaveErrors(items)).toBe(false);
2222
});
2323

2424
it('returns true when every account has an error', () => {
2525
const items: AccountNotifications[] = [
26-
mockAccountWithError(Errors.NETWORK),
27-
mockAccountWithError(Errors.RATE_LIMITED),
26+
createMockAccountWithError(Errors.NETWORK),
27+
createMockAccountWithError(Errors.RATE_LIMITED),
2828
];
2929

3030
expect(doesAllAccountsHaveErrors(items)).toBe(true);
@@ -39,26 +39,26 @@ describe('renderer/utils/errors.ts', () => {
3939
it('returns true when all errors are identical object reference', () => {
4040
const err = Errors.NETWORK;
4141
const items: AccountNotifications[] = [
42-
mockAccountWithError(err),
43-
mockAccountWithError(err),
42+
createMockAccountWithError(err),
43+
createMockAccountWithError(err),
4444
];
4545

4646
expect(areAllAccountErrorsSame(items)).toBe(true);
4747
});
4848

4949
it('returns false when errors differ', () => {
5050
const items: AccountNotifications[] = [
51-
mockAccountWithError(Errors.NETWORK),
52-
mockAccountWithError(Errors.RATE_LIMITED),
51+
createMockAccountWithError(Errors.NETWORK),
52+
createMockAccountWithError(Errors.RATE_LIMITED),
5353
];
5454

5555
expect(areAllAccountErrorsSame(items)).toBe(false);
5656
});
5757

5858
it('returns false when one account has null error', () => {
5959
const items: AccountNotifications[] = [
60-
mockAccountWithError(Errors.NETWORK),
61-
mockAccountWithError(null),
60+
createMockAccountWithError(Errors.NETWORK),
61+
createMockAccountWithError(null),
6262
];
6363

6464
expect(areAllAccountErrorsSame(items)).toBe(false);

0 commit comments

Comments
 (0)