Use renderInTestApp

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-09-17 08:27:57 +02:00
parent a5e881809a
commit 86c716c60b
4 changed files with 49 additions and 77 deletions
@@ -22,8 +22,7 @@ import {
} from '@backstage/core-app-api';
import { configApiRef } from '@backstage/core-plugin-api';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
import { wrapInTestApp } from '@backstage/test-utils';
import { act, render } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import React from 'react';
import { catalogImportApiRef, CatalogImportClient } from '../../api';
import { DefaultImportPage } from './DefaultImportPage';
@@ -68,18 +67,14 @@ describe('<DefaultImportPage />', () => {
});
it('renders without exploding', async () => {
await act(async () => {
const { getByText } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<DefaultImportPage />
</ApiProvider>,
),
);
const { getByText } = await renderInTestApp(
<ApiProvider apis={apis}>
<DefaultImportPage />
</ApiProvider>,
);
expect(
getByText('Start tracking your component in Backstage'),
).toBeInTheDocument();
});
expect(
getByText('Start tracking your component in Backstage'),
).toBeInTheDocument();
});
});
@@ -20,8 +20,7 @@ import {
ConfigReader,
} from '@backstage/core-app-api';
import { configApiRef } from '@backstage/core-plugin-api';
import { wrapInTestApp } from '@backstage/test-utils';
import { act, render } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import React from 'react';
import { CatalogImportApi, catalogImportApiRef } from '../../api';
import { ImportInfoCard } from './ImportInfoCard';
@@ -52,50 +51,38 @@ describe('<ImportInfoCard />', () => {
new ConfigReader({ integrations: {} }),
).with(catalogImportApiRef, catalogImportApi);
await act(async () => {
const { getByText } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<ImportInfoCard />
</ApiProvider>,
),
);
const { getByText } = await renderInTestApp(
<ApiProvider apis={apis}>
<ImportInfoCard />
</ApiProvider>,
);
expect(getByText('Register an existing component')).toBeInTheDocument();
});
expect(getByText('Register an existing component')).toBeInTheDocument();
});
it('renders section on GitHub discovery if supported', async () => {
catalogImportApi.preparePullRequest = async () => ({ title: '', body: '' });
await act(async () => {
const { getByText } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<ImportInfoCard />
</ApiProvider>,
),
);
const { getByText } = await renderInTestApp(
<ApiProvider apis={apis}>
<ImportInfoCard />
</ApiProvider>,
);
expect(getByText(/The wizard discovers all/)).toBeInTheDocument();
});
expect(getByText(/The wizard discovers all/)).toBeInTheDocument();
});
it('renders section on pull requests if supported', async () => {
catalogImportApi.preparePullRequest = async () => ({ title: '', body: '' });
await act(async () => {
const { getByText } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<ImportInfoCard />
</ApiProvider>,
),
);
const { getByText } = await renderInTestApp(
<ApiProvider apis={apis}>
<ImportInfoCard />
</ApiProvider>,
);
expect(
getByText(/the wizard will prepare a Pull Request/),
).toBeInTheDocument();
});
expect(
getByText(/the wizard will prepare a Pull Request/),
).toBeInTheDocument();
});
});
@@ -22,8 +22,7 @@ import {
} from '@backstage/core-app-api';
import { configApiRef } from '@backstage/core-plugin-api';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
import { wrapInTestApp } from '@backstage/test-utils';
import { act, render } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import React from 'react';
import { useOutlet } from 'react-router';
import { catalogImportApiRef, CatalogImportClient } from '../../api';
@@ -76,34 +75,26 @@ describe('<ImportPage />', () => {
afterEach(() => jest.resetAllMocks());
it('renders without exploding', async () => {
await act(async () => {
const { getByText } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<ImportPage />
</ApiProvider>,
),
);
const { getByText } = await renderInTestApp(
<ApiProvider apis={apis}>
<ImportPage />
</ApiProvider>,
);
expect(
getByText('Start tracking your component in Backstage'),
).toBeInTheDocument();
});
expect(
getByText('Start tracking your component in Backstage'),
).toBeInTheDocument();
});
it('renders with custom children', async () => {
(useOutlet as jest.Mock).mockReturnValue(<div>Hello World</div>);
await act(async () => {
const { getByText } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<ImportPage />
</ApiProvider>,
),
);
const { getByText } = await renderInTestApp(
<ApiProvider apis={apis}>
<ImportPage />
</ApiProvider>,
);
expect(getByText('Hello World')).toBeInTheDocument();
});
expect(getByText('Hello World')).toBeInTheDocument();
});
});
@@ -14,15 +14,14 @@
* limitations under the License.
*/
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { errorApiRef } from '@backstage/core-plugin-api';
import { act, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { AnalyzeResult, catalogImportApiRef } from '../../api/';
import { StepInitAnalyzeUrl } from './StepInitAnalyzeUrl';
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { errorApiRef } from '@backstage/core-plugin-api';
describe('<StepInitAnalyzeUrl />', () => {
const catalogImportApi: jest.Mocked<typeof catalogImportApiRef.T> = {
analyzeUrl: jest.fn(),
@@ -313,7 +312,7 @@ describe('<StepInitAnalyzeUrl />', () => {
);
await act(async () => {
await userEvent.type(
userEvent.type(
getByRole('textbox', { name: /Repository/i }),
'https://my-repository-2',
);
@@ -357,7 +356,7 @@ describe('<StepInitAnalyzeUrl />', () => {
);
await act(async () => {
await userEvent.type(
userEvent.type(
getByRole('textbox', { name: /Repository/i }),
'https://my-repository-2',
);