Skip to content

Commit f6b610e

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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+332
-328
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Constants } from '../constants';
2+
import type {
3+
Account,
4+
AccountNotifications,
5+
GitifyError,
6+
Hostname,
7+
Token,
8+
} from '../types';
9+
import {
10+
mockEnterpriseNotifications,
11+
mockGitHubNotifications,
12+
mockSingleNotification,
13+
} from '../utils/api/__mocks__/response-mocks';
14+
import { mockGitifyUser } from './user-mocks';
15+
16+
export const mockPersonalAccessTokenAccount: Account = {
17+
platform: 'GitHub Cloud',
18+
method: 'Personal Access Token',
19+
token: 'token-123-456' as Token,
20+
hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
21+
user: mockGitifyUser,
22+
hasRequiredScopes: true,
23+
};
24+
25+
export const mockOAuthAccount: Account = {
26+
platform: 'GitHub Enterprise Server',
27+
method: 'OAuth App',
28+
token: '1234568790' as Token,
29+
hostname: 'github.gitify.io' as Hostname,
30+
user: mockGitifyUser,
31+
hasRequiredScopes: true,
32+
};
33+
34+
export const mockGitHubCloudAccount: Account = {
35+
platform: 'GitHub Cloud',
36+
method: 'Personal Access Token',
37+
token: 'token-123-456' as Token,
38+
hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
39+
user: mockGitifyUser,
40+
version: 'latest',
41+
hasRequiredScopes: true,
42+
};
43+
44+
export const mockGitHubEnterpriseServerAccount: Account = {
45+
platform: 'GitHub Enterprise Server',
46+
method: 'Personal Access Token',
47+
token: '1234568790' as Token,
48+
hostname: 'github.gitify.io' as Hostname,
49+
user: mockGitifyUser,
50+
hasRequiredScopes: true,
51+
};
52+
53+
export const mockGitHubAppAccount: Account = {
54+
platform: 'GitHub Cloud',
55+
method: 'GitHub App',
56+
token: '987654321' as Token,
57+
hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
58+
user: mockGitifyUser,
59+
hasRequiredScopes: true,
60+
};
61+
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+
83+
export function mockAccountWithError(error: GitifyError): AccountNotifications {
84+
return {
85+
account: mockGitHubCloudAccount,
86+
notifications: [],
87+
error,
88+
};
89+
}

src/renderer/__mocks__/notifications-mocks.ts

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,17 @@
1-
import type { AccountNotifications, GitifyError } from '../types';
1+
import { Constants } from '../constants';
2+
import type { Hostname } from '../types';
23
import type {
34
Notification,
5+
Repository,
46
StateType,
57
Subject,
68
SubjectType,
79
} from '../typesGitHub';
8-
import {
9-
mockEnterpriseNotifications,
10-
mockGitHubNotifications,
11-
mockSingleNotification,
12-
} from '../utils/api/__mocks__/response-mocks';
13-
import {
14-
mockGitHubCloudAccount,
15-
mockGitHubEnterpriseServerAccount,
16-
} from './state-mocks';
10+
import { mockGitHubCloudAccount } from './account-mocks';
11+
import { mockToken } from './state-mocks';
12+
import { mockGitifyUser } from './user-mocks';
1713

18-
export const mockAccountNotifications: AccountNotifications[] = [
19-
{
20-
account: mockGitHubCloudAccount,
21-
notifications: mockGitHubNotifications,
22-
error: null,
23-
},
24-
{
25-
account: mockGitHubEnterpriseServerAccount,
26-
notifications: mockEnterpriseNotifications,
27-
error: null,
28-
},
29-
];
30-
31-
export const mockSingleAccountNotifications: AccountNotifications[] = [
32-
{
33-
account: mockGitHubCloudAccount,
34-
notifications: [mockSingleNotification],
35-
error: null,
36-
},
37-
];
38-
39-
export function createSubjectMock(mocks: {
14+
export function createMockSubject(mocks: {
4015
title?: string;
4116
type?: SubjectType;
4217
state?: StateType;
@@ -50,12 +25,24 @@ export function createSubjectMock(mocks: {
5025
};
5126
}
5227

53-
export function mockAccountWithError(error: GitifyError): AccountNotifications {
54-
return {
55-
account: mockGitHubCloudAccount,
56-
notifications: [],
57-
error,
28+
export function createPartialMockNotification(
29+
subject: Partial<Subject>,
30+
repository?: Partial<Repository>,
31+
): Notification {
32+
const mockNotification: Partial<Notification> = {
33+
account: {
34+
method: 'Personal Access Token',
35+
platform: 'GitHub Cloud',
36+
hostname: Constants.GITHUB_API_BASE_URL as Hostname,
37+
token: mockToken,
38+
user: mockGitifyUser,
39+
hasRequiredScopes: true,
40+
},
41+
subject: subject as Subject,
42+
repository: repository as Repository,
5843
};
44+
45+
return mockNotification as Notification;
5946
}
6047

6148
export function createMockNotificationForRepoName(

src/renderer/__mocks__/partial-mocks.ts

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

src/renderer/__mocks__/state-mocks.ts

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { Constants } from '../constants';
22
import {
3-
type Account,
43
type AppearanceSettingsState,
54
type AuthState,
65
FetchType,
76
type FilterSettingsState,
87
type GitifyState,
9-
type GitifyUser,
108
GroupBy,
11-
type Hostname,
12-
type Link,
139
type NotificationSettingsState,
1410
OpenPreference,
1511
type Percentage,
@@ -19,59 +15,10 @@ import {
1915
type Token,
2016
type TraySettingsState,
2117
} from '../types';
22-
23-
export const mockGitifyUser: GitifyUser = {
24-
login: 'octocat',
25-
name: 'Mona Lisa Octocat',
26-
id: 123456789,
27-
avatar: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
28-
};
29-
30-
export const mockPersonalAccessTokenAccount: Account = {
31-
platform: 'GitHub Cloud',
32-
method: 'Personal Access Token',
33-
token: 'token-123-456' as Token,
34-
hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
35-
user: mockGitifyUser,
36-
hasRequiredScopes: true,
37-
};
38-
39-
export const mockOAuthAccount: Account = {
40-
platform: 'GitHub Enterprise Server',
41-
method: 'OAuth App',
42-
token: '1234568790' as Token,
43-
hostname: 'github.gitify.io' as Hostname,
44-
user: mockGitifyUser,
45-
hasRequiredScopes: true,
46-
};
47-
48-
export const mockGitHubCloudAccount: Account = {
49-
platform: 'GitHub Cloud',
50-
method: 'Personal Access Token',
51-
token: 'token-123-456' as Token,
52-
hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
53-
user: mockGitifyUser,
54-
version: 'latest',
55-
hasRequiredScopes: true,
56-
};
57-
58-
export const mockGitHubEnterpriseServerAccount: Account = {
59-
platform: 'GitHub Enterprise Server',
60-
method: 'Personal Access Token',
61-
token: '1234568790' as Token,
62-
hostname: 'github.gitify.io' as Hostname,
63-
user: mockGitifyUser,
64-
hasRequiredScopes: true,
65-
};
66-
67-
export const mockGitHubAppAccount: Account = {
68-
platform: 'GitHub Cloud',
69-
method: 'GitHub App',
70-
token: '987654321' as Token,
71-
hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname,
72-
user: mockGitifyUser,
73-
hasRequiredScopes: true,
74-
};
18+
import {
19+
mockGitHubCloudAccount,
20+
mockGitHubEnterpriseServerAccount,
21+
} from './account-mocks';
7522

7623
export const mockAuth: AuthState = {
7724
accounts: [mockGitHubCloudAccount, mockGitHubEnterpriseServerAccount],
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { GitifyUser, Link } from '../types';
2+
import type { User } from '../typesGitHub';
3+
4+
export const mockGitifyUser: GitifyUser = {
5+
login: 'octocat',
6+
name: 'Mona Lisa Octocat',
7+
id: 123456789,
8+
avatar: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
9+
};
10+
11+
export function createPartialMockUser(login: string): User {
12+
const mockUser: Partial<User> = {
13+
login: login,
14+
html_url: `https://github.com/${login}` as Link,
15+
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
16+
type: 'User',
17+
};
18+
19+
return mockUser as User;
20+
}

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__/notifications-mocks';
6+
import { mockAccountNotifications } from '../__mocks__/account-mocks';
77
import * as comms from '../utils/comms';
88
import { Sidebar } from './Sidebar';
99

src/renderer/components/fields/Tooltip.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33

44
import { renderWithAppContext } from '../../__helpers__/test-utils';
5-
import { mockSettings } from '../../__mocks__/state-mocks';
65
import { Tooltip, type TooltipProps } from './Tooltip';
76

87
describe('renderer/components/fields/Tooltip.tsx', () => {

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__/notifications-mocks';
7+
import { mockAccountNotifications } from '../../__mocks__/account-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__/notifications-mocks';
2+
import { mockAccountNotifications } from '../../__mocks__/account-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__/notifications-mocks';
2+
import { mockAccountNotifications } from '../../__mocks__/account-mocks';
33
import { StateFilter } from './StateFilter';
44

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

0 commit comments

Comments
 (0)