Fix tests
This commit is contained in:
@@ -36,8 +36,8 @@ const Route: (props: SubRoute) => null = () => null;
|
||||
attachComponentData(Route, 'core.gatherMountPoints', true);
|
||||
|
||||
export function createSubRoutesFromChildren(children: ReactNode): SubRoute[] {
|
||||
// Directly comparing child.type with Route will not work with
|
||||
// react-hot-loader for example in storybook
|
||||
// Directly comparing child.type with Route will not work with in
|
||||
// combination with react-hot-loader in storybook
|
||||
// https://github.com/gaearon/react-hot-loader/issues/304
|
||||
const routeType = (
|
||||
<Route path="" title="">
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
ApiRegistry,
|
||||
} from '@backstage/core';
|
||||
import { catalogApiRef, EntityContext } from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp, withLogCollector } from '@backstage/test-utils';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import { fireEvent } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
@@ -59,34 +59,11 @@ describe('EntityLayout', () => {
|
||||
</ApiProvider>,
|
||||
);
|
||||
|
||||
expect(rendered.getByText('my-entity')).toBeInTheDocument();
|
||||
expect(rendered.getByText('tabbed-test-title')).toBeInTheDocument();
|
||||
expect(rendered.getByText('tabbed-test-content')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('throws if any other component is a child of TabbedLayout', async () => {
|
||||
const { error } = await withLogCollector(async () => {
|
||||
await expect(
|
||||
renderInTestApp(
|
||||
<EntityLayout>
|
||||
<EntityLayout.Route path="/" title="tabbed-test-title">
|
||||
<div>tabbed-test-content</div>
|
||||
</EntityLayout.Route>
|
||||
<div>This will cause app to throw</div>
|
||||
</EntityLayout>,
|
||||
),
|
||||
).rejects.toThrow(/Child of EntityLayout must be an EntityLayout.Route/);
|
||||
});
|
||||
|
||||
expect(error).toEqual([
|
||||
expect.stringMatching(
|
||||
/Child of EntityLayout must be an EntityLayout.Route/,
|
||||
),
|
||||
expect.stringMatching(
|
||||
/The above error occurred in the <EntityLayout> component/,
|
||||
),
|
||||
]);
|
||||
});
|
||||
|
||||
it('navigates when user clicks different tab', async () => {
|
||||
const rendered = await renderInTestApp(
|
||||
<Routes>
|
||||
|
||||
@@ -40,14 +40,6 @@ import { EntityContextMenu } from '../EntityContextMenu/EntityContextMenu';
|
||||
import { FavouriteEntity } from '../FavouriteEntity/FavouriteEntity';
|
||||
import { UnregisterEntityDialog } from '../UnregisterEntityDialog/UnregisterEntityDialog';
|
||||
|
||||
type SubRoute = {
|
||||
path: string;
|
||||
title: string;
|
||||
children: JSX.Element;
|
||||
};
|
||||
|
||||
const Route = (props: SubRoute) => <TabbedLayout.Route {...props} />;
|
||||
|
||||
const EntityLayoutTitle = ({
|
||||
entity,
|
||||
title,
|
||||
@@ -164,4 +156,4 @@ export const EntityLayout = ({ children }: PropsWithChildren<{}>) => {
|
||||
);
|
||||
};
|
||||
|
||||
EntityLayout.Route = Route;
|
||||
EntityLayout.Route = TabbedLayout.Route;
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('<DomainCard />', () => {
|
||||
expect(getByText('artists')).toBeInTheDocument();
|
||||
expect(getByText('Everything about artists')).toBeInTheDocument();
|
||||
expect(getByText('a-tag')).toBeInTheDocument();
|
||||
expect(getByText('Explore')).toHaveAttribute(
|
||||
expect(getByText('Explore').parentElement).toHaveAttribute(
|
||||
'href',
|
||||
'/catalog/default/domain/artists',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user