diff --git a/src/main/updater.test.ts b/src/main/updater.test.ts index 7c460aa09..fc858ff48 100644 --- a/src/main/updater.test.ts +++ b/src/main/updater.test.ts @@ -205,12 +205,12 @@ describe('main/updater.ts', () => { }); it('performs initial check and schedules periodic checks', async () => { - const originalSetInterval = global.setInterval; + const originalSetInterval = globalThis.setInterval; const setIntervalSpy = jest - .spyOn(global, 'setInterval') + .spyOn(globalThis, 'setInterval') .mockImplementation(((fn: () => void) => { fn(); - return 0 as unknown as NodeJS.Timer; + return 0 as unknown as NodeJS.Timeout; }) as unknown as typeof setInterval); try { await updater.start(); @@ -224,7 +224,7 @@ describe('main/updater.ts', () => { ); } finally { setIntervalSpy.mockRestore(); - global.setInterval = originalSetInterval; + globalThis.setInterval = originalSetInterval; } }); }); diff --git a/src/renderer/__helpers__/test-utils.tsx b/src/renderer/__helpers__/test-utils.tsx new file mode 100644 index 000000000..f26f9223f --- /dev/null +++ b/src/renderer/__helpers__/test-utils.tsx @@ -0,0 +1,76 @@ +import { render } from '@testing-library/react'; +import type { ReactElement, ReactNode } from 'react'; +import { useMemo } from 'react'; + +import { BaseStyles, ThemeProvider } from '@primer/react'; + +import { mockAuth, mockSettings } from '../__mocks__/state-mocks'; +import type { AppContextState } from '../context/App'; +import { AppContext } from '../context/App'; + +/** + * Props for the AppContextProvider wrapper + */ +interface AppContextProviderProps { + readonly children: ReactNode; + readonly value?: Partial; +} + +/** + * Wrapper component that provides ThemeProvider, BaseStyles, and AppContext + * with sensible defaults for testing. + */ +export function AppContextProvider({ + children, + value = {}, +}: AppContextProviderProps) { + const defaultValue: Partial = useMemo(() => { + return { + auth: mockAuth, + settings: mockSettings, + + notifications: [], + + status: 'success', + globalError: null, + + ...value, + } as Partial; + }, [value]); + + return ( + + + + {children} + + + + ); +} + +/** + * Custom render that wraps components with AppContextProvider by default. + * + * Usage: + * renderWithAppContext(, { auth, settings, ... }) + */ +export function renderWithAppContext( + ui: ReactElement, + context: Partial = {}, +) { + const value: Partial = { ...context }; + + return render(ui, { + wrapper: ({ children }) => ( + {children} + ), + }); +} + +/** + * Ensure stable snapshots for our randomized emoji use-cases + */ +export function ensureStableEmojis() { + global.Math.random = jest.fn(() => 0.1); +} diff --git a/src/renderer/__mocks__/account-mocks.ts b/src/renderer/__mocks__/account-mocks.ts new file mode 100644 index 000000000..5e104f4ca --- /dev/null +++ b/src/renderer/__mocks__/account-mocks.ts @@ -0,0 +1,63 @@ +import { Constants } from '../constants'; +import type { + Account, + AccountNotifications, + GitifyError, + Hostname, + Token, +} from '../types'; +import { mockGitifyUser } from './user-mocks'; + +export const mockPersonalAccessTokenAccount: Account = { + platform: 'GitHub Cloud', + method: 'Personal Access Token', + token: 'token-123-456' as Token, + hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname, + user: mockGitifyUser, + hasRequiredScopes: true, +}; + +export const mockOAuthAccount: Account = { + platform: 'GitHub Enterprise Server', + method: 'OAuth App', + token: '1234568790' as Token, + hostname: 'github.gitify.io' as Hostname, + user: mockGitifyUser, + hasRequiredScopes: true, +}; + +export const mockGitHubCloudAccount: Account = { + platform: 'GitHub Cloud', + method: 'Personal Access Token', + token: 'token-123-456' as Token, + hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname, + user: mockGitifyUser, + version: 'latest', + hasRequiredScopes: true, +}; + +export const mockGitHubEnterpriseServerAccount: Account = { + platform: 'GitHub Enterprise Server', + method: 'Personal Access Token', + token: '1234568790' as Token, + hostname: 'github.gitify.io' as Hostname, + user: mockGitifyUser, + hasRequiredScopes: true, +}; + +export const mockGitHubAppAccount: Account = { + platform: 'GitHub Cloud', + method: 'GitHub App', + token: '987654321' as Token, + hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname, + user: mockGitifyUser, + hasRequiredScopes: true, +}; + +export function mockAccountWithError(error: GitifyError): AccountNotifications { + return { + account: mockGitHubCloudAccount, + notifications: [], + error, + }; +} diff --git a/src/renderer/__mocks__/notifications-mocks.ts b/src/renderer/__mocks__/notifications-mocks.ts index f4dadb94b..7b678e777 100644 --- a/src/renderer/__mocks__/notifications-mocks.ts +++ b/src/renderer/__mocks__/notifications-mocks.ts @@ -1,6 +1,8 @@ -import type { AccountNotifications, GitifyError } from '../types'; +import { Constants } from '../constants'; +import type { AccountNotifications, Hostname } from '../types'; import type { Notification, + Repository, StateType, Subject, SubjectType, @@ -13,30 +15,11 @@ import { import { mockGitHubCloudAccount, mockGitHubEnterpriseServerAccount, -} from './state-mocks'; +} from './account-mocks'; +import { mockToken } from './state-mocks'; +import { mockGitifyUser } from './user-mocks'; -export const mockAccountNotifications: AccountNotifications[] = [ - { - account: mockGitHubCloudAccount, - notifications: mockGitHubNotifications, - error: null, - }, - { - account: mockGitHubEnterpriseServerAccount, - notifications: mockEnterpriseNotifications, - error: null, - }, -]; - -export const mockSingleAccountNotifications: AccountNotifications[] = [ - { - account: mockGitHubCloudAccount, - notifications: [mockSingleNotification], - error: null, - }, -]; - -export function createSubjectMock(mocks: { +export function createMockSubject(mocks: { title?: string; type?: SubjectType; state?: StateType; @@ -50,12 +33,24 @@ export function createSubjectMock(mocks: { }; } -export function mockAccountWithError(error: GitifyError): AccountNotifications { - return { - account: mockGitHubCloudAccount, - notifications: [], - error, +export function createPartialMockNotification( + subject: Partial, + repository?: Partial, +): Notification { + const mockNotification: Partial = { + account: { + method: 'Personal Access Token', + platform: 'GitHub Cloud', + hostname: Constants.GITHUB_API_BASE_URL as Hostname, + token: mockToken, + user: mockGitifyUser, + hasRequiredScopes: true, + }, + subject: subject as Subject, + repository: repository as Repository, }; + + return mockNotification as Notification; } export function createMockNotificationForRepoName( @@ -68,3 +63,24 @@ export function createMockNotificationForRepoName( account: mockGitHubCloudAccount, } as Notification; } + +export const mockAccountNotifications: AccountNotifications[] = [ + { + account: mockGitHubCloudAccount, + notifications: mockGitHubNotifications, + error: null, + }, + { + account: mockGitHubEnterpriseServerAccount, + notifications: mockEnterpriseNotifications, + error: null, + }, +]; + +export const mockSingleAccountNotifications: AccountNotifications[] = [ + { + account: mockGitHubCloudAccount, + notifications: [mockSingleNotification], + error: null, + }, +]; diff --git a/src/renderer/__mocks__/partial-mocks.ts b/src/renderer/__mocks__/partial-mocks.ts deleted file mode 100644 index d40b01e73..000000000 --- a/src/renderer/__mocks__/partial-mocks.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Constants } from '../constants'; -import type { Hostname, Link } from '../types'; -import type { Notification, Repository, Subject, User } from '../typesGitHub'; -import { mockGitifyUser, mockToken } from './state-mocks'; - -export function partialMockNotification( - subject: Partial, - repository?: Partial, -): Notification { - const mockNotification: Partial = { - account: { - method: 'Personal Access Token', - platform: 'GitHub Cloud', - hostname: Constants.GITHUB_API_BASE_URL as Hostname, - token: mockToken, - user: mockGitifyUser, - hasRequiredScopes: true, - }, - subject: subject as Subject, - repository: repository as Repository, - }; - - return mockNotification as Notification; -} - -export function partialMockUser(login: string): User { - const mockUser: Partial = { - login: login, - html_url: `https://github.com/${login}` as Link, - avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link, - type: 'User', - }; - - return mockUser as User; -} diff --git a/src/renderer/__mocks__/state-mocks.ts b/src/renderer/__mocks__/state-mocks.ts index 5dcf04044..63ad1f1c0 100644 --- a/src/renderer/__mocks__/state-mocks.ts +++ b/src/renderer/__mocks__/state-mocks.ts @@ -1,15 +1,11 @@ import { Constants } from '../constants'; import { - type Account, type AppearanceSettingsState, type AuthState, FetchType, type FilterSettingsState, type GitifyState, - type GitifyUser, GroupBy, - type Hostname, - type Link, type NotificationSettingsState, OpenPreference, type Percentage, @@ -19,59 +15,10 @@ import { type Token, type TraySettingsState, } from '../types'; - -export const mockGitifyUser: GitifyUser = { - login: 'octocat', - name: 'Mona Lisa Octocat', - id: 123456789, - avatar: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link, -}; - -export const mockPersonalAccessTokenAccount: Account = { - platform: 'GitHub Cloud', - method: 'Personal Access Token', - token: 'token-123-456' as Token, - hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname, - user: mockGitifyUser, - hasRequiredScopes: true, -}; - -export const mockOAuthAccount: Account = { - platform: 'GitHub Enterprise Server', - method: 'OAuth App', - token: '1234568790' as Token, - hostname: 'github.gitify.io' as Hostname, - user: mockGitifyUser, - hasRequiredScopes: true, -}; - -export const mockGitHubCloudAccount: Account = { - platform: 'GitHub Cloud', - method: 'Personal Access Token', - token: 'token-123-456' as Token, - hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname, - user: mockGitifyUser, - version: 'latest', - hasRequiredScopes: true, -}; - -export const mockGitHubEnterpriseServerAccount: Account = { - platform: 'GitHub Enterprise Server', - method: 'Personal Access Token', - token: '1234568790' as Token, - hostname: 'github.gitify.io' as Hostname, - user: mockGitifyUser, - hasRequiredScopes: true, -}; - -export const mockGitHubAppAccount: Account = { - platform: 'GitHub Cloud', - method: 'GitHub App', - token: '987654321' as Token, - hostname: Constants.DEFAULT_AUTH_OPTIONS.hostname, - user: mockGitifyUser, - hasRequiredScopes: true, -}; +import { + mockGitHubCloudAccount, + mockGitHubEnterpriseServerAccount, +} from './account-mocks'; export const mockAuth: AuthState = { accounts: [mockGitHubCloudAccount, mockGitHubEnterpriseServerAccount], diff --git a/src/renderer/__mocks__/user-mocks.ts b/src/renderer/__mocks__/user-mocks.ts new file mode 100644 index 000000000..3cb316d3d --- /dev/null +++ b/src/renderer/__mocks__/user-mocks.ts @@ -0,0 +1,20 @@ +import type { GitifyUser, Link } from '../types'; +import type { User } from '../typesGitHub'; + +export const mockGitifyUser: GitifyUser = { + login: 'octocat', + name: 'Mona Lisa Octocat', + id: 123456789, + avatar: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link, +}; + +export function createPartialMockUser(login: string): User { + const mockUser: Partial = { + login: login, + html_url: `https://github.com/${login}` as Link, + avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link, + type: 'User', + }; + + return mockUser as User; +} diff --git a/src/renderer/__mocks__/utils.ts b/src/renderer/__mocks__/utils.ts deleted file mode 100644 index 2b832d466..000000000 --- a/src/renderer/__mocks__/utils.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Ensure stable snapshots for our randomized emoji use-cases - */ -export function ensureStableEmojis() { - global.Math.random = jest.fn(() => 0.1); -} diff --git a/src/renderer/components/AllRead.test.tsx b/src/renderer/components/AllRead.test.tsx index 743e4d6cf..c8f07fbf9 100644 --- a/src/renderer/components/AllRead.test.tsx +++ b/src/renderer/components/AllRead.test.tsx @@ -1,8 +1,10 @@ -import { act, render } from '@testing-library/react'; +import { act } from '@testing-library/react'; +import { + ensureStableEmojis, + renderWithAppContext, +} from '../__helpers__/test-utils'; import { mockSettings } from '../__mocks__/state-mocks'; -import { ensureStableEmojis } from '../__mocks__/utils'; -import { AppContext } from '../context/App'; import { AllRead } from './AllRead'; describe('renderer/components/AllRead.tsx', () => { @@ -11,41 +13,29 @@ describe('renderer/components/AllRead.tsx', () => { }); it('should render itself & its children - no filters', async () => { - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { - tree = render( - - - , - ); + tree = renderWithAppContext(, { + settings: { + ...mockSettings, + }, + }); }); expect(tree).toMatchSnapshot(); }); it('should render itself & its children - with filters', async () => { - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { - tree = render( - - - , - ); + tree = renderWithAppContext(, { + settings: { + ...mockSettings, + filterReasons: ['author'], + }, + }); }); expect(tree).toMatchSnapshot(); diff --git a/src/renderer/components/Oops.test.tsx b/src/renderer/components/Oops.test.tsx index 9eb16be2f..d2fc67a00 100644 --- a/src/renderer/components/Oops.test.tsx +++ b/src/renderer/components/Oops.test.tsx @@ -1,6 +1,9 @@ -import { act, render } from '@testing-library/react'; +import { act } from '@testing-library/react'; -import { ensureStableEmojis } from '../__mocks__/utils'; +import { + ensureStableEmojis, + renderWithAppContext, +} from '../__helpers__/test-utils'; import { Oops } from './Oops'; describe('renderer/components/Oops.tsx', () => { @@ -15,20 +18,20 @@ describe('renderer/components/Oops.tsx', () => { emojis: ['🔥'], }; - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { - tree = render(); + tree = renderWithAppContext(); }); expect(tree).toMatchSnapshot(); }); it('should render itself & its children - fallback to unknown error', async () => { - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { - tree = render(); + tree = renderWithAppContext(); }); expect(tree).toMatchSnapshot(); diff --git a/src/renderer/components/Sidebar.test.tsx b/src/renderer/components/Sidebar.test.tsx index 55c7186bf..93626c1e5 100644 --- a/src/renderer/components/Sidebar.test.tsx +++ b/src/renderer/components/Sidebar.test.tsx @@ -1,10 +1,9 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { MemoryRouter } from 'react-router-dom'; +import { renderWithAppContext } from '../__helpers__/test-utils'; import { mockAccountNotifications } from '../__mocks__/notifications-mocks'; -import { mockAuth, mockSettings } from '../__mocks__/state-mocks'; -import { AppContext } from '../context/App'; import * as comms from '../utils/comms'; import { Sidebar } from './Sidebar'; @@ -15,8 +14,8 @@ jest.mock('react-router-dom', () => ({ })); describe('renderer/components/Sidebar.tsx', () => { - const fetchNotifications = jest.fn(); - const openExternalLinkMock = jest + const mockFetchNotifications = jest.fn(); + const mockOpenExternalLink = jest .spyOn(comms, 'openExternalLink') .mockImplementation(); @@ -25,56 +24,39 @@ describe('renderer/components/Sidebar.tsx', () => { }); it('should render itself & its children (logged in)', () => { - const tree = render( - - - - - , + const tree = renderWithAppContext( + + + , + { + isLoggedIn: true, + }, ); expect(tree).toMatchSnapshot(); }); it('should render itself & its children (logged out)', () => { - const tree = render( - - - - - , + const tree = renderWithAppContext( + + + , + { + isLoggedIn: false, + }, ); expect(tree).toMatchSnapshot(); }); it('should navigate home when clicking the gitify logo', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: false, + }, ); await userEvent.click(screen.getByTestId('sidebar-home')); @@ -84,62 +66,46 @@ describe('renderer/components/Sidebar.tsx', () => { describe('notifications icon', () => { it('opens notifications home when clicked', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + }, ); await userEvent.click(screen.getByTestId('sidebar-notifications')); - expect(openExternalLinkMock).toHaveBeenCalledTimes(1); - expect(openExternalLinkMock).toHaveBeenCalledWith( + expect(mockOpenExternalLink).toHaveBeenCalledTimes(1); + expect(mockOpenExternalLink).toHaveBeenCalledWith( 'https://github.com/notifications', ); }); it('renders correct icon when there are no notifications', () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + notifications: [], + }, ); expect(screen.getByTestId('sidebar-notifications')).toMatchSnapshot(); }); it('renders correct icon when there are notifications', () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + notifications: mockAccountNotifications, + }, ); expect(screen.getByTestId('sidebar-notifications')).toMatchSnapshot(); @@ -148,19 +114,13 @@ describe('renderer/components/Sidebar.tsx', () => { describe('Filter notifications', () => { it('go to the filters route', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + }, ); await userEvent.click(screen.getByTestId('sidebar-filter-notifications')); @@ -169,19 +129,13 @@ describe('renderer/components/Sidebar.tsx', () => { }); it('go to the home if filters path already shown', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + }, ); await userEvent.click(screen.getByTestId('sidebar-filter-notifications')); @@ -192,49 +146,39 @@ describe('renderer/components/Sidebar.tsx', () => { describe('quick links', () => { it('opens my github issues page', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + notifications: mockAccountNotifications, + }, ); await userEvent.click(screen.getByTestId('sidebar-my-issues')); - expect(openExternalLinkMock).toHaveBeenCalledTimes(1); - expect(openExternalLinkMock).toHaveBeenCalledWith( + expect(mockOpenExternalLink).toHaveBeenCalledTimes(1); + expect(mockOpenExternalLink).toHaveBeenCalledWith( 'https://github.com/issues', ); }); it('opens my github pull requests page', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + notifications: mockAccountNotifications, + }, ); await userEvent.click(screen.getByTestId('sidebar-my-pull-requests')); - expect(openExternalLinkMock).toHaveBeenCalledTimes(1); - expect(openExternalLinkMock).toHaveBeenCalledWith( + expect(mockOpenExternalLink).toHaveBeenCalledTimes(1); + expect(mockOpenExternalLink).toHaveBeenCalledWith( 'https://github.com/pulls', ); }); @@ -242,67 +186,51 @@ describe('renderer/components/Sidebar.tsx', () => { describe('Refresh Notifications', () => { it('should refresh the notifications when status is not loading', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + notifications: [], + fetchNotifications: mockFetchNotifications, + status: 'success', + }, ); await userEvent.click(screen.getByTestId('sidebar-refresh')); - expect(fetchNotifications).toHaveBeenCalledTimes(1); + expect(mockFetchNotifications).toHaveBeenCalledTimes(1); }); it('should not refresh the notifications when status is loading', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + notifications: [], + fetchNotifications: mockFetchNotifications, + status: 'loading', + }, ); await userEvent.click(screen.getByTestId('sidebar-refresh')); - expect(fetchNotifications).not.toHaveBeenCalled(); + expect(mockFetchNotifications).not.toHaveBeenCalled(); }); }); describe('Settings', () => { it('go to the settings route', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + }, ); await userEvent.click(screen.getByTestId('sidebar-settings')); @@ -311,49 +239,37 @@ describe('renderer/components/Sidebar.tsx', () => { }); it('go to the home if settings path already shown', async () => { - render( - - - - - , + renderWithAppContext( + + + , + { + isLoggedIn: true, + fetchNotifications: mockFetchNotifications, + }, ); await userEvent.click(screen.getByTestId('sidebar-settings')); - expect(fetchNotifications).toHaveBeenCalledTimes(1); + expect(mockFetchNotifications).toHaveBeenCalledTimes(1); expect(mockNavigate).toHaveBeenNthCalledWith(1, '/', { replace: true }); }); }); it('should quit the app', async () => { - const quitAppMock = jest.spyOn(comms, 'quitApp'); - - render( - - - - - , + const mockQuitApp = jest.spyOn(comms, 'quitApp'); + + renderWithAppContext( + + + , + { + isLoggedIn: false, + }, ); await userEvent.click(screen.getByTestId('sidebar-quit')); - expect(quitAppMock).toHaveBeenCalledTimes(1); + expect(mockQuitApp).toHaveBeenCalledTimes(1); }); }); diff --git a/src/renderer/components/__snapshots__/AllRead.test.tsx.snap b/src/renderer/components/__snapshots__/AllRead.test.tsx.snap index 2680d7bb3..7fb910ac5 100644 --- a/src/renderer/components/__snapshots__/AllRead.test.tsx.snap +++ b/src/renderer/components/__snapshots__/AllRead.test.tsx.snap @@ -6,45 +6,56 @@ exports[`renderer/components/AllRead.tsx should render itself & its children - n "baseElement":
- 🎊 -
-
- No new notifications +
+
+ 🎊 +
+
+ No new notifications +
+
@@ -53,45 +64,56 @@ exports[`renderer/components/AllRead.tsx should render itself & its children - n , "container":
- 🎊 -
-
- No new notifications +
+
+ 🎊 +
+
+ No new notifications +
+
@@ -157,45 +179,56 @@ exports[`renderer/components/AllRead.tsx should render itself & its children - w "baseElement":
- 🎊 -
-
- No new filtered notifications +
+
+ 🎊 +
+
+ No new filtered notifications +
+
@@ -204,45 +237,56 @@ exports[`renderer/components/AllRead.tsx should render itself & its children - w , "container":
- 🎊 -
-
- No new filtered notifications +
+
+ 🎊 +
+
+ No new filtered notifications +
+
diff --git a/src/renderer/components/__snapshots__/Oops.test.tsx.snap b/src/renderer/components/__snapshots__/Oops.test.tsx.snap index 73af1dc40..e4a068b56 100644 --- a/src/renderer/components/__snapshots__/Oops.test.tsx.snap +++ b/src/renderer/components/__snapshots__/Oops.test.tsx.snap @@ -6,51 +6,62 @@ exports[`renderer/components/Oops.tsx should render itself & its children - fall "baseElement":
- 🤔 +
+
+ 🤔 +
+
+ Oops! Something went wrong +
+
+
+ Please try again later. +
-
- Oops! Something went wrong -
-
-
- Please try again later.
@@ -58,52 +69,63 @@ exports[`renderer/components/Oops.tsx should render itself & its children - fall , "container":
- 🤔 -
-
- Oops! Something went wrong +
+
+ 🤔 +
+
+ Oops! Something went wrong +
+
+
+ Please try again later. +
-
- Please try again later. -
, @@ -167,51 +189,62 @@ exports[`renderer/components/Oops.tsx should render itself & its children - spec "baseElement":
- 🔥 +
+
+ 🔥 +
+
+ Error title +
+
+
+ Error description +
-
- Error title -
-
-
- Error description
@@ -219,52 +252,63 @@ exports[`renderer/components/Oops.tsx should render itself & its children - spec , "container":
- 🔥 -
-
- Error title +
+
+ 🔥 +
+
+ Error title +
+
+
+ Error description +
-
- Error description -
, diff --git a/src/renderer/components/__snapshots__/Sidebar.test.tsx.snap b/src/renderer/components/__snapshots__/Sidebar.test.tsx.snap index 69431d354..7e2af5527 100644 --- a/src/renderer/components/__snapshots__/Sidebar.test.tsx.snap +++ b/src/renderer/components/__snapshots__/Sidebar.test.tsx.snap @@ -2,7 +2,7 @@ exports[`renderer/components/Sidebar.tsx notifications icon renders correct icon when there are no notifications 1`] = ` + + + + +
-
- + + + +
+
- - - - +
+ +
+ + + +
+
, "container":
- + + + + + + - - - - - - - -
-
- + + + +
+
- - - - +
+ +
+ + + +
+
, @@ -637,510 +823,532 @@ exports[`renderer/components/Sidebar.tsx should render itself & its children (lo "baseElement":
- + + + + +
-
- + +
+
- - - - + + +
+
, "container":
- + + + + + + - - - - - - - -
-
- + +
+
- - - - + + +
+
, diff --git a/src/renderer/components/avatars/AvatarWithFallback.test.tsx b/src/renderer/components/avatars/AvatarWithFallback.test.tsx index 090109855..b82fffaf9 100644 --- a/src/renderer/components/avatars/AvatarWithFallback.test.tsx +++ b/src/renderer/components/avatars/AvatarWithFallback.test.tsx @@ -1,5 +1,6 @@ -import { fireEvent, render, screen } from '@testing-library/react'; +import { fireEvent, screen } from '@testing-library/react'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { type Link, Size } from '../../types'; import { AvatarWithFallback, @@ -16,25 +17,27 @@ describe('renderer/components/avatars/AvatarWithFallback.tsx', () => { }; it('should render avatar - human user', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should render avatar - non-human user', () => { - const tree = render( + const tree = renderWithAppContext( , ); expect(tree).toMatchSnapshot(); }); it('renders the fallback icon when no src url - human user', () => { - const tree = render(); + const tree = renderWithAppContext( + , + ); expect(tree).toMatchSnapshot(); }); it('renders the fallback icon when no src url - non human user', () => { - const tree = render( + const tree = renderWithAppContext( , ); @@ -42,7 +45,7 @@ describe('renderer/components/avatars/AvatarWithFallback.tsx', () => { }); it('renders the fallback icon when the image fails to load (isBroken = true) - human user', () => { - render(); + renderWithAppContext(); // Find the avatar element by its alt text const avatar = screen.getByAltText('gitify-app') as HTMLImageElement; @@ -54,7 +57,7 @@ describe('renderer/components/avatars/AvatarWithFallback.tsx', () => { }); it('renders the fallback icon when the image fails to load (isBroken = true) - non human user', () => { - render(); + renderWithAppContext(); // Find the avatar element by its alt text const avatar = screen.getByAltText('gitify-app') as HTMLImageElement; diff --git a/src/renderer/components/avatars/__snapshots__/AvatarWithFallback.test.tsx.snap b/src/renderer/components/avatars/__snapshots__/AvatarWithFallback.test.tsx.snap index 262ce90c7..c5b1f1085 100644 --- a/src/renderer/components/avatars/__snapshots__/AvatarWithFallback.test.tsx.snap +++ b/src/renderer/components/avatars/__snapshots__/AvatarWithFallback.test.tsx.snap @@ -6,76 +6,98 @@ exports[`renderer/components/avatars/AvatarWithFallback.tsx renders the fallback "baseElement":
-
- @gitify-app +
+ +
+ @gitify-app +
+
, "container":
-
- @gitify-app +
+ +
+ @gitify-app +
+
, @@ -139,76 +161,98 @@ exports[`renderer/components/avatars/AvatarWithFallback.tsx renders the fallback "baseElement":
-
- @gitify-app +
+ +
+ @gitify-app +
+
, "container":
-
- @gitify-app +
+ +
+ @gitify-app +
+
, @@ -348,62 +392,84 @@ exports[`renderer/components/avatars/AvatarWithFallback.tsx should render avatar "baseElement":
- gitify-app
- @gitify-app +
+ gitify-app +
+ @gitify-app +
+
, "container":
- gitify-app
- @gitify-app +
+ gitify-app +
+ @gitify-app +
+
, @@ -467,64 +533,86 @@ exports[`renderer/components/avatars/AvatarWithFallback.tsx should render avatar "baseElement":
- gitify-app
- @gitify-app +
+ gitify-app +
+ @gitify-app +
+
, "container":
- gitify-app
- @gitify-app +
+ gitify-app +
+ @gitify-app +
+
, diff --git a/src/renderer/components/fields/Checkbox.test.tsx b/src/renderer/components/fields/Checkbox.test.tsx index 0050b58c6..9cd8a0bb1 100644 --- a/src/renderer/components/fields/Checkbox.test.tsx +++ b/src/renderer/components/fields/Checkbox.test.tsx @@ -1,5 +1,4 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { Checkbox, type CheckboxProps } from './Checkbox'; describe('renderer/components/fields/Checkbox.tsx', () => { @@ -11,39 +10,43 @@ describe('renderer/components/fields/Checkbox.tsx', () => { }; it('should render - visible', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should render - not visible', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should render - disabled', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should render - tooltip', () => { - const tree = render( + const tree = renderWithAppContext( Hello world} />, ); expect(tree).toMatchSnapshot(); }); it('should render - positive counter unselected', () => { - const tree = render(); + const tree = renderWithAppContext( + , + ); expect(tree).toMatchSnapshot(); }); it('should render - positive counter selected', () => { - const tree = render(); + const tree = renderWithAppContext( + , + ); expect(tree).toMatchSnapshot(); }); it('should render - zero counter', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); }); diff --git a/src/renderer/components/fields/FieldLabel.test.tsx b/src/renderer/components/fields/FieldLabel.test.tsx index 26a243bfa..44a3037d8 100644 --- a/src/renderer/components/fields/FieldLabel.test.tsx +++ b/src/renderer/components/fields/FieldLabel.test.tsx @@ -1,5 +1,4 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { FieldLabel, type FieldLabelProps } from './FieldLabel'; describe('renderer/components/fields/FieldLabel.tsx', () => { @@ -9,7 +8,7 @@ describe('renderer/components/fields/FieldLabel.tsx', () => { }; it('should render', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); }); diff --git a/src/renderer/components/fields/RadioGroup.test.tsx b/src/renderer/components/fields/RadioGroup.test.tsx index 9f7aed66b..2f6f4789f 100644 --- a/src/renderer/components/fields/RadioGroup.test.tsx +++ b/src/renderer/components/fields/RadioGroup.test.tsx @@ -1,5 +1,4 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { RadioGroup, type RadioGroupProps } from './RadioGroup'; describe('renderer/components/fields/RadioGroup.tsx', () => { @@ -15,14 +14,14 @@ describe('renderer/components/fields/RadioGroup.tsx', () => { }; it('should render', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should render as disabled', () => { const mockProps = { ...props, disabled: true }; - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); }); diff --git a/src/renderer/components/fields/Tooltip.test.tsx b/src/renderer/components/fields/Tooltip.test.tsx index 40d59fc6d..3669ed4db 100644 --- a/src/renderer/components/fields/Tooltip.test.tsx +++ b/src/renderer/components/fields/Tooltip.test.tsx @@ -1,10 +1,7 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { BaseStyles, ThemeProvider } from '@primer/react'; - -import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { Tooltip, type TooltipProps } from './Tooltip'; describe('renderer/components/fields/Tooltip.tsx', () => { @@ -14,37 +11,13 @@ describe('renderer/components/fields/Tooltip.tsx', () => { }; it('should render', () => { - render( - - - - - - - , - ); + renderWithAppContext(, {}); expect(screen.getByTestId('tooltip-test')).toBeInTheDocument(); }); it('should display on mouse enter / leave', async () => { - render( - - - - - - - , - ); + renderWithAppContext(, {}); const tooltipElement = screen.getByTestId('tooltip-test'); diff --git a/src/renderer/components/fields/__snapshots__/Checkbox.test.tsx.snap b/src/renderer/components/fields/__snapshots__/Checkbox.test.tsx.snap index 191184d5d..a2f43b44f 100644 --- a/src/renderer/components/fields/__snapshots__/Checkbox.test.tsx.snap +++ b/src/renderer/components/fields/__snapshots__/Checkbox.test.tsx.snap @@ -6,55 +6,77 @@ exports[`renderer/components/fields/Checkbox.tsx should render - disabled 1`] = "baseElement":
- - +
+ + +
+
, "container":
- - +
+ + +
+
, "debug": [Function], @@ -115,9 +137,31 @@ exports[`renderer/components/fields/Checkbox.tsx should render - not visible 1`] { "asFragment": [Function], "baseElement": -
+
+
+
+
+
, - "container":
, + "container":
+
+
+
+
, "debug": [Function], "findAllByAltText": [Function], "findAllByDisplayValue": [Function], @@ -178,63 +222,85 @@ exports[`renderer/components/fields/Checkbox.tsx should render - positive counte "baseElement":
- - - - 5 - +
+ + + + 5 + +
+
, "container":
- - - - 5 - +
+ + + + 5 + +
+
, "debug": [Function], @@ -297,61 +363,83 @@ exports[`renderer/components/fields/Checkbox.tsx should render - positive counte "baseElement":
- - - - 5 - +
+ + + + 5 + +
+
, "container":
- - - - 5 - +
+ + + + 5 + +
+
, "debug": [Function], @@ -414,105 +502,127 @@ exports[`renderer/components/fields/Checkbox.tsx should render - tooltip 1`] = ` "baseElement":
- - - + + +
+
, "container":
- - - + + +
+
, "debug": [Function], @@ -575,53 +685,75 @@ exports[`renderer/components/fields/Checkbox.tsx should render - visible 1`] = ` "baseElement":
- - +
+ + +
+
, "container":
- - +
+ + +
+
, "debug": [Function], @@ -684,63 +816,85 @@ exports[`renderer/components/fields/Checkbox.tsx should render - zero counter 1` "baseElement":
- - - - 0 - +
+ + + + 0 + +
+
, "container":
- - - - 0 - +
+ + + + 0 + +
+
, "debug": [Function], diff --git a/src/renderer/components/fields/__snapshots__/FieldLabel.test.tsx.snap b/src/renderer/components/fields/__snapshots__/FieldLabel.test.tsx.snap index e69ae5347..2f560d960 100644 --- a/src/renderer/components/fields/__snapshots__/FieldLabel.test.tsx.snap +++ b/src/renderer/components/fields/__snapshots__/FieldLabel.test.tsx.snap @@ -5,21 +5,43 @@ exports[`renderer/components/fields/FieldLabel.tsx should render 1`] = ` "asFragment": [Function], "baseElement":
- +
+ +
+
, "container":
- +
+ +
+
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/fields/__snapshots__/RadioGroup.test.tsx.snap b/src/renderer/components/fields/__snapshots__/RadioGroup.test.tsx.snap index 0363ddb3c..9093243d7 100644 --- a/src/renderer/components/fields/__snapshots__/RadioGroup.test.tsx.snap +++ b/src/renderer/components/fields/__snapshots__/RadioGroup.test.tsx.snap @@ -6,46 +6,95 @@ exports[`renderer/components/fields/RadioGroup.tsx should render 1`] = ` "baseElement":
-
- - + +
+ + +
+
+ + +
+
+
+ + , + "container":
+
+
- +
+ + +
+
+ + +
- , - "container":
-
- -
- - -
-
- - -
-
, "debug": [Function], "findAllByAltText": [Function], @@ -199,46 +221,95 @@ exports[`renderer/components/fields/RadioGroup.tsx should render as disabled 1`] "baseElement":
-
- - + +
+ + +
+
+ + +
+
+
+
+ , + "container":
+
+
- +
+ + +
+
+ + +
- , - "container":
-
- -
- - -
-
- - -
-
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/filters/FilterSection.test.tsx b/src/renderer/components/filters/FilterSection.test.tsx index 0d28d4248..62a1338d9 100644 --- a/src/renderer/components/filters/FilterSection.test.tsx +++ b/src/renderer/components/filters/FilterSection.test.tsx @@ -1,71 +1,64 @@ -import { act, render, screen } from '@testing-library/react'; +import { act, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { MarkGithubIcon } from '@primer/octicons-react'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { mockAccountNotifications } from '../../__mocks__/notifications-mocks'; import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; -import type { SettingsState } from '../../types'; import { stateFilter } from '../../utils/notifications/filters'; import { FilterSection } from './FilterSection'; describe('renderer/components/filters/FilterSection.tsx', () => { - const updateFilter = jest.fn(); + const mockUpdateFilter = jest.fn(); const mockFilter = stateFilter; const mockFilterSetting = 'filterStates'; describe('should render itself & its children', () => { it('with detailed notifications enabled', () => { - const tree = render( - - - , + filterSetting={mockFilterSetting} + icon={MarkGithubIcon} + id={'FilterSectionTest'} + title={'FilterSectionTitle'} + />, + { + settings: { + ...mockSettings, + detailedNotifications: true, + }, + notifications: mockAccountNotifications, + }, ); expect(tree).toMatchSnapshot(); }); it('with detailed notifications disabled', () => { - const tree = render( - - - , + filterSetting={mockFilterSetting} + icon={MarkGithubIcon} + id={'FilterSectionTest'} + title={'FilterSectionTitle'} + />, + { + settings: { + ...mockSettings, + detailedNotifications: false, + }, + notifications: mockAccountNotifications, + }, ); expect(tree).toMatchSnapshot(); @@ -74,31 +67,31 @@ describe('renderer/components/filters/FilterSection.tsx', () => { it('should be able to toggle filter value - none already set', async () => { await act(async () => { - render( - - - , + renderWithAppContext( + , + { + settings: { + ...mockSettings, + filterStates: [], + }, + updateFilter: mockUpdateFilter, + }, ); }); await userEvent.click(screen.getByLabelText('Open')); - expect(updateFilter).toHaveBeenCalledWith(mockFilterSetting, 'open', true); + expect(mockUpdateFilter).toHaveBeenCalledWith( + mockFilterSetting, + 'open', + true, + ); expect( screen.getByLabelText('Open').parentNode.parentNode, @@ -107,31 +100,27 @@ describe('renderer/components/filters/FilterSection.tsx', () => { it('should be able to toggle filter value - some filters already set', async () => { await act(async () => { - render( - - - , + renderWithAppContext( + , + { + settings: { + ...mockSettings, + filterStates: ['open'], + }, + updateFilter: mockUpdateFilter, + }, ); }); await userEvent.click(screen.getByLabelText('Closed')); - expect(updateFilter).toHaveBeenCalledWith( + expect(mockUpdateFilter).toHaveBeenCalledWith( mockFilterSetting, 'closed', true, diff --git a/src/renderer/components/filters/ReasonFilter.test.tsx b/src/renderer/components/filters/ReasonFilter.test.tsx index 81beb41ce..8267d14da 100644 --- a/src/renderer/components/filters/ReasonFilter.test.tsx +++ b/src/renderer/components/filters/ReasonFilter.test.tsx @@ -1,22 +1,12 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { mockAccountNotifications } from '../../__mocks__/notifications-mocks'; -import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; import { ReasonFilter } from './ReasonFilter'; describe('renderer/components/filters/ReasonFilter.tsx', () => { it('should render itself & its children', () => { - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + notifications: mockAccountNotifications, + }); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/filters/RequiresDetailedNotificationsWarning.test.tsx b/src/renderer/components/filters/RequiresDetailedNotificationsWarning.test.tsx index cd57cb5f8..1e9ff68de 100644 --- a/src/renderer/components/filters/RequiresDetailedNotificationsWarning.test.tsx +++ b/src/renderer/components/filters/RequiresDetailedNotificationsWarning.test.tsx @@ -1,22 +1,9 @@ -import { render } from '@testing-library/react'; - -import { mockAccountNotifications } from '../../__mocks__/notifications-mocks'; -import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { RequiresDetailedNotificationWarning } from './RequiresDetailedNotificationsWarning'; describe('renderer/components/filters/RequiresDetailedNotificationsWarning.tsx', () => { it('should render itself & its children', () => { - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/filters/SearchFilter.test.tsx b/src/renderer/components/filters/SearchFilter.test.tsx index 2299ce16c..1ddb2791b 100644 --- a/src/renderer/components/filters/SearchFilter.test.tsx +++ b/src/renderer/components/filters/SearchFilter.test.tsx @@ -1,29 +1,26 @@ -import { fireEvent, render, screen } from '@testing-library/react'; +import { fireEvent, screen } from '@testing-library/react'; -import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { SearchFilter } from './SearchFilter'; -const updateFilter = jest.fn(); - describe('renderer/components/filters/SearchFilter.tsx', () => { + const mockUpdateFilter = jest.fn(); + afterEach(() => { jest.clearAllMocks(); }); describe('Include Search Tokens', () => { it('adds include actor token with prefix', () => { - render( - - - , - ); + renderWithAppContext(, { + updateFilter: mockUpdateFilter, + }); const includeInput = screen.getByTitle('Include searches'); fireEvent.change(includeInput, { target: { value: 'author:octocat' } }); fireEvent.keyDown(includeInput, { key: 'Enter' }); - expect(updateFilter).toHaveBeenCalledWith( + expect(mockUpdateFilter).toHaveBeenCalledWith( 'filterIncludeSearchTokens', 'author:octocat', true, @@ -31,17 +28,15 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); it('adds include org token with prefix', () => { - render( - - - , - ); + renderWithAppContext(, { + updateFilter: mockUpdateFilter, + }); const includeInput = screen.getByTitle('Include searches'); fireEvent.change(includeInput, { target: { value: 'org:gitify-app' } }); fireEvent.keyDown(includeInput, { key: 'Enter' }); - expect(updateFilter).toHaveBeenCalledWith( + expect(mockUpdateFilter).toHaveBeenCalledWith( 'filterIncludeSearchTokens', 'org:gitify-app', true, @@ -49,11 +44,9 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); it('adds include repo token with prefix', () => { - render( - - - , - ); + renderWithAppContext(, { + updateFilter: mockUpdateFilter, + }); const includeInput = screen.getByTitle('Include searches'); fireEvent.change(includeInput, { @@ -61,7 +54,7 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); fireEvent.keyDown(includeInput, { key: 'Enter' }); - expect(updateFilter).toHaveBeenCalledWith( + expect(mockUpdateFilter).toHaveBeenCalledWith( 'filterIncludeSearchTokens', 'repo:gitify-app/gitify', true, @@ -69,11 +62,9 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); it('prevent unrecognized include prefixes', () => { - render( - - - , - ); + renderWithAppContext(, { + updateFilter: mockUpdateFilter, + }); const includeInput = screen.getByTitle('Include searches'); fireEvent.change(includeInput, { @@ -81,23 +72,21 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); fireEvent.keyDown(includeInput, { key: 'Enter' }); - expect(updateFilter).not.toHaveBeenCalledWith(); + expect(mockUpdateFilter).not.toHaveBeenCalledWith(); }); }); describe('Exclude Search Tokens', () => { it('adds exclude actor token with prefix', () => { - render( - - - , - ); + renderWithAppContext(, { + updateFilter: mockUpdateFilter, + }); const includeInput = screen.getByTitle('Exclude searches'); fireEvent.change(includeInput, { target: { value: 'author:octocat' } }); fireEvent.keyDown(includeInput, { key: 'Enter' }); - expect(updateFilter).toHaveBeenCalledWith( + expect(mockUpdateFilter).toHaveBeenCalledWith( 'filterExcludeSearchTokens', 'author:octocat', true, @@ -105,17 +94,15 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); it('adds exclude org token with prefix', () => { - render( - - - , - ); + renderWithAppContext(, { + updateFilter: mockUpdateFilter, + }); const excludeInput = screen.getByTitle('Exclude searches'); fireEvent.change(excludeInput, { target: { value: 'org:gitify-app' } }); fireEvent.keyDown(excludeInput, { key: 'Enter' }); - expect(updateFilter).toHaveBeenCalledWith( + expect(mockUpdateFilter).toHaveBeenCalledWith( 'filterExcludeSearchTokens', 'org:gitify-app', true, @@ -123,11 +110,9 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); it('adds exclude repo token with prefix', () => { - render( - - - , - ); + renderWithAppContext(, { + updateFilter: mockUpdateFilter, + }); const excludeInput = screen.getByTitle('Exclude searches'); fireEvent.change(excludeInput, { @@ -135,7 +120,7 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); fireEvent.keyDown(excludeInput, { key: 'Enter' }); - expect(updateFilter).toHaveBeenCalledWith( + expect(mockUpdateFilter).toHaveBeenCalledWith( 'filterExcludeSearchTokens', 'repo:gitify-app/gitify', true, @@ -143,11 +128,9 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); it('prevent unrecognized exclude prefixes', () => { - render( - - - , - ); + renderWithAppContext(, { + updateFilter: mockUpdateFilter, + }); const excludeInput = screen.getByTitle('Exclude searches'); fireEvent.change(excludeInput, { @@ -155,7 +138,7 @@ describe('renderer/components/filters/SearchFilter.tsx', () => { }); fireEvent.keyDown(excludeInput, { key: 'Enter' }); - expect(updateFilter).not.toHaveBeenCalledWith(); + expect(mockUpdateFilter).not.toHaveBeenCalledWith(); }); }); }); diff --git a/src/renderer/components/filters/SearchFilterSuggestions.test.tsx b/src/renderer/components/filters/SearchFilterSuggestions.test.tsx index 49faa8b3e..0671d1637 100644 --- a/src/renderer/components/filters/SearchFilterSuggestions.test.tsx +++ b/src/renderer/components/filters/SearchFilterSuggestions.test.tsx @@ -1,91 +1,67 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; -import type { SettingsState } from '../../types'; import { SearchFilterSuggestions } from './SearchFilterSuggestions'; describe('renderer/components/filters/SearchFilterSuggestions.tsx', () => { it('should render itself & its children - closed', () => { - const tree = render( - - - , + const tree = renderWithAppContext( + , ); expect(tree).toMatchSnapshot(); }); - it('should render itself & its children - open', () => { - const tree = render( - - - , + it('should render itself & its children - open without detailed notifications enabled', () => { + const tree = renderWithAppContext( + , + { + settings: { + ...mockSettings, + detailedNotifications: false, + }, + }, ); expect(tree).toMatchSnapshot(); }); - it('should render itself & its children - open with detailed enabled', () => { - const tree = render( - - - , + it('should render itself & its children - open with detailed notifications enabled', () => { + const tree = renderWithAppContext( + , + { + settings: { + ...mockSettings, + detailedNotifications: true, + }, + }, ); expect(tree).toMatchSnapshot(); }); it('should render itself & its children - input token invalid', () => { - const tree = render( - - - , + const tree = renderWithAppContext( + , + { + settings: { + ...mockSettings, + detailedNotifications: false, + }, + }, ); expect(tree).toMatchSnapshot(); }); it('should render itself & its children - input token valid', () => { - const tree = render( - - - , + const tree = renderWithAppContext( + , + { + settings: { + ...mockSettings, + detailedNotifications: false, + }, + }, ); expect(tree).toMatchSnapshot(); diff --git a/src/renderer/components/filters/StateFilter.test.tsx b/src/renderer/components/filters/StateFilter.test.tsx index a924580ac..fb9974a7b 100644 --- a/src/renderer/components/filters/StateFilter.test.tsx +++ b/src/renderer/components/filters/StateFilter.test.tsx @@ -1,26 +1,12 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { mockAccountNotifications } from '../../__mocks__/notifications-mocks'; -import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; -import type { SettingsState } from '../../types'; import { StateFilter } from './StateFilter'; describe('renderer/components/filters/StateFilter.tsx', () => { it('should render itself & its children', () => { - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + notifications: mockAccountNotifications, + }); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/filters/SubjectTypeFilter.test.tsx b/src/renderer/components/filters/SubjectTypeFilter.test.tsx index 1015df381..6105f02f9 100644 --- a/src/renderer/components/filters/SubjectTypeFilter.test.tsx +++ b/src/renderer/components/filters/SubjectTypeFilter.test.tsx @@ -1,25 +1,12 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { mockAccountNotifications } from '../../__mocks__/notifications-mocks'; -import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; -import type { SettingsState } from '../../types'; import { SubjectTypeFilter } from './SubjectTypeFilter'; describe('renderer/components/filters/SubjectTypeFilter.tsx', () => { it('should render itself & its children', () => { - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + notifications: mockAccountNotifications, + }); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/filters/UserTypeFilter.test.tsx b/src/renderer/components/filters/UserTypeFilter.test.tsx index fa3009361..f582cf701 100644 --- a/src/renderer/components/filters/UserTypeFilter.test.tsx +++ b/src/renderer/components/filters/UserTypeFilter.test.tsx @@ -1,26 +1,12 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { mockAccountNotifications } from '../../__mocks__/notifications-mocks'; -import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; -import type { SettingsState } from '../../types'; import { UserTypeFilter } from './UserTypeFilter'; describe('renderer/components/filters/UserTypeFilter.tsx', () => { it('should render itself & its children', () => { - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + notifications: mockAccountNotifications, + }); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/filters/__snapshots__/FilterSection.test.tsx.snap b/src/renderer/components/filters/__snapshots__/FilterSection.test.tsx.snap index 089ad252c..256207e3a 100644 --- a/src/renderer/components/filters/__snapshots__/FilterSection.test.tsx.snap +++ b/src/renderer/components/filters/__snapshots__/FilterSection.test.tsx.snap @@ -458,539 +458,561 @@ exports[`renderer/components/filters/FilterSection.tsx should render itself & it "asFragment": [Function], "baseElement":
-
- -
+
+ +
+
+ +

+ FilterSectionTitle +

+
+
+
- -

+ Closed + + + + 0 + +

+
- FilterSectionTitle - -
-
-
-
-
- - -
+
- - - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - -
+
- - - - - 1 - -
-
- - -
+
- - - - - 3 - -
+ + + + 3 + +
+
+
- + , "container":
-
- -
+
+ +
+
+ +

+ FilterSectionTitle +

+
+
+
- -

+ Closed + + + + 0 + +

+
- FilterSectionTitle - -
-
-
-
-
- - -
+
- - - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - -
+
- - - - - 1 - -
-
- - -
+
- - - - - 3 - -
+ + + + 3 + +
+
+ - + , "debug": [Function], "findAllByAltText": [Function], @@ -1051,539 +1073,561 @@ exports[`renderer/components/filters/FilterSection.tsx should render itself & it "asFragment": [Function], "baseElement":
-
- -
+
+ +
+
+ +

+ FilterSectionTitle +

+
+
+
- -

+ Closed + + + + 0 + +

+
- FilterSectionTitle - -
-
-
-
-
- - -
+
- - - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - -
+
- - - - - 1 - -
-
- - -
+
- - - - - 3 - -
+ + + + 3 + +
+
+ - + , "container":
-
- -
+
+ +
+
+ +

+ FilterSectionTitle +

+
+
+
- -

+ Closed + + + + 0 + +

+
- FilterSectionTitle - -
-
-
-
-
- - -
+
- - - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - -
+
- - - - - 1 - -
-
- - -
+
- - - - - 3 - -
+ + + + 3 + +
+
+ - + , "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/filters/__snapshots__/ReasonFilter.test.tsx.snap b/src/renderer/components/filters/__snapshots__/ReasonFilter.test.tsx.snap index fa2882829..bf54b0923 100644 --- a/src/renderer/components/filters/__snapshots__/ReasonFilter.test.tsx.snap +++ b/src/renderer/components/filters/__snapshots__/ReasonFilter.test.tsx.snap @@ -5,1755 +5,1777 @@ exports[`renderer/components/filters/ReasonFilter.tsx should render itself & its "asFragment": [Function], "baseElement":
-
- -
+
+ +
+
+ +

+ Reason +

+ +
+
+
- -

- Reason -

- -
-
-
-
-
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 1 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 3 - -
-
- - -
+
- - - - - 0 - -
+ + + + 0 + +
+
+ - + , "container":
-
- -
+
+ +
+
+ +

+ Reason +

+ +
+
+
- -

- Reason -

- -
-
-
-
-
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 1 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 0 - -
-
- - -
+
- - - - - 3 - -
-
- - -
+
- - - - - 0 - -
+ + + + 0 + +
+
+ - + , "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/filters/__snapshots__/RequiresDetailedNotificationsWarning.test.tsx.snap b/src/renderer/components/filters/__snapshots__/RequiresDetailedNotificationsWarning.test.tsx.snap index fa47e974f..8bcb0d895 100644 --- a/src/renderer/components/filters/__snapshots__/RequiresDetailedNotificationsWarning.test.tsx.snap +++ b/src/renderer/components/filters/__snapshots__/RequiresDetailedNotificationsWarning.test.tsx.snap @@ -5,33 +5,55 @@ exports[`renderer/components/filters/RequiresDetailedNotificationsWarning.tsx sh "asFragment": [Function], "baseElement":
- - ⚠️ This filter requires the - - Detailed Notifications - - - setting to be enabled. - + + ⚠️ This filter requires the + + Detailed Notifications + + + setting to be enabled. + +
+ , "container":
- - ⚠️ This filter requires the - - Detailed Notifications - - - setting to be enabled. - + + ⚠️ This filter requires the + + Detailed Notifications + + + setting to be enabled. + +
+ , "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/filters/__snapshots__/SearchFilterSuggestions.test.tsx.snap b/src/renderer/components/filters/__snapshots__/SearchFilterSuggestions.test.tsx.snap index 0c72c3a55..1285a2a14 100644 --- a/src/renderer/components/filters/__snapshots__/SearchFilterSuggestions.test.tsx.snap +++ b/src/renderer/components/filters/__snapshots__/SearchFilterSuggestions.test.tsx.snap @@ -4,9 +4,31 @@ exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render i { "asFragment": [Function], "baseElement": -
+
+
+
+
+
, - "container":
, + "container":
+
+
+
+
, "debug": [Function], "findAllByAltText": [Function], "findAllByDisplayValue": [Function], @@ -67,32 +89,43 @@ exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render i "baseElement":
-
- +
- Please use one of the supported filters [ - org, repo - ] - +
+ + Please use one of the supported filters [ + org, repo + ] + +
+
@@ -101,32 +134,43 @@ exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render i , "container":
-
- +
- Please use one of the supported filters [ - org, repo - ] - +
+ + Please use one of the supported filters [ + org, repo + ] + +
+
@@ -192,44 +236,55 @@ exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render i "baseElement":
-
+
- - repo: - - - filter by repository full name - +
+
+ + repo: + + + filter by repository full name + +
+
@@ -239,44 +294,55 @@ exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render i , "container":
-
+
- - repo: - - - filter by repository full name - +
+
+ + repo: + + + filter by repository full name + +
+
@@ -337,94 +403,105 @@ exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render i } `; -exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render itself & its children - open 1`] = ` +exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render itself & its children - open with detailed notifications enabled 1`] = ` { "asFragment": [Function], "baseElement":
-
-
- - author: - - - filter by notification author - -
-
-
-
- - org: - - - filter by organization owner - -
-
-
+
- - repo: - - - filter by repository full name - +
+
+ + author: + + + filter by notification author + +
+
+
+
+ + org: + + + filter by organization owner + +
+
+
+
+ + repo: + + + filter by repository full name + +
+
@@ -434,88 +511,99 @@ exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render i , "container":
-
-
- - author: - - - filter by notification author - -
-
-
-
- - org: - - - filter by organization owner - -
-
-
+
- - repo: - - - filter by repository full name - +
+
+ + author: + + + filter by notification author + +
+
+
+
+ + org: + + + filter by organization owner + +
+
+
+
+ + repo: + + + filter by repository full name + +
+
@@ -576,94 +664,83 @@ exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render i } `; -exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render itself & its children - open with detailed enabled 1`] = ` +exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render itself & its children - open without detailed notifications enabled 1`] = ` { "asFragment": [Function], "baseElement":
-
-
- - author: - - - filter by notification author - -
-
-
-
- - org: - - - filter by organization owner - -
-
-
+
- - repo: - - - filter by repository full name - +
+
+ + org: + + + filter by organization owner + +
+
+
+
+ + repo: + + + filter by repository full name + +
+
@@ -673,88 +750,77 @@ exports[`renderer/components/filters/SearchFilterSuggestions.tsx should render i , "container":
-
-
- - author: - - - filter by notification author - -
-
-
-
- - org: - - - filter by organization owner - -
-
-
+
- - repo: - - - filter by repository full name - +
+
+ + org: + + + filter by organization owner + +
+
+
+
+ + repo: + + + filter by repository full name + +
+
diff --git a/src/renderer/components/filters/__snapshots__/StateFilter.test.tsx.snap b/src/renderer/components/filters/__snapshots__/StateFilter.test.tsx.snap index 2be84f3d9..049ef2dfd 100644 --- a/src/renderer/components/filters/__snapshots__/StateFilter.test.tsx.snap +++ b/src/renderer/components/filters/__snapshots__/StateFilter.test.tsx.snap @@ -5,59 +5,343 @@ exports[`renderer/components/filters/StateFilter.tsx should render itself & its "asFragment": [Function], "baseElement":
-
- -
+
+ +
+
+ +

+ State +

+ +
+
+
- + 0 + +
+
+ - -

+ Draft + + + 0 + +

+
- State - -
+
+ + + + + 1 + +
+
+ + + + + 3 + +
+
+
+
+
+
+ , + "container":
+
+
+
+ +
+
- +

+ State +

+ +
-
- -
+
- - - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - - - - 1 - -
-
- - - + - - - - - 3 - -
-
- -
- , - "container":
-
- -
-
-
+
- - - -

- State -

- -
-
-
-
-
- - -
+
- - - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - -
+
- - - - - 1 - -
-
- - -
+
- - - - - 3 - -
+ + + + 3 + +
+
+
- +
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/filters/__snapshots__/SubjectTypeFilter.test.tsx.snap b/src/renderer/components/filters/__snapshots__/SubjectTypeFilter.test.tsx.snap index 5d17d9770..16eb2ef0a 100644 --- a/src/renderer/components/filters/__snapshots__/SubjectTypeFilter.test.tsx.snap +++ b/src/renderer/components/filters/__snapshots__/SubjectTypeFilter.test.tsx.snap @@ -5,56 +5,397 @@ exports[`renderer/components/filters/SubjectTypeFilter.tsx should render itself "asFragment": [Function], "baseElement":
-
- -
+
+ +
+
+ +

+ Type +

+ +
+
+
- + 0 + +
+
+ + + + 0 + +
+
+ + + + 0 + +
+
+ + + + 0 + +
+
+ + + + 0 + +
+
+ + + + 2 + +
+
+ + + + 1 + +
+
+ + + + 1 + +
+
+ + + + 0 + +
+
+ - -

- Type -

-
+
+
+
+
+
+ , + "container":
+
+
+
+ +
+
- +

+ Type +

+ +
-
- -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
+
- - - - 0 - -
-
- - - - 2 - -
-
- - - - 1 - -
-
- -
+
- Release - - + + + 0 + +
+
- 1 - -
-
- -
+
- Vulnerability Alert - - + + + 0 + +
+
- 0 - -
-
- -
+
- Workflow Run - - + + + 2 + +
+
- 0 - -
-
- -
- , - "container":
-
- -
-
- + + + 1 + +
+
- - -

+ Release + + + 1 + +

+
- Type - -
+
- - + + + + 0 + +
-
- -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - - - 0 - -
-
- - - - 2 - -
-
- - - - 1 - -
-
- - - - 1 - -
-
- - - - 0 - -
-
- - - - 0 - -
+
- +
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/filters/__snapshots__/UserTypeFilter.test.tsx.snap b/src/renderer/components/filters/__snapshots__/UserTypeFilter.test.tsx.snap index aa0485c8e..027b9be44 100644 --- a/src/renderer/components/filters/__snapshots__/UserTypeFilter.test.tsx.snap +++ b/src/renderer/components/filters/__snapshots__/UserTypeFilter.test.tsx.snap @@ -5,50 +5,317 @@ exports[`renderer/components/filters/UserTypeFilter.tsx should render itself & i "asFragment": [Function], "baseElement":
-
- -
+
+ +
+
+ +

+ User Type +

+ +
+
+
- + 0 + +
+
+ + + + 0 + +
+
- - -

+ User + + + 1 + +

+
+
+
+
+
+ , + "container":
+
+
+
+ +
+
+ +

+ User Type +

+ +
+
+
+
+
+ + + + 0 +
-
- -
-
- - - - - 0 - -
-
- - - - 0 - -
-
- - - - 1 - -
-
-
-
- , - "container":
-
- -
-
- + 0 + +
+
- - -

- User Type -

- + User + + + 1 + +
-
- -
-
- - - - - 0 - -
-
- - - - 0 - -
-
- - - - 1 - -
+
- +
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/icons/LogoIcon.test.tsx b/src/renderer/components/icons/LogoIcon.test.tsx index ccd4f61a3..754ce5fec 100644 --- a/src/renderer/components/icons/LogoIcon.test.tsx +++ b/src/renderer/components/icons/LogoIcon.test.tsx @@ -1,25 +1,26 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { Size } from '../../types'; import { LogoIcon } from './LogoIcon'; describe('renderer/components/icons/LogoIcon.tsx', () => { it('renders correctly (light)', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('renders correctly (dark)', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should click on the logo', async () => { const onClick = jest.fn(); - render(); + renderWithAppContext(); await userEvent.click(screen.getByLabelText('Gitify Logo')); @@ -27,19 +28,19 @@ describe('renderer/components/icons/LogoIcon.tsx', () => { }); it('should render small size', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should render medium size', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should render large size', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/icons/__snapshots__/LogoIcon.test.tsx.snap b/src/renderer/components/icons/__snapshots__/LogoIcon.test.tsx.snap index b7226d4e1..12867d6a7 100644 --- a/src/renderer/components/icons/__snapshots__/LogoIcon.test.tsx.snap +++ b/src/renderer/components/icons/__snapshots__/LogoIcon.test.tsx.snap @@ -5,97 +5,119 @@ exports[`renderer/components/icons/LogoIcon.tsx renders correctly (dark) 1`] = ` "asFragment": [Function], "baseElement":
- + + + + + + + + + + +
+
, "container":
- + + + + + + + + + + +
+
, "debug": [Function], "findAllByAltText": [Function], @@ -156,97 +178,119 @@ exports[`renderer/components/icons/LogoIcon.tsx renders correctly (light) 1`] = "asFragment": [Function], "baseElement":
- + + + + + + + + + + +
+
, "container":
- + + + + + + + + + + +
+
, "debug": [Function], "findAllByAltText": [Function], @@ -307,97 +351,119 @@ exports[`renderer/components/icons/LogoIcon.tsx should render large size 1`] = ` "asFragment": [Function], "baseElement":
- + + + + + + + + + + +
+
, "container":
- + + + + + + + + + + +
+
, "debug": [Function], "findAllByAltText": [Function], @@ -458,97 +524,119 @@ exports[`renderer/components/icons/LogoIcon.tsx should render medium size 1`] = "asFragment": [Function], "baseElement":
- + + + + + + + + + + +
+
, "container":
- + + + + + + + + + + +
+
, "debug": [Function], "findAllByAltText": [Function], @@ -609,97 +697,119 @@ exports[`renderer/components/icons/LogoIcon.tsx should render small size 1`] = ` "asFragment": [Function], "baseElement":
- + + + + + + + + + + +
+
, "container":
- + + + + + + + + + + +
+
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/layout/AppLayout.test.tsx b/src/renderer/components/layout/AppLayout.test.tsx index 2a41945d2..7a74c0d02 100644 --- a/src/renderer/components/layout/AppLayout.test.tsx +++ b/src/renderer/components/layout/AppLayout.test.tsx @@ -1,24 +1,14 @@ -import { render } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; -import { mockAuth, mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { AppLayout } from './AppLayout'; describe('renderer/components/layout/AppLayout.tsx', () => { it('should render itself & its children', () => { - const tree = render( - - - Test - - , + const tree = renderWithAppContext( + + Test + , ); expect(tree).toMatchSnapshot(); diff --git a/src/renderer/components/layout/Centered.test.tsx b/src/renderer/components/layout/Centered.test.tsx index 9bb464304..f84b5dc33 100644 --- a/src/renderer/components/layout/Centered.test.tsx +++ b/src/renderer/components/layout/Centered.test.tsx @@ -1,16 +1,19 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { Centered } from './Centered'; describe('renderer/components/layout/Centered.tsx', () => { it('should render itself & its children - full height true', () => { - const tree = render(Test); + const tree = renderWithAppContext( + Test, + ); expect(tree).toMatchSnapshot(); }); it('should render itself & its children - full height false', () => { - const tree = render(Test); + const tree = renderWithAppContext( + Test, + ); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/layout/Contents.test.tsx b/src/renderer/components/layout/Contents.test.tsx index c8d2bce0d..554ad4942 100644 --- a/src/renderer/components/layout/Contents.test.tsx +++ b/src/renderer/components/layout/Contents.test.tsx @@ -1,10 +1,9 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { Contents } from './Contents'; describe('renderer/components/layout/Contents.tsx', () => { it('should render itself & its children', () => { - const tree = render(Test); + const tree = renderWithAppContext(Test); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/layout/EmojiSplash.test.tsx b/src/renderer/components/layout/EmojiSplash.test.tsx index a8fb9529e..044a30b54 100644 --- a/src/renderer/components/layout/EmojiSplash.test.tsx +++ b/src/renderer/components/layout/EmojiSplash.test.tsx @@ -1,14 +1,17 @@ -import { act, render } from '@testing-library/react'; +import { act } from '@testing-library/react'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { EmojiSplash } from './EmojiSplash'; describe('renderer/components/layout/EmojiSplash.tsx', () => { it('should render itself & its children - heading only', async () => { - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { tree = await act(async () => { - return render(); + return renderWithAppContext( + , + ); }); }); @@ -16,11 +19,11 @@ describe('renderer/components/layout/EmojiSplash.tsx', () => { }); it('should render itself & its children - heading and sub-heading', async () => { - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { tree = await act(async () => { - return render( + return renderWithAppContext( { it('should render itself & its children', () => { - const tree = render(Test); + const tree = renderWithAppContext(Test); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/layout/__snapshots__/AppLayout.test.tsx.snap b/src/renderer/components/layout/__snapshots__/AppLayout.test.tsx.snap index 4c9132afa..341a2d837 100644 --- a/src/renderer/components/layout/__snapshots__/AppLayout.test.tsx.snap +++ b/src/renderer/components/layout/__snapshots__/AppLayout.test.tsx.snap @@ -6,543 +6,565 @@ exports[`renderer/components/layout/AppLayout.tsx should render itself & its chi "baseElement":
- + + + + +
-
- + +
+
- - - -
+
+
- Quit Gitify - + Test +
-
- Test -
, "container":
- + + + + +
-
- + +
+
- - - -
+
+
- Quit Gitify - + Test +
-
- Test -
, "debug": [Function], diff --git a/src/renderer/components/layout/__snapshots__/Centered.test.tsx.snap b/src/renderer/components/layout/__snapshots__/Centered.test.tsx.snap index 1e88c7fb1..e93e2714c 100644 --- a/src/renderer/components/layout/__snapshots__/Centered.test.tsx.snap +++ b/src/renderer/components/layout/__snapshots__/Centered.test.tsx.snap @@ -6,27 +6,49 @@ exports[`renderer/components/layout/Centered.tsx should render itself & its chil "baseElement":
- Test +
+
+ Test +
+
, "container":
- Test +
+
+ Test +
+
, "debug": [Function], @@ -89,27 +111,49 @@ exports[`renderer/components/layout/Centered.tsx should render itself & its chil "baseElement":
- Test +
+
+ Test +
+
, "container":
- Test +
+
+ Test +
+
, "debug": [Function], diff --git a/src/renderer/components/layout/__snapshots__/Contents.test.tsx.snap b/src/renderer/components/layout/__snapshots__/Contents.test.tsx.snap index fd184a9b4..15ccc0ec3 100644 --- a/src/renderer/components/layout/__snapshots__/Contents.test.tsx.snap +++ b/src/renderer/components/layout/__snapshots__/Contents.test.tsx.snap @@ -6,17 +6,39 @@ exports[`renderer/components/layout/Contents.tsx should render itself & its chil "baseElement":
- Test +
+
+ Test +
+
, "container":
- Test +
+
+ Test +
+
, "debug": [Function], diff --git a/src/renderer/components/layout/__snapshots__/EmojiSplash.test.tsx.snap b/src/renderer/components/layout/__snapshots__/EmojiSplash.test.tsx.snap index 5c88794fc..595073fcb 100644 --- a/src/renderer/components/layout/__snapshots__/EmojiSplash.test.tsx.snap +++ b/src/renderer/components/layout/__snapshots__/EmojiSplash.test.tsx.snap @@ -6,51 +6,62 @@ exports[`renderer/components/layout/EmojiSplash.tsx should render itself & its c "baseElement":
- 🍺 +
+
+ 🍺 +
+
+ Test Heading +
+
+
+ Test Sub-Heading +
-
- Test Heading -
-
-
- Test Sub-Heading
@@ -58,52 +69,63 @@ exports[`renderer/components/layout/EmojiSplash.tsx should render itself & its c , "container":
- 🍺 -
-
- Test Heading +
+
+ 🍺 +
+
+ Test Heading +
+
+
+ Test Sub-Heading +
-
- Test Sub-Heading -
, @@ -167,45 +189,56 @@ exports[`renderer/components/layout/EmojiSplash.tsx should render itself & its c "baseElement":
- 🍺 -
-
- Test Heading +
+
+ 🍺 +
+
+ Test Heading +
+
@@ -214,45 +247,56 @@ exports[`renderer/components/layout/EmojiSplash.tsx should render itself & its c , "container":
- 🍺 -
-
- Test Heading +
+
+ 🍺 +
+
+ Test Heading +
+
diff --git a/src/renderer/components/layout/__snapshots__/Page.test.tsx.snap b/src/renderer/components/layout/__snapshots__/Page.test.tsx.snap index 4c981c9d6..9c849210b 100644 --- a/src/renderer/components/layout/__snapshots__/Page.test.tsx.snap +++ b/src/renderer/components/layout/__snapshots__/Page.test.tsx.snap @@ -6,19 +6,41 @@ exports[`renderer/components/layout/Page.tsx should render itself & its children "baseElement":
- Test +
+
+ Test +
+
, "container":
- Test +
+
+ Test +
+
, "debug": [Function], diff --git a/src/renderer/components/metrics/MetricGroup.test.tsx b/src/renderer/components/metrics/MetricGroup.test.tsx index c74849a39..030c171c4 100644 --- a/src/renderer/components/metrics/MetricGroup.test.tsx +++ b/src/renderer/components/metrics/MetricGroup.test.tsx @@ -1,7 +1,5 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; import type { Milestone } from '../../typesGitHub'; import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks'; import { MetricGroup } from './MetricGroup'; @@ -15,15 +13,9 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { ...mockSettings, showPills: false }, + }); expect(tree).toMatchSnapshot(); }); }); @@ -37,15 +29,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); @@ -57,15 +41,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); }); @@ -79,15 +55,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); @@ -99,15 +67,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); @@ -119,15 +79,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); }); @@ -141,15 +93,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); }); @@ -166,15 +110,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); @@ -189,15 +125,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); }); diff --git a/src/renderer/components/metrics/MetricPill.test.tsx b/src/renderer/components/metrics/MetricPill.test.tsx index f6e37ff1d..9f619f6c9 100644 --- a/src/renderer/components/metrics/MetricPill.test.tsx +++ b/src/renderer/components/metrics/MetricPill.test.tsx @@ -1,7 +1,6 @@ -import { render } from '@testing-library/react'; - import { MarkGithubIcon } from '@primer/octicons-react'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { IconColor } from '../../types'; import { MetricPill, type MetricPillProps } from './MetricPill'; @@ -13,7 +12,7 @@ describe('renderer/components/metrics/MetricPill.tsx', () => { icon: MarkGithubIcon, color: IconColor.GREEN, }; - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); @@ -23,7 +22,7 @@ describe('renderer/components/metrics/MetricPill.tsx', () => { icon: MarkGithubIcon, color: IconColor.GREEN, }; - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); }); diff --git a/src/renderer/components/metrics/__snapshots__/MetricGroup.test.tsx.snap b/src/renderer/components/metrics/__snapshots__/MetricGroup.test.tsx.snap index be088f070..a4ea8ade5 100644 --- a/src/renderer/components/metrics/__snapshots__/MetricGroup.test.tsx.snap +++ b/src/renderer/components/metrics/__snapshots__/MetricGroup.test.tsx.snap @@ -6,325 +6,347 @@ exports[`renderer/components/metrics/MetricGroup.tsx comment pills should render "baseElement":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="1 comment" + > +
+ + + 1 + +
-
+
, "container":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="1 comment" + > +
+ + + 1 + +
-
+
, "debug": [Function], @@ -387,325 +409,347 @@ exports[`renderer/components/metrics/MetricGroup.tsx comment pills should render "baseElement":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="2 comments" + > +
+ + + 2 + +
-
+
, "container":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="2 comments" + > +
+ + + 2 + +
-
+
, "debug": [Function], @@ -768,249 +812,271 @@ exports[`renderer/components/metrics/MetricGroup.tsx comment pills should render "baseElement":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
+
, "container":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
+
, "debug": [Function], @@ -1073,403 +1139,425 @@ exports[`renderer/components/metrics/MetricGroup.tsx label pills should render l "baseElement":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="2 comments" + > +
+ + + 2 + +
-
-
- -
- - 2 +
+ + + 2 + +
-
+
, "container":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="2 comments" + > +
+ + + 2 + +
-
-
- -
- - 2 +
+ + + 2 + +
-
+
, "debug": [Function], @@ -1532,249 +1620,271 @@ exports[`renderer/components/metrics/MetricGroup.tsx linked issue pills should r "baseElement":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
+
, "container":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
+
, "debug": [Function], @@ -1837,249 +1947,271 @@ exports[`renderer/components/metrics/MetricGroup.tsx linked issue pills should r "baseElement":
-
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issue #1" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
+
, "container":
-
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issue #1" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
+
, "debug": [Function], @@ -2142,469 +2274,491 @@ exports[`renderer/components/metrics/MetricGroup.tsx milestone pills should rend "baseElement":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="2 comments" + > +
+ + + 2 + +
-
-
- -
- - 2 +
+ + + 2 + +
+
+ +
+ +
-
- -
- -
-
+
, "container":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="2 comments" + > +
+ + + 2 + +
-
-
- -
- +
+ + + 2 + +
+ - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Milestone 1" + > +
+ +
-
- -
- -
-
+
, "debug": [Function], @@ -2667,469 +2821,491 @@ exports[`renderer/components/metrics/MetricGroup.tsx milestone pills should rend "baseElement":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="2 comments" + > +
+ + + 2 + +
-
-
- -
- - 2 +
+ + + 2 + +
+
+ +
+ +
-
- -
- -
-
+
, "container":
-
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Linked to issues #1, #2" + > +
+ + + 2 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="octocat approved these changes" + > +
+ + + 1 + +
-
-
- -
- - 1 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="gitify-app requested changes" + > +
+ + + 1 + +
-
-
- -
- - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="2 comments" + > +
+ + + 2 + +
-
-
- -
- +
+ + + 2 + +
+ - 2 + class="hover:bg-gitify-notification-pill-hover prc-Label-Label--LG6X" + data-size="small" + data-variant="secondary" + title="Milestone 1" + > +
+ +
-
- -
- -
-
+
, "debug": [Function], @@ -3190,9 +3366,31 @@ exports[`renderer/components/metrics/MetricGroup.tsx showPills disabled should n { "asFragment": [Function], "baseElement": -
+
+
+
+
+
, - "container":
, + "container":
+
+
+
+
, "debug": [Function], "findAllByAltText": [Function], "findAllByDisplayValue": [Function], diff --git a/src/renderer/components/metrics/__snapshots__/MetricPill.test.tsx.snap b/src/renderer/components/metrics/__snapshots__/MetricPill.test.tsx.snap index 6e4b0941a..8e4cd72c1 100644 --- a/src/renderer/components/metrics/__snapshots__/MetricPill.test.tsx.snap +++ b/src/renderer/components/metrics/__snapshots__/MetricPill.test.tsx.snap @@ -5,85 +5,107 @@ exports[`renderer/components/metrics/MetricPill.tsx should render with metric 1` "asFragment": [Function], "baseElement":
-
- - 1 +
+ + + 1 + +
-
+
, "container":
-
- - 1 +
+ + + 1 + +
-
+
, "debug": [Function], "findAllByAltText": [Function], @@ -144,75 +166,97 @@ exports[`renderer/components/metrics/MetricPill.tsx should render without metric "asFragment": [Function], "baseElement":
-
- +
+ +
+
-
+
, "container":
-
- +
+ +
+
-
+
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/notifications/AccountNotifications.test.tsx b/src/renderer/components/notifications/AccountNotifications.test.tsx index 0c848f588..5c023bbaf 100644 --- a/src/renderer/components/notifications/AccountNotifications.test.tsx +++ b/src/renderer/components/notifications/AccountNotifications.test.tsx @@ -1,13 +1,12 @@ -import { act, render, screen } from '@testing-library/react'; +import { act, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { - mockAuth, - mockGitHubCloudAccount, - mockSettings, -} from '../../__mocks__/state-mocks'; -import { ensureStableEmojis } from '../../__mocks__/utils'; -import { AppContext } from '../../context/App'; + ensureStableEmojis, + renderWithAppContext, +} from '../../__helpers__/test-utils'; +import { mockGitHubCloudAccount } from '../../__mocks__/account-mocks'; +import { mockSettings } from '../../__mocks__/state-mocks'; import { GroupBy } from '../../types'; import { mockGitHubNotifications } from '../../utils/api/__mocks__/response-mocks'; import * as links from '../../utils/links'; @@ -30,13 +29,9 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => { error: null, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { ...mockSettings, groupBy: GroupBy.REPOSITORY }, + }); expect(tree).toMatchSnapshot(); }); @@ -49,13 +44,9 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => { error: null, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { ...mockSettings, groupBy: GroupBy.DATE }, + }); expect(tree).toMatchSnapshot(); }); @@ -68,14 +59,10 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => { error: null, }; - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { - tree = render( - - - , - ); + tree = renderWithAppContext(); }); expect(tree).toMatchSnapshot(); @@ -93,19 +80,12 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => { showAccountHeader: true, }; - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { - tree = render( - - - , - ); + tree = renderWithAppContext(, { + auth: { accounts: [mockGitHubCloudAccount] }, + }); }); expect(tree).toMatchSnapshot(); @@ -123,21 +103,17 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => { showAccountHeader: true, }; - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { - tree = render( - - - , - ); + tree = renderWithAppContext(); }); expect(tree).toMatchSnapshot(); }); it('should open profile when clicked', async () => { - const openAccountProfileMock = jest + const mockOpenAccountProfile = jest .spyOn(links, 'openAccountProfile') .mockImplementation(); @@ -148,20 +124,16 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => { error: null, }; - render( - - - , - ); + renderWithAppContext(); await userEvent.click(screen.getByTestId('account-profile')); - expect(openAccountProfileMock).toHaveBeenCalledTimes(1); - expect(openAccountProfileMock).toHaveBeenCalledWith(mockGitHubCloudAccount); + expect(mockOpenAccountProfile).toHaveBeenCalledTimes(1); + expect(mockOpenAccountProfile).toHaveBeenCalledWith(mockGitHubCloudAccount); }); it('should open my issues when clicked', async () => { - const openMyIssuesMock = jest + const mockOpenGitHubIssues = jest .spyOn(links, 'openGitHubIssues') .mockImplementation(); @@ -172,22 +144,18 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => { error: null, }; - render( - - - , - ); + renderWithAppContext(); await userEvent.click(screen.getByTestId('account-issues')); - expect(openMyIssuesMock).toHaveBeenCalledTimes(1); - expect(openMyIssuesMock).toHaveBeenCalledWith( + expect(mockOpenGitHubIssues).toHaveBeenCalledTimes(1); + expect(mockOpenGitHubIssues).toHaveBeenCalledWith( mockGitHubCloudAccount.hostname, ); }); it('should open my pull requests when clicked', async () => { - const openPullRequestsMock = jest + const mockOpenGitHubPulls = jest .spyOn(links, 'openGitHubPulls') .mockImplementation(); @@ -198,16 +166,12 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => { error: null, }; - render( - - - , - ); + renderWithAppContext(); await userEvent.click(screen.getByTestId('account-pull-requests')); - expect(openPullRequestsMock).toHaveBeenCalledTimes(1); - expect(openPullRequestsMock).toHaveBeenCalledWith( + expect(mockOpenGitHubPulls).toHaveBeenCalledTimes(1); + expect(mockOpenGitHubPulls).toHaveBeenCalledWith( mockGitHubCloudAccount.hostname, ); }); @@ -220,19 +184,12 @@ describe('renderer/components/notifications/AccountNotifications.tsx', () => { error: null, }; - render( - - - , - ); + renderWithAppContext(); await userEvent.click(screen.getByTestId('account-toggle')); - const tree = render( - - - , - ); + const tree = renderWithAppContext(); + expect(tree).toMatchSnapshot(); }); }); diff --git a/src/renderer/components/notifications/NotificationFooter.test.tsx b/src/renderer/components/notifications/NotificationFooter.test.tsx index f7ee60fa8..465612ddb 100644 --- a/src/renderer/components/notifications/NotificationFooter.test.tsx +++ b/src/renderer/components/notifications/NotificationFooter.test.tsx @@ -1,12 +1,9 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { - mockGitHubCloudAccount, - mockSettings, -} from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; -import { GroupBy, type Link } from '../../types'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; +import { mockGitHubCloudAccount } from '../../__mocks__/account-mocks'; +import type { Link } from '../../types'; import type { UserType } from '../../typesGitHub'; import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks'; import * as comms from '../../utils/comms'; @@ -19,27 +16,21 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => { it('should render itself & its children', async () => { jest - .spyOn(global.Date, 'now') + .spyOn(globalThis.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); const props = { notification: mockSingleNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should render itself & its children when last_read_at is null', async () => { jest - .spyOn(global.Date, 'now') + .spyOn(globalThis.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); const mockNotification = mockSingleNotification; @@ -49,11 +40,7 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); @@ -61,7 +48,7 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => { describe('security alerts should use github icon for avatar', () => { it('Repository Dependabot Alerts Thread', async () => { jest - .spyOn(global.Date, 'now') + .spyOn(globalThis.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); const mockNotification = mockSingleNotification; @@ -71,18 +58,14 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('Repository Vulnerability Alert', async () => { jest - .spyOn(global.Date, 'now') + .spyOn(globalThis.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); const mockNotification = mockSingleNotification; @@ -92,11 +75,7 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); @@ -104,7 +83,7 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => { it('should default to known avatar if no user found', async () => { jest - .spyOn(global.Date, 'now') + .spyOn(globalThis.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); const mockNotification = mockSingleNotification; @@ -114,17 +93,13 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => { notification: mockNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); it('should open notification user profile', async () => { - const openExternalLinkMock = jest + const mockOpenExternalLink = jest .spyOn(comms, 'openExternalLink') .mockImplementation(); @@ -146,20 +121,12 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => { account: mockGitHubCloudAccount, }; - render( - - - , - ); + renderWithAppContext(); await userEvent.click(screen.getByTestId('view-profile')); - expect(openExternalLinkMock).toHaveBeenCalledTimes(1); - expect(openExternalLinkMock).toHaveBeenCalledWith( + expect(mockOpenExternalLink).toHaveBeenCalledTimes(1); + expect(mockOpenExternalLink).toHaveBeenCalledWith( props.notification.subject.user.html_url, ); }); diff --git a/src/renderer/components/notifications/NotificationHeader.test.tsx b/src/renderer/components/notifications/NotificationHeader.test.tsx index 712977216..b54e7e8d4 100644 --- a/src/renderer/components/notifications/NotificationHeader.test.tsx +++ b/src/renderer/components/notifications/NotificationHeader.test.tsx @@ -1,8 +1,8 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; import { GroupBy } from '../../types'; import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks'; import * as comms from '../../utils/comms'; @@ -18,13 +18,9 @@ describe('renderer/components/notifications/NotificationHeader.tsx', () => { notification: mockSingleNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { ...mockSettings, groupBy: GroupBy.REPOSITORY }, + }); expect(tree).toMatchSnapshot(); }); @@ -35,13 +31,9 @@ describe('renderer/components/notifications/NotificationHeader.tsx', () => { notification: mockSingleNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { ...mockSettings, groupBy: GroupBy.DATE }, + }); expect(tree).toMatchSnapshot(); }); @@ -51,19 +43,13 @@ describe('renderer/components/notifications/NotificationHeader.tsx', () => { notification: mockSingleNotification, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { + ...mockSettings, + showNumber: false, + groupBy: GroupBy.DATE, + }, + }); expect(tree).toMatchSnapshot(); }); @@ -76,20 +62,16 @@ describe('renderer/components/notifications/NotificationHeader.tsx', () => { }, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { ...mockSettings, groupBy: GroupBy.DATE }, + }); expect(tree).toMatchSnapshot(); }); }); it('should open notification user profile - group by date', async () => { - const openExternalLinkMock = jest + const mockOpenExternalLink = jest .spyOn(comms, 'openExternalLink') .mockImplementation(); @@ -97,18 +79,14 @@ describe('renderer/components/notifications/NotificationHeader.tsx', () => { notification: mockSingleNotification, }; - render( - - - , - ); + renderWithAppContext(, { + settings: { ...mockSettings, groupBy: GroupBy.DATE }, + }); await userEvent.click(screen.getByTestId('view-repository')); - expect(openExternalLinkMock).toHaveBeenCalledTimes(1); - expect(openExternalLinkMock).toHaveBeenCalledWith( + expect(mockOpenExternalLink).toHaveBeenCalledTimes(1); + expect(mockOpenExternalLink).toHaveBeenCalledWith( props.notification.repository.html_url, ); }); diff --git a/src/renderer/components/notifications/NotificationRow.test.tsx b/src/renderer/components/notifications/NotificationRow.test.tsx index 2feb18a85..29c7ee9d3 100644 --- a/src/renderer/components/notifications/NotificationRow.test.tsx +++ b/src/renderer/components/notifications/NotificationRow.test.tsx @@ -1,12 +1,9 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { - mockAuth, - mockGitHubCloudAccount, - mockSettings, -} from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; +import { mockGitHubCloudAccount } from '../../__mocks__/account-mocks'; +import { mockSettings } from '../../__mocks__/state-mocks'; import { GroupBy } from '../../types'; import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks'; import * as comms from '../../utils/comms'; @@ -23,7 +20,7 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { it('should render itself & its children - group by date', async () => { jest - .spyOn(global.Date, 'now') + .spyOn(globalThis.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); const props = { @@ -31,20 +28,16 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { account: mockGitHubCloudAccount, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { ...mockSettings, groupBy: GroupBy.DATE }, + }); expect(tree).toMatchSnapshot(); }); it('should render itself & its children - group by repositories', async () => { jest - .spyOn(global.Date, 'now') + .spyOn(globalThis.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); const props = { @@ -52,20 +45,16 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { account: mockGitHubCloudAccount, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { ...mockSettings, groupBy: GroupBy.REPOSITORY }, + }); expect(tree).toMatchSnapshot(); }); it('should render itself & its children - hide numbers', async () => { jest - .spyOn(global.Date, 'now') + .spyOn(globalThis.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); const props = { @@ -73,20 +62,16 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { account: mockGitHubCloudAccount, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(, { + settings: { ...mockSettings, showNumber: false }, + }); expect(tree).toMatchSnapshot(); }); it('should render itself & its children - notification is read', async () => { jest - .spyOn(global.Date, 'now') + .spyOn(globalThis.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); const props = { @@ -97,40 +82,29 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { account: mockGitHubCloudAccount, }; - const tree = render( - - - , - ); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); describe('notification interactions', () => { it('should open a notification in the browser - click', async () => { - const markNotificationsAsRead = jest.fn(); + const mockMarkNotificationsAsRead = jest.fn(); const props = { notification: mockSingleNotification, account: mockGitHubCloudAccount, }; - render( - - - , - ); + renderWithAppContext(, { + settings: { ...mockSettings, markAsDoneOnOpen: false }, + markNotificationsAsRead: mockMarkNotificationsAsRead, + }); await userEvent.click(screen.getByTestId('notification-row')); expect(links.openNotification).toHaveBeenCalledTimes(1); - expect(markNotificationsAsRead).toHaveBeenCalledTimes(1); + expect(mockMarkNotificationsAsRead).toHaveBeenCalledTimes(1); }); it('should open a notification in the browser - delay notification setting enabled', async () => { @@ -141,21 +115,14 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { account: mockGitHubCloudAccount, }; - render( - - - , - ); + renderWithAppContext(, { + settings: { + ...mockSettings, + markAsDoneOnOpen: false, + delayNotificationState: true, + }, + markNotificationsAsRead, + }); await userEvent.click(screen.getByTestId('notification-row')); @@ -164,99 +131,77 @@ describe('renderer/components/notifications/NotificationRow.tsx', () => { }); it('should open a notification in browser & mark it as done', async () => { - const markNotificationsAsDone = jest.fn(); + const mockMarkNotificationsAsDone = jest.fn(); const props = { notification: mockSingleNotification, account: mockGitHubCloudAccount, }; - render( - - - , - ); + renderWithAppContext(, { + settings: { ...mockSettings, markAsDoneOnOpen: true }, + markNotificationsAsDone: mockMarkNotificationsAsDone, + }); await userEvent.click(screen.getByTestId('notification-row')); expect(links.openNotification).toHaveBeenCalledTimes(1); - expect(markNotificationsAsDone).toHaveBeenCalledTimes(1); + expect(mockMarkNotificationsAsDone).toHaveBeenCalledTimes(1); }); it('should mark notifications as read', async () => { - const markNotificationsAsRead = jest.fn(); + const mockMarkNotificationsAsRead = jest.fn(); const props = { notification: mockSingleNotification, account: mockGitHubCloudAccount, }; - render( - - - , - ); + renderWithAppContext(, { + settings: { ...mockSettings, markAsDoneOnOpen: false }, + markNotificationsAsRead: mockMarkNotificationsAsRead, + }); await userEvent.click(screen.getByTestId('notification-mark-as-read')); - expect(markNotificationsAsRead).toHaveBeenCalledTimes(1); + expect(mockMarkNotificationsAsRead).toHaveBeenCalledTimes(1); }); it('should mark notifications as done', async () => { - const markNotificationsAsDone = jest.fn(); + const mockMarkNotificationsAsDone = jest.fn(); const props = { notification: mockSingleNotification, account: mockGitHubCloudAccount, }; - render( - - - , - ); + renderWithAppContext(, { + settings: mockSettings, + markNotificationsAsDone: mockMarkNotificationsAsDone, + }); await userEvent.click(screen.getByTestId('notification-mark-as-done')); - expect(markNotificationsAsDone).toHaveBeenCalledTimes(1); + expect(mockMarkNotificationsAsDone).toHaveBeenCalledTimes(1); }); it('should unsubscribe from a notification thread', async () => { - const unsubscribeNotification = jest.fn(); + const mockUnsubscribeNotification = jest.fn(); const props = { notification: mockSingleNotification, account: mockGitHubCloudAccount, }; - render( - - - - - , - ); + renderWithAppContext(, { + unsubscribeNotification: mockUnsubscribeNotification, + }); await userEvent.click( screen.getByTestId('notification-unsubscribe-from-thread'), ); - expect(unsubscribeNotification).toHaveBeenCalledTimes(1); + expect(mockUnsubscribeNotification).toHaveBeenCalledTimes(1); }); }); }); diff --git a/src/renderer/components/notifications/RepositoryNotifications.test.tsx b/src/renderer/components/notifications/RepositoryNotifications.test.tsx index bd352b37e..ddcb5f6fa 100644 --- a/src/renderer/components/notifications/RepositoryNotifications.test.tsx +++ b/src/renderer/components/notifications/RepositoryNotifications.test.tsx @@ -1,11 +1,9 @@ -import { act, render, screen } from '@testing-library/react'; +import { act, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { - mockGitHubCloudAccount, - mockSettings, -} from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; +import { mockGitHubCloudAccount } from '../../__mocks__/account-mocks'; +import { mockSettings } from '../../__mocks__/state-mocks'; import type { Link } from '../../types'; import { mockGitHubNotifications } from '../../utils/api/__mocks__/response-mocks'; import * as comms from '../../utils/comms'; @@ -30,10 +28,9 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () => }); it('should render itself & its children', () => { - const tree = render( - - - , + const tree = renderWithAppContext( + , + {}, ); expect(tree).toMatchSnapshot(); @@ -44,42 +41,34 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () => n.unread = false; } - const tree = render( - - - , + const tree = renderWithAppContext( + , + {}, ); expect(tree).toMatchSnapshot(); }); it('should open the browser when clicking on the repo name', async () => { - const openExternalLinkMock = jest + const mockOpenExternalLink = jest .spyOn(comms, 'openExternalLink') .mockImplementation(); - render( - - - , - ); + renderWithAppContext(); await userEvent.click(screen.getByTestId('open-repository')); - expect(openExternalLinkMock).toHaveBeenCalledTimes(1); - expect(openExternalLinkMock).toHaveBeenCalledWith( + expect(mockOpenExternalLink).toHaveBeenCalledTimes(1); + expect(mockOpenExternalLink).toHaveBeenCalledWith( 'https://github.com/gitify-app/notifications-test', ); }); it('should mark a repo as read', async () => { - render( - - - , - ); + renderWithAppContext(, { + settings: { ...mockSettings }, + markNotificationsAsRead, + }); await userEvent.click(screen.getByTestId('repository-mark-as-read')); @@ -89,13 +78,10 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () => }); it('should mark a repo as done', async () => { - render( - - - , - ); + renderWithAppContext(, { + settings: { ...mockSettings }, + markNotificationsAsDone, + }); await userEvent.click(screen.getByTestId('repository-mark-as-done')); @@ -107,10 +93,9 @@ 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 = render( - - - , + const tree = renderWithAppContext( + , + {}, ); expect(tree).toMatchSnapshot(); @@ -118,12 +103,12 @@ describe('renderer/components/notifications/RepositoryNotifications.tsx', () => it('should toggle repository notifications visibility', async () => { await act(async () => { - render(); + renderWithAppContext(); }); await userEvent.click(screen.getByTestId('repository-toggle')); - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); }); diff --git a/src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap b/src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap index 75dafb55a..6989e7d7b 100644 --- a/src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap +++ b/src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap @@ -6,471 +6,493 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should rende "baseElement":
-
-
+ + +
+
-
- 🔥 -
-
- Error title -
-
-
- Error description -
-
- - - , - "container":
-
+ , + "container":
-
- 🔥 -
-
- Error title + + +
+ octocat +
+ @octocat +
+
+
+ + + +  ( + 0 + ) + + +
+ +
- Error description +
+
+
+ 🔥 +
+
+ Error title +
+
+
+ Error description +
+
@@ -535,472 +557,494 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should rende "baseElement":
+
+
+
+
+ 🔥 +
+
+ Error title +
+
+
+ Error description +
+
+
+
+
+
+ , + "container":
+
+
+
-
-
-
- 🔥 -
-
- Error title -
-
-
- Error description -
-
-
-
- , - "container":
- -
-
-
-
- 🔥 -
-
- Error title + Error description +
-
- Error description -
, @@ -1064,263 +1108,42 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should rende "baseElement":
-
-
- -
-
-
- -
-
-
+ + + + +  ( + 2 + ) + + + +
- - I am a robot and this is a test! - -
+
+
+
- - Updated - - - May 20, 2017 - -
-
-
- - - 1 - +
+ gitify-app/notifications-test +
+ gitify-app/notifications-test +
+
+ +
- - -
+
+ + I am a robot and this is a test! + +
+
+ +
- - 1 + Updated + + May 20, 2017 +
- -
-
-
-
-
- - - -
-
-
-
- - -
-
-
- -
+
- - Improve the UI - -
+
+
-
-
+ +
- - Authored - - - May 20, 2017 - -
-
-
-
-
-
- - - -
-
-
- , - "container":
- +
+ + Improve the UI + +
+
+
+ +
+
+ + Authored + + + May 20, 2017 + +
+
+
+
+
- octocat -
- @octocat -
+ + + +
- - - - -  ( - 2 - ) - - - - - +
+ , + "container":
- -
-
-
- -
-
-
-
- - I am a robot and this is a test! + + + + +  ( + 2 + ) + + -
+
+ + +
+
+
+
+ +
- - Updated - - - May 20, 2017 - -
-
-
- - - 1 - +
+ gitify-app/notifications-test +
+ gitify-app/notifications-test +
+
+ +
- - +
+ + I am a robot and this is a test! + +
+
+
- - 1 + Updated + + May 20, 2017 +
- -
-
-
-
-
- - - -
-
-
-
- - -
-
-
- -
+
- - Improve the UI - -
+
+
-
-
+ +
- - Authored - - + +
+
+
+
- May 20, 2017 - + + Improve the UI + +
+
+
+ +
+
+ + Authored + + + May 20, 2017 + +
+
+
-
-
-
-
- - - + + + +
+
, @@ -2819,382 +2885,404 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should rende "baseElement":
+
+
+ Repository Notifications +
+
+
+
+ , + "container":
+
+
-
-
- Repository Notifications -
-
- , - "container":
- +
+ Repository Notifications +
-
- Repository Notifications -
, "debug": [Function], "findAllByAltText": [Function], @@ -3256,460 +3344,482 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should rende "baseElement":
+
-
- octocat
- @octocat + 🎊 +
+
+ No new notifications
-
- - - -  ( - 0 - ) - - - - +
+
+ + + + , + "container":
+
+
-
-
-
-
- 🎊 -
-
- No new notifications -
-
-
-
-
- , - "container":
- -
-
+ + +
+
- 🎊 -
-
- No new notifications +
+
+ 🎊 +
+
+ No new notifications +
+
@@ -3775,568 +3885,601 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should toggl "baseElement":
+
+
+ +
+
+
+ +
+
+ Repository Notifications +
+
+
+ + , + "container":
+
+
-
-
-
- -
- Repository Notifications -
-
- , - "container":
- +
+ Repository Notifications +
-
- Repository Notifications -
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/notifications/__snapshots__/NotificationFooter.test.tsx.snap b/src/renderer/components/notifications/__snapshots__/NotificationFooter.test.tsx.snap index ba7b41aa4..0fd0f5a3d 100644 --- a/src/renderer/components/notifications/__snapshots__/NotificationFooter.test.tsx.snap +++ b/src/renderer/components/notifications/__snapshots__/NotificationFooter.test.tsx.snap @@ -6,280 +6,302 @@ exports[`renderer/components/notifications/NotificationFooter.tsx security alert "baseElement":
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
, "container":
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
, @@ -343,280 +365,302 @@ exports[`renderer/components/notifications/NotificationFooter.tsx security alert "baseElement":
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
, "container":
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
, @@ -680,282 +724,304 @@ exports[`renderer/components/notifications/NotificationFooter.tsx should default "baseElement":
- -
-
- - Updated - - - May 20, 2017 - -
-
-
- - 1 -
-
-
- + Updated + + + May 20, 2017 + +
+
+ +
+ + + 1 + +
+
- 1 +
+ + + 1 + +
-
+
, "container":
- -
-
- - Updated - - - May 20, 2017 - -
-
-
- - 1 -
-
-
- + Updated + + + May 20, 2017 + +
+
- 1 +
+ + + 1 + +
+
+ +
+ + + 1 + +
-
+
, @@ -1019,280 +1085,302 @@ exports[`renderer/components/notifications/NotificationFooter.tsx should render "baseElement":
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
, "container":
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
, @@ -1356,280 +1444,302 @@ exports[`renderer/components/notifications/NotificationFooter.tsx should render "baseElement":
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
, "container":
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
, diff --git a/src/renderer/components/notifications/__snapshots__/NotificationHeader.test.tsx.snap b/src/renderer/components/notifications/__snapshots__/NotificationHeader.test.tsx.snap index b8f897c1f..8a531806d 100644 --- a/src/renderer/components/notifications/__snapshots__/NotificationHeader.test.tsx.snap +++ b/src/renderer/components/notifications/__snapshots__/NotificationHeader.test.tsx.snap @@ -6,22 +6,16 @@ exports[`renderer/components/notifications/NotificationHeader.tsx should render "baseElement":
- +
- -
+
, "container":
- +
- -
+
, @@ -173,22 +195,16 @@ exports[`renderer/components/notifications/NotificationHeader.tsx should render "baseElement":
- + - -
, "container":
- + - -
, @@ -340,22 +384,16 @@ exports[`renderer/components/notifications/NotificationHeader.tsx should render "baseElement":
- +
- -
+
, "container":
- +
- -
+
, @@ -505,9 +571,31 @@ exports[`renderer/components/notifications/NotificationHeader.tsx should render { "asFragment": [Function], "baseElement": -
+
+
+
+
+
, - "container":
, + "container":
+
+
+
+
, "debug": [Function], "findAllByAltText": [Function], "findAllByDisplayValue": [Function], diff --git a/src/renderer/components/notifications/__snapshots__/NotificationRow.test.tsx.snap b/src/renderer/components/notifications/__snapshots__/NotificationRow.test.tsx.snap index abcb9ff5c..331b81ab3 100644 --- a/src/renderer/components/notifications/__snapshots__/NotificationRow.test.tsx.snap +++ b/src/renderer/components/notifications/__snapshots__/NotificationRow.test.tsx.snap @@ -6,79 +6,73 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its "baseElement":
- -
+ +
- +
- -
-
-
-
- - I am a robot and this is a test! - -
-
-
- gitify-app + I am a robot and this is a test! + +
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
-
-
-
- - - -
-
-
- , - "container":
-
-
- - -
-
+ + -
+
+
+
+ , + "container":
+
+
+
- - I am a robot and this is a test! - -
-
+
- - Updated - - - May 20, 2017 - -
-
-
- - - 1 - +
+ gitify-app/notifications-test +
+ gitify-app/notifications-test +
+
+ +
- - +
+ + I am a robot and this is a test! + +
+
+
- + Updated + + + May 20, 2017 + +
+
+ +
+ + + 1 + +
+
- 1 +
+ + + 1 + +
- +
-
-
-
- - - + + + +
+
, @@ -807,640 +829,662 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its "baseElement":
- -
- - I am a robot and this is a test! - - -
-
+
- - Updated - - - May 20, 2017 - -
-
- + I am a robot and this is a test! + + +
+
+
- - 1 + Updated + + May 20, 2017 +
- -
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
-
-
-
- - - + + + +
+
, "container":
- -
- - I am a robot and this is a test! - - -
-
+
- - Updated - - - May 20, 2017 - -
-
- + I am a robot and this is a test! + + +
+
+
- - 1 + Updated + + May 20, 2017 +
- -
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
-
-
-
- - - + + + +
+
, @@ -1504,640 +1548,662 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its "baseElement":
- -
- - I am a robot and this is a test! - -
-
+ +
+
+ + I am a robot and this is a test! + +
- gitify-app -
- -
- - Updated - - - May 20, 2017 - -
-
- +
- - 1 + Updated + + May 20, 2017 +
-
-
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
-
-
-
- - - + + + +
+
, "container":
- -
- - I am a robot and this is a test! - -
-
+
- - Updated - - - May 20, 2017 - -
-
- + I am a robot and this is a test! + +
+
+
- - 1 + Updated + + May 20, 2017 +
- -
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
-
-
-
- - - + + + +
+
, @@ -2196,645 +2262,667 @@ exports[`renderer/components/notifications/NotificationRow.tsx should render its `; exports[`renderer/components/notifications/NotificationRow.tsx should render itself & its children - notification is read 1`] = ` -{ - "asFragment": [Function], - "baseElement": -
-
-
- - -
-
- - I am a robot and this is a test! - - -
+{ + "asFragment": [Function], + "baseElement": +
+
+
+
+
- - Updated - - - May 20, 2017 - -
-
- + I am a robot and this is a test! + + +
+
+
- - 1 + Updated + + May 20, 2017 +
- -
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
-
-
-
- - - + + + +
+
, "container":
- -
- - I am a robot and this is a test! - - -
-
+
- - Updated - - - May 20, 2017 - -
-
- + I am a robot and this is a test! + + +
+
+
- - 1 + Updated + + May 20, 2017 +
- -
- +
+ + + 1 + +
+ - 1 +
+ + + 1 + +
-
+
-
-
-
- - - + + + +
+
, diff --git a/src/renderer/components/notifications/__snapshots__/RepositoryNotifications.test.tsx.snap b/src/renderer/components/notifications/__snapshots__/RepositoryNotifications.test.tsx.snap index 418d22b09..37c845653 100644 --- a/src/renderer/components/notifications/__snapshots__/RepositoryNotifications.test.tsx.snap +++ b/src/renderer/components/notifications/__snapshots__/RepositoryNotifications.test.tsx.snap @@ -6,382 +6,404 @@ exports[`renderer/components/notifications/RepositoryNotifications.tsx should re "baseElement":
-
+ + + + +  ( + 2 + ) + + + + +
- -
+
+
+ NotificationRow +
+
+ NotificationRow +
+ + + + , + "container":
+
+
- - -
-
-
- NotificationRow -
-
- NotificationRow -
-
- , - "container":
-
- + + -
- - - + + +
+
+
+ NotificationRow +
+
+ NotificationRow +
-
- NotificationRow -
-
- NotificationRow -
, "debug": [Function], "findAllByAltText": [Function], @@ -443,382 +465,404 @@ exports[`renderer/components/notifications/RepositoryNotifications.tsx should re "baseElement":
-
+ + + + +  ( + 2 + ) + + + + +
- -
+
+
+ NotificationRow +
+
+ NotificationRow +
+ + + + , + "container":
+
+
- - -
-
-
- NotificationRow -
-
- NotificationRow -
-
- , - "container":
-
- + + -
- - - + + +
+
+
+ NotificationRow +
+
+ NotificationRow +
-
- NotificationRow -
-
- NotificationRow -
, "debug": [Function], "findAllByAltText": [Function], @@ -880,586 +924,619 @@ exports[`renderer/components/notifications/RepositoryNotifications.tsx should to "baseElement":
- +
+
- - -
- +
+
- - -
+
+
+ NotificationRow +
+
+ NotificationRow +
+ + + + , + "container":
+
+
- - -
-
-
- NotificationRow -
-
- NotificationRow -
-
- , - "container":
-
- + -
- - - + + +
+
+
+ NotificationRow +
+
+ NotificationRow +
-
- NotificationRow -
-
- NotificationRow -
, "debug": [Function], "findAllByAltText": [Function], @@ -1521,396 +1598,418 @@ exports[`renderer/components/notifications/RepositoryNotifications.tsx should us "baseElement":
- +
+
- - -
+
+
+ NotificationRow +
+
+ NotificationRow +
+ + + + , + "container":
+
+
- - -
-
-
- NotificationRow -
-
- NotificationRow -
-
- , - "container":
-
- + -
- - - + + +
+
+
+ NotificationRow +
+
+ NotificationRow +
-
- NotificationRow -
-
- NotificationRow -
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/primitives/CustomCounter.test.tsx b/src/renderer/components/primitives/CustomCounter.test.tsx index d477615c5..3533ca63d 100644 --- a/src/renderer/components/primitives/CustomCounter.test.tsx +++ b/src/renderer/components/primitives/CustomCounter.test.tsx @@ -1,10 +1,9 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { CustomCounter } from './CustomCounter'; describe('renderer/components/primitives/CustomCounter.tsx', () => { it('should render itself & its children', () => { - const tree = render(); + const tree = renderWithAppContext(); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/primitives/EmojiText.test.tsx b/src/renderer/components/primitives/EmojiText.test.tsx index 4a374c56b..3d1186fe7 100644 --- a/src/renderer/components/primitives/EmojiText.test.tsx +++ b/src/renderer/components/primitives/EmojiText.test.tsx @@ -1,5 +1,6 @@ -import { act, render } from '@testing-library/react'; +import { act } from '@testing-library/react'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { EmojiText, type IEmojiText } from './EmojiText'; describe('renderer/components/primitives/EmojiText.tsx', () => { @@ -8,10 +9,10 @@ describe('renderer/components/primitives/EmojiText.tsx', () => { text: '🍺', }; - let tree: ReturnType | null = null; + let tree: ReturnType | null = null; await act(async () => { - tree = render(); + tree = renderWithAppContext(); }); expect(tree).toMatchSnapshot(); diff --git a/src/renderer/components/primitives/Footer.test.tsx b/src/renderer/components/primitives/Footer.test.tsx index e932c704e..6f8cb1fa4 100644 --- a/src/renderer/components/primitives/Footer.test.tsx +++ b/src/renderer/components/primitives/Footer.test.tsx @@ -1,16 +1,17 @@ -import { render } from '@testing-library/react'; - +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { Footer } from './Footer'; describe('renderer/components/primitives/Footer.tsx', () => { it('should render itself & its children - space-between', () => { - const tree = render(
Test
); + const tree = renderWithAppContext( +
Test
, + ); expect(tree).toMatchSnapshot(); }); it('should render itself & its children - end', () => { - const tree = render(
Test
); + const tree = renderWithAppContext(
Test
); expect(tree).toMatchSnapshot(); }); diff --git a/src/renderer/components/primitives/Header.test.tsx b/src/renderer/components/primitives/Header.test.tsx index bc90e3d57..7a1f665b2 100644 --- a/src/renderer/components/primitives/Header.test.tsx +++ b/src/renderer/components/primitives/Header.test.tsx @@ -1,9 +1,9 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { MarkGithubIcon } from '@primer/octicons-react'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { Header } from './Header'; const mockNavigate = jest.fn(); @@ -13,20 +13,22 @@ jest.mock('react-router-dom', () => ({ })); describe('renderer/components/primitives/Header.tsx', () => { - const fetchNotifications = jest.fn(); + const mockFetchNotifications = jest.fn(); afterEach(() => { jest.resetAllMocks(); }); it('should render itself & its children', () => { - const tree = render(
Test Header
); + const tree = renderWithAppContext( +
Test Header
, + ); expect(tree).toMatchSnapshot(); }); it('should navigate back', async () => { - render(
Test Header
); + renderWithAppContext(
Test Header
); await userEvent.click(screen.getByTestId('header-nav-back')); @@ -34,21 +36,16 @@ describe('renderer/components/primitives/Header.tsx', () => { }); it('should navigate back and fetch notifications', async () => { - render( - -
- Test Header -
-
, + renderWithAppContext( +
+ Test Header +
, + { fetchNotifications: mockFetchNotifications }, ); await userEvent.click(screen.getByTestId('header-nav-back')); expect(mockNavigate).toHaveBeenNthCalledWith(1, -1); - expect(fetchNotifications).toHaveBeenCalledTimes(1); + expect(mockFetchNotifications).toHaveBeenCalledTimes(1); }); }); diff --git a/src/renderer/components/primitives/HoverButton.test.tsx b/src/renderer/components/primitives/HoverButton.test.tsx index adc447273..3956da573 100644 --- a/src/renderer/components/primitives/HoverButton.test.tsx +++ b/src/renderer/components/primitives/HoverButton.test.tsx @@ -1,14 +1,13 @@ -import { render } from '@testing-library/react'; - import { MarkGithubIcon } from '@primer/octicons-react'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { HoverButton } from './HoverButton'; describe('renderer/components/primitives/HoverButton.tsx', () => { it('should render', () => { const mockAction = jest.fn(); - const tree = render( + const tree = renderWithAppContext( { it('should render - disabled', () => { const mockAction = jest.fn(); - const tree = render( + const tree = renderWithAppContext( { it('should render', () => { - const tree = render( + const tree = renderWithAppContext( Hover Group , diff --git a/src/renderer/components/primitives/Title.test.tsx b/src/renderer/components/primitives/Title.test.tsx index b134bc91e..eb0b7b2d7 100644 --- a/src/renderer/components/primitives/Title.test.tsx +++ b/src/renderer/components/primitives/Title.test.tsx @@ -1,18 +1,19 @@ -import { render } from '@testing-library/react'; - import { PersonFillIcon } from '@primer/octicons-react'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { Title } from './Title'; describe('renderer/routes/components/primitives/Title.tsx', () => { it('should render the title - default size', async () => { - const { container } = render(Legend); + const { container } = renderWithAppContext( + Legend, + ); expect(container).toMatchSnapshot(); }); it('should render the title - specific size', async () => { - const { container } = render( + const { container } = renderWithAppContext( Legend , diff --git a/src/renderer/components/primitives/__snapshots__/CustomCounter.test.tsx.snap b/src/renderer/components/primitives/__snapshots__/CustomCounter.test.tsx.snap index e886442b1..97e8c2405 100644 --- a/src/renderer/components/primitives/__snapshots__/CustomCounter.test.tsx.snap +++ b/src/renderer/components/primitives/__snapshots__/CustomCounter.test.tsx.snap @@ -5,19 +5,41 @@ exports[`renderer/components/primitives/CustomCounter.tsx should render itself & "asFragment": [Function], "baseElement":
- - 100 - +
+ + 100 + +
+
, "container":
- - 100 - +
+ + 100 + +
+
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/primitives/__snapshots__/EmojiText.test.tsx.snap b/src/renderer/components/primitives/__snapshots__/EmojiText.test.tsx.snap index 9474fc8e9..1f1db6f7c 100644 --- a/src/renderer/components/primitives/__snapshots__/EmojiText.test.tsx.snap +++ b/src/renderer/components/primitives/__snapshots__/EmojiText.test.tsx.snap @@ -6,27 +6,49 @@ exports[`renderer/components/primitives/EmojiText.tsx should render 1`] = ` "baseElement":
- 🍺 +
+
+ 🍺 +
+
, "container":
- 🍺 +
+
+ 🍺 +
+
, "debug": [Function], diff --git a/src/renderer/components/primitives/__snapshots__/Footer.test.tsx.snap b/src/renderer/components/primitives/__snapshots__/Footer.test.tsx.snap index d2f027b24..9cfa61637 100644 --- a/src/renderer/components/primitives/__snapshots__/Footer.test.tsx.snap +++ b/src/renderer/components/primitives/__snapshots__/Footer.test.tsx.snap @@ -6,34 +6,56 @@ exports[`renderer/components/primitives/Footer.tsx should render itself & its ch "baseElement":
, "container":
, @@ -97,34 +119,56 @@ exports[`renderer/components/primitives/Footer.tsx should render itself & its ch "baseElement":
, "container":
, diff --git a/src/renderer/components/primitives/__snapshots__/Header.test.tsx.snap b/src/renderer/components/primitives/__snapshots__/Header.test.tsx.snap index 8c8ad8ee9..9b8488282 100644 --- a/src/renderer/components/primitives/__snapshots__/Header.test.tsx.snap +++ b/src/renderer/components/primitives/__snapshots__/Header.test.tsx.snap @@ -6,62 +6,40 @@ exports[`renderer/components/primitives/Header.tsx should render itself & its ch "baseElement":
- -
-
-

+ +
- Test Header -

-
+
+ +

+ Test Header +

+
+
+
- +
, "container":
- -
-
-

+ +
- Test Header -

-
+
+ +

+ Test Header +

+
+
+
- +
, diff --git a/src/renderer/components/primitives/__snapshots__/HoverButton.test.tsx.snap b/src/renderer/components/primitives/__snapshots__/HoverButton.test.tsx.snap index 2f8faf61f..fa46e4d70 100644 --- a/src/renderer/components/primitives/__snapshots__/HoverButton.test.tsx.snap +++ b/src/renderer/components/primitives/__snapshots__/HoverButton.test.tsx.snap @@ -4,9 +4,31 @@ exports[`renderer/components/primitives/HoverButton.tsx should render - disabled { "asFragment": [Function], "baseElement": -
+
+
+
+
+
, - "container":
, + "container":
+
+
+
+
, "debug": [Function], "findAllByAltText": [Function], "findAllByDisplayValue": [Function], @@ -66,69 +88,91 @@ exports[`renderer/components/primitives/HoverButton.tsx should render 1`] = ` "asFragment": [Function], "baseElement":
- + +
+
, "container":
- + +
+
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/components/primitives/__snapshots__/HoverGroup.test.tsx.snap b/src/renderer/components/primitives/__snapshots__/HoverGroup.test.tsx.snap index 9b64288f0..1fcf38d90 100644 --- a/src/renderer/components/primitives/__snapshots__/HoverGroup.test.tsx.snap +++ b/src/renderer/components/primitives/__snapshots__/HoverGroup.test.tsx.snap @@ -6,29 +6,51 @@ exports[`renderer/components/primitives/HoverGroup.tsx should render 1`] = ` "baseElement":
- Hover Group +
+
+ Hover Group +
+
, "container":
- Hover Group +
+
+ Hover Group +
+
, "debug": [Function], diff --git a/src/renderer/components/primitives/__snapshots__/Title.test.tsx.snap b/src/renderer/components/primitives/__snapshots__/Title.test.tsx.snap index 6eb907e2d..69ed7dc05 100644 --- a/src/renderer/components/primitives/__snapshots__/Title.test.tsx.snap +++ b/src/renderer/components/primitives/__snapshots__/Title.test.tsx.snap @@ -2,86 +2,108 @@ exports[`renderer/routes/components/primitives/Title.tsx should render the title - default size 1`] = `
- +
-
-
- - -

- Legend -

-
+
+ +

+ Legend +

+
+
+
- +
`; exports[`renderer/routes/components/primitives/Title.tsx should render the title - specific size 1`] = `
- +
-
- -

+
- Legend -

-
+
+ +

+ Legend +

+
+
+
-
+
`; diff --git a/src/renderer/components/settings/AppearanceSettings.test.tsx b/src/renderer/components/settings/AppearanceSettings.test.tsx index 9aa4eacd7..1491bb5f4 100644 --- a/src/renderer/components/settings/AppearanceSettings.test.tsx +++ b/src/renderer/components/settings/AppearanceSettings.test.tsx @@ -1,16 +1,12 @@ -import { act, fireEvent, render, screen } from '@testing-library/react'; +import { act, fireEvent, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { - mockAuth, - mockGitHubAppAccount, - mockSettings, -} from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; +import { mockGitHubAppAccount } from '../../__mocks__/account-mocks'; import { AppearanceSettings } from './AppearanceSettings'; describe('renderer/components/settings/AppearanceSettings.tsx', () => { - const updateSetting = jest.fn(); + const mockUpdateSetting = jest.fn(); const zoomTimeout = () => new Promise((r) => setTimeout(r, 300)); afterEach(() => { @@ -19,17 +15,9 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { it('should change the theme mode dropdown', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.selectOptions( @@ -37,55 +25,40 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { 'LIGHT', ); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('theme', 'LIGHT'); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('theme', 'LIGHT'); }); it('should toggle increase contrast checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + auth: { + accounts: [mockGitHubAppAccount], + }, + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-increaseContrast')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('increaseContrast', true); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('increaseContrast', true); }); it('should update the zoom value when using CMD + and CMD -', async () => { window.gitify.zoom.getLevel = jest.fn().mockReturnValue(-1); await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); fireEvent(window, new Event('resize')); await zoomTimeout(); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('zoomPercentage', 50); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('zoomPercentage', 50); }); it('should update the zoom values when using the zoom buttons', async () => { @@ -96,17 +69,9 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { }); await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); // Zoom Out @@ -114,16 +79,20 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { await userEvent.click(screen.getByTestId('settings-zoom-out')); await zoomTimeout(); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('zoomPercentage', 90); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('zoomPercentage', 90); }); await act(async () => { await userEvent.click(screen.getByTestId('settings-zoom-out')); await zoomTimeout(); - expect(updateSetting).toHaveBeenCalledTimes(2); - expect(updateSetting).toHaveBeenNthCalledWith(2, 'zoomPercentage', 80); + expect(mockUpdateSetting).toHaveBeenCalledTimes(2); + expect(mockUpdateSetting).toHaveBeenNthCalledWith( + 2, + 'zoomPercentage', + 80, + ); }); // Zoom In @@ -131,8 +100,12 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { await userEvent.click(screen.getByTestId('settings-zoom-in')); await zoomTimeout(); - expect(updateSetting).toHaveBeenCalledTimes(3); - expect(updateSetting).toHaveBeenNthCalledWith(3, 'zoomPercentage', 90); + expect(mockUpdateSetting).toHaveBeenCalledTimes(3); + expect(mockUpdateSetting).toHaveBeenNthCalledWith( + 3, + 'zoomPercentage', + 90, + ); }); // Zoom Reset @@ -140,54 +113,47 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => { await userEvent.click(screen.getByTestId('settings-zoom-reset')); await zoomTimeout(); - expect(updateSetting).toHaveBeenCalledTimes(4); - expect(updateSetting).toHaveBeenNthCalledWith(4, 'zoomPercentage', 100); + expect(mockUpdateSetting).toHaveBeenCalledTimes(4); + expect(mockUpdateSetting).toHaveBeenNthCalledWith( + 4, + 'zoomPercentage', + 100, + ); }); }); it('should toggle account header checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + auth: { + accounts: [mockGitHubAppAccount], + }, + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-showAccountHeader')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('showAccountHeader', true); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('showAccountHeader', true); }); it('should toggle wrap notification title checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + auth: { + accounts: [mockGitHubAppAccount], + }, + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-wrapNotificationTitle')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('wrapNotificationTitle', true); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith( + 'wrapNotificationTitle', + true, + ); }); }); diff --git a/src/renderer/components/settings/NotificationSettings.test.tsx b/src/renderer/components/settings/NotificationSettings.test.tsx index e7e8a1ba3..bf0463b7a 100644 --- a/src/renderer/components/settings/NotificationSettings.test.tsx +++ b/src/renderer/components/settings/NotificationSettings.test.tsx @@ -1,16 +1,14 @@ -import { act, render, screen } from '@testing-library/react'; +import { act, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { BaseStyles, ThemeProvider } from '@primer/react'; - -import { mockAuth, mockSettings } from '../../__mocks__/state-mocks'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; +import { mockSettings } from '../../__mocks__/state-mocks'; import { Constants } from '../../constants'; -import { AppContext } from '../../context/App'; import * as comms from '../../utils/comms'; import { NotificationSettings } from './NotificationSettings'; describe('renderer/components/settings/NotificationSettings.tsx', () => { - const updateSetting = jest.fn(); + const mockUpdateSetting = jest.fn(); afterEach(() => { jest.clearAllMocks(); @@ -18,60 +16,36 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { it('should change the groupBy radio group', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('radio-groupBy-date')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('groupBy', 'DATE'); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('groupBy', 'DATE'); }); it('should change the fetchType radio group', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('radio-fetchType-inactivity')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('fetchType', 'INACTIVITY'); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('fetchType', 'INACTIVITY'); }); describe('fetch interval settings', () => { it('should update the fetch interval values when using the buttons', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); // Increase fetch interval @@ -80,8 +54,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-increase'), ); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('fetchInterval', 120000); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('fetchInterval', 120000); }); await act(async () => { @@ -89,8 +63,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-increase'), ); - expect(updateSetting).toHaveBeenCalledTimes(2); - expect(updateSetting).toHaveBeenNthCalledWith( + expect(mockUpdateSetting).toHaveBeenCalledTimes(2); + expect(mockUpdateSetting).toHaveBeenNthCalledWith( 2, 'fetchInterval', 180000, @@ -103,8 +77,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-decrease'), ); - expect(updateSetting).toHaveBeenCalledTimes(3); - expect(updateSetting).toHaveBeenNthCalledWith( + expect(mockUpdateSetting).toHaveBeenCalledTimes(3); + expect(mockUpdateSetting).toHaveBeenNthCalledWith( 3, 'fetchInterval', 120000, @@ -117,8 +91,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-reset'), ); - expect(updateSetting).toHaveBeenCalledTimes(4); - expect(updateSetting).toHaveBeenNthCalledWith( + expect(mockUpdateSetting).toHaveBeenCalledTimes(4); + expect(mockUpdateSetting).toHaveBeenNthCalledWith( 4, 'fetchInterval', 60000, @@ -128,22 +102,15 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { it('should prevent going lower than minimum interval', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + settings: { + ...mockSettings, + fetchInterval: + Constants.MIN_FETCH_NOTIFICATIONS_INTERVAL_MS + + Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS, + }, + updateSetting: mockUpdateSetting, + }); }); await act(async () => { @@ -151,8 +118,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-decrease'), ); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenNthCalledWith( + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenNthCalledWith( 1, 'fetchInterval', 60000, @@ -165,28 +132,21 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-decrease'), ); - expect(updateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); }); }); it('should prevent going above maximum interval', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + settings: { + ...mockSettings, + fetchInterval: + Constants.MAX_FETCH_NOTIFICATIONS_INTERVAL_MS - + Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS, + }, + updateSetting: mockUpdateSetting, + }); }); await act(async () => { @@ -194,8 +154,8 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-increase'), ); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenNthCalledWith( + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenNthCalledWith( 1, 'fetchInterval', 3600000, @@ -208,137 +168,91 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { screen.getByTestId('settings-fetch-interval-increase'), ); - expect(updateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); }); }); }); it('should toggle the fetchAllNotifications checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-fetchAllNotifications')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('fetchAllNotifications', false); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith( + 'fetchAllNotifications', + false, + ); }); it('should toggle detailed notifications checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-detailedNotifications')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('detailedNotifications', false); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith( + 'detailedNotifications', + false, + ); }); it('should toggle metric pills checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-showPills')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('showPills', false); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('showPills', false); }); it('should toggle show number checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-showNumber')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('showNumber', false); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('showNumber', false); }); it('should toggle the showOnlyParticipating checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-showOnlyParticipating')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('participating', true); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('participating', true); }); it('should open official docs for showOnlyParticipating tooltip', async () => { - const openExternalLinkMock = jest + const mockOpenExternalLink = jest .spyOn(comms, 'openExternalLink') .mockImplementation(); await act(async () => { - render( - - - - - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); const tooltipElement = screen.getByLabelText( @@ -352,76 +266,58 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => { ), ); - expect(openExternalLinkMock).toHaveBeenCalledTimes(1); - expect(openExternalLinkMock).toHaveBeenCalledWith( + expect(mockOpenExternalLink).toHaveBeenCalledTimes(1); + expect(mockOpenExternalLink).toHaveBeenCalledWith( 'https://docs.github.com/en/account-and-profile/managing-subscriptions-and-notifications-on-github/setting-up-notifications/configuring-notifications#about-participating-and-watching-notifications', ); }); it('should toggle the markAsDoneOnOpen checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-markAsDoneOnOpen')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('markAsDoneOnOpen', true); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('markAsDoneOnOpen', true); }); it('should toggle the markAsDoneOnUnsubscribe checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click( screen.getByTestId('checkbox-markAsDoneOnUnsubscribe'), ); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('markAsDoneOnUnsubscribe', true); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith( + 'markAsDoneOnUnsubscribe', + true, + ); }); it('should toggle the delayNotificationState checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click( screen.getByTestId('checkbox-delayNotificationState'), ); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('delayNotificationState', true); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith( + 'delayNotificationState', + true, + ); }); }); diff --git a/src/renderer/components/settings/SettingsFooter.test.tsx b/src/renderer/components/settings/SettingsFooter.test.tsx index 4fec2ae51..f7438c8eb 100644 --- a/src/renderer/components/settings/SettingsFooter.test.tsx +++ b/src/renderer/components/settings/SettingsFooter.test.tsx @@ -1,8 +1,7 @@ -import { act, render, screen } from '@testing-library/react'; +import { act, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { mockAuth, mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import * as comms from '../../utils/comms'; import { SettingsFooter } from './SettingsFooter'; @@ -27,59 +26,32 @@ describe('renderer/components/settings/SettingsFooter.tsx', () => { it('should show app version', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(); }); expect(screen.getByTestId('settings-release-notes')).toMatchSnapshot(); }); it('should open release notes', async () => { - const openExternalLinkMock = jest + const mockOpenExternalLink = jest .spyOn(comms, 'openExternalLink') .mockImplementation(); await act(async () => { - render( - - - , - ); + renderWithAppContext(); }); await userEvent.click(screen.getByTestId('settings-release-notes')); - expect(openExternalLinkMock).toHaveBeenCalledTimes(1); - expect(openExternalLinkMock).toHaveBeenCalledWith( + expect(mockOpenExternalLink).toHaveBeenCalledTimes(1); + expect(mockOpenExternalLink).toHaveBeenCalledWith( 'https://github.com/gitify-app/gitify/releases/tag/v0.0.1', ); }); it('should open account management', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(); }); await userEvent.click(screen.getByTestId('settings-accounts')); @@ -88,23 +60,14 @@ describe('renderer/components/settings/SettingsFooter.tsx', () => { }); it('should quit the app', async () => { - const quitAppMock = jest.spyOn(comms, 'quitApp'); + const mockQuitApp = jest.spyOn(comms, 'quitApp'); await act(async () => { - render( - - - , - ); + renderWithAppContext(); }); await userEvent.click(screen.getByTestId('settings-quit')); - expect(quitAppMock).toHaveBeenCalledTimes(1); + expect(mockQuitApp).toHaveBeenCalledTimes(1); }); }); diff --git a/src/renderer/components/settings/SettingsReset.test.tsx b/src/renderer/components/settings/SettingsReset.test.tsx index ef058dc2b..daa7770f2 100644 --- a/src/renderer/components/settings/SettingsReset.test.tsx +++ b/src/renderer/components/settings/SettingsReset.test.tsx @@ -1,60 +1,43 @@ -import { act, render, screen } from '@testing-library/react'; +import { act, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { mockAuth, mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { SettingsReset } from './SettingsReset'; describe('renderer/components/settings/SettingsReset.tsx', () => { - const resetSettings = jest.fn(); + const mockResetSettings = jest.fn(); afterEach(() => { jest.clearAllMocks(); }); it('should reset default settings when `OK`', async () => { - window.confirm = jest.fn(() => true); // always click 'OK' + globalThis.confirm = jest.fn(() => true); // always click 'OK' await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + resetSettings: mockResetSettings, + }); }); await userEvent.click(screen.getByTestId('settings-reset')); await userEvent.click(screen.getByText('Reset')); - expect(resetSettings).toHaveBeenCalled(); + expect(mockResetSettings).toHaveBeenCalled(); }); it('should skip reset default settings when `cancelled`', async () => { - window.confirm = jest.fn(() => false); // always click 'cancel' + globalThis.confirm = jest.fn(() => false); // always click 'cancel' await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + resetSettings: mockResetSettings, + }); }); await userEvent.click(screen.getByTestId('settings-reset')); await userEvent.click(screen.getByText('Cancel')); - expect(resetSettings).not.toHaveBeenCalled(); + expect(mockResetSettings).not.toHaveBeenCalled(); }); }); diff --git a/src/renderer/components/settings/SystemSettings.test.tsx b/src/renderer/components/settings/SystemSettings.test.tsx index 23f4dce74..ba7933640 100644 --- a/src/renderer/components/settings/SystemSettings.test.tsx +++ b/src/renderer/components/settings/SystemSettings.test.tsx @@ -1,13 +1,13 @@ -import { act, render, screen } from '@testing-library/react'; +import { act, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { mockAuth, mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; +import { mockSettings } from '../../__mocks__/state-mocks'; import type { Percentage } from '../../types'; import { SystemSettings } from './SystemSettings'; describe('renderer/components/settings/SystemSettings.tsx', () => { - const updateSetting = jest.fn(); + const mockUpdateSetting = jest.fn(); afterEach(() => { jest.clearAllMocks(); @@ -15,181 +15,100 @@ describe('renderer/components/settings/SystemSettings.tsx', () => { it('should change the open links radio group', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('radio-openLinks-background')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('openLinks', 'BACKGROUND'); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('openLinks', 'BACKGROUND'); }); it('should toggle the keyboardShortcut checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-keyboardShortcut')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('keyboardShortcut', false); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('keyboardShortcut', false); }); it('should toggle the showNotifications checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-showNotifications')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('showNotifications', false); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('showNotifications', false); }); describe('playSound', () => { it('should toggle the playSound checkbox', async () => { - const { rerender } = render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); await userEvent.click(screen.getByTestId('checkbox-playSound')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('playSound', false); - - // Simulate update to context with playSound = false - rerender( - - - , - ); - - expect(screen.getByTestId('settings-volume-group')).not.toBeVisible(); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('playSound', false); }); it('should increase notification volume', async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); await userEvent.click(screen.getByTestId('settings-volume-up')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('notificationVolume', 30); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('notificationVolume', 30); }); it('should decrease notification volume', async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); await userEvent.click(screen.getByTestId('settings-volume-down')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('notificationVolume', 10); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('notificationVolume', 10); }); it('should reset notification volume', async () => { - render( - - - , - ); + renderWithAppContext(, { + settings: { ...mockSettings, notificationVolume: 30 as Percentage }, + updateSetting: mockUpdateSetting, + }); await userEvent.click(screen.getByTestId('settings-volume-reset')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('notificationVolume', 20); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('notificationVolume', 20); }); }); it('should toggle the openAtStartup checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-openAtStartup')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('openAtStartup', true); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith('openAtStartup', true); }); }); diff --git a/src/renderer/components/settings/TraySettings.test.tsx b/src/renderer/components/settings/TraySettings.test.tsx index 98737b2cd..422cffd18 100644 --- a/src/renderer/components/settings/TraySettings.test.tsx +++ b/src/renderer/components/settings/TraySettings.test.tsx @@ -1,12 +1,11 @@ -import { act, render, screen } from '@testing-library/react'; +import { act, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { mockAuth, mockSettings } from '../../__mocks__/state-mocks'; -import { AppContext } from '../../context/App'; +import { renderWithAppContext } from '../../__helpers__/test-utils'; import { TraySettings } from './TraySettings'; describe('renderer/components/settings/TraySettings.tsx', () => { - const updateSetting = jest.fn(); + const mockUpdateSetting = jest.fn(); afterEach(() => { jest.clearAllMocks(); @@ -14,25 +13,17 @@ describe('renderer/components/settings/TraySettings.tsx', () => { it('should toggle the showNotificationsCountInTray checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click( screen.getByTestId('checkbox-showNotificationsCountInTray'), ); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith( + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith( 'showNotificationsCountInTray', false, ); @@ -40,43 +31,33 @@ describe('renderer/components/settings/TraySettings.tsx', () => { it('should toggle the useUnreadActiveIcon checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-useUnreadActiveIcon')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('useUnreadActiveIcon', false); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith( + 'useUnreadActiveIcon', + false, + ); }); it('should toggle the useAlternateIdleIcon checkbox', async () => { await act(async () => { - render( - - - , - ); + renderWithAppContext(, { + updateSetting: mockUpdateSetting, + }); }); await userEvent.click(screen.getByTestId('checkbox-useAlternateIdleIcon')); - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('useAlternateIdleIcon', true); + expect(mockUpdateSetting).toHaveBeenCalledTimes(1); + expect(mockUpdateSetting).toHaveBeenCalledWith( + 'useAlternateIdleIcon', + true, + ); }); }); diff --git a/src/renderer/components/settings/__snapshots__/SettingsFooter.test.tsx.snap b/src/renderer/components/settings/__snapshots__/SettingsFooter.test.tsx.snap index 3e4b49a6e..a02b0f6ca 100644 --- a/src/renderer/components/settings/__snapshots__/SettingsFooter.test.tsx.snap +++ b/src/renderer/components/settings/__snapshots__/SettingsFooter.test.tsx.snap @@ -2,7 +2,7 @@ exports[`renderer/components/settings/SettingsFooter.tsx should show app version 1`] = ` - -
-
- -

- Accounts -

-
-
-
- - -
-
-
-
- -
-
-
-
-
- - - Mona Lisa Octocat - -
-
- - - github.com - -
-
- - - Personal Access Token - -
-
-
-
- - - - -
- -
- - - -
-
-
-
-
-
-
- -
-
-
-
-
- - - Mona Lisa Octocat - -
-
- - - github.gitify.io - -
-
- - - OAuth App - -
-
-
-
- - - - -
- -
- - - -
-
-
-
-
-
-
- -
-
-
-
-
- - - Mona Lisa Octocat - -
-
- - - github.com - -
-
- - - GitHub App - -
-
-
-
- - - - -
- -
- - - -
-
-
-
-
- - -`; - -exports[`renderer/routes/Accounts.tsx Account interactions should set account as primary account 1`] = ` -
-
-
- - -
-
- -

- Accounts -

-
-
-
-
-
-
-
-
-
- -
-
-
-
-
- - - Mona Lisa Octocat - -
-
- - - github.com - -
-
- - - Personal Access Token - -
-
-
-
- - - - -
- -
- - - -
-
-
-
-
-
-
- -
-
-
-
-
- - - Mona Lisa Octocat - -
-
- - - github.gitify.io - -
-
- - - OAuth App - -
-
-
-
- - - - -
- -
- - - -
-
-
-
-
-
-
- -
-
-
-
-
- - - Mona Lisa Octocat - -
-
- - - github.com - -
-
- - - GitHub App - -
-
-
-
- - - - -
- -
- - - -
-
-
-
-
- -
-`; - -exports[`renderer/routes/Accounts.tsx General should render itself & its children 1`] = ` -
-
-
- - -
-
- -

- Accounts -

-
-
-
-
-
-
-
-
-
- -
-
-
-
-
- - - Mona Lisa Octocat - -
-
- - - github.com - -
-
- - - Personal Access Token - -
-
-
-
- - - - -
- -
- - - -
-
-
-
-
-
-
- -
-
-
-
-
- - - Mona Lisa Octocat - -
-
- - - github.gitify.io - -
-
- - - OAuth App - -
-
-
-
- - - - -
- -
- - - -
-
-
-
-
-
-
- -
-
-
-
-
- - - Mona Lisa Octocat - -
-
- - - github.com - -
-
- - - GitHub App - -
-
-
-
- - - - -
- -
- - - -
-
-
-
-
- -
-`; diff --git a/src/renderer/routes/__snapshots__/Filters.test.tsx.snap b/src/renderer/routes/__snapshots__/Filters.test.tsx.snap index 3887338dc..b618312f0 100644 --- a/src/renderer/routes/__snapshots__/Filters.test.tsx.snap +++ b/src/renderer/routes/__snapshots__/Filters.test.tsx.snap @@ -17,7 +17,7 @@ exports[`renderer/routes/Filters.tsx General should render itself & its children data-wrap="nowrap" > - - + + + + + + GitHub + + + + + + + @@ -235,228 +246,239 @@ exports[`renderer/routes/Login.tsx should render itself & its children 1`] = ` , "container":
- -
-

- GitHub Notifications -

-

- on your menu bar -

-
- - Login with - - - -
+
- + Login with - - OAuth App - - - + + + + + + GitHub + + + + + +
+
diff --git a/src/renderer/routes/__snapshots__/LoginWithOAuthApp.test.tsx.snap b/src/renderer/routes/__snapshots__/LoginWithOAuthApp.test.tsx.snap index 9707a5e76..b68ec672e 100644 --- a/src/renderer/routes/__snapshots__/LoginWithOAuthApp.test.tsx.snap +++ b/src/renderer/routes/__snapshots__/LoginWithOAuthApp.test.tsx.snap @@ -6,66 +6,44 @@ exports[`renderer/routes/LoginWithOAuthApp.tsx renders correctly 1`] = ` "baseElement":
- -
-
-

+ +
- Login with OAuth App -

-
+
+ +

+ Login with OAuth App +

+
+
+
- -
-
-
-
+
- - - - - +
+ + + and use your + + client id & secret + + below. + +
+
+ + + + +
+
+ + + + + + + + +
+
+
+ +
+ + + + , + "container":
+
+
+
+
+ +
+
- +

+ Login with OAuth App +

+
+
+
+
+
+
+
+
+ + + - - - and use your - - client id & secret - - below. - -
-
-
+
- - - Client ID - - - * + + + + + + Create new OAuth App + + + + and use your + + client id & secret + + below. - - - - -
-
-
-
- -
-
- , - "container":
-
-
-
- - -
-
- -

- Login with OAuth App -

-
-
-
-
-
-
-
-
- - - - - - - Change only if you are using GitHub Enterprise Server - - -
-
- - - and use your - - client id & secret - - below. - -
-
- - - - -
-
- - - - - - - -
-
-
-
diff --git a/src/renderer/routes/__snapshots__/LoginWithPersonalAccessToken.test.tsx.snap b/src/renderer/routes/__snapshots__/LoginWithPersonalAccessToken.test.tsx.snap index 90139820e..aee7a7dd4 100644 --- a/src/renderer/routes/__snapshots__/LoginWithPersonalAccessToken.test.tsx.snap +++ b/src/renderer/routes/__snapshots__/LoginWithPersonalAccessToken.test.tsx.snap @@ -6,66 +6,44 @@ exports[`renderer/routes/LoginWithPersonalAccessToken.tsx renders correctly 1`] "baseElement":
- -
-
-

+ +
- Login with Personal Access Token -

-
+
+ +

+ Login with Personal Access Token +

+
+
+
- -
-
-
-
+
- - - - - - +
- Change only if you are using GitHub Enterprise Server - - +
+ + + on GitHub to paste the token below. + +
+ + The + + + + + will be automatically selected for you. + +
+
+ + + + + + + + +
+
- - on GitHub to paste the token below. - -
- - The - - - - will be automatically selected for you. - -
-
- - - - - - - +
+
+ + + , + "container":
+
+
-
-
- , - "container":
-
-
-
- -
+
+ + + + + + + Change only if you are using GitHub Enterprise Server + + +
- -

+ + + + + + Generate a PAT + + + + + on GitHub to paste the token below. + +

+ - Login with Personal Access Token - + The + + + + + will be automatically selected for you. +
-
- -
-
-
-
-
- - - - - - - Change only if you are using GitHub Enterprise Server - - +
+
- - on GitHub to paste the token below. - -
- - The - - - - will be automatically selected for you. - -
-
- - - - - - - -
-
-
- diff --git a/src/renderer/routes/__snapshots__/Notifications.test.tsx.snap b/src/renderer/routes/__snapshots__/Notifications.test.tsx.snap index e2500c2b2..c5fbe4781 100644 --- a/src/renderer/routes/__snapshots__/Notifications.test.tsx.snap +++ b/src/renderer/routes/__snapshots__/Notifications.test.tsx.snap @@ -5,15 +5,37 @@ exports[`renderer/routes/Notifications.tsx should render itself & its children ( "asFragment": [Function], "baseElement":
-

- AllRead -

+
+
+

+ AllRead +

+
+
, "container":
-

- AllRead -

+
+
+

+ AllRead +

+
+
, "debug": [Function], "findAllByAltText": [Function], @@ -74,15 +96,37 @@ exports[`renderer/routes/Notifications.tsx should render itself & its children ( "asFragment": [Function], "baseElement":
-

- Oops -

+
+
+

+ Oops +

+
+
, "container":
-

- Oops -

+
+
+

+ Oops +

+
+
, "debug": [Function], "findAllByAltText": [Function], @@ -143,15 +187,37 @@ exports[`renderer/routes/Notifications.tsx should render itself & its children ( "asFragment": [Function], "baseElement":
-

- Oops -

+
+
+

+ Oops +

+
+
, "container":
-

- Oops -

+
+
+

+ Oops +

+
+
, "debug": [Function], "findAllByAltText": [Function], @@ -212,15 +278,37 @@ exports[`renderer/routes/Notifications.tsx should render itself & its children ( "asFragment": [Function], "baseElement":
-

- Oops -

+
+
+

+ Oops +

+
+
, "container":
-

- Oops -

+
+
+

+ Oops +

+
+
, "debug": [Function], "findAllByAltText": [Function], @@ -281,15 +369,37 @@ exports[`renderer/routes/Notifications.tsx should render itself & its children ( "asFragment": [Function], "baseElement":
-

- Oops -

+
+
+

+ Oops +

+
+
, "container":
-

- Oops -

+
+
+

+ Oops +

+
+
, "debug": [Function], "findAllByAltText": [Function], @@ -350,15 +460,37 @@ exports[`renderer/routes/Notifications.tsx should render itself & its children ( "asFragment": [Function], "baseElement":
-

- Oops -

+
+
+

+ Oops +

+
+
, "container":
-

- Oops -

+
+
+

+ Oops +

+
+
, "debug": [Function], "findAllByAltText": [Function], @@ -419,15 +551,37 @@ exports[`renderer/routes/Notifications.tsx should render itself & its children ( "asFragment": [Function], "baseElement":
-

- AllRead -

+
+
+

+ AllRead +

+
+
, "container":
-

- AllRead -

+
+
+

+ AllRead +

+
+
, "debug": [Function], "findAllByAltText": [Function], @@ -488,15 +642,37 @@ exports[`renderer/routes/Notifications.tsx should render itself & its children ( "asFragment": [Function], "baseElement":
-

- AllRead -

+
+
+

+ AllRead +

+
+
, "container":
-

- AllRead -

+
+
+

+ AllRead +

+
+
, "debug": [Function], "findAllByAltText": [Function], diff --git a/src/renderer/routes/__snapshots__/Settings.test.tsx.snap b/src/renderer/routes/__snapshots__/Settings.test.tsx.snap index fc1029368..8654c70bf 100644 --- a/src/renderer/routes/__snapshots__/Settings.test.tsx.snap +++ b/src/renderer/routes/__snapshots__/Settings.test.tsx.snap @@ -17,7 +17,7 @@ exports[`renderer/routes/Settings.tsx should render itself & its children 1`] = data-wrap="nowrap" >