From 6d3fe015fe33b2a906048694021b19c2087ef5dd Mon Sep 17 00:00:00 2001 From: Erik Engervall Date: Tue, 20 Apr 2021 19:24:29 +0200 Subject: [PATCH] Fix tests & add tests for Cards Signed-off-by: Erik Engervall --- .../src/cards/Cards.test.tsx | 53 +++++++++++++++++++ .../src/cards/Patch/hooks/usePatch.test.ts | 1 + .../hooks/usePromoteRc.test.ts | 1 + .../src/cards/createRc/CreateRc.test.tsx | 2 +- .../cards/createRc/hooks/useCreateRc.test.tsx | 2 +- .../src/hooks/useGetGitHubBatchInfo.ts | 2 +- .../src/test-helpers/test-helpers.ts | 8 ++- 7 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 plugins/github-release-manager/src/cards/Cards.test.tsx diff --git a/plugins/github-release-manager/src/cards/Cards.test.tsx b/plugins/github-release-manager/src/cards/Cards.test.tsx new file mode 100644 index 0000000000..2a67a9f62c --- /dev/null +++ b/plugins/github-release-manager/src/cards/Cards.test.tsx @@ -0,0 +1,53 @@ +/* + * Copyright 2021 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { render, act, waitFor } from '@testing-library/react'; + +import { mockApiClient, mockCalverProject } from '../test-helpers/test-helpers'; +import { TEST_IDS } from '../test-helpers/test-ids'; + +jest.mock('../contexts/PluginApiClientContext', () => ({ + usePluginApiClientContext: () => mockApiClient, +})); +jest.mock('../contexts/ProjectContext', () => ({ + useProjectContext: jest.fn(() => mockCalverProject), +})); + +import { Cards } from './Cards'; + +describe('Cards', () => { + it('should render info', async () => { + const { getByTestId } = render( + , + ); + + await act(async () => { + await waitFor(() => getByTestId(TEST_IDS.info.info)); + }); + + expect(getByTestId(TEST_IDS.info.info).innerHTML).toMatchInlineSnapshot( + `"
Terminology

GitHub: The source control system where releases reside in a practical sense. Read more about GitHub releases. (Note that this plugin works just as well with GitHub Enterprise.)

Release Candidate: A GitHub prerelease intended primarily for internal testing

Release Version: A GitHub release intended for end users

"`, + ); + }); +}); diff --git a/plugins/github-release-manager/src/cards/Patch/hooks/usePatch.test.ts b/plugins/github-release-manager/src/cards/Patch/hooks/usePatch.test.ts index ff280ed181..a7b6b2b58d 100644 --- a/plugins/github-release-manager/src/cards/Patch/hooks/usePatch.test.ts +++ b/plugins/github-release-manager/src/cards/Patch/hooks/usePatch.test.ts @@ -113,6 +113,7 @@ describe('patch', () => { }, ], "run": [Function], + "runInvoked": true, } `); }); diff --git a/plugins/github-release-manager/src/cards/PromoteReleaseCandidate/hooks/usePromoteRc.test.ts b/plugins/github-release-manager/src/cards/PromoteReleaseCandidate/hooks/usePromoteRc.test.ts index a055e4acd8..4803f2a551 100644 --- a/plugins/github-release-manager/src/cards/PromoteReleaseCandidate/hooks/usePromoteRc.test.ts +++ b/plugins/github-release-manager/src/cards/PromoteReleaseCandidate/hooks/usePromoteRc.test.ts @@ -76,6 +76,7 @@ describe('usePromoteRc', () => { }, ], "run": [Function], + "runInvoked": true, } `); }); diff --git a/plugins/github-release-manager/src/cards/createRc/CreateRc.test.tsx b/plugins/github-release-manager/src/cards/createRc/CreateRc.test.tsx index 4363d12c98..f4aaaa29ee 100644 --- a/plugins/github-release-manager/src/cards/createRc/CreateRc.test.tsx +++ b/plugins/github-release-manager/src/cards/createRc/CreateRc.test.tsx @@ -44,7 +44,7 @@ jest.mock('./hooks/useCreateRc', () => ({ run: jest.fn(), responseSteps: [], progress: 0, - runLoading: false, + runInvoked: false, } as ReturnType), })); diff --git a/plugins/github-release-manager/src/cards/createRc/hooks/useCreateRc.test.tsx b/plugins/github-release-manager/src/cards/createRc/hooks/useCreateRc.test.tsx index dd47ec086a..e4549b5cb8 100644 --- a/plugins/github-release-manager/src/cards/createRc/hooks/useCreateRc.test.tsx +++ b/plugins/github-release-manager/src/cards/createRc/hooks/useCreateRc.test.tsx @@ -94,7 +94,7 @@ describe('useCreateRc', () => { }, ], "run": [Function], - "runLoading": false, + "runInvoked": true, } `); }); diff --git a/plugins/github-release-manager/src/hooks/useGetGitHubBatchInfo.ts b/plugins/github-release-manager/src/hooks/useGetGitHubBatchInfo.ts index 5cf5115116..e09d165871 100644 --- a/plugins/github-release-manager/src/hooks/useGetGitHubBatchInfo.ts +++ b/plugins/github-release-manager/src/hooks/useGetGitHubBatchInfo.ts @@ -36,7 +36,7 @@ export const useGetGitHubBatchInfo = ({ pluginApiClient.getLatestRelease({ ...project }), ]); - if (latestRelease === null) { + if (!latestRelease) { return { latestRelease, releaseBranch: null, diff --git a/plugins/github-release-manager/src/test-helpers/test-helpers.ts b/plugins/github-release-manager/src/test-helpers/test-helpers.ts index f13e5c1c04..e138512971 100644 --- a/plugins/github-release-manager/src/test-helpers/test-helpers.ts +++ b/plugins/github-release-manager/src/test-helpers/test-helpers.ts @@ -158,9 +158,13 @@ export const mockApiClient: IPluginApiClient = { createMockRecentCommit({ sha: 'mock_sha_recent_commits_2' }), ]), - getLatestRelease: jest.fn(), + getLatestRelease: jest.fn(async () => createMockRelease()), - getRepository: jest.fn(), + getRepository: jest.fn(async () => ({ + pushPermissions: true, + defaultBranch: mockDefaultBranch, + name: mockRepo, + })), getLatestCommit: jest.fn(async () => ({ sha: 'latestCommit.sha',