From ac396e8e0b78057ebf0e7bdbd7d6b39856f936d3 Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Fri, 29 Jan 2021 14:54:13 +0100 Subject: [PATCH] Fix tests --- .../components/TabbedLayout/TabbedLayout.tsx | 4 +-- .../EntityLayout/EntityLayout.test.tsx | 27 ++----------------- .../components/EntityLayout/EntityLayout.tsx | 10 +------ .../components/DomainCard/DomainCard.test.tsx | 2 +- 4 files changed, 6 insertions(+), 37 deletions(-) diff --git a/packages/core/src/components/TabbedLayout/TabbedLayout.tsx b/packages/core/src/components/TabbedLayout/TabbedLayout.tsx index 07ed444859..b455df4d79 100644 --- a/packages/core/src/components/TabbedLayout/TabbedLayout.tsx +++ b/packages/core/src/components/TabbedLayout/TabbedLayout.tsx @@ -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 = ( diff --git a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx index 0d8ae56262..7356ccc27b 100644 --- a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx +++ b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx @@ -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', () => { , ); + 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( - - -
tabbed-test-content
-
-
This will cause app to throw
-
, - ), - ).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 component/, - ), - ]); - }); - it('navigates when user clicks different tab', async () => { const rendered = await renderInTestApp( diff --git a/plugins/catalog/src/components/EntityLayout/EntityLayout.tsx b/plugins/catalog/src/components/EntityLayout/EntityLayout.tsx index 597a389097..c4cd4c5c71 100644 --- a/plugins/catalog/src/components/EntityLayout/EntityLayout.tsx +++ b/plugins/catalog/src/components/EntityLayout/EntityLayout.tsx @@ -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) => ; - const EntityLayoutTitle = ({ entity, title, @@ -164,4 +156,4 @@ export const EntityLayout = ({ children }: PropsWithChildren<{}>) => { ); }; -EntityLayout.Route = Route; +EntityLayout.Route = TabbedLayout.Route; diff --git a/plugins/explore/src/components/DomainCard/DomainCard.test.tsx b/plugins/explore/src/components/DomainCard/DomainCard.test.tsx index e0d116269d..9d409051f6 100644 --- a/plugins/explore/src/components/DomainCard/DomainCard.test.tsx +++ b/plugins/explore/src/components/DomainCard/DomainCard.test.tsx @@ -41,7 +41,7 @@ describe('', () => { 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', );