fix tests

This commit is contained in:
Fredrik Adelöw
2020-08-26 10:52:30 +02:00
parent ddc7030731
commit 26159c01e9
2 changed files with 37 additions and 22 deletions
@@ -15,12 +15,18 @@
*/
import { Entity } from '@backstage/catalog-model';
import { wrapInTestApp } from '@backstage/test-utils';
import { render } from '@testing-library/react';
import {
ApiProvider,
ApiRegistry,
ConfigApi,
configApiRef,
} from '@backstage/core';
import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils';
import * as React from 'react';
import { CatalogApi, catalogApiRef } from '../../api/types';
import { CatalogTable } from './CatalogTable';
const entites: Entity[] = [
const entities: Entity[] = [
{
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
@@ -39,15 +45,22 @@ const entites: Entity[] = [
];
describe('CatalogTable component', () => {
const apis = ApiRegistry.from([
[configApiRef, ({} as Partial<ConfigApi>) as ConfigApi],
[catalogApiRef, ({} as Partial<CatalogApi>) as CatalogApi],
]);
it('should render error message when error is passed in props', async () => {
const rendered = render(
const rendered = await renderWithEffects(
wrapInTestApp(
<CatalogTable
titlePreamble="Owned"
entities={[]}
loading={false}
error={{ code: 'error' }}
/>,
<ApiProvider apis={apis}>
<CatalogTable
titlePreamble="Owned"
entities={[]}
loading={false}
error={{ code: 'error' }}
/>
</ApiProvider>,
),
);
const errorMessage = await rendered.findByText(
@@ -57,13 +70,15 @@ describe('CatalogTable component', () => {
});
it('should display entity names when loading has finished and no error occurred', async () => {
const rendered = render(
const rendered = await renderWithEffects(
wrapInTestApp(
<CatalogTable
titlePreamble="Owned"
entities={entites}
loading={false}
/>,
<ApiProvider apis={apis}>
<CatalogTable
titlePreamble="Owned"
entities={entities}
loading={false}
/>
</ApiProvider>,
),
);
expect(rendered.getByText(/Owned \(3\)/)).toBeInTheDocument();
@@ -51,12 +51,12 @@ describe('useEntityFilterGroup', () => {
it('works for an empty set of filters', async () => {
catalogApi.getEntities.mockResolvedValue([]);
const group: FilterGroup = { filters: {} };
const { result, wait } = renderHook(
const { result, waitFor } = renderHook(
() => useEntityFilterGroup('g1', group),
{ wrapper },
);
await wait(() => expect(result.current.state.type).toBe('ready'));
await waitFor(() => expect(result.current.state.type).toBe('ready'));
});
it('works for a single group', async () => {
@@ -73,12 +73,12 @@ describe('useEntityFilterGroup', () => {
f2: e => e.metadata.name !== 'n',
},
};
const { result, wait } = renderHook(
const { result, waitFor } = renderHook(
() => useEntityFilterGroup('g1', group),
{ wrapper },
);
await wait(() => expect(result.current.state.type).toEqual('ready'));
await waitFor(() => expect(result.current.state.type).toEqual('ready'));
let state = result.current.state as FilterGroupStatesReady;
expect(state.state.filters.f1).toEqual({
isSelected: false,
@@ -91,7 +91,7 @@ describe('useEntityFilterGroup', () => {
act(() => result.current.setSelectedFilters(['f1']));
await wait(() => expect(result.current.state.type).toEqual('ready'));
await waitFor(() => expect(result.current.state.type).toEqual('ready'));
state = result.current.state as FilterGroupStatesReady;
expect(state.state.filters.f1).toEqual({
isSelected: true,
@@ -104,7 +104,7 @@ describe('useEntityFilterGroup', () => {
act(() => result.current.setSelectedFilters(['f2']));
await wait(() => expect(result.current.state.type).toEqual('ready'));
await waitFor(() => expect(result.current.state.type).toEqual('ready'));
state = result.current.state as FilterGroupStatesReady;
expect(state.state.filters.f1).toEqual({
isSelected: false,