chore: fixing up the tests for the scaffolder tasks now the API has changed

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-05-13 11:11:08 +02:00
parent bcb040de3e
commit 2de8c51462
3 changed files with 27 additions and 10 deletions
+4 -1
View File
@@ -17,6 +17,7 @@
import { ConfigReader } from '@backstage/core-app-api';
import { ScmIntegrations } from '@backstage/integration';
import { MockFetchApi, setupRequestMockHandlers } from '@backstage/test-utils';
import { identity } from 'lodash';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { ScaffolderClient } from './api';
@@ -60,6 +61,9 @@ describe('api', () => {
fetchApi,
identityApi,
});
jest.restoreAllMocks();
identityApi.getBackstageIdentity.mockReturnValue({});
});
it('should return default and custom integrations', async () => {
@@ -345,7 +349,6 @@ describe('api', () => {
);
const result = await apiClient.listTasks('all');
expect(identityApi.getBackstageIdentity).not.toBeCalled();
expect(result).toHaveLength(2);
});
it('should list task using the current user as owner', async () => {
@@ -105,19 +105,23 @@ describe('<ListTasksPage />', () => {
{
id: 'a-random-id',
spec: {
createdBy: 'user:default/foo',
user: { ref: 'user:default/foo' },
templateInfo: {
entityRef: 'template:default/test',
},
} as any,
status: 'completed',
createdAt: '',
lastHeartbeatAt: '',
},
]);
scaffolderApiMock.getTemplateParameterSchema.mockResolvedValue({
title: 'One Template',
steps: [],
});
const { getByText } = await renderInTestApp(
const { getByText, findByText } = await renderInTestApp(
<TestApiProvider
apis={[
[catalogApiRef, catalogApi],
@@ -139,8 +143,8 @@ describe('<ListTasksPage />', () => {
expect(getByText('List template tasks')).toBeInTheDocument();
expect(getByText('All tasks that have been started')).toBeInTheDocument();
expect(getByText('Tasks')).toBeInTheDocument();
expect(getByText('One Template')).toBeInTheDocument();
expect(getByText('BackUser')).toBeInTheDocument();
expect(await findByText('One Template')).toBeInTheDocument();
expect(await findByText('BackUser')).toBeInTheDocument();
});
it('should render all tasks', async () => {
@@ -172,7 +176,10 @@ describe('<ListTasksPage />', () => {
{
id: 'a-random-id',
spec: {
createdBy: 'user:default/foo',
user: { ref: 'user:default/foo' },
templateInfo: {
entityRef: 'template:default/mock',
},
} as any,
status: 'completed',
createdAt: '',
@@ -183,7 +190,12 @@ describe('<ListTasksPage />', () => {
{
id: 'b-random-id',
spec: {
createdBy: 'user:default/boo',
templateInfo: {
entityRef: 'template:default/mock',
},
user: {
ref: 'user:default/boo',
},
} as any,
status: 'completed',
createdAt: '',
@@ -196,7 +208,7 @@ describe('<ListTasksPage />', () => {
steps: [],
});
const { getByText } = await renderInTestApp(
const { getByText, findByText } = await renderInTestApp(
<TestApiProvider
apis={[
[catalogApiRef, catalogApi],
@@ -220,7 +232,7 @@ describe('<ListTasksPage />', () => {
});
expect(scaffolderApiMock.listTasks).toBeCalledWith('all');
expect(getByText('One Template')).toBeInTheDocument();
expect(getByText('OtherUser')).toBeInTheDocument();
expect(await findByText('One Template')).toBeInTheDocument();
expect(await findByText('OtherUser')).toBeInTheDocument();
});
});
@@ -20,6 +20,7 @@ import React from 'react';
import { TemplateTitleColumn } from './TemplateTitleColumn';
import { scaffolderApiRef } from '../../../api';
import { ScaffolderApi } from '../../../types';
import { entityRouteRef } from '@backstage/plugin-catalog-react';
describe('<TemplateTitleColumn />', () => {
const scaffolderApiMock: jest.Mocked<ScaffolderApi> = {
@@ -40,6 +41,7 @@ describe('<TemplateTitleColumn />', () => {
<TestApiProvider apis={[[scaffolderApiRef, scaffolderApiMock]]}>
<TemplateTitleColumn {...props} />
</TestApiProvider>,
{ mountedRoutes: { '/test': entityRouteRef } },
);
const text = getByText('One Template');