diff --git a/src/main/events.test.ts b/src/main/events.test.ts index afc42f597..97eefdf2a 100644 --- a/src/main/events.test.ts +++ b/src/main/events.test.ts @@ -22,41 +22,41 @@ describe('main/events', () => { }); it('onMainEvent registers ipcMain.on listener', () => { - const listener = jest.fn(); + const listenerMock = jest.fn(); onMainEvent( EVENTS.WINDOW_SHOW, - listener as unknown as (e: Electron.IpcMainEvent, d: unknown) => void, + listenerMock as unknown as (e: Electron.IpcMainEvent, d: unknown) => void, ); - expect(onMock).toHaveBeenCalledWith(EVENTS.WINDOW_SHOW, listener); + expect(onMock).toHaveBeenCalledWith(EVENTS.WINDOW_SHOW, listenerMock); }); it('handleMainEvent registers ipcMain.handle listener', () => { - const listener = jest.fn(); + const listenerMock = jest.fn(); handleMainEvent( EVENTS.VERSION, - listener as unknown as ( + listenerMock as unknown as ( e: Electron.IpcMainInvokeEvent, d: unknown, ) => void, ); - expect(handleMock).toHaveBeenCalledWith(EVENTS.VERSION, listener); + expect(handleMock).toHaveBeenCalledWith(EVENTS.VERSION, listenerMock); }); it('sendRendererEvent forwards event to webContents with data', () => { - const send = jest.fn(); - const mb: MockMenubar = { window: { webContents: { send } } }; + const sendMock = jest.fn(); + const mb: MockMenubar = { window: { webContents: { send: sendMock } } }; sendRendererEvent( mb as unknown as Menubar, EVENTS.UPDATE_ICON_TITLE, 'title', ); - expect(send).toHaveBeenCalledWith(EVENTS.UPDATE_ICON_TITLE, 'title'); + expect(sendMock).toHaveBeenCalledWith(EVENTS.UPDATE_ICON_TITLE, 'title'); }); it('sendRendererEvent forwards event without data', () => { - const send = jest.fn(); - const mb: MockMenubar = { window: { webContents: { send } } }; + const sendMock = jest.fn(); + const mb: MockMenubar = { window: { webContents: { send: sendMock } } }; sendRendererEvent(mb as unknown as Menubar, EVENTS.RESET_APP); - expect(send).toHaveBeenCalledWith(EVENTS.RESET_APP, undefined); + expect(sendMock).toHaveBeenCalledWith(EVENTS.RESET_APP, undefined); }); }); diff --git a/src/main/first-run.test.ts b/src/main/first-run.test.ts index 84e690cd2..a3a339b01 100644 --- a/src/main/first-run.test.ts +++ b/src/main/first-run.test.ts @@ -1,39 +1,39 @@ import path from 'node:path'; -// Mocks -const existsSync = jest.fn(); -const mkdirSync = jest.fn(); -const writeFileSync = jest.fn(); +const existsSyncMock = jest.fn(); +const mkdirSyncMock = jest.fn(); +const writeFileSyncMock = jest.fn(); + jest.mock('node:fs', () => ({ __esModule: true, default: { - existsSync: (...a: unknown[]) => existsSync(...a), - mkdirSync: (...a: unknown[]) => mkdirSync(...a), - writeFileSync: (...a: unknown[]) => writeFileSync(...a), + existsSync: (...a: unknown[]) => existsSyncMock(...a), + mkdirSync: (...a: unknown[]) => mkdirSyncMock(...a), + writeFileSync: (...a: unknown[]) => writeFileSyncMock(...a), }, - existsSync: (...a: unknown[]) => existsSync(...a), - mkdirSync: (...a: unknown[]) => mkdirSync(...a), - writeFileSync: (...a: unknown[]) => writeFileSync(...a), + existsSync: (...a: unknown[]) => existsSyncMock(...a), + mkdirSync: (...a: unknown[]) => mkdirSyncMock(...a), + writeFileSync: (...a: unknown[]) => writeFileSyncMock(...a), })); -const moveToApplicationsFolder = jest.fn(); -const isInApplicationsFolder = jest.fn(() => false); -const getPath = jest.fn(() => '/User/Data'); +const moveToApplicationsFolderMock = jest.fn(); +const isInApplicationsFolderMock = jest.fn(() => false); +const getPathMock = jest.fn(() => '/User/Data'); -const showMessageBox = jest.fn(async () => ({ response: 0 })); +const showMessageBoxMock = jest.fn(async () => ({ response: 0 })); jest.mock('electron', () => ({ app: { - getPath: () => getPath(), - isInApplicationsFolder: () => isInApplicationsFolder(), - moveToApplicationsFolder: () => moveToApplicationsFolder(), + getPath: () => getPathMock(), + isInApplicationsFolder: () => isInApplicationsFolderMock(), + moveToApplicationsFolder: () => moveToApplicationsFolderMock(), }, - dialog: { showMessageBox: () => showMessageBox() }, + dialog: { showMessageBox: () => showMessageBoxMock() }, })); -const logError = jest.fn(); +const logErrorMock = jest.fn(); jest.mock('../shared/logger', () => ({ - logError: (...a: unknown[]) => logError(...a), + logError: (...a: unknown[]) => logErrorMock(...a), })); let mac = true; @@ -54,28 +54,28 @@ describe('main/first-run', () => { }); it('creates first-run marker when not existing and returns true', async () => { - existsSync.mockReturnValueOnce(false); // marker absent - existsSync.mockReturnValueOnce(false); // folder absent + existsSyncMock.mockReturnValueOnce(false); // marker absent + existsSyncMock.mockReturnValueOnce(false); // folder absent await onFirstRunMaybe(); - expect(mkdirSync).toHaveBeenCalledWith(path.dirname(configPath())); - expect(writeFileSync).toHaveBeenCalledWith(configPath(), ''); + expect(mkdirSyncMock).toHaveBeenCalledWith(path.dirname(configPath())); + expect(writeFileSyncMock).toHaveBeenCalledWith(configPath(), ''); }); it('skips writing when marker exists', async () => { - existsSync.mockReturnValueOnce(true); // marker present + existsSyncMock.mockReturnValueOnce(true); // marker present await onFirstRunMaybe(); - expect(writeFileSync).not.toHaveBeenCalled(); - expect(mkdirSync).not.toHaveBeenCalled(); + expect(writeFileSyncMock).not.toHaveBeenCalled(); + expect(mkdirSyncMock).not.toHaveBeenCalled(); }); it('handles fs write error gracefully', async () => { - existsSync.mockReturnValueOnce(false); // marker absent - existsSync.mockReturnValueOnce(true); // folder exists - writeFileSync.mockImplementation(() => { + existsSyncMock.mockReturnValueOnce(false); // marker absent + existsSyncMock.mockReturnValueOnce(true); // folder exists + writeFileSyncMock.mockImplementation(() => { throw new Error('fail'); }); await onFirstRunMaybe(); - expect(logError).toHaveBeenCalledWith( + expect(logErrorMock).toHaveBeenCalledWith( 'isFirstRun', 'Unable to write firstRun file', expect.any(Error), @@ -83,26 +83,26 @@ describe('main/first-run', () => { }); it('prompts and moves app on macOS when user accepts', async () => { - existsSync.mockReturnValueOnce(false); // marker - existsSync.mockReturnValueOnce(false); // folder - showMessageBox.mockResolvedValueOnce({ response: 0 }); + existsSyncMock.mockReturnValueOnce(false); // marker + existsSyncMock.mockReturnValueOnce(false); // folder + showMessageBoxMock.mockResolvedValueOnce({ response: 0 }); await onFirstRunMaybe(); - expect(moveToApplicationsFolder).toHaveBeenCalled(); + expect(moveToApplicationsFolderMock).toHaveBeenCalled(); }); it('does not move when user declines', async () => { - existsSync.mockReturnValueOnce(false); - existsSync.mockReturnValueOnce(false); - showMessageBox.mockResolvedValueOnce({ response: 1 }); + existsSyncMock.mockReturnValueOnce(false); + existsSyncMock.mockReturnValueOnce(false); + showMessageBoxMock.mockResolvedValueOnce({ response: 1 }); await onFirstRunMaybe(); - expect(moveToApplicationsFolder).not.toHaveBeenCalled(); + expect(moveToApplicationsFolderMock).not.toHaveBeenCalled(); }); it('skips prompt on non-macOS', async () => { mac = false; - existsSync.mockReturnValueOnce(false); - existsSync.mockReturnValueOnce(false); + existsSyncMock.mockReturnValueOnce(false); + existsSyncMock.mockReturnValueOnce(false); await onFirstRunMaybe(); - expect(showMessageBox).not.toHaveBeenCalled(); + expect(showMessageBoxMock).not.toHaveBeenCalled(); }); }); diff --git a/src/preload/index.test.ts b/src/preload/index.test.ts index 46dac3057..ae084f12c 100644 --- a/src/preload/index.test.ts +++ b/src/preload/index.test.ts @@ -1,34 +1,34 @@ import { EVENTS } from '../shared/events'; // Mocks shared modules used inside preload -const sendMainEvent = jest.fn(); -const invokeMainEvent = jest.fn(); -const onRendererEvent = jest.fn(); -const logError = jest.fn(); +const sendMainEventMock = jest.fn(); +const invokeMainEventMock = jest.fn(); +const onRendererEventMock = jest.fn(); +const logErrorMock = jest.fn(); jest.mock('./utils', () => ({ - sendMainEvent: (...args: unknown[]) => sendMainEvent(...args), - invokeMainEvent: (...args: unknown[]) => invokeMainEvent(...args), - onRendererEvent: (...args: unknown[]) => onRendererEvent(...args), + sendMainEvent: (...args: unknown[]) => sendMainEventMock(...args), + invokeMainEvent: (...args: unknown[]) => invokeMainEventMock(...args), + onRendererEvent: (...args: unknown[]) => onRendererEventMock(...args), })); jest.mock('../shared/logger', () => ({ - logError: (...args: unknown[]) => logError(...args), + logError: (...args: unknown[]) => logErrorMock(...args), })); // We'll reconfigure the electron mock per context isolation scenario. -const exposeInMainWorld = jest.fn(); -const getZoomLevel = jest.fn(() => 1); -const setZoomLevel = jest.fn((_level: number) => undefined); +const exposeInMainWorldMock = jest.fn(); +const getZoomLevelMock = jest.fn(() => 1); +const setZoomLevelMock = jest.fn((_level: number) => undefined); jest.mock('electron', () => ({ contextBridge: { exposeInMainWorld: (key: string, value: unknown) => - exposeInMainWorld(key, value), + exposeInMainWorldMock(key, value), }, webFrame: { - getZoomLevel: () => getZoomLevel(), - setZoomLevel: (level: number) => setZoomLevel(level), + getZoomLevel: () => getZoomLevelMock(), + setZoomLevel: (level: number) => setZoomLevelMock(level), }, })); @@ -79,7 +79,7 @@ describe('preload/index', () => { const w = window as unknown as { gitify: Record }; expect(w.gitify).toBeDefined(); - expect(exposeInMainWorld).not.toHaveBeenCalled(); + expect(exposeInMainWorldMock).not.toHaveBeenCalled(); }); it('exposes api via contextBridge when context isolation enabled', async () => { @@ -87,9 +87,9 @@ describe('preload/index', () => { true; await importPreload(); - expect(exposeInMainWorld).toHaveBeenCalledTimes(1); + expect(exposeInMainWorldMock).toHaveBeenCalledTimes(1); - const [key, api] = exposeInMainWorld.mock.calls[0]; + const [key, api] = exposeInMainWorldMock.mock.calls[0]; expect(key).toBe('gitify'); expect(api).toHaveProperty('openExternalLink'); }); @@ -100,7 +100,7 @@ describe('preload/index', () => { const api = (window as unknown as { gitify: TestApi }).gitify; // casting only in test boundary api.tray.updateColor(-1); - expect(sendMainEvent).toHaveBeenNthCalledWith( + expect(sendMainEventMock).toHaveBeenNthCalledWith( 1, EVENTS.UPDATE_ICON_COLOR, -1, @@ -113,7 +113,7 @@ describe('preload/index', () => { const api = (window as unknown as { gitify: TestApi }).gitify; api.openExternalLink('https://example.com', true); - expect(sendMainEvent).toHaveBeenCalledWith(EVENTS.OPEN_EXTERNAL, { + expect(sendMainEventMock).toHaveBeenCalledWith(EVENTS.OPEN_EXTERNAL, { url: 'https://example.com', activate: true, }); @@ -135,7 +135,7 @@ describe('preload/index', () => { const originalEnv = process.env.NODE_ENV; process.env.NODE_ENV = 'production'; - invokeMainEvent.mockResolvedValueOnce('1.2.3'); + invokeMainEventMock.mockResolvedValueOnce('1.2.3'); await importPreload(); @@ -149,19 +149,19 @@ describe('preload/index', () => { await importPreload(); const api = (window as unknown as { gitify: TestApi }).gitify; - const callback = jest.fn(); - api.onSystemThemeUpdate(callback); + const callbackMock = jest.fn(); + api.onSystemThemeUpdate(callbackMock); - expect(onRendererEvent).toHaveBeenCalledWith( + expect(onRendererEventMock).toHaveBeenCalledWith( EVENTS.UPDATE_THEME, expect.any(Function), ); // Simulate event - const listener = onRendererEvent.mock.calls[0][1]; + const listener = onRendererEventMock.mock.calls[0][1]; listener({}, 'dark'); - expect(callback).toHaveBeenCalledWith('dark'); + expect(callbackMock).toHaveBeenCalledWith('dark'); }); it('raiseNativeNotification without url calls app.show', async () => { diff --git a/src/preload/utils.test.ts b/src/preload/utils.test.ts index 4cc5c91c3..ff313c91e 100644 --- a/src/preload/utils.test.ts +++ b/src/preload/utils.test.ts @@ -50,10 +50,10 @@ describe('preload/utils', () => { }); it('onRendererEvent registers listener and receives emitted data', () => { - const handler = jest.fn(); + const handlerMock = jest.fn(); onRendererEvent( EVENTS.UPDATE_ICON_TITLE, - handler as unknown as ( + handlerMock as unknown as ( e: Electron.IpcRendererEvent, args: string, ) => void, @@ -65,8 +65,8 @@ describe('preload/utils', () => { ).__emit(EVENTS.UPDATE_ICON_TITLE, 'payload'); expect(ipcRenderer.on).toHaveBeenCalledWith( EVENTS.UPDATE_ICON_TITLE, - handler, + handlerMock, ); - expect(handler).toHaveBeenCalledWith({}, 'payload'); + expect(handlerMock).toHaveBeenCalledWith({}, 'payload'); }); }); diff --git a/src/renderer/__helpers__/test-utils.tsx b/src/renderer/__helpers__/test-utils.tsx index 51bf06a84..8e6f874ff 100644 --- a/src/renderer/__helpers__/test-utils.tsx +++ b/src/renderer/__helpers__/test-utils.tsx @@ -26,6 +26,7 @@ export function AppContextProvider({ return { auth: mockAuth, settings: mockSettings, + isLoggedIn: true, notifications: [], diff --git a/src/renderer/components/Sidebar.test.tsx b/src/renderer/components/Sidebar.test.tsx index 064c2f8c8..a20f31ce5 100644 --- a/src/renderer/components/Sidebar.test.tsx +++ b/src/renderer/components/Sidebar.test.tsx @@ -4,17 +4,18 @@ import { MemoryRouter } from 'react-router-dom'; import { renderWithAppContext } from '../__helpers__/test-utils'; import { mockAccountNotifications } from '../__mocks__/notifications-mocks'; +import { mockSettings } from '../__mocks__/state-mocks'; import * as comms from '../utils/comms'; import { Sidebar } from './Sidebar'; -const mockNavigate = jest.fn(); +const navigateMock = jest.fn(); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavigate, + useNavigate: () => navigateMock, })); describe('renderer/components/Sidebar.tsx', () => { - const mockFetchNotifications = jest.fn(); + const fetchNotificationsMock = jest.fn(); const openExternalLinkSpy = jest .spyOn(comms, 'openExternalLink') .mockImplementation(); @@ -49,20 +50,17 @@ describe('renderer/components/Sidebar.tsx', () => { expect(tree).toMatchSnapshot(); }); - it('should navigate home when clicking the gitify logo', async () => { + it('should navigate home when clicking logo', async () => { renderWithAppContext( , - { - isLoggedIn: false, - }, ); await userEvent.click(screen.getByTestId('sidebar-home')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/', { replace: true }); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/', { replace: true }); }); describe('notifications icon', () => { @@ -71,9 +69,6 @@ describe('renderer/components/Sidebar.tsx', () => { , - { - isLoggedIn: true, - }, ); await userEvent.click(screen.getByTestId('sidebar-notifications')); @@ -90,7 +85,6 @@ describe('renderer/components/Sidebar.tsx', () => { , { - isLoggedIn: true, notifications: [], }, ); @@ -104,7 +98,6 @@ describe('renderer/components/Sidebar.tsx', () => { , { - isLoggedIn: true, notifications: mockAccountNotifications, }, ); @@ -119,15 +112,12 @@ describe('renderer/components/Sidebar.tsx', () => { , - { - isLoggedIn: true, - }, ); await userEvent.click(screen.getByTestId('sidebar-filter-notifications')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/filters'); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/filters'); }); it('go to the home if filters path already shown', async () => { @@ -135,15 +125,30 @@ describe('renderer/components/Sidebar.tsx', () => { , - { - isLoggedIn: true, - }, ); await userEvent.click(screen.getByTestId('sidebar-filter-notifications')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/', { replace: true }); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/', { replace: true }); + }); + + it('highlight filters sidebar if any are saved', () => { + renderWithAppContext( + + + , + { + settings: { + ...mockSettings, + filterReasons: ['assign'], + }, + }, + ); + + expect( + screen.getByTestId('sidebar-filter-notifications'), + ).toMatchSnapshot(); }); }); @@ -154,7 +159,6 @@ describe('renderer/components/Sidebar.tsx', () => { , { - isLoggedIn: true, notifications: mockAccountNotifications, }, ); @@ -173,7 +177,6 @@ describe('renderer/components/Sidebar.tsx', () => { , { - isLoggedIn: true, notifications: mockAccountNotifications, }, ); @@ -194,16 +197,14 @@ describe('renderer/components/Sidebar.tsx', () => { , { - isLoggedIn: true, - notifications: [], - fetchNotifications: mockFetchNotifications, + fetchNotifications: fetchNotificationsMock, status: 'success', }, ); await userEvent.click(screen.getByTestId('sidebar-refresh')); - expect(mockFetchNotifications).toHaveBeenCalledTimes(1); + expect(fetchNotificationsMock).toHaveBeenCalledTimes(1); }); it('should not refresh the notifications when status is loading', async () => { @@ -212,16 +213,14 @@ describe('renderer/components/Sidebar.tsx', () => { , { - isLoggedIn: true, - notifications: [], - fetchNotifications: mockFetchNotifications, + fetchNotifications: fetchNotificationsMock, status: 'loading', }, ); await userEvent.click(screen.getByTestId('sidebar-refresh')); - expect(mockFetchNotifications).not.toHaveBeenCalled(); + expect(fetchNotificationsMock).not.toHaveBeenCalled(); }); }); @@ -231,15 +230,12 @@ describe('renderer/components/Sidebar.tsx', () => { , - { - isLoggedIn: true, - }, ); await userEvent.click(screen.getByTestId('sidebar-settings')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/settings'); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/settings'); }); it('go to the home if settings path already shown', async () => { @@ -248,16 +244,15 @@ describe('renderer/components/Sidebar.tsx', () => { , { - isLoggedIn: true, - fetchNotifications: mockFetchNotifications, + fetchNotifications: fetchNotificationsMock, }, ); await userEvent.click(screen.getByTestId('sidebar-settings')); - expect(mockFetchNotifications).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/', { replace: true }); + expect(fetchNotificationsMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/', { replace: true }); }); }); diff --git a/src/renderer/components/__snapshots__/Sidebar.test.tsx.snap b/src/renderer/components/__snapshots__/Sidebar.test.tsx.snap index 7e2af5527..f7bac811c 100644 --- a/src/renderer/components/__snapshots__/Sidebar.test.tsx.snap +++ b/src/renderer/components/__snapshots__/Sidebar.test.tsx.snap @@ -1,8 +1,40 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +exports[`renderer/components/Sidebar.tsx Filter notifications highlight filters sidebar if any are saved 1`] = ` + +`; + exports[`renderer/components/Sidebar.tsx notifications icon renders correct icon when there are no notifications 1`] = ` + + + + @@ -269,10 +351,10 @@ exports[`renderer/components/layout/AppLayout.tsx should render itself & its chi aria-hidden="true" class="prc-TooltipV2-Tooltip-cYMVY" data-direction="e" - id="_r_9_" + id="_r_d_" popover="auto" > - Quit Gitify + Settings @@ -430,8 +512,47 @@ exports[`renderer/components/layout/AppLayout.tsx should render itself & its chi undefined unread notifications ↗ + + + + @@ -551,10 +715,10 @@ exports[`renderer/components/layout/AppLayout.tsx should render itself & its chi aria-hidden="true" class="prc-TooltipV2-Tooltip-cYMVY" data-direction="e" - id="_r_9_" + id="_r_d_" popover="auto" > - Quit Gitify + Settings diff --git a/src/renderer/components/notifications/NotificationRow.test.tsx b/src/renderer/components/notifications/NotificationRow.test.tsx index 65704bc2f..14ed55fc6 100644 --- a/src/renderer/components/notifications/NotificationRow.test.tsx +++ b/src/renderer/components/notifications/NotificationRow.test.tsx @@ -76,7 +76,7 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { describe('notification interactions', () => { it('should open a notification in the browser - click', async () => { - const mockMarkNotificationsAsRead = jest.fn(); + const markNotificationsAsReadMock = jest.fn(); const props = { notification: mockSingleNotification, @@ -85,17 +85,17 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { renderWithAppContext(, { settings: { ...mockSettings, markAsDoneOnOpen: false }, - markNotificationsAsRead: mockMarkNotificationsAsRead, + markNotificationsAsRead: markNotificationsAsReadMock, }); await userEvent.click(screen.getByTestId('notification-row')); expect(links.openNotification).toHaveBeenCalledTimes(1); - expect(mockMarkNotificationsAsRead).toHaveBeenCalledTimes(1); + expect(markNotificationsAsReadMock).toHaveBeenCalledTimes(1); }); it('should open a notification in the browser - delay notification setting enabled', async () => { - const markNotificationsAsRead = jest.fn(); + const markNotificationsAsReadMock = jest.fn(); const props = { notification: mockSingleNotification, @@ -108,17 +108,17 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { markAsDoneOnOpen: false, delayNotificationState: true, }, - markNotificationsAsRead, + markNotificationsAsRead: markNotificationsAsReadMock, }); await userEvent.click(screen.getByTestId('notification-row')); expect(links.openNotification).toHaveBeenCalledTimes(1); - expect(markNotificationsAsRead).toHaveBeenCalledTimes(1); + expect(markNotificationsAsReadMock).toHaveBeenCalledTimes(1); }); it('should open a notification in browser & mark it as done', async () => { - const mockMarkNotificationsAsDone = jest.fn(); + const markNotificationsAsDoneMock = jest.fn(); const props = { notification: mockSingleNotification, @@ -127,17 +127,17 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { renderWithAppContext(, { settings: { ...mockSettings, markAsDoneOnOpen: true }, - markNotificationsAsDone: mockMarkNotificationsAsDone, + markNotificationsAsDone: markNotificationsAsDoneMock, }); await userEvent.click(screen.getByTestId('notification-row')); expect(links.openNotification).toHaveBeenCalledTimes(1); - expect(mockMarkNotificationsAsDone).toHaveBeenCalledTimes(1); + expect(markNotificationsAsDoneMock).toHaveBeenCalledTimes(1); }); it('should mark notifications as read', async () => { - const mockMarkNotificationsAsRead = jest.fn(); + const markNotificationsAsReadMock = jest.fn(); const props = { notification: mockSingleNotification, @@ -146,16 +146,16 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { renderWithAppContext(, { settings: { ...mockSettings, markAsDoneOnOpen: false }, - markNotificationsAsRead: mockMarkNotificationsAsRead, + markNotificationsAsRead: markNotificationsAsReadMock, }); await userEvent.click(screen.getByTestId('notification-mark-as-read')); - expect(mockMarkNotificationsAsRead).toHaveBeenCalledTimes(1); + expect(markNotificationsAsReadMock).toHaveBeenCalledTimes(1); }); it('should mark notifications as done', async () => { - const mockMarkNotificationsAsDone = jest.fn(); + const markNotificationsAsDoneMock = jest.fn(); const props = { notification: mockSingleNotification, @@ -164,16 +164,16 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { renderWithAppContext(, { settings: mockSettings, - markNotificationsAsDone: mockMarkNotificationsAsDone, + markNotificationsAsDone: markNotificationsAsDoneMock, }); await userEvent.click(screen.getByTestId('notification-mark-as-done')); - expect(mockMarkNotificationsAsDone).toHaveBeenCalledTimes(1); + expect(markNotificationsAsDoneMock).toHaveBeenCalledTimes(1); }); it('should unsubscribe from a notification thread', async () => { - const mockUnsubscribeNotification = jest.fn(); + const unsubscribeNotificationMock = jest.fn(); const props = { notification: mockSingleNotification, @@ -181,14 +181,14 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { }; renderWithAppContext(, { - unsubscribeNotification: mockUnsubscribeNotification, + unsubscribeNotification: unsubscribeNotificationMock, }); await userEvent.click( screen.getByTestId('notification-unsubscribe-from-thread'), ); - expect(mockUnsubscribeNotification).toHaveBeenCalledTimes(1); + expect(unsubscribeNotificationMock).toHaveBeenCalledTimes(1); }); }); }); diff --git a/src/renderer/components/notifications/RepositoryNotifications.test.tsx b/src/renderer/components/notifications/RepositoryNotifications.test.tsx index 9849596a3..61bc44cfa 100644 --- a/src/renderer/components/notifications/RepositoryNotifications.test.tsx +++ b/src/renderer/components/notifications/RepositoryNotifications.test.tsx @@ -14,8 +14,8 @@ jest.mock('./NotificationRow', () => ({ })); describe('renderer/components/notifications/RepositoryNotifications.tsx', () => { - const markNotificationsAsRead = jest.fn(); - const markNotificationsAsDone = jest.fn(); + const markNotificationsAsReadMock = jest.fn(); + const markNotificationsAsDoneMock = jest.fn(); const props = { account: mockGitHubCloudAccount, @@ -28,10 +28,7 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () => }); it('should render itself & its children', () => { - const tree = renderWithAppContext( - , - {}, - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); @@ -41,10 +38,7 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () => n.unread = false; } - const tree = renderWithAppContext( - , - {}, - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); @@ -67,12 +61,12 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () => it('should mark a repo as read', async () => { renderWithAppContext(, { settings: { ...mockSettings }, - markNotificationsAsRead, + markNotificationsAsRead: markNotificationsAsReadMock, }); await userEvent.click(screen.getByTestId('repository-mark-as-read')); - expect(markNotificationsAsRead).toHaveBeenCalledWith( + expect(markNotificationsAsReadMock).toHaveBeenCalledWith( mockGitHubNotifications, ); }); @@ -80,12 +74,12 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () => it('should mark a repo as done', async () => { renderWithAppContext(, { settings: { ...mockSettings }, - markNotificationsAsDone, + markNotificationsAsDone: markNotificationsAsDoneMock, }); await userEvent.click(screen.getByTestId('repository-mark-as-done')); - expect(markNotificationsAsDone).toHaveBeenCalledWith( + expect(markNotificationsAsDoneMock).toHaveBeenCalledWith( mockGitHubNotifications, ); }); @@ -93,10 +87,7 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () => it('should use default repository icon when avatar is not available', () => { props.repoNotifications[0].repository.owner.avatar_url = '' as Link; - const tree = renderWithAppContext( - , - {}, - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/primitives/Header.test.tsx b/src/renderer/components/primitives/Header.test.tsx index 1af920270..e8efd1d82 100644 --- a/src/renderer/components/primitives/Header.test.tsx +++ b/src/renderer/components/primitives/Header.test.tsx @@ -6,14 +6,14 @@ import { MarkGithubIcon } from '@primer/octicons-react'; import { renderWithAppContext } from '../../__helpers__/test-utils'; import { Header } from './Header'; -const mockNavigate = jest.fn(); +const navigateMock = jest.fn(); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavigate, + useNavigate: () => navigateMock, })); describe('renderer/components/primitives/Header.tsx', () => { - const mockFetchNotifications = jest.fn(); + const fetchNotificationsMock = jest.fn(); afterEach(() => { jest.resetAllMocks(); @@ -32,8 +32,8 @@ describe('renderer/components/primitives/Header.tsx', () => { await userEvent.click(screen.getByTestId('header-nav-back')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); it('should navigate back and fetch notifications', async () => { @@ -41,13 +41,13 @@ describe('renderer/components/primitives/Header.tsx', () => {
Test Header
, - { fetchNotifications: mockFetchNotifications }, + { fetchNotifications: fetchNotificationsMock }, ); await userEvent.click(screen.getByTestId('header-nav-back')); - expect(mockFetchNotifications).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(fetchNotificationsMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); }); diff --git a/src/renderer/components/primitives/HoverButton.test.tsx b/src/renderer/components/primitives/HoverButton.test.tsx index 3956da573..c30be3542 100644 --- a/src/renderer/components/primitives/HoverButton.test.tsx +++ b/src/renderer/components/primitives/HoverButton.test.tsx @@ -5,11 +5,11 @@ import { HoverButton } from './HoverButton'; describe('renderer/components/primitives/HoverButton.tsx', () => { it('should render', () => { - const mockAction = jest.fn(); + const actionMock = jest.fn(); const tree = renderWithAppContext( { }); it('should render - disabled', () => { - const mockAction = jest.fn(); + const actionMock = jest.fn(); const tree = renderWithAppContext( { - const mockUpdateSetting = jest.fn(); + const updateSettingMock = jest.fn(); const zoomTimeout = () => new Promise((r) => setTimeout(r, 300)); afterEach(() => { @@ -16,7 +16,7 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { it('should change the theme mode dropdown', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); @@ -25,8 +25,8 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { 'LIGHT', ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('theme', 'LIGHT'); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('theme', 'LIGHT'); }); it('should toggle increase contrast checkbox', async () => { @@ -35,14 +35,14 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { auth: { accounts: [mockGitHubAppAccount], }, - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-increaseContrast')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('increaseContrast', true); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('increaseContrast', true); }); it('should update the zoom value when using CMD + and CMD -', async () => { @@ -50,15 +50,15 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); fireEvent(window, new Event('resize')); await zoomTimeout(); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('zoomPercentage', 50); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('zoomPercentage', 50); }); it('should update the zoom values when using the zoom buttons', async () => { @@ -70,7 +70,7 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); @@ -79,8 +79,8 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { await userEvent.click(screen.getByTestId('settings-zoom-out')); await zoomTimeout(); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenNthCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenNthCalledWith( 1, 'zoomPercentage', 90, @@ -91,8 +91,8 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { await userEvent.click(screen.getByTestId('settings-zoom-out')); await zoomTimeout(); - expect(mockUpdateSetting).toHaveBeenCalledTimes(2); - expect(mockUpdateSetting).toHaveBeenNthCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(2); + expect(updateSettingMock).toHaveBeenNthCalledWith( 2, 'zoomPercentage', 80, @@ -104,8 +104,8 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { await userEvent.click(screen.getByTestId('settings-zoom-in')); await zoomTimeout(); - expect(mockUpdateSetting).toHaveBeenCalledTimes(3); - expect(mockUpdateSetting).toHaveBeenNthCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(3); + expect(updateSettingMock).toHaveBeenNthCalledWith( 3, 'zoomPercentage', 90, @@ -117,8 +117,8 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { await userEvent.click(screen.getByTestId('settings-zoom-reset')); await zoomTimeout(); - expect(mockUpdateSetting).toHaveBeenCalledTimes(4); - expect(mockUpdateSetting).toHaveBeenNthCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(4); + expect(updateSettingMock).toHaveBeenNthCalledWith( 4, 'zoomPercentage', 100, @@ -132,14 +132,14 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { auth: { accounts: [mockGitHubAppAccount], }, - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-showAccountHeader')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('showAccountHeader', true); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('showAccountHeader', true); }); it('should toggle wrap notification title checkbox', async () => { @@ -148,14 +148,14 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { auth: { accounts: [mockGitHubAppAccount], }, - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-wrapNotificationTitle')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith( 'wrapNotificationTitle', true, ); diff --git a/src/renderer/components/settings/NotificationSettings.test.tsx b/src/renderer/components/settings/NotificationSettings.test.tsx index a8d867fd4..648bf8c76 100644 --- a/src/renderer/components/settings/NotificationSettings.test.tsx +++ b/src/renderer/components/settings/NotificationSettings.test.tsx @@ -8,7 +8,7 @@ import * as comms from '../../utils/comms'; import { NotificationSettings } from './NotificationSettings'; describe('renderer/components/settings/NotificationSettings.tsx', () => { - const mockUpdateSetting = jest.fn(); + const updateSettingMock = jest.fn(); afterEach(() => { jest.clearAllMocks(); @@ -17,34 +17,34 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { it('should change the groupBy radio group', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('radio-groupBy-date')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('groupBy', 'DATE'); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('groupBy', 'DATE'); }); it('should change the fetchType radio group', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('radio-fetchType-inactivity')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('fetchType', 'INACTIVITY'); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('fetchType', 'INACTIVITY'); }); describe('fetch interval settings', () => { it('should update the fetch interval values when using the buttons', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); @@ -54,8 +54,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-increase'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenNthCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenNthCalledWith( 1, 'fetchInterval', 120000, @@ -67,8 +67,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-increase'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(2); - expect(mockUpdateSetting).toHaveBeenNthCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(2); + expect(updateSettingMock).toHaveBeenNthCalledWith( 2, 'fetchInterval', 180000, @@ -81,8 +81,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-decrease'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(3); - expect(mockUpdateSetting).toHaveBeenNthCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(3); + expect(updateSettingMock).toHaveBeenNthCalledWith( 3, 'fetchInterval', 120000, @@ -95,8 +95,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-reset'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(4); - expect(mockUpdateSetting).toHaveBeenNthCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(4); + expect(updateSettingMock).toHaveBeenNthCalledWith( 4, 'fetchInterval', 60000, @@ -113,7 +113,7 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { Constants.MIN_FETCH_NOTIFICATIONS_INTERVAL_MS + Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS, }, - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); @@ -122,8 +122,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-decrease'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('fetchInterval', 60000); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('fetchInterval', 60000); }); // Attempt to go below the minimum interval, update settings should not be called @@ -132,7 +132,7 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-decrease'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledTimes(1); }); }); @@ -145,7 +145,7 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { Constants.MAX_FETCH_NOTIFICATIONS_INTERVAL_MS - Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS, }, - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); @@ -154,8 +154,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-increase'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith( 'fetchInterval', 3600000, ); @@ -167,7 +167,7 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-increase'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledTimes(1); }); }); }); @@ -175,14 +175,14 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { it('should toggle the fetchAllNotifications checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-fetchAllNotifications')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith( 'fetchAllNotifications', false, ); @@ -191,14 +191,14 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { it('should toggle detailed notifications checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-detailedNotifications')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith( 'detailedNotifications', false, ); @@ -207,40 +207,40 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { it('should toggle metric pills checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-showPills')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('showPills', false); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('showPills', false); }); it('should toggle show number checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-showNumber')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('showNumber', false); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('showNumber', false); }); it('should toggle the showOnlyParticipating checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-showOnlyParticipating')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('participating', true); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('participating', true); }); it('should open official docs for showOnlyParticipating tooltip', async () => { @@ -250,7 +250,7 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); @@ -274,20 +274,20 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { it('should toggle the markAsDoneOnOpen checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-markAsDoneOnOpen')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('markAsDoneOnOpen', true); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('markAsDoneOnOpen', true); }); it('should toggle the markAsDoneOnUnsubscribe checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); @@ -295,8 +295,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('checkbox-markAsDoneOnUnsubscribe'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith( 'markAsDoneOnUnsubscribe', true, ); @@ -305,7 +305,7 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { it('should toggle the delayNotificationState checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); @@ -313,8 +313,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('checkbox-delayNotificationState'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith( 'delayNotificationState', true, ); diff --git a/src/renderer/components/settings/SettingsFooter.test.tsx b/src/renderer/components/settings/SettingsFooter.test.tsx index 4352b2f4e..151d31c7d 100644 --- a/src/renderer/components/settings/SettingsFooter.test.tsx +++ b/src/renderer/components/settings/SettingsFooter.test.tsx @@ -5,10 +5,10 @@ import { renderWithAppContext } from '../../__helpers__/test-utils'; import * as comms from '../../utils/comms'; import { SettingsFooter } from './SettingsFooter'; -const mockNavigate = jest.fn(); +const navigateMock = jest.fn(); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavigate, + useNavigate: () => navigateMock, })); describe('renderer/components/settings/SettingsFooter.tsx', () => { @@ -56,7 +56,7 @@ describe('renderer/components/settings/SettingsFooter.tsx', () => { await userEvent.click(screen.getByTestId('settings-accounts')); - expect(mockNavigate).toHaveBeenCalledWith('/accounts'); + expect(navigateMock).toHaveBeenCalledWith('/accounts'); }); it('should quit the app', async () => { diff --git a/src/renderer/components/settings/SettingsReset.test.tsx b/src/renderer/components/settings/SettingsReset.test.tsx index 78ac8793a..d278720f9 100644 --- a/src/renderer/components/settings/SettingsReset.test.tsx +++ b/src/renderer/components/settings/SettingsReset.test.tsx @@ -6,7 +6,7 @@ import * as logger from '../../utils/logger'; import { SettingsReset } from './SettingsReset'; describe('renderer/components/settings/SettingsReset.tsx', () => { - const mockResetSettings = jest.fn(); + const resetSettingsMock = jest.fn(); afterEach(() => { jest.clearAllMocks(); @@ -21,14 +21,14 @@ describe('renderer/components/settings/SettingsReset.tsx', () => { await act(async () => { renderWithAppContext(, { - resetSettings: mockResetSettings, + resetSettings: resetSettingsMock, }); }); await userEvent.click(screen.getByTestId('settings-reset')); await userEvent.click(screen.getByText('Reset')); - expect(mockResetSettings).toHaveBeenCalled(); + expect(resetSettingsMock).toHaveBeenCalled(); expect(rendererLogInfoSpy).toHaveBeenCalled(); }); @@ -37,13 +37,13 @@ describe('renderer/components/settings/SettingsReset.tsx', () => { await act(async () => { renderWithAppContext(, { - resetSettings: mockResetSettings, + resetSettings: resetSettingsMock, }); }); await userEvent.click(screen.getByTestId('settings-reset')); await userEvent.click(screen.getByText('Cancel')); - expect(mockResetSettings).not.toHaveBeenCalled(); + expect(resetSettingsMock).not.toHaveBeenCalled(); }); }); diff --git a/src/renderer/components/settings/SystemSettings.test.tsx b/src/renderer/components/settings/SystemSettings.test.tsx index f7c85b90d..7e2422d5a 100644 --- a/src/renderer/components/settings/SystemSettings.test.tsx +++ b/src/renderer/components/settings/SystemSettings.test.tsx @@ -7,7 +7,7 @@ import type { Percentage } from '../../types'; import { SystemSettings } from './SystemSettings'; describe('renderer/components/settings/SystemSettings.tsx', () => { - const mockUpdateSetting = jest.fn(); + const updateSettingMock = jest.fn(); afterEach(() => { jest.clearAllMocks(); @@ -16,57 +16,57 @@ describe('renderer/components/settings/SystemSettings.tsx', () => { it('should change the open links radio group', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('radio-openLinks-background')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('openLinks', 'BACKGROUND'); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('openLinks', 'BACKGROUND'); }); it('should toggle the keyboardShortcut checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-keyboardShortcut')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('keyboardShortcut', false); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('keyboardShortcut', false); }); it('should toggle the showNotifications checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-showNotifications')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('showNotifications', false); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('showNotifications', false); }); describe('playSound', () => { it('should toggle the playSound checkbox', async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); await userEvent.click(screen.getByTestId('checkbox-playSound')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('playSound', false); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('playSound', false); }); it('volume controls should not be shown if playSound checkbox is false', async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, settings: { ...mockSettings, playSound: false }, }); @@ -75,7 +75,7 @@ describe('renderer/components/settings/SystemSettings.tsx', () => { it('volume controls should be shown if playSound checkbox is true', async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, settings: { ...mockSettings, playSound: true }, }); @@ -84,49 +84,49 @@ describe('renderer/components/settings/SystemSettings.tsx', () => { it('should increase notification volume', async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); await userEvent.click(screen.getByTestId('settings-volume-up')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('notificationVolume', 30); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('notificationVolume', 30); }); it('should decrease notification volume', async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); await userEvent.click(screen.getByTestId('settings-volume-down')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('notificationVolume', 10); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('notificationVolume', 10); }); it('should reset notification volume', async () => { renderWithAppContext(, { settings: { ...mockSettings, notificationVolume: 30 as Percentage }, - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); await userEvent.click(screen.getByTestId('settings-volume-reset')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('notificationVolume', 20); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('notificationVolume', 20); }); }); it('should toggle the openAtStartup checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-openAtStartup')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith('openAtStartup', true); + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith('openAtStartup', true); }); }); diff --git a/src/renderer/components/settings/TraySettings.test.tsx b/src/renderer/components/settings/TraySettings.test.tsx index 422cffd18..965ddad70 100644 --- a/src/renderer/components/settings/TraySettings.test.tsx +++ b/src/renderer/components/settings/TraySettings.test.tsx @@ -5,7 +5,7 @@ import { renderWithAppContext } from '../../__helpers__/test-utils'; import { TraySettings } from './TraySettings'; describe('renderer/components/settings/TraySettings.tsx', () => { - const mockUpdateSetting = jest.fn(); + const updateSettingMock = jest.fn(); afterEach(() => { jest.clearAllMocks(); @@ -14,7 +14,7 @@ describe('renderer/components/settings/TraySettings.tsx', () => { it('should toggle the showNotificationsCountInTray checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); @@ -22,8 +22,8 @@ describe('renderer/components/settings/TraySettings.tsx', () => { screen.getByTestId('checkbox-showNotificationsCountInTray'), ); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith( 'showNotificationsCountInTray', false, ); @@ -32,14 +32,14 @@ describe('renderer/components/settings/TraySettings.tsx', () => { it('should toggle the useUnreadActiveIcon checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-useUnreadActiveIcon')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith( 'useUnreadActiveIcon', false, ); @@ -48,14 +48,14 @@ describe('renderer/components/settings/TraySettings.tsx', () => { it('should toggle the useAlternateIdleIcon checkbox', async () => { await act(async () => { renderWithAppContext(, { - updateSetting: mockUpdateSetting, + updateSetting: updateSettingMock, }); }); await userEvent.click(screen.getByTestId('checkbox-useAlternateIdleIcon')); - expect(mockUpdateSetting).toHaveBeenCalledTimes(1); - expect(mockUpdateSetting).toHaveBeenCalledWith( + expect(updateSettingMock).toHaveBeenCalledTimes(1); + expect(updateSettingMock).toHaveBeenCalledWith( 'useAlternateIdleIcon', true, ); diff --git a/src/renderer/context/App.test.tsx b/src/renderer/context/App.test.tsx index 592571b8d..ea88529d7 100644 --- a/src/renderer/context/App.test.tsx +++ b/src/renderer/context/App.test.tsx @@ -8,7 +8,6 @@ import { useNotifications } from '../hooks/useNotifications'; import type { AuthState, Hostname, SettingsState, Token } from '../types'; import { mockSingleNotification } from '../utils/api/__mocks__/response-mocks'; import * as apiRequests from '../utils/api/request'; -import * as comms from '../utils/comms'; import * as notifications from '../utils/notifications/notifications'; import * as storage from '../utils/storage'; import * as tray from '../utils/tray'; @@ -51,8 +50,23 @@ const renderContextButton = ( }; describe('renderer/context/App.tsx', () => { + const mockFetchNotifications = jest.fn(); + const markNotificationsAsReadMock = jest.fn(); + const markNotificationsAsDoneMock = jest.fn(); + const unsubscribeNotificationMock = jest.fn(); + + const saveStateSpy = jest + .spyOn(storage, 'saveState') + .mockImplementation(jest.fn()); + beforeEach(() => { jest.useFakeTimers(); + (useNotifications as jest.Mock).mockReturnValue({ + fetchNotifications: mockFetchNotifications, + markNotificationsAsRead: markNotificationsAsReadMock, + markNotificationsAsDone: markNotificationsAsDoneMock, + unsubscribeNotification: unsubscribeNotificationMock, + }); }); afterEach(() => { @@ -73,30 +87,12 @@ describe('renderer/context/App.tsx', () => { .spyOn(notifications, 'getUnreadNotificationCount') .mockImplementation(jest.fn()); - const mockFetchNotifications = jest.fn(); - const mockMarkNotificationsAsRead = jest.fn(); - const mockMarkNotificationsAsDone = jest.fn(); - const mockUnsubscribeNotification = jest.fn(); - const mockDefaultState = { auth: { accounts: [] }, settings: mockSettings, }; - beforeEach(() => { - (useNotifications as jest.Mock).mockReturnValue({ - fetchNotifications: mockFetchNotifications, - markNotificationsAsRead: mockMarkNotificationsAsRead, - markNotificationsAsDone: mockMarkNotificationsAsDone, - unsubscribeNotification: mockUnsubscribeNotification, - }); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - - it('fetch notifications every minute', async () => { + it('fetch notifications each interval', async () => { renderWithAppContext({null}); await waitFor(() => @@ -142,8 +138,8 @@ describe('renderer/context/App.tsx', () => { fireEvent.click(button); - expect(mockMarkNotificationsAsRead).toHaveBeenCalledTimes(1); - expect(mockMarkNotificationsAsRead).toHaveBeenCalledWith( + expect(markNotificationsAsReadMock).toHaveBeenCalledTimes(1); + expect(markNotificationsAsReadMock).toHaveBeenCalledWith( mockDefaultState, [mockSingleNotification], ); @@ -157,8 +153,8 @@ describe('renderer/context/App.tsx', () => { fireEvent.click(button); - expect(mockMarkNotificationsAsDone).toHaveBeenCalledTimes(1); - expect(mockMarkNotificationsAsDone).toHaveBeenCalledWith( + expect(markNotificationsAsDoneMock).toHaveBeenCalledTimes(1); + expect(markNotificationsAsDoneMock).toHaveBeenCalledWith( mockDefaultState, [mockSingleNotification], ); @@ -173,8 +169,8 @@ describe('renderer/context/App.tsx', () => { fireEvent.click(button); - expect(mockUnsubscribeNotification).toHaveBeenCalledTimes(1); - expect(mockUnsubscribeNotification).toHaveBeenCalledWith( + expect(unsubscribeNotificationMock).toHaveBeenCalledTimes(1); + expect(unsubscribeNotificationMock).toHaveBeenCalledWith( mockDefaultState, mockSingleNotification, ); @@ -184,16 +180,25 @@ describe('renderer/context/App.tsx', () => { describe('authentication methods', () => { const apiRequestAuthSpy = jest.spyOn(apiRequests, 'apiRequestAuth'); - const mockFetchNotifications = jest.fn(); - beforeEach(() => { - (useNotifications as jest.Mock).mockReturnValue({ - fetchNotifications: mockFetchNotifications, - }); + it('should call loginWithGitHubApp', async () => { + const { button } = renderContextButton('loginWithGitHubApp'); + + fireEvent.click(button); + + await waitFor(() => + expect(mockFetchNotifications).toHaveBeenCalledTimes(1), + ); }); - afterEach(() => { - jest.clearAllMocks(); + it('should call loginWithOAuthApp', async () => { + const { button } = renderContextButton('loginWithOAuthApp'); + + fireEvent.click(button); + + await waitFor(() => + expect(mockFetchNotifications).toHaveBeenCalledTimes(1), + ); }); it('should call loginWithPersonalAccessToken', async () => { @@ -220,30 +225,20 @@ describe('renderer/context/App.tsx', () => { }); describe('settings methods', () => { - const mockFetchNotifications = jest.fn(); - - beforeEach(() => { - (useNotifications as jest.Mock).mockReturnValue({ - fetchNotifications: mockFetchNotifications, - }); - }); + const saveStateSpy = jest + .spyOn(storage, 'saveState') + .mockImplementation(jest.fn()); it('should call updateSetting', async () => { - const mockSaveState = jest - .spyOn(storage, 'saveState') - .mockImplementation(jest.fn()); - const { button } = renderContextButton( 'updateSetting', 'participating', true, ); - act(() => { - fireEvent.click(button); - }); + fireEvent.click(button); - expect(mockSaveState).toHaveBeenCalledWith({ + expect(saveStateSpy).toHaveBeenCalledWith({ auth: { accounts: [], } as AuthState, @@ -254,23 +249,51 @@ describe('renderer/context/App.tsx', () => { }); }); - it('should call updateSetting and set auto launch(openAtStartup)', async () => { - const setAutoLaunchSpy = jest.spyOn(comms, 'setAutoLaunch'); - const saveStateSpy = jest - .spyOn(storage, 'saveState') - .mockImplementation(jest.fn()); + it('should call resetSettings', async () => { + const { button } = renderContextButton('resetSettings'); + + fireEvent.click(button); + expect(saveStateSpy).toHaveBeenCalledWith({ + auth: { + accounts: [], + } as AuthState, + settings: defaultSettings, + }); + }); + }); + + describe('filter methods', () => { + it('should call updateFilter - checked', async () => { const { button } = renderContextButton( - 'updateSetting', - 'openAtStartup', + 'updateFilter', + 'filterReasons', + 'assign', true, ); - act(() => { - fireEvent.click(button); + fireEvent.click(button); + + expect(saveStateSpy).toHaveBeenCalledWith({ + auth: { + accounts: [], + } as AuthState, + settings: { + ...defaultSettings, + filterReasons: ['assign'], + } as SettingsState, }); + }); - expect(setAutoLaunchSpy).toHaveBeenCalledWith(true); + it('should call updateFilter - unchecked', async () => { + const { button } = renderContextButton( + 'updateFilter', + 'filterReasons', + 'assign', + false, + ); + + fireEvent.click(button); expect(saveStateSpy).toHaveBeenCalledWith({ auth: { @@ -278,21 +301,15 @@ describe('renderer/context/App.tsx', () => { } as AuthState, settings: { ...defaultSettings, - openAtStartup: true, + filterReasons: [], } as SettingsState, }); }); it('should clear filters back to default', async () => { - const saveStateSpy = jest - .spyOn(storage, 'saveState') - .mockImplementation(jest.fn()); - const { button } = renderContextButton('clearFilters'); - act(() => { - fireEvent.click(button); - }); + fireEvent.click(button); expect(saveStateSpy).toHaveBeenCalledWith({ auth: { @@ -309,24 +326,5 @@ describe('renderer/context/App.tsx', () => { }, }); }); - - it('should call resetSettings', async () => { - const saveStateSpy = jest - .spyOn(storage, 'saveState') - .mockImplementation(jest.fn()); - - const { button } = renderContextButton('resetSettings'); - - act(() => { - fireEvent.click(button); - }); - - expect(saveStateSpy).toHaveBeenCalledWith({ - auth: { - accounts: [], - } as AuthState, - settings: defaultSettings, - }); - }); }); }); diff --git a/src/renderer/routes/Accounts.test.tsx b/src/renderer/routes/Accounts.test.tsx index 1eae8d661..a108313d0 100644 --- a/src/renderer/routes/Accounts.test.tsx +++ b/src/renderer/routes/Accounts.test.tsx @@ -13,10 +13,10 @@ import * as links from '../utils/links'; import * as storage from '../utils/storage'; import { AccountsRoute } from './Accounts'; -const mockNavigate = jest.fn(); +const navigateMock = jest.fn(); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavigate, + useNavigate: () => navigateMock, })); describe('renderer/routes/Accounts.tsx', () => { @@ -49,8 +49,8 @@ describe('renderer/routes/Accounts.tsx', () => { await userEvent.click(screen.getByTestId('header-nav-back')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); }); @@ -171,45 +171,45 @@ describe('renderer/routes/Accounts.tsx', () => { await userEvent.click(screen.getByTestId('account-refresh')); expect(refreshAccountSpy).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/accounts', { + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/accounts', { replace: true, }); }); it('should logout', async () => { - const mockLogoutFromAccount = jest.fn(); + const logoutFromAccountMock = jest.fn(); await act(async () => { renderWithAppContext(, { auth: { accounts: [mockPersonalAccessTokenAccount] }, - logoutFromAccount: mockLogoutFromAccount, + logoutFromAccount: logoutFromAccountMock, }); }); await userEvent.click(screen.getByTestId('account-logout')); - expect(mockLogoutFromAccount).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(logoutFromAccountMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); }); describe('Add new accounts', () => { it('should show login with github app', async () => { - const mockLoginWithGitHubApp = jest.fn(); + const loginWithGitHubAppMock = jest.fn(); await act(async () => { renderWithAppContext(, { auth: { accounts: [mockOAuthAccount] }, - loginWithGitHubApp: mockLoginWithGitHubApp, + loginWithGitHubApp: loginWithGitHubAppMock, }); }); await userEvent.click(screen.getByTestId('account-add-new')); await userEvent.click(screen.getByTestId('account-add-github')); - expect(mockLoginWithGitHubApp).toHaveBeenCalled(); + expect(loginWithGitHubAppMock).toHaveBeenCalled(); }); it('should show login with personal access token', async () => { @@ -222,8 +222,8 @@ describe('renderer/routes/Accounts.tsx', () => { await userEvent.click(screen.getByTestId('account-add-new')); await userEvent.click(screen.getByTestId('account-add-pat')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith( + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith( '/login-personal-access-token', { replace: true, @@ -241,8 +241,8 @@ describe('renderer/routes/Accounts.tsx', () => { await userEvent.click(screen.getByTestId('account-add-new')); await userEvent.click(screen.getByTestId('account-add-oauth-app')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/login-oauth-app', { + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/login-oauth-app', { replace: true, }); }); diff --git a/src/renderer/routes/Filters.test.tsx b/src/renderer/routes/Filters.test.tsx index 5abd987d7..544862671 100644 --- a/src/renderer/routes/Filters.test.tsx +++ b/src/renderer/routes/Filters.test.tsx @@ -4,15 +4,15 @@ import userEvent from '@testing-library/user-event'; import { renderWithAppContext } from '../__helpers__/test-utils'; import { FiltersRoute } from './Filters'; -const mockNavigate = jest.fn(); +const navigateMock = jest.fn(); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavigate, + useNavigate: () => navigateMock, })); describe('renderer/routes/Filters.tsx', () => { - const mockClearFilters = jest.fn(); - const mockFetchNotifications = jest.fn(); + const clearFiltersMock = jest.fn(); + const fetchNotificationsMock = jest.fn(); afterEach(() => { jest.clearAllMocks(); @@ -30,15 +30,15 @@ describe('renderer/routes/Filters.tsx', () => { it('should go back by pressing the icon', async () => { await act(async () => { renderWithAppContext(, { - fetchNotifications: mockFetchNotifications, + fetchNotifications: fetchNotificationsMock, }); }); await userEvent.click(screen.getByTestId('header-nav-back')); - expect(mockFetchNotifications).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(fetchNotificationsMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); }); @@ -46,13 +46,13 @@ describe('renderer/routes/Filters.tsx', () => { it('should clear filters', async () => { await act(async () => { renderWithAppContext(, { - clearFilters: mockClearFilters, + clearFilters: clearFiltersMock, }); }); await userEvent.click(screen.getByTestId('filters-clear')); - expect(mockClearFilters).toHaveBeenCalled(); + expect(clearFiltersMock).toHaveBeenCalled(); }); }); }); diff --git a/src/renderer/routes/Login.test.tsx b/src/renderer/routes/Login.test.tsx index dd2a3405f..fcfd4759f 100644 --- a/src/renderer/routes/Login.test.tsx +++ b/src/renderer/routes/Login.test.tsx @@ -5,10 +5,10 @@ import { renderWithAppContext } from '../__helpers__/test-utils'; import * as comms from '../utils/comms'; import { LoginRoute } from './Login'; -const mockNavigate = jest.fn(); +const navigateMock = jest.fn(); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavigate, + useNavigate: () => navigateMock, })); describe('renderer/routes/Login.tsx', () => { @@ -21,7 +21,7 @@ describe('renderer/routes/Login.tsx', () => { expect(tree).toMatchSnapshot(); - expect(mockNavigate).toHaveBeenCalledTimes(0); + expect(navigateMock).toHaveBeenCalledTimes(0); }); it('should redirect to notifications once logged in', () => { @@ -32,37 +32,38 @@ describe('renderer/routes/Login.tsx', () => { }); expect(showWindowSpy).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/', { replace: true }); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/', { replace: true }); }); it('should login with github', async () => { - const mockLoginWithGitHubApp = jest.fn(); + const loginWithGitHubAppMock = jest.fn(); renderWithAppContext(, { - loginWithGitHubApp: mockLoginWithGitHubApp, + isLoggedIn: false, + loginWithGitHubApp: loginWithGitHubAppMock, }); await userEvent.click(screen.getByTestId('login-github')); - expect(mockLoginWithGitHubApp).toHaveBeenCalled(); + expect(loginWithGitHubAppMock).toHaveBeenCalled(); }); it('should navigate to login with personal access token', async () => { - renderWithAppContext(); + renderWithAppContext(, { isLoggedIn: false }); await userEvent.click(screen.getByTestId('login-pat')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/login-personal-access-token'); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/login-personal-access-token'); }); it('should navigate to login with oauth app', async () => { - renderWithAppContext(); + renderWithAppContext(, { isLoggedIn: false }); await userEvent.click(screen.getByTestId('login-oauth-app')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith('/login-oauth-app'); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith('/login-oauth-app'); }); }); diff --git a/src/renderer/routes/LoginWithOAuthApp.test.tsx b/src/renderer/routes/LoginWithOAuthApp.test.tsx index 848d9301c..a95490fc5 100644 --- a/src/renderer/routes/LoginWithOAuthApp.test.tsx +++ b/src/renderer/routes/LoginWithOAuthApp.test.tsx @@ -11,14 +11,14 @@ import { validateForm, } from './LoginWithOAuthApp'; -const mockNavigate = jest.fn(); +const navigateMock = jest.fn(); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavigate, + useNavigate: () => navigateMock, })); describe('renderer/routes/LoginWithOAuthApp.tsx', () => { - const mockLoginWithOAuthApp = jest.fn(); + const loginWithOAuthAppMock = jest.fn(); const openExternalLinkSpy = jest .spyOn(comms, 'openExternalLink') @@ -39,8 +39,8 @@ describe('renderer/routes/LoginWithOAuthApp.tsx', () => { await userEvent.click(screen.getByTestId('header-nav-back')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); describe('form validation', () => { @@ -98,10 +98,10 @@ describe('renderer/routes/LoginWithOAuthApp.tsx', () => { }); it('should login using a token - success', async () => { - mockLoginWithOAuthApp.mockResolvedValueOnce(null); + loginWithOAuthAppMock.mockResolvedValueOnce(null); renderWithAppContext(, { - loginWithOAuthApp: mockLoginWithOAuthApp, + loginWithOAuthApp: loginWithOAuthAppMock, }); const hostname = screen.getByTestId('login-hostname'); @@ -120,19 +120,19 @@ describe('renderer/routes/LoginWithOAuthApp.tsx', () => { await userEvent.click(screen.getByTestId('login-submit')); - expect(mockLoginWithOAuthApp).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(loginWithOAuthAppMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); it('should login using a token - failure', async () => { const rendererLogErrorSpy = jest .spyOn(logger, 'rendererLogError') .mockImplementation(); - mockLoginWithOAuthApp.mockRejectedValueOnce(null); + loginWithOAuthAppMock.mockRejectedValueOnce(null); renderWithAppContext(, { - loginWithOAuthApp: mockLoginWithOAuthApp, + loginWithOAuthApp: loginWithOAuthAppMock, }); const hostname = screen.getByTestId('login-hostname'); @@ -151,8 +151,8 @@ describe('renderer/routes/LoginWithOAuthApp.tsx', () => { await userEvent.click(screen.getByTestId('login-submit')); - expect(mockLoginWithOAuthApp).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(0); + expect(loginWithOAuthAppMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledTimes(0); expect(rendererLogErrorSpy).toHaveBeenCalledTimes(1); }); diff --git a/src/renderer/routes/LoginWithPersonalAccessToken.test.tsx b/src/renderer/routes/LoginWithPersonalAccessToken.test.tsx index c1f559c94..c3ba041bb 100644 --- a/src/renderer/routes/LoginWithPersonalAccessToken.test.tsx +++ b/src/renderer/routes/LoginWithPersonalAccessToken.test.tsx @@ -11,14 +11,14 @@ import { validateForm, } from './LoginWithPersonalAccessToken'; -const mockNavigate = jest.fn(); +const navigateMock = jest.fn(); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavigate, + useNavigate: () => navigateMock, })); describe('renderer/routes/LoginWithPersonalAccessToken.tsx', () => { - const mockLoginWithPersonalAccessToken = jest.fn(); + const loginWithPersonalAccessTokenMock = jest.fn(); const openExternalLinkSpy = jest .spyOn(comms, 'openExternalLink') .mockImplementation(); @@ -38,8 +38,8 @@ describe('renderer/routes/LoginWithPersonalAccessToken.tsx', () => { await userEvent.click(screen.getByTestId('header-nav-back')); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); describe('form validation', () => { @@ -66,7 +66,7 @@ describe('renderer/routes/LoginWithPersonalAccessToken.tsx', () => { describe("'Generate a PAT' button", () => { it('should be disabled if no hostname configured', async () => { renderWithAppContext(, { - loginWithPersonalAccessToken: mockLoginWithPersonalAccessToken, + loginWithPersonalAccessToken: loginWithPersonalAccessTokenMock, }); await userEvent.clear(screen.getByTestId('login-hostname')); @@ -78,7 +78,7 @@ describe('renderer/routes/LoginWithPersonalAccessToken.tsx', () => { it('should open in browser if hostname configured', async () => { renderWithAppContext(, { - loginWithPersonalAccessToken: mockLoginWithPersonalAccessToken, + loginWithPersonalAccessToken: loginWithPersonalAccessTokenMock, }); await userEvent.click(screen.getByTestId('login-create-token')); @@ -88,10 +88,10 @@ describe('renderer/routes/LoginWithPersonalAccessToken.tsx', () => { }); it('should login using a token - success', async () => { - mockLoginWithPersonalAccessToken.mockResolvedValueOnce(null); + loginWithPersonalAccessTokenMock.mockResolvedValueOnce(null); renderWithAppContext(, { - loginWithPersonalAccessToken: mockLoginWithPersonalAccessToken, + loginWithPersonalAccessToken: loginWithPersonalAccessTokenMock, }); const hostname = screen.getByTestId('login-hostname'); @@ -105,19 +105,19 @@ describe('renderer/routes/LoginWithPersonalAccessToken.tsx', () => { await userEvent.click(screen.getByTestId('login-submit')); - expect(mockLoginWithPersonalAccessToken).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(loginWithPersonalAccessTokenMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); it('should login using a token - failure', async () => { const rendererLogErrorSpy = jest .spyOn(logger, 'rendererLogError') .mockImplementation(); - mockLoginWithPersonalAccessToken.mockRejectedValueOnce(null); + loginWithPersonalAccessTokenMock.mockRejectedValueOnce(null); renderWithAppContext(, { - loginWithPersonalAccessToken: mockLoginWithPersonalAccessToken, + loginWithPersonalAccessToken: loginWithPersonalAccessTokenMock, }); const hostname = screen.getByTestId('login-hostname'); @@ -131,8 +131,8 @@ describe('renderer/routes/LoginWithPersonalAccessToken.tsx', () => { await userEvent.click(screen.getByTestId('login-submit')); - expect(mockLoginWithPersonalAccessToken).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(0); + expect(loginWithPersonalAccessTokenMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledTimes(0); expect(rendererLogErrorSpy).toHaveBeenCalledTimes(1); }); @@ -153,7 +153,7 @@ describe('renderer/routes/LoginWithPersonalAccessToken.tsx', () => { it('should open help docs in the browser', async () => { renderWithAppContext(, { - loginWithPersonalAccessToken: mockLoginWithPersonalAccessToken, + loginWithPersonalAccessToken: loginWithPersonalAccessTokenMock, }); await userEvent.click(screen.getByTestId('login-docs')); diff --git a/src/renderer/routes/Settings.test.tsx b/src/renderer/routes/Settings.test.tsx index aa4a75e73..027e2481f 100644 --- a/src/renderer/routes/Settings.test.tsx +++ b/src/renderer/routes/Settings.test.tsx @@ -4,14 +4,14 @@ import userEvent from '@testing-library/user-event'; import { renderWithAppContext } from '../__helpers__/test-utils'; import { SettingsRoute } from './Settings'; -const mockNavigate = jest.fn(); +const navigateMock = jest.fn(); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useNavigate: () => mockNavigate, + useNavigate: () => navigateMock, })); describe('renderer/routes/Settings.tsx', () => { - const mockFetchNotifications = jest.fn(); + const fetchNotificationsMock = jest.fn(); afterEach(() => { jest.clearAllMocks(); @@ -28,14 +28,14 @@ describe('renderer/routes/Settings.tsx', () => { it('should go back by pressing the icon', async () => { await act(async () => { renderWithAppContext(, { - fetchNotifications: mockFetchNotifications, + fetchNotifications: fetchNotificationsMock, }); }); await userEvent.click(screen.getByTestId('header-nav-back')); - expect(mockFetchNotifications).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledTimes(1); - expect(mockNavigate).toHaveBeenCalledWith(-1); + expect(fetchNotificationsMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledTimes(1); + expect(navigateMock).toHaveBeenCalledWith(-1); }); });