From f8e2ebe605c98ad1b1e489de15cde5ab170d7bbe Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 20 Mar 2024 09:55:21 -0400 Subject: [PATCH] refactor(jest): align test suite names to match code under test (#902) --- src/components/AllRead.test.tsx | 2 +- src/components/Loading.test.tsx | 2 +- src/components/Logo.test.tsx | 2 +- src/components/NotificationRow.test.tsx | 2 +- src/components/Oops.test.tsx | 2 +- .../__snapshots__/AllRead.test.tsx.snap | 2 +- .../__snapshots__/Logo.test.tsx.snap | 4 +- .../NotificationRow.test.tsx.snap | 2 +- .../__snapshots__/Oops.test.tsx.snap | 2 +- src/routes/LoginEnterprise.test.tsx | 2 +- src/routes/LoginWithToken.test.tsx | 2 +- src/routes/Notifications.test.tsx | 2 +- .../LoginEnterprise.test.tsx.snap | 2 +- .../LoginWithToken.test.tsx.snap | 2 +- .../__snapshots__/Notifications.test.tsx.snap | 6 +- .../__snapshots__/github-api.test.ts.snap | 62 +++---- src/utils/appearance.test.ts | 2 +- src/utils/github-api.test.ts | 168 +++++++++--------- src/utils/remove-notifications.test.ts | 2 +- src/utils/subject.test.ts | 2 +- 20 files changed, 136 insertions(+), 136 deletions(-) diff --git a/src/components/AllRead.test.tsx b/src/components/AllRead.test.tsx index e262e6418..fc3e06550 100644 --- a/src/components/AllRead.test.tsx +++ b/src/components/AllRead.test.tsx @@ -5,7 +5,7 @@ import { mockMathRandom } from './test-utils'; import { AllRead } from './AllRead'; -describe('components/all-read.tsx', function () { +describe('components/AllRead.tsx', function () { // The read emoji randomly rotates, but then the snapshots would never match // Have to make it consistent so the emojis are always the same mockMathRandom(0.1); diff --git a/src/components/Loading.test.tsx b/src/components/Loading.test.tsx index 21b06474b..5e96865f3 100644 --- a/src/components/Loading.test.tsx +++ b/src/components/Loading.test.tsx @@ -12,7 +12,7 @@ jest.mock('nprogress', () => ({ remove: jest.fn(), })); -describe('components/Loading.js', () => { +describe('components/Loading.tsx', () => { beforeEach(() => { jest.clearAllMocks(); }); diff --git a/src/components/Logo.test.tsx b/src/components/Logo.test.tsx index 2821b090e..10ab08db3 100644 --- a/src/components/Logo.test.tsx +++ b/src/components/Logo.test.tsx @@ -4,7 +4,7 @@ import { fireEvent, render } from '@testing-library/react'; import { Logo } from './Logo'; -describe('components/ui/logo.tsx', () => { +describe('components/Logo.tsx', () => { it('renders correctly (light)', () => { const tree = TestRenderer.create(); diff --git a/src/components/NotificationRow.test.tsx b/src/components/NotificationRow.test.tsx index 9158a62d6..035a77220 100644 --- a/src/components/NotificationRow.test.tsx +++ b/src/components/NotificationRow.test.tsx @@ -9,7 +9,7 @@ import { mockedSingleNotification } from '../__mocks__/mockedData'; import { NotificationRow } from './NotificationRow'; import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; -describe('components/Notification.js', () => { +describe('components/NotificationRow.tsx', () => { beforeEach(() => { jest.spyOn(helpers, 'openInBrowser'); }); diff --git a/src/components/Oops.test.tsx b/src/components/Oops.test.tsx index 816fa7020..68aa3ee72 100644 --- a/src/components/Oops.test.tsx +++ b/src/components/Oops.test.tsx @@ -5,7 +5,7 @@ import { mockMathRandom } from './test-utils'; import { Oops } from './Oops'; -describe('components/oops.tsx', function () { +describe('components/Oops.tsx', function () { // The error emoji randomly rotates, but then the snapshots would never match // Have to make it consistent so the emojis are always the same mockMathRandom(0.1); diff --git a/src/components/__snapshots__/AllRead.test.tsx.snap b/src/components/__snapshots__/AllRead.test.tsx.snap index 704062fd7..b1874989f 100644 --- a/src/components/__snapshots__/AllRead.test.tsx.snap +++ b/src/components/__snapshots__/AllRead.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`components/all-read.tsx should render itself & its children 1`] = ` +exports[`components/AllRead.tsx should render itself & its children 1`] = `
diff --git a/src/components/__snapshots__/Logo.test.tsx.snap b/src/components/__snapshots__/Logo.test.tsx.snap index 96060c7d0..635657bb8 100644 --- a/src/components/__snapshots__/Logo.test.tsx.snap +++ b/src/components/__snapshots__/Logo.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`components/ui/logo.tsx renders correctly (light) 1`] = ` +exports[`components/Logo.tsx renders correctly (light) 1`] = ` `; -exports[`components/ui/logo.tsx renders correctly(dark) 1`] = ` +exports[`components/Logo.tsx renders correctly(dark) 1`] = ` diff --git a/src/components/__snapshots__/Oops.test.tsx.snap b/src/components/__snapshots__/Oops.test.tsx.snap index c6ef9f63f..661f8d201 100644 --- a/src/components/__snapshots__/Oops.test.tsx.snap +++ b/src/components/__snapshots__/Oops.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`components/oops.tsx should render itself & its children 1`] = ` +exports[`components/Oops.tsx should render itself & its children 1`] = `
diff --git a/src/routes/LoginEnterprise.test.tsx b/src/routes/LoginEnterprise.test.tsx index f6c31c0f2..64c69f7d5 100644 --- a/src/routes/LoginEnterprise.test.tsx +++ b/src/routes/LoginEnterprise.test.tsx @@ -16,7 +16,7 @@ jest.mock('react-router-dom', () => ({ useNavigate: () => mockNavigate, })); -describe('routes/LoginEnterprise.js', () => { +describe('routes/LoginEnterprise.tsx', () => { const mockAccounts: AuthState = { enterpriseAccounts: [], user: null, diff --git a/src/routes/LoginWithToken.test.tsx b/src/routes/LoginWithToken.test.tsx index a1e0d0eb4..1e34d288c 100644 --- a/src/routes/LoginWithToken.test.tsx +++ b/src/routes/LoginWithToken.test.tsx @@ -13,7 +13,7 @@ jest.mock('react-router-dom', () => ({ useNavigate: () => mockNavigate, })); -describe('routes/LoginWithToken.js', () => { +describe('routes/LoginWithToken.tsx', () => { const openExternalMock = jest.spyOn(shell, 'openExternal'); const mockValidateToken = jest.fn(); diff --git a/src/routes/Notifications.test.tsx b/src/routes/Notifications.test.tsx index 89e37d7a6..9f7f8ee65 100644 --- a/src/routes/Notifications.test.tsx +++ b/src/routes/Notifications.test.tsx @@ -17,7 +17,7 @@ jest.mock('../components/Oops', () => ({ Oops: 'Oops', })); -describe('routes/Notifications.ts', () => { +describe('routes/Notifications.tsx', () => { it('should render itself & its children (with notifications)', () => { const tree = TestRenderer.create( diff --git a/src/routes/__snapshots__/LoginWithToken.test.tsx.snap b/src/routes/__snapshots__/LoginWithToken.test.tsx.snap index 448a5372b..8be1db86c 100644 --- a/src/routes/__snapshots__/LoginWithToken.test.tsx.snap +++ b/src/routes/__snapshots__/LoginWithToken.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`routes/LoginWithToken.js renders correctly 1`] = ` +exports[`routes/LoginWithToken.tsx renders correctly 1`] = `
diff --git a/src/routes/__snapshots__/Notifications.test.tsx.snap b/src/routes/__snapshots__/Notifications.test.tsx.snap index 1f16aa3dc..ab3a6744d 100644 --- a/src/routes/__snapshots__/Notifications.test.tsx.snap +++ b/src/routes/__snapshots__/Notifications.test.tsx.snap @@ -1,10 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`routes/Notifications.ts should render itself & its children (all read notifications) 1`] = ``; +exports[`routes/Notifications.tsx should render itself & its children (all read notifications) 1`] = ``; -exports[`routes/Notifications.ts should render itself & its children (error page - oops) 1`] = ``; +exports[`routes/Notifications.tsx should render itself & its children (error page - oops) 1`] = ``; -exports[`routes/Notifications.ts should render itself & its children (with notifications) 1`] = ` +exports[`routes/Notifications.tsx should render itself & its children (with notifications) 1`] = `
diff --git a/src/utils/__snapshots__/github-api.test.ts.snap b/src/utils/__snapshots__/github-api.test.ts.snap index 2ad7e8e99..b12b53e88 100644 --- a/src/utils/__snapshots__/github-api.test.ts.snap +++ b/src/utils/__snapshots__/github-api.test.ts.snap @@ -1,143 +1,143 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`formatReason should format the notification reason 1`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 1`] = ` { "description": "You were requested to review and approve a deployment.", "type": "Approval Requested", } `; -exports[`formatReason should format the notification reason 2`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 2`] = ` { "description": "You were assigned to the issue.", "type": "Assign", } `; -exports[`formatReason should format the notification reason 3`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 3`] = ` { "description": "You created the thread.", "type": "Author", } `; -exports[`formatReason should format the notification reason 4`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 4`] = ` { "description": "A GitHub Actions workflow run was triggered for your repository", "type": "Workflow Run", } `; -exports[`formatReason should format the notification reason 5`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 5`] = ` { "description": "You commented on the thread.", "type": "Comment", } `; -exports[`formatReason should format the notification reason 6`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 6`] = ` { "description": "You accepted an invitation to contribute to the repository.", "type": "Invitation", } `; -exports[`formatReason should format the notification reason 7`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 7`] = ` { "description": "You subscribed to the thread (via an issue or pull request).", "type": "Manual", } `; -exports[`formatReason should format the notification reason 8`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 8`] = ` { "description": "Organization members have requested to enable a feature such as Draft Pull Requests or CoPilot.", "type": "Member Feature Requested", } `; -exports[`formatReason should format the notification reason 9`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 9`] = ` { "description": "You were specifically @mentioned in the content.", "type": "Mention", } `; -exports[`formatReason should format the notification reason 10`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 10`] = ` { "description": "You, or a team you're a member of, were requested to review a pull request.", "type": "Review Requested", } `; -exports[`formatReason should format the notification reason 11`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 11`] = ` { "description": "You were credited for contributing to a security advisory.", "type": "Security Advisory Credit", } `; -exports[`formatReason should format the notification reason 12`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 12`] = ` { "description": "GitHub discovered a security vulnerability in your repository.", "type": "Security Alert", } `; -exports[`formatReason should format the notification reason 13`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 13`] = ` { "description": "You changed the thread state (for example, closing an issue or merging a pull request).", "type": "State Change", } `; -exports[`formatReason should format the notification reason 14`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 14`] = ` { "description": "You're watching the repository.", "type": "Subscribed", } `; -exports[`formatReason should format the notification reason 15`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 15`] = ` { "description": "You were on a team that was mentioned.", "type": "Team Mention", } `; -exports[`formatReason should format the notification reason 16`] = ` +exports[`utils/github-api.ts formatReason - should format the notification reason 16`] = ` { "description": "The reason for this notification is not supported by the app.", "type": "Unknown", } `; -exports[`getNotificationTypeIconColor should format the notification color for check suite 1`] = `"text-gray-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 1`] = `"text-gray-500"`; -exports[`getNotificationTypeIconColor should format the notification color for check suite 2`] = `"text-red-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 2`] = `"text-red-500"`; -exports[`getNotificationTypeIconColor should format the notification color for check suite 3`] = `"text-gray-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 3`] = `"text-gray-500"`; -exports[`getNotificationTypeIconColor should format the notification color for check suite 4`] = `"text-green-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 4`] = `"text-green-500"`; -exports[`getNotificationTypeIconColor should format the notification color for check suite 5`] = `"text-gray-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 5`] = `"text-gray-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 1`] = `"text-green-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 1`] = `"text-green-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 2`] = `"text-red-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 2`] = `"text-red-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 3`] = `"text-purple-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 3`] = `"text-purple-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 4`] = `"text-gray-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 4`] = `"text-gray-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 5`] = `"text-purple-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 5`] = `"text-purple-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 6`] = `"text-gray-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 6`] = `"text-gray-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 7`] = `"text-green-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 7`] = `"text-green-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 8`] = `"text-green-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 8`] = `"text-green-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 9`] = `"text-purple-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 9`] = `"text-purple-500"`; -exports[`getNotificationTypeIconColor should format the notification color for state 10`] = `"text-gray-500"`; +exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 10`] = `"text-gray-500"`; diff --git a/src/utils/appearance.test.ts b/src/utils/appearance.test.ts index a9d7f0b05..a6f8005ea 100644 --- a/src/utils/appearance.test.ts +++ b/src/utils/appearance.test.ts @@ -3,7 +3,7 @@ import { setAppearance } from './appearance'; import * as appearanceHelpers from './appearance'; -describe('utils/appearance.tsx', () => { +describe('utils/appearance.ts', () => { beforeAll(() => { jest.spyOn(appearanceHelpers, 'setLightMode'); jest.spyOn(appearanceHelpers, 'setDarkMode'); diff --git a/src/utils/github-api.test.ts b/src/utils/github-api.test.ts index dbb5fe929..5a3cffc94 100644 --- a/src/utils/github-api.test.ts +++ b/src/utils/github-api.test.ts @@ -5,8 +5,8 @@ import { } from './github-api'; import { Reason, StateType, Subject, SubjectType } from '../typesGithub'; -describe('formatReason', () => { - it('should format the notification reason', () => { +describe('utils/github-api.ts', () => { + it('formatReason - should format the notification reason', () => { expect(formatReason('approval_requested')).toMatchSnapshot(); expect(formatReason('assign')).toMatchSnapshot(); expect(formatReason('author')).toMatchSnapshot(); @@ -24,10 +24,8 @@ describe('formatReason', () => { expect(formatReason('team_mention')).toMatchSnapshot(); expect(formatReason('something_else_unknown' as Reason)).toMatchSnapshot(); }); -}); -describe('getNotificationTypeIcon', () => { - it('should get the notification type icon', () => { + describe('getNotificationTypeIcon - should get the notification type icon', () => { expect( getNotificationTypeIcon( createSubjectMock({ type: 'CheckSuite', state: null }), @@ -188,88 +186,90 @@ describe('getNotificationTypeIcon', () => { 'QuestionIcon', ); }); -}); -describe('getNotificationTypeIconColor', () => { - it('should format the notification color for check suite', () => { - expect( - getNotificationTypeIconColor( - createSubjectMock({ - type: 'CheckSuite', - state: 'cancelled', - }), - ), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor( - createSubjectMock({ - type: 'CheckSuite', - state: 'failure', - }), - ), - ).toMatchSnapshot(); + describe('getNotificationTypeIconColor', () => { + it('should format the notification color for check suite', () => { + expect( + getNotificationTypeIconColor( + createSubjectMock({ + type: 'CheckSuite', + state: 'cancelled', + }), + ), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor( + createSubjectMock({ + type: 'CheckSuite', + state: 'failure', + }), + ), + ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor( - createSubjectMock({ - type: 'CheckSuite', - state: 'skipped', - }), - ), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor( - createSubjectMock({ - type: 'CheckSuite', - state: 'success', - }), - ), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor( - createSubjectMock({ - type: 'CheckSuite', - state: null, - }), - ), - ).toMatchSnapshot(); - }); + expect( + getNotificationTypeIconColor( + createSubjectMock({ + type: 'CheckSuite', + state: 'skipped', + }), + ), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor( + createSubjectMock({ + type: 'CheckSuite', + state: 'success', + }), + ), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor( + createSubjectMock({ + type: 'CheckSuite', + state: null, + }), + ), + ).toMatchSnapshot(); + }); - it('should format the notification color for state', () => { - expect( - getNotificationTypeIconColor(createSubjectMock({ state: 'ANSWERED' })), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor(createSubjectMock({ state: 'closed' })), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor(createSubjectMock({ state: 'completed' })), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor(createSubjectMock({ state: 'draft' })), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor(createSubjectMock({ state: 'merged' })), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor(createSubjectMock({ state: 'not_planned' })), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor(createSubjectMock({ state: 'open' })), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor(createSubjectMock({ state: 'reopened' })), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor(createSubjectMock({ state: 'RESOLVED' })), - ).toMatchSnapshot(); - expect( - getNotificationTypeIconColor( - createSubjectMock({ - state: 'something_else_unknown' as StateType, - }), - ), - ).toMatchSnapshot(); + it('should format the notification color for state', () => { + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'ANSWERED' })), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'closed' })), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'completed' })), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'draft' })), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'merged' })), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor( + createSubjectMock({ state: 'not_planned' }), + ), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'open' })), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'reopened' })), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor(createSubjectMock({ state: 'RESOLVED' })), + ).toMatchSnapshot(); + expect( + getNotificationTypeIconColor( + createSubjectMock({ + state: 'something_else_unknown' as StateType, + }), + ), + ).toMatchSnapshot(); + }); }); }); diff --git a/src/utils/remove-notifications.test.ts b/src/utils/remove-notifications.test.ts index 5c9da500f..0ec62a900 100644 --- a/src/utils/remove-notifications.test.ts +++ b/src/utils/remove-notifications.test.ts @@ -5,7 +5,7 @@ import { } from '../__mocks__/mockedData'; import { removeNotifications } from './remove-notifications'; -describe('utils/remove-notification.ts', () => { +describe('utils/remove-notifications.ts', () => { const repoSlug = mockedSingleNotification.repository.full_name; const hostname = mockedSingleAccountNotifications[0].hostname; diff --git a/src/utils/subject.test.ts b/src/utils/subject.test.ts index b4c659afb..325fbeb9c 100644 --- a/src/utils/subject.test.ts +++ b/src/utils/subject.test.ts @@ -9,7 +9,7 @@ import { getWorkflowRunAttributes, } from './subject'; import { SubjectType } from '../typesGithub'; -describe('utils/state.ts', () => { +describe('utils/subject.ts', () => { beforeEach(() => { // axios will default to using the XHR adapter which can't be intercepted // by nock. So, configure axios to use the node adapter.