Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions src/__mocks__/mock-state.ts

This file was deleted.

24 changes: 24 additions & 0 deletions src/__mocks__/notifications-mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { AccountNotifications } from '../types';
import {
mockedEnterpriseNotifications,
mockedGitHubNotifications,
mockedSingleNotification,
} from '../utils/api/__mocks__/response-mocks';

export const mockedAccountNotifications: AccountNotifications[] = [
{
hostname: 'github.com',
notifications: mockedGitHubNotifications,
},
{
hostname: 'github.gitify.io',
notifications: mockedEnterpriseNotifications,
},
];

export const mockedSingleAccountNotifications: AccountNotifications[] = [
{
hostname: 'github.com',
notifications: [mockedSingleNotification],
},
];
12 changes: 6 additions & 6 deletions src/__mocks__/partial-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import type { Notification, Subject, User } from '../typesGitHub';
import Constants from '../utils/constants';

export function partialMockNotification(
export function partialMockedNotification(
subject: Partial<Subject>,
): Notification {
const mockNotification: Partial<Notification> = {
const mockedNotification: Partial<Notification> = {
hostname: Constants.GITHUB_API_BASE_URL,
subject: subject as Subject,
};

return mockNotification as Notification;
return mockedNotification as Notification;
}

export function partialMockUser(login: string): User {
const mockUser: Partial<User> = {
export function partialMockedUser(login: string): User {
const mockedUser: Partial<User> = {
login: login,
html_url: `https://github.com/${login}`,
avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4',
type: 'User',
};

return mockUser as User;
return mockedUser as User;
}
40 changes: 40 additions & 0 deletions src/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
type AuthState,
type EnterpriseAccount,
type GitifyUser,
type SettingsState,
Theme,
} from '../types';

export const mockedEnterpriseAccounts: EnterpriseAccount[] = [
{
hostname: 'github.gitify.io',
token: '1234568790',
},
];

export const mockedUser: GitifyUser = {
login: 'octocat',
name: 'Mona Lisa Octocat',
id: 123456789,
};

export const mockedAccounts: AuthState = {
token: 'token-123-456',
enterpriseAccounts: mockedEnterpriseAccounts,
user: mockedUser,
};

export const mockedSettings: SettingsState = {
participating: false,
playSound: true,
showNotifications: true,
showBots: true,
showNotificationsCountInTray: false,
openAtStartup: false,
theme: Theme.SYSTEM,
detailedNotifications: true,
markAsDoneOnOpen: false,
showAccountHostname: false,
delayNotificationState: false,
};
2 changes: 1 addition & 1 deletion src/components/AccountNotifications.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render } from '@testing-library/react';
import { mockedGitHubNotifications } from '../__mocks__/mockedData';
import { mockedGitHubNotifications } from '../utils/api/__mocks__/response-mocks';
import { AccountNotifications } from './AccountNotifications';

jest.mock('./Repository', () => ({
Expand Down
28 changes: 14 additions & 14 deletions src/components/NotificationRow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { shell } from 'electron';
import { mockAccounts, mockSettings } from '../__mocks__/mock-state';
import { mockedSingleNotification } from '../__mocks__/mockedData';
import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks';
import { AppContext } from '../context/App';
import type { UserType } from '../typesGitHub';
import { mockedSingleNotification } from '../utils/api/__mocks__/response-mocks';
import * as helpers from '../utils/helpers';
import { NotificationRow } from './NotificationRow';

Expand Down Expand Up @@ -129,9 +129,9 @@ describe('components/NotificationRow.tsx', () => {
render(
<AppContext.Provider
value={{
settings: { ...mockSettings, markAsDoneOnOpen: false },
settings: { ...mockedSettings, markAsDoneOnOpen: false },
removeNotificationFromState,
accounts: mockAccounts,
accounts: mockedAccounts,
}}
>
<NotificationRow {...props} />
Expand All @@ -154,9 +154,9 @@ describe('components/NotificationRow.tsx', () => {
render(
<AppContext.Provider
value={{
settings: { ...mockSettings, markAsDoneOnOpen: false },
settings: { ...mockedSettings, markAsDoneOnOpen: false },
removeNotificationFromState,
accounts: mockAccounts,
accounts: mockedAccounts,
}}
>
<NotificationRow {...props} />
Expand All @@ -179,9 +179,9 @@ describe('components/NotificationRow.tsx', () => {
render(
<AppContext.Provider
value={{
settings: { ...mockSettings, markAsDoneOnOpen: true },
settings: { ...mockedSettings, markAsDoneOnOpen: true },
markNotificationDone,
accounts: mockAccounts,
accounts: mockedAccounts,
}}
>
<NotificationRow {...props} />
Expand All @@ -204,8 +204,8 @@ describe('components/NotificationRow.tsx', () => {
render(
<AppContext.Provider
value={{
settings: { ...mockSettings, markAsDoneOnOpen: false },
accounts: mockAccounts,
settings: { ...mockedSettings, markAsDoneOnOpen: false },
accounts: mockedAccounts,
}}
>
<AppContext.Provider value={{ markNotificationRead }}>
Expand All @@ -229,8 +229,8 @@ describe('components/NotificationRow.tsx', () => {
render(
<AppContext.Provider
value={{
settings: { ...mockSettings },
accounts: mockAccounts,
settings: { ...mockedSettings },
accounts: mockedAccounts,
}}
>
<AppContext.Provider value={{ markNotificationDone }}>
Expand Down Expand Up @@ -284,8 +284,8 @@ describe('components/NotificationRow.tsx', () => {
render(
<AppContext.Provider
value={{
settings: { ...mockSettings },
accounts: mockAccounts,
settings: { ...mockedSettings },
accounts: mockedAccounts,
}}
>
<NotificationRow {...props} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Repository.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { mockedGitHubNotifications } from '../__mocks__/mockedData';
import { AppContext } from '../context/App';
import { mockedGitHubNotifications } from '../utils/api/__mocks__/response-mocks';
import { RepositoryNotifications } from './Repository';
const { shell } = require('electron');

Expand Down
6 changes: 3 additions & 3 deletions src/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
const { shell, ipcRenderer } = require('electron');
import { mockSettings } from '../__mocks__/mock-state';
import { mockedAccountNotifications } from '../__mocks__/mockedData';
import { mockedAccountNotifications } from '../__mocks__/notifications-mocks';
import { mockedSettings } from '../__mocks__/state-mocks';
import { AppContext } from '../context/App';
import { Sidebar } from './Sidebar';

Expand Down Expand Up @@ -31,7 +31,7 @@ describe('components/Sidebar.tsx', () => {
const tree = render(
<AppContext.Provider
value={{
settings: mockSettings,
settings: mockedSettings,
notifications: mockedAccountNotifications,
}}
>
Expand Down
15 changes: 8 additions & 7 deletions src/context/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { act, fireEvent, render, waitFor } from '@testing-library/react';
import { useContext } from 'react';
import { mockAccounts, mockSettings } from '../__mocks__/mock-state';

import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks';
import { useNotifications } from '../hooks/useNotifications';
import type { AuthState, SettingsState } from '../types';
import * as apiRequests from '../utils/api/request';
Expand All @@ -14,8 +15,8 @@ jest.mock('../hooks/useNotifications');

const customRender = (
ui,
accounts: AuthState = mockAccounts,
settings: SettingsState = mockSettings,
accounts: AuthState = mockedAccounts,
settings: SettingsState = mockedSettings,
) => {
return render(
<AppContext.Provider value={{ accounts, settings }}>
Expand Down Expand Up @@ -135,7 +136,7 @@ describe('context/App.tsx', () => {
token: null,
user: null,
},
mockSettings,
mockedSettings,
'123-456',
'github.com',
);
Expand Down Expand Up @@ -164,7 +165,7 @@ describe('context/App.tsx', () => {
expect(markNotificationDoneMock).toHaveBeenCalledTimes(1);
expect(markNotificationDoneMock).toHaveBeenCalledWith(
{ enterpriseAccounts: [], token: null, user: null },
mockSettings,
mockedSettings,
'123-456',
'github.com',
);
Expand Down Expand Up @@ -193,7 +194,7 @@ describe('context/App.tsx', () => {
expect(unsubscribeNotificationMock).toHaveBeenCalledTimes(1);
expect(unsubscribeNotificationMock).toHaveBeenCalledWith(
{ enterpriseAccounts: [], token: null, user: null },
mockSettings,
mockedSettings,
'123-456',
'github.com',
);
Expand Down Expand Up @@ -227,7 +228,7 @@ describe('context/App.tsx', () => {
expect(markRepoNotificationsMock).toHaveBeenCalledTimes(1);
expect(markRepoNotificationsMock).toHaveBeenCalledWith(
{ enterpriseAccounts: [], token: null, user: null },
mockSettings,
mockedSettings,
'gitify-app/notifications-test',
'github.com',
);
Expand Down
Loading