diff --git a/src/__mocks__/mock-state.ts b/src/__mocks__/mock-state.ts deleted file mode 100644 index 4a930d0e7..000000000 --- a/src/__mocks__/mock-state.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { type AuthState, type SettingsState, Theme } from '../types'; -import { mockedEnterpriseAccounts, mockedUser } from './mockedData'; - -export const mockAccounts: AuthState = { - token: 'token-123-456', - enterpriseAccounts: mockedEnterpriseAccounts, - user: mockedUser, -}; - -export const mockSettings: SettingsState = { - participating: false, - playSound: true, - showNotifications: true, - showBots: true, - showNotificationsCountInTray: false, - openAtStartup: false, - theme: Theme.SYSTEM, - detailedNotifications: true, - markAsDoneOnOpen: false, - showAccountHostname: false, - delayNotificationState: false, -}; diff --git a/src/__mocks__/notifications-mocks.ts b/src/__mocks__/notifications-mocks.ts new file mode 100644 index 000000000..a4a359f10 --- /dev/null +++ b/src/__mocks__/notifications-mocks.ts @@ -0,0 +1,24 @@ +import type { AccountNotifications } from '../types'; +import { + mockEnterpriseNotifications, + mockGitHubNotifications, + mockSingleNotification, +} from '../utils/api/__mocks__/response-mocks'; + +export const mockAccountNotifications: AccountNotifications[] = [ + { + hostname: 'github.com', + notifications: mockGitHubNotifications, + }, + { + hostname: 'github.gitify.io', + notifications: mockEnterpriseNotifications, + }, +]; + +export const mockSingleAccountNotifications: AccountNotifications[] = [ + { + hostname: 'github.com', + notifications: [mockSingleNotification], + }, +]; diff --git a/src/__mocks__/state-mocks.ts b/src/__mocks__/state-mocks.ts new file mode 100644 index 000000000..4a701fab6 --- /dev/null +++ b/src/__mocks__/state-mocks.ts @@ -0,0 +1,40 @@ +import { + type AuthState, + type EnterpriseAccount, + type GitifyUser, + type SettingsState, + Theme, +} from '../types'; + +export const mockEnterpriseAccounts: EnterpriseAccount[] = [ + { + hostname: 'github.gitify.io', + token: '1234568790', + }, +]; + +export const mockUser: GitifyUser = { + login: 'octocat', + name: 'Mona Lisa Octocat', + id: 123456789, +}; + +export const mockAccounts: AuthState = { + token: 'token-123-456', + enterpriseAccounts: mockEnterpriseAccounts, + user: mockUser, +}; + +export const mockSettings: SettingsState = { + participating: false, + playSound: true, + showNotifications: true, + showBots: true, + showNotificationsCountInTray: false, + openAtStartup: false, + theme: Theme.SYSTEM, + detailedNotifications: true, + markAsDoneOnOpen: false, + showAccountHostname: false, + delayNotificationState: false, +}; diff --git a/src/components/AccountNotifications.test.tsx b/src/components/AccountNotifications.test.tsx index 3c87901a5..f52955e5b 100644 --- a/src/components/AccountNotifications.test.tsx +++ b/src/components/AccountNotifications.test.tsx @@ -1,5 +1,5 @@ import { render } from '@testing-library/react'; -import { mockedGitHubNotifications } from '../__mocks__/mockedData'; +import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; import { AccountNotifications } from './AccountNotifications'; jest.mock('./Repository', () => ({ @@ -10,7 +10,7 @@ describe('components/AccountNotifications.tsx', () => { it('should render itself (github.com with notifications)', () => { const props = { hostname: 'github.com', - notifications: mockedGitHubNotifications, + notifications: mockGitHubNotifications, showAccountHostname: true, }; diff --git a/src/components/NotificationRow.test.tsx b/src/components/NotificationRow.test.tsx index b751bfd11..6657a9bad 100644 --- a/src/components/NotificationRow.test.tsx +++ b/src/components/NotificationRow.test.tsx @@ -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 { mockAccounts, mockSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import type { UserType } from '../typesGitHub'; +import { mockSingleNotification } from '../utils/api/__mocks__/response-mocks'; import * as helpers from '../utils/helpers'; import { NotificationRow } from './NotificationRow'; @@ -22,7 +22,7 @@ describe('components/NotificationRow.tsx', () => { .mockImplementation(() => new Date('2024').valueOf()); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; @@ -35,7 +35,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.last_read_at = null; const props = { @@ -52,7 +52,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.subject.user = null; const props = { @@ -70,7 +70,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.subject.comments = null; const props = { @@ -87,7 +87,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.subject.comments = 1; const props = { @@ -104,7 +104,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.subject.comments = 2; const props = { @@ -122,7 +122,7 @@ describe('components/NotificationRow.tsx', () => { const removeNotificationFromState = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; @@ -147,7 +147,7 @@ describe('components/NotificationRow.tsx', () => { const removeNotificationFromState = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; @@ -172,7 +172,7 @@ describe('components/NotificationRow.tsx', () => { const markNotificationDone = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; @@ -197,7 +197,7 @@ describe('components/NotificationRow.tsx', () => { const markNotificationRead = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; @@ -222,7 +222,7 @@ describe('components/NotificationRow.tsx', () => { const markNotificationDone = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; @@ -247,7 +247,7 @@ describe('components/NotificationRow.tsx', () => { const unsubscribeNotification = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; @@ -265,9 +265,9 @@ describe('components/NotificationRow.tsx', () => { it('should open notification user profile', () => { const props = { notification: { - ...mockedSingleNotification, + ...mockSingleNotification, subject: { - ...mockedSingleNotification.subject, + ...mockSingleNotification.subject, user: { login: 'some-user', html_url: 'https://github.com/some-user', diff --git a/src/components/Repository.test.tsx b/src/components/Repository.test.tsx index f6f7f5c69..888e76584 100644 --- a/src/components/Repository.test.tsx +++ b/src/components/Repository.test.tsx @@ -1,7 +1,7 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { shell } from 'electron'; -import { mockedGitHubNotifications } from '../__mocks__/mockedData'; import { AppContext } from '../context/App'; +import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; import { RepositoryNotifications } from './Repository'; jest.mock('./NotificationRow', () => ({ @@ -15,7 +15,7 @@ describe('components/Repository.tsx', () => { const props = { hostname: 'github.com', repoName: 'gitify-app/notifications-test', - repoNotifications: mockedGitHubNotifications, + repoNotifications: mockGitHubNotifications, }; beforeEach(() => { diff --git a/src/components/Sidebar.test.tsx b/src/components/Sidebar.test.tsx index 3b8c59a6b..a100c21c8 100644 --- a/src/components/Sidebar.test.tsx +++ b/src/components/Sidebar.test.tsx @@ -1,8 +1,8 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { ipcRenderer, shell } from 'electron'; import { MemoryRouter } from 'react-router-dom'; -import { mockSettings } from '../__mocks__/mock-state'; -import { mockedAccountNotifications } from '../__mocks__/mockedData'; +import { mockAccountNotifications } from '../__mocks__/notifications-mocks'; +import { mockSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import { Sidebar } from './Sidebar'; @@ -32,7 +32,7 @@ describe('components/Sidebar.tsx', () => { @@ -46,7 +46,7 @@ describe('components/Sidebar.tsx', () => { it('should render itself & its children (logged out)', () => { const tree = render( @@ -131,7 +131,7 @@ describe('components/Sidebar.tsx', () => { @@ -195,7 +195,7 @@ describe('components/Sidebar.tsx', () => { diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx index 7d569dbf6..0ab7083f2 100644 --- a/src/context/App.test.tsx +++ b/src/context/App.test.tsx @@ -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 { mockAccounts, mockSettings } from '../__mocks__/state-mocks'; import { useNotifications } from '../hooks/useNotifications'; import type { AuthState, SettingsState } from '../types'; import * as apiRequests from '../utils/api/request'; diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index 30539cd45..0eedb7527 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -1,9 +1,10 @@ import { act, renderHook, waitFor } from '@testing-library/react'; import axios, { AxiosError } from 'axios'; import nock from 'nock'; -import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; -import { mockedNotificationUser, mockedUser } from '../__mocks__/mockedData'; + +import { mockAccounts, mockSettings, mockUser } from '../__mocks__/state-mocks'; import type { AuthState } from '../types'; +import { mockNotificationUser } from '../utils/api/__mocks__/response-mocks'; import { Errors } from '../utils/constants'; import { useNotifications } from './useNotifications'; @@ -169,7 +170,7 @@ describe('hooks/useNotifications.ts', () => { const accounts: AuthState = { ...mockAccounts, enterpriseAccounts: [], - user: mockedUser, + user: mockUser, }; const notifications = [ @@ -234,7 +235,7 @@ describe('hooks/useNotifications.ts', () => { const accounts: AuthState = { ...mockAccounts, enterpriseAccounts: [], - user: mockedUser, + user: mockUser, }; const notifications = [ @@ -366,24 +367,24 @@ describe('hooks/useNotifications.ts', () => { .reply(200, { state: 'closed', merged: true, - user: mockedNotificationUser, + user: mockNotificationUser, }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/3/comments') .reply(200, { - user: mockedNotificationUser, + user: mockNotificationUser, }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/pulls/4') .reply(200, { state: 'closed', merged: false, - user: mockedNotificationUser, + user: mockNotificationUser, }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/4/comments') .reply(200, { - user: mockedNotificationUser, + user: mockNotificationUser, }); const { result } = renderHook(() => useNotifications()); diff --git a/src/routes/LoginWithOAuthApp.test.tsx b/src/routes/LoginWithOAuthApp.test.tsx index 957c4bd0a..3a34c277e 100644 --- a/src/routes/LoginWithOAuthApp.test.tsx +++ b/src/routes/LoginWithOAuthApp.test.tsx @@ -2,7 +2,7 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { ipcRenderer } from 'electron'; import { shell } from 'electron'; import { MemoryRouter } from 'react-router-dom'; -import { mockedEnterpriseAccounts } from '../__mocks__/mockedData'; +import { mockEnterpriseAccounts } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import type { AuthState } from '../types'; import { LoginWithOAuthApp, validate } from './LoginWithOAuthApp'; @@ -125,7 +125,7 @@ describe('routes/LoginWithOAuthApp.tsx', () => { ({ describe('routes/Notifications.tsx', () => { it('should render itself & its children (with notifications)', () => { const tree = render( - + , ); @@ -43,7 +41,7 @@ describe('routes/Notifications.tsx', () => { const tree = render( diff --git a/src/routes/Settings.test.tsx b/src/routes/Settings.test.tsx index a8701a277..5049dd3e0 100644 --- a/src/routes/Settings.test.tsx +++ b/src/routes/Settings.test.tsx @@ -1,7 +1,7 @@ import { act, fireEvent, render, screen } from '@testing-library/react'; import { ipcRenderer, shell } from 'electron'; import { MemoryRouter } from 'react-router-dom'; -import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; +import { mockAccounts, mockSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import { SettingsRoute } from './Settings'; diff --git a/src/__mocks__/mockedData.ts b/src/utils/api/__mocks__/response-mocks.ts similarity index 93% rename from src/__mocks__/mockedData.ts rename to src/utils/api/__mocks__/response-mocks.ts index 085fa8e1a..dcaf441b5 100644 --- a/src/__mocks__/mockedData.ts +++ b/src/utils/api/__mocks__/response-mocks.ts @@ -1,8 +1,3 @@ -import type { - AccountNotifications, - EnterpriseAccount, - GitifyUser, -} from '../types'; import type { Discussion, DiscussionAuthor, @@ -11,23 +6,10 @@ import type { Notification, Repository, User, -} from '../typesGitHub'; -import Constants from '../utils/constants'; - -export const mockedEnterpriseAccounts: EnterpriseAccount[] = [ - { - hostname: 'github.gitify.io', - token: '1234568790', - }, -]; +} from '../../../typesGitHub'; +import Constants from '../../constants'; -export const mockedUser: GitifyUser = { - login: 'octocat', - name: 'Mona Lisa Octocat', - id: 123456789, -}; - -export const mockedNotificationUser: User = { +export const mockNotificationUser: User = { login: 'octocat', id: 123456789, node_id: 'MDQ6VXNlcjE=', @@ -49,8 +31,9 @@ export const mockedNotificationUser: User = { }; // 2 Notifications +// Hostname : 'github.com' // Repository : 'gitify-app/notifications-test' -export const mockedGitHubNotifications: Notification[] = [ +export const mockGitHubNotifications: Notification[] = [ { hostname: Constants.GITHUB_API_BASE_URL, id: '138661096', @@ -255,8 +238,9 @@ export const mockedGitHubNotifications: Notification[] = [ ]; // 2 Notifications +// Hostname : 'github.gitify.io' // Repository : 'myorg/notifications-test' -export const mockedEnterpriseNotifications: Notification[] = [ +export const mockEnterpriseNotifications: Notification[] = [ { hostname: 'https://github.gitify.io/api/v3', id: '3', @@ -367,27 +351,6 @@ export const mockedEnterpriseNotifications: Notification[] = [ }, ]; -export const mockedSingleNotification: Notification = - mockedGitHubNotifications[0]; - -export const mockedAccountNotifications: AccountNotifications[] = [ - { - hostname: 'github.com', - notifications: mockedGitHubNotifications, - }, - { - hostname: 'github.gitify.io', - notifications: mockedEnterpriseNotifications, - }, -]; - -export const mockedSingleAccountNotifications: AccountNotifications[] = [ - { - hostname: 'github.com', - notifications: [mockedSingleNotification], - }, -]; - const mockDiscussionAuthor: DiscussionAuthor = { login: 'comment-user', url: 'https://github.com/comment-user', @@ -422,7 +385,7 @@ export const mockDiscussionComments: DiscussionComments = { totalCount: 2, }; -export const mockedGraphQLResponse: GraphQLSearch = { +export const mockGraphQLResponse: GraphQLSearch = { data: { search: { nodes: [ @@ -443,3 +406,5 @@ export const mockedGraphQLResponse: GraphQLSearch = { }, }, }; + +export const mockSingleNotification: Notification = mockGitHubNotifications[0]; diff --git a/src/utils/helpers.test.ts b/src/utils/helpers.test.ts index d22a64113..533330085 100644 --- a/src/utils/helpers.test.ts +++ b/src/utils/helpers.test.ts @@ -1,11 +1,10 @@ import type { AxiosPromise, AxiosResponse } from 'axios'; -import { mockAccounts } from '../__mocks__/mock-state'; -import { - mockedGraphQLResponse, - mockedSingleNotification, - mockedUser, -} from '../__mocks__/mockedData'; +import { mockAccounts, mockUser } from '../__mocks__/state-mocks'; import type { SubjectType } from '../typesGitHub'; +import { + mockGraphQLResponse, + mockSingleNotification, +} from './api/__mocks__/response-mocks'; import * as apiRequests from './api/request'; import { formatForDisplay, @@ -67,8 +66,8 @@ describe('utils/helpers.ts', () => { describe('generateNotificationReferrerId', () => { it('should generate the notification_referrer_id', () => { const referrerId = generateNotificationReferrerId( - mockedSingleNotification.id, - mockedUser.id, + mockSingleNotification.id, + mockUser.id, ); expect(referrerId).toBe( 'MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk=', @@ -77,9 +76,9 @@ describe('utils/helpers.ts', () => { }); describe('generateGitHubWebUrl', () => { - const mockedHtmlUrl = + const mockHtmlUrl = 'https://github.com/gitify-app/notifications-test/issues/785'; - const mockedNotificationReferrer = + const mockNotificationReferrer = 'notification_referrer_id=MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk%3D'; const apiRequestAuthMock = jest.spyOn(apiRequests, 'apiRequestAuth'); @@ -99,7 +98,7 @@ describe('utils/helpers.ts', () => { const requestPromise = new Promise((resolve) => resolve({ data: { - html_url: mockedHtmlUrl, + html_url: mockHtmlUrl, }, } as AxiosResponse), ) as AxiosPromise; @@ -108,7 +107,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -120,7 +119,7 @@ describe('utils/helpers.ts', () => { 'GET', mockAccounts.token, ); - expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`); + expect(result).toBe(`${mockHtmlUrl}?${mockNotificationReferrer}`); }); it('Subject Url: when no latest comment url available, fetch subject html url', async () => { @@ -134,7 +133,7 @@ describe('utils/helpers.ts', () => { const requestPromise = new Promise((resolve) => resolve({ data: { - html_url: mockedHtmlUrl, + html_url: mockHtmlUrl, }, } as AxiosResponse), ) as AxiosPromise; @@ -143,7 +142,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -155,7 +154,7 @@ describe('utils/helpers.ts', () => { 'GET', mockAccounts.token, ); - expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`); + expect(result).toBe(`${mockHtmlUrl}?${mockNotificationReferrer}`); }); describe('Check Suite URLs', () => { @@ -169,7 +168,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -177,7 +176,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Asuccess+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Asuccess+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -191,7 +190,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -199,7 +198,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Afailure+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Afailure+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -213,7 +212,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -221,7 +220,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Afailure+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Afailure+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -235,7 +234,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -243,7 +242,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Askipped+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Askipped+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -257,7 +256,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -265,7 +264,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?${mockNotificationReferrer}`, ); }); @@ -279,7 +278,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -287,7 +286,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -301,7 +300,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -309,7 +308,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?${mockNotificationReferrer}`, ); }); }); @@ -333,7 +332,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -341,7 +340,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(result).toBe( - `${mockedSingleNotification.repository.html_url}/discussions?${mockedNotificationReferrer}`, + `${mockSingleNotification.repository.html_url}/discussions?${mockNotificationReferrer}`, ); }); @@ -356,7 +355,7 @@ describe('utils/helpers.ts', () => { const requestPromise = new Promise((resolve) => resolve({ data: { - ...mockedGraphQLResponse, + ...mockGraphQLResponse, }, } as AxiosResponse), ) as AxiosPromise; @@ -365,7 +364,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -373,7 +372,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/discussions/612?${mockedNotificationReferrer}#discussioncomment-2300902`, + `https://github.com/gitify-app/notifications-test/discussions/612?${mockNotificationReferrer}#discussioncomment-2300902`, ); }); @@ -393,7 +392,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -401,7 +400,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/discussions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/discussions?${mockNotificationReferrer}`, ); }); }); @@ -417,7 +416,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -425,7 +424,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/invitations?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/invitations?${mockNotificationReferrer}`, ); }); @@ -440,7 +439,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -448,7 +447,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=is%3Awaiting&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=is%3Awaiting&${mockNotificationReferrer}`, ); }); @@ -463,7 +462,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -471,7 +470,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?${mockNotificationReferrer}`, ); }); @@ -485,7 +484,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -493,7 +492,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?${mockNotificationReferrer}`, ); }); }); @@ -508,7 +507,7 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, mockAccounts, @@ -516,7 +515,7 @@ describe('utils/helpers.ts', () => { expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `${mockedSingleNotification.repository.html_url}?${mockedNotificationReferrer}`, + `${mockSingleNotification.repository.html_url}?${mockNotificationReferrer}`, ); }); diff --git a/src/utils/notifications.test.ts b/src/utils/notifications.test.ts index 667f08187..6488677bc 100644 --- a/src/utils/notifications.test.ts +++ b/src/utils/notifications.test.ts @@ -1,13 +1,17 @@ import { ipcRenderer } from 'electron'; -import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; + import { - mockedAccountNotifications, - mockedGitHubNotifications, - mockedSingleAccountNotifications, -} from '../__mocks__/mockedData'; + mockAccountNotifications, + mockSingleAccountNotifications, +} from '../__mocks__/notifications-mocks'; import { partialMockNotification } from '../__mocks__/partial-mocks'; +import { mockAccounts, mockSettings } from '../__mocks__/state-mocks'; import { defaultSettings } from '../context/App'; import type { SettingsState } from '../types'; +import { + mockGitHubNotifications, + mockSingleNotification, +} from './api/__mocks__/response-mocks'; import * as helpers from './helpers'; import * as notificationsHelpers from './notifications'; import { filterNotifications } from './notifications'; @@ -29,7 +33,7 @@ describe('utils/notifications.ts', () => { notificationsHelpers.triggerNativeNotifications( [], - mockedAccountNotifications, + mockAccountNotifications, settings, mockAccounts, ); @@ -54,7 +58,7 @@ describe('utils/notifications.ts', () => { notificationsHelpers.triggerNativeNotifications( [], - mockedAccountNotifications, + mockAccountNotifications, settings, mockAccounts, ); @@ -74,8 +78,8 @@ describe('utils/notifications.ts', () => { jest.spyOn(notificationsHelpers, 'raiseSoundNotification'); notificationsHelpers.triggerNativeNotifications( - mockedSingleAccountNotifications, - mockedSingleAccountNotifications, + mockSingleAccountNotifications, + mockSingleAccountNotifications, settings, mockAccounts, ); @@ -110,14 +114,14 @@ describe('utils/notifications.ts', () => { const nativeNotification: Notification = notificationsHelpers.raiseNativeNotification( - [mockedGitHubNotifications[0]], + [mockSingleNotification], mockAccounts, ); nativeNotification.onclick(null); expect(helpers.openInBrowser).toHaveBeenCalledTimes(1); expect(helpers.openInBrowser).toHaveBeenLastCalledWith( - mockedGitHubNotifications[0], + mockSingleNotification, mockAccounts, ); expect(ipcRenderer.send).toHaveBeenCalledWith('hide-window'); @@ -125,7 +129,7 @@ describe('utils/notifications.ts', () => { it('should click on a native notification (with more than 1 notification)', () => { const nativeNotification = notificationsHelpers.raiseNativeNotification( - mockedGitHubNotifications, + mockGitHubNotifications, mockAccounts, ); nativeNotification.onclick(null); diff --git a/src/utils/remove-notification.test.ts b/src/utils/remove-notification.test.ts index 625d00d4f..28789ac7f 100644 --- a/src/utils/remove-notification.test.ts +++ b/src/utils/remove-notification.test.ts @@ -1,22 +1,20 @@ -import { mockSettings } from '../__mocks__/mock-state'; -import { - mockedSingleAccountNotifications, - mockedSingleNotification, -} from '../__mocks__/mockedData'; +import { mockSingleAccountNotifications } from '../__mocks__/notifications-mocks'; +import { mockSettings } from '../__mocks__/state-mocks'; +import { mockSingleNotification } from './api/__mocks__/response-mocks'; import Constants from './constants'; import { removeNotification } from './remove-notification'; describe('utils/remove-notification.ts', () => { - const notificationId = mockedSingleNotification.id; - const hostname = mockedSingleAccountNotifications[0].hostname; + const notificationId = mockSingleNotification.id; + const hostname = mockSingleAccountNotifications[0].hostname; it('should remove a notification if it exists', () => { - expect(mockedSingleAccountNotifications[0].notifications.length).toBe(1); + expect(mockSingleAccountNotifications[0].notifications.length).toBe(1); const result = removeNotification( { ...mockSettings, delayNotificationState: false }, notificationId, - mockedSingleAccountNotifications, + mockSingleAccountNotifications, hostname, ); @@ -25,21 +23,21 @@ describe('utils/remove-notification.ts', () => { it('should set notification as opaque if delayNotificationState enabled', () => { const mockElement = document.createElement('div'); - mockElement.id = mockedSingleAccountNotifications[0].notifications[0].id; + mockElement.id = mockSingleAccountNotifications[0].notifications[0].id; jest.spyOn(document, 'getElementById').mockReturnValue(mockElement); - expect(mockedSingleAccountNotifications[0].notifications.length).toBe(1); + expect(mockSingleAccountNotifications[0].notifications.length).toBe(1); const result = removeNotification( { ...mockSettings, delayNotificationState: true }, notificationId, - mockedSingleAccountNotifications, + mockSingleAccountNotifications, hostname, ); expect(result[0].notifications.length).toBe(1); expect(document.getElementById).toHaveBeenCalledWith( - mockedSingleAccountNotifications[0].notifications[0].id, + mockSingleAccountNotifications[0].notifications[0].id, ); expect(mockElement.className).toContain(Constants.READ_CLASS_NAME); }); diff --git a/src/utils/remove-notifications.test.ts b/src/utils/remove-notifications.test.ts index 0ec62a900..181a245f2 100644 --- a/src/utils/remove-notifications.test.ts +++ b/src/utils/remove-notifications.test.ts @@ -1,20 +1,20 @@ import { - mockedAccountNotifications, - mockedSingleAccountNotifications, - mockedSingleNotification, -} from '../__mocks__/mockedData'; + mockAccountNotifications, + mockSingleAccountNotifications, +} from '../__mocks__/notifications-mocks'; +import { mockSingleNotification } from './api/__mocks__/response-mocks'; import { removeNotifications } from './remove-notifications'; describe('utils/remove-notifications.ts', () => { - const repoSlug = mockedSingleNotification.repository.full_name; - const hostname = mockedSingleAccountNotifications[0].hostname; + const repoSlug = mockSingleNotification.repository.full_name; + const hostname = mockSingleAccountNotifications[0].hostname; it("should remove a repo's notifications - single", () => { - expect(mockedSingleAccountNotifications[0].notifications.length).toBe(1); + expect(mockSingleAccountNotifications[0].notifications.length).toBe(1); const result = removeNotifications( repoSlug, - mockedSingleAccountNotifications, + mockSingleAccountNotifications, hostname, ); @@ -22,12 +22,12 @@ describe('utils/remove-notifications.ts', () => { }); it("should remove a repo's notifications - multiple", () => { - expect(mockedAccountNotifications[0].notifications.length).toBe(2); - expect(mockedAccountNotifications[1].notifications.length).toBe(2); + expect(mockAccountNotifications[0].notifications.length).toBe(2); + expect(mockAccountNotifications[1].notifications.length).toBe(2); const result = removeNotifications( repoSlug, - mockedAccountNotifications, + mockAccountNotifications, hostname, ); diff --git a/src/utils/storage.test.ts b/src/utils/storage.test.ts index 34e298a24..37fdafc6a 100644 --- a/src/utils/storage.test.ts +++ b/src/utils/storage.test.ts @@ -1,4 +1,4 @@ -import { mockSettings } from '../__mocks__/mock-state'; +import { mockSettings } from '../__mocks__/state-mocks'; import { clearState, loadState, saveState } from './storage'; describe('utils/storage.ts', () => { diff --git a/src/utils/subject.test.ts b/src/utils/subject.test.ts index 497c6686f..4864732d7 100644 --- a/src/utils/subject.test.ts +++ b/src/utils/subject.test.ts @@ -1,10 +1,11 @@ import axios from 'axios'; import nock from 'nock'; -import { mockAccounts } from '../__mocks__/mock-state'; + import { partialMockNotification, partialMockUser, } from '../__mocks__/partial-mocks'; +import { mockAccounts } from '../__mocks__/state-mocks'; import type { Discussion, DiscussionAuthor, @@ -223,7 +224,7 @@ describe('utils/subject.ts', () => { }; const mockNotification = partialMockNotification({ - title: 'This is a mocked discussion', + title: 'This is a mock discussion', type: 'Discussion', }); mockNotification.updated_at = '2024-01-01T00:00:00Z'; @@ -404,7 +405,7 @@ describe('utils/subject.ts', () => { let mockNotification: Notification; beforeEach(() => { mockNotification = partialMockNotification({ - title: 'This is a mocked issue', + title: 'This is a mock issue', type: 'Issue', url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/1', latest_comment_url: @@ -583,7 +584,7 @@ describe('utils/subject.ts', () => { beforeEach(() => { mockNotification = partialMockNotification({ - title: 'This is a mocked pull request', + title: 'This is a mock pull request', type: 'PullRequest', url: 'https://api.github.com/repos/gitify-app/notifications-test/pulls/1', latest_comment_url: @@ -869,7 +870,7 @@ describe('utils/subject.ts', () => { describe('Releases', () => { it('release notification', async () => { const mockNotification = partialMockNotification({ - title: 'This is a mocked release', + title: 'This is a mock release', type: 'Release', url: 'https://api.github.com/repos/gitify-app/notifications-test/releases/1', latest_comment_url: @@ -1154,7 +1155,7 @@ function mockDiscussionNode( isAnswered: boolean, ): Discussion { return { - title: 'This is a mocked discussion', + title: 'This is a mock discussion', url: 'https://github.com/gitify-app/notifications-test/discussions/1', stateReason: state, isAnswered: isAnswered,