Fix tests & add tests for Cards
Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
@@ -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(
|
||||
<Cards
|
||||
components={{
|
||||
info: { omit: false },
|
||||
createRc: { omit: true },
|
||||
promoteRc: { omit: true },
|
||||
patch: { omit: true },
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await waitFor(() => getByTestId(TEST_IDS.info.info));
|
||||
});
|
||||
|
||||
expect(getByTestId(TEST_IDS.info.info).innerHTML).toMatchInlineSnapshot(
|
||||
`"<h6 class=\\"MuiTypography-root MuiTypography-h6\\">Terminology</h6><p class=\\"MuiTypography-root MuiTypography-body1\\"><strong>GitHub</strong>: The source control system where releases reside in a practical sense. Read more about <a class=\\"MuiTypography-root MuiLink-root MuiLink-underlineHover MuiTypography-colorPrimary\\" href=\\"https://docs.github.com/en/github/administering-a-repository/managing-releases-in-a-repository\\" target=\\"_blank\\">GitHub releases</a>. (Note that this plugin works just as well with GitHub Enterprise.)</p><p class=\\"MuiTypography-root MuiTypography-body1\\"><strong>Release Candidate</strong>: A GitHub <i>prerelease</i> intended primarily for internal testing</p><p class=\\"MuiTypography-root MuiTypography-body1\\"><strong>Release Version</strong>: A GitHub release intended for end users</p>"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -113,6 +113,7 @@ describe('patch', () => {
|
||||
},
|
||||
],
|
||||
"run": [Function],
|
||||
"runInvoked": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
+1
@@ -76,6 +76,7 @@ describe('usePromoteRc', () => {
|
||||
},
|
||||
],
|
||||
"run": [Function],
|
||||
"runInvoked": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ jest.mock('./hooks/useCreateRc', () => ({
|
||||
run: jest.fn(),
|
||||
responseSteps: [],
|
||||
progress: 0,
|
||||
runLoading: false,
|
||||
runInvoked: false,
|
||||
} as ReturnType<typeof useCreateRc>),
|
||||
}));
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('useCreateRc', () => {
|
||||
},
|
||||
],
|
||||
"run": [Function],
|
||||
"runLoading": false,
|
||||
"runInvoked": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ export const useGetGitHubBatchInfo = ({
|
||||
pluginApiClient.getLatestRelease({ ...project }),
|
||||
]);
|
||||
|
||||
if (latestRelease === null) {
|
||||
if (!latestRelease) {
|
||||
return {
|
||||
latestRelease,
|
||||
releaseBranch: null,
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user