diff --git a/.changeset/few-sloths-raise.md b/.changeset/few-sloths-raise.md new file mode 100644 index 0000000000..ab0eac93d5 --- /dev/null +++ b/.changeset/few-sloths-raise.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-catalog': patch +'@backstage/plugin-catalog-react': patch +--- + +Name column will now render entity `metadata.title` if its present diff --git a/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx b/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx index 340a1b4559..ac09b717f7 100644 --- a/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx +++ b/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -71,6 +72,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText(/Consumed APIs/i)).toBeInTheDocument(); @@ -116,6 +122,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/api-docs/src/components/ApisCards/HasApisCard.test.tsx b/plugins/api-docs/src/components/ApisCards/HasApisCard.test.tsx index e7a53446bc..ac833251e3 100644 --- a/plugins/api-docs/src/components/ApisCards/HasApisCard.test.tsx +++ b/plugins/api-docs/src/components/ApisCards/HasApisCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -71,6 +72,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('APIs')).toBeInTheDocument(); @@ -116,6 +122,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx b/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx index afc81c2e84..f2719d0f4b 100644 --- a/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx +++ b/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -71,6 +72,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText(/Provided APIs/i)).toBeInTheDocument(); @@ -116,6 +122,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx b/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx index 5c47ec1476..274962c346 100644 --- a/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx +++ b/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -70,6 +71,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Consumers')).toBeInTheDocument(); @@ -121,6 +127,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx b/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx index 77cc75535c..879944749a 100644 --- a/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx +++ b/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -70,6 +71,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Providers')).toBeInTheDocument(); @@ -121,6 +127,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/catalog-react/src/components/EntityRefLink/EntityRefLink.test.tsx b/plugins/catalog-react/src/components/EntityRefLink/EntityRefLink.test.tsx index 45411a9d5e..eaaaab39bc 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/EntityRefLink.test.tsx +++ b/plugins/catalog-react/src/components/EntityRefLink/EntityRefLink.test.tsx @@ -14,13 +14,13 @@ * limitations under the License. */ -import { render } from '@testing-library/react'; +import { renderInTestApp } from '@backstage/test-utils'; import React from 'react'; -import { MemoryRouter } from 'react-router'; +import { entityRouteRef } from '../../routes'; import { EntityRefLink } from './EntityRefLink'; describe('', () => { - it('renders link for entity in default namespace', () => { + it('renders link for entity in default namespace', async () => { const entity = { apiVersion: 'v1', kind: 'Component', @@ -33,9 +33,14 @@ describe('', () => { lifecycle: 'production', }, }; - const { getByText } = render(, { - wrapper: MemoryRouter, - }); + const { getByText } = await renderInTestApp( + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, + ); expect(getByText('component:software')).toHaveAttribute( 'href', @@ -43,7 +48,7 @@ describe('', () => { ); }); - it('renders link for entity in other namespace', () => { + it('renders link for entity in other namespace', async () => { const entity = { apiVersion: 'v1', kind: 'Component', @@ -57,16 +62,21 @@ describe('', () => { lifecycle: 'production', }, }; - const { getByText } = render(, { - wrapper: MemoryRouter, - }); + const { getByText } = await renderInTestApp( + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, + ); expect(getByText('component:test/software')).toHaveAttribute( 'href', '/catalog/test/component/software', ); }); - it('renders link for entity and hides default kind', () => { + it('renders link for entity and hides default kind', async () => { const entity = { apiVersion: 'v1', kind: 'Component', @@ -80,10 +90,12 @@ describe('', () => { lifecycle: 'production', }, }; - const { getByText } = render( + const { getByText } = await renderInTestApp( , { - wrapper: MemoryRouter, + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, }, ); expect(getByText('test/software')).toHaveAttribute( @@ -92,46 +104,58 @@ describe('', () => { ); }); - it('renders link for entity name in default namespace', () => { + it('renders link for entity name in default namespace', async () => { const entityName = { kind: 'Component', namespace: 'default', name: 'software', }; - const { getByText } = render(, { - wrapper: MemoryRouter, - }); + const { getByText } = await renderInTestApp( + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, + ); expect(getByText('component:software')).toHaveAttribute( 'href', '/catalog/default/component/software', ); }); - it('renders link for entity name in other namespace', () => { + it('renders link for entity name in other namespace', async () => { const entityName = { kind: 'Component', namespace: 'test', name: 'software', }; - const { getByText } = render(, { - wrapper: MemoryRouter, - }); + const { getByText } = await renderInTestApp( + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, + ); expect(getByText('component:test/software')).toHaveAttribute( 'href', '/catalog/test/component/software', ); }); - it('renders link for entity name and hides default kind', () => { + it('renders link for entity name and hides default kind', async () => { const entityName = { kind: 'Component', namespace: 'test', name: 'software', }; - const { getByText } = render( + const { getByText } = await renderInTestApp( , { - wrapper: MemoryRouter, + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, }, ); expect(getByText('test/software')).toHaveAttribute( @@ -140,18 +164,20 @@ describe('', () => { ); }); - it('renders link with custom children', () => { + it('renders link with custom children', async () => { const entityName = { kind: 'Component', namespace: 'test', name: 'software', }; - const { getByText } = render( + const { getByText } = await renderInTestApp( Custom Children , { - wrapper: MemoryRouter, + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, }, ); expect(getByText('Custom Children')).toHaveAttribute( diff --git a/plugins/catalog-react/src/components/EntityRefLink/EntityRefLink.tsx b/plugins/catalog-react/src/components/EntityRefLink/EntityRefLink.tsx index e220acc543..02e63e60e3 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/EntityRefLink.tsx +++ b/plugins/catalog-react/src/components/EntityRefLink/EntityRefLink.tsx @@ -19,20 +19,23 @@ import { ENTITY_DEFAULT_NAMESPACE, } from '@backstage/catalog-model'; import React, { forwardRef } from 'react'; -import { generatePath } from 'react-router'; -import { entityRoute } from '../../routes'; +import { entityRouteRef } from '../../routes'; import { formatEntityRefTitle } from './format'; import { Link, LinkProps } from '@backstage/core-components'; +import { useRouteRef } from '@backstage/core-plugin-api'; +import { Tooltip } from '@material-ui/core'; export type EntityRefLinkProps = { entityRef: Entity | EntityName; defaultKind?: string; + title?: string; children?: React.ReactNode; } & Omit; export const EntityRefLink = forwardRef( (props, ref) => { - const { entityRef, defaultKind, children, ...linkProps } = props; + const { entityRef, defaultKind, title, children, ...linkProps } = props; + const entityRoute = useRouteRef(entityRouteRef); let kind; let namespace; @@ -56,17 +59,21 @@ export const EntityRefLink = forwardRef( namespace?.toLocaleLowerCase('en-US') ?? ENTITY_DEFAULT_NAMESPACE, name, }; + const formattedEntityRefTitle = formatEntityRefTitle(entityRef, { + defaultKind, + }); - // TODO: Use useRouteRef here to generate the path - return ( - + const link = ( + {children} - {!children && formatEntityRefTitle(entityRef, { defaultKind })} + {!children && (title ?? formattedEntityRefTitle)} ); + + return title ? ( + {link} + ) : ( + link + ); }, ); diff --git a/plugins/catalog-react/src/components/EntityRefLink/EntityRefLinks.test.tsx b/plugins/catalog-react/src/components/EntityRefLink/EntityRefLinks.test.tsx index 97817f3de9..147e139749 100644 --- a/plugins/catalog-react/src/components/EntityRefLink/EntityRefLinks.test.tsx +++ b/plugins/catalog-react/src/components/EntityRefLink/EntityRefLinks.test.tsx @@ -14,13 +14,13 @@ * limitations under the License. */ -import { render } from '@testing-library/react'; +import { renderInTestApp } from '@backstage/test-utils'; import React from 'react'; -import { MemoryRouter } from 'react-router'; +import { entityRouteRef } from '../../routes'; import { EntityRefLinks } from './EntityRefLinks'; describe('', () => { - it('renders a single link', () => { + it('renders a single link', async () => { const entityNames = [ { kind: 'Component', @@ -28,16 +28,21 @@ describe('', () => { name: 'software', }, ]; - const { getByText } = render(, { - wrapper: MemoryRouter, - }); + const { getByText } = await renderInTestApp( + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, + ); expect(getByText('component:software')).toHaveAttribute( 'href', '/catalog/default/component/software', ); }); - it('renders multiple links', () => { + it('renders multiple links', async () => { const entityNames = [ { kind: 'Component', @@ -50,9 +55,14 @@ describe('', () => { name: 'interface', }, ]; - const { getByText } = render(, { - wrapper: MemoryRouter, - }); + const { getByText } = await renderInTestApp( + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, + ); expect(getByText(',')).toBeInTheDocument(); expect(getByText('component:software')).toHaveAttribute( 'href', diff --git a/plugins/catalog-react/src/components/EntityTable/columns.tsx b/plugins/catalog-react/src/components/EntityTable/columns.tsx index 6956d6a900..9a48b2d554 100644 --- a/plugins/catalog-react/src/components/EntityTable/columns.tsx +++ b/plugins/catalog-react/src/components/EntityTable/columns.tsx @@ -58,7 +58,11 @@ export function createEntityRefColumn({ return formatContent(entity1).localeCompare(formatContent(entity2)); }, render: entity => ( - + ), }; } diff --git a/plugins/catalog-react/src/components/EntityTable/presets.test.tsx b/plugins/catalog-react/src/components/EntityTable/presets.test.tsx index 6e18508b1f..a509b67477 100644 --- a/plugins/catalog-react/src/components/EntityTable/presets.test.tsx +++ b/plugins/catalog-react/src/components/EntityTable/presets.test.tsx @@ -23,6 +23,7 @@ import { import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; import React from 'react'; +import { entityRouteRef } from '../../routes'; import { EntityTable } from './EntityTable'; import { componentEntityColumns, systemEntityColumns } from './presets'; @@ -68,6 +69,11 @@ describe('systemEntityColumns', () => { emptyContent={
EMPTY
} columns={systemEntityColumns} />, + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); await waitFor(() => { @@ -123,6 +129,11 @@ describe('componentEntityColumns', () => { emptyContent={
EMPTY
} columns={componentEntityColumns} />, + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx b/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx index 339323c1bf..eccf824c2e 100644 --- a/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx +++ b/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx @@ -22,6 +22,7 @@ import { UnregisterEntityDialog } from './UnregisterEntityDialog'; import { ORIGIN_LOCATION_ANNOTATION } from '@backstage/catalog-model'; import { CatalogClient } from '@backstage/catalog-client'; import { catalogApiRef } from '../../api'; +import { entityRouteRef } from '../../routes'; import { screen, waitFor } from '@testing-library/react'; import { renderInTestApp } from '@backstage/test-utils'; import * as state from './useUnregisterEntityDialogState'; @@ -89,6 +90,11 @@ describe('UnregisterEntityDialog', () => { entity={entity} /> , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); userEvent.click(screen.getByText('Cancel')); @@ -110,6 +116,11 @@ describe('UnregisterEntityDialog', () => { entity={entity} /> , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); await waitFor(() => { @@ -132,6 +143,11 @@ describe('UnregisterEntityDialog', () => { entity={entity} /> , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); await waitFor(() => { @@ -159,6 +175,11 @@ describe('UnregisterEntityDialog', () => { entity={entity} /> , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); await waitFor(() => { @@ -198,6 +219,11 @@ describe('UnregisterEntityDialog', () => { entity={entity} /> , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); await waitFor(() => { @@ -239,6 +265,11 @@ describe('UnregisterEntityDialog', () => { entity={entity} /> , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); await waitFor(() => { @@ -282,6 +313,11 @@ describe('UnregisterEntityDialog', () => { entity={entity} /> , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx index 3b64ee6b73..d6f13ed22d 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx @@ -28,6 +28,7 @@ import { catalogApiRef, EntityProvider, CatalogApi, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import userEvent from '@testing-library/user-event'; @@ -85,6 +86,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('service')).toBeInTheDocument(); @@ -132,6 +138,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('View Source').closest('a')).toHaveAttribute( 'href', @@ -178,6 +189,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); const editLink = getByTitle('Edit Metadata').closest('a'); @@ -211,6 +227,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('View Source').closest('a')).not.toHaveAttribute('href'); }); @@ -243,6 +264,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(catalogApi.refreshEntity).not.toHaveBeenCalledWith( @@ -280,6 +306,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(queryByTitle('Schedule entity refresh')).not.toBeInTheDocument(); @@ -326,6 +357,7 @@ describe('', () => { { mountedRoutes: { '/docs/:namespace/:kind/:name': viewTechDocRouteRef, + '/catalog/:namespace/:kind/:name': entityRouteRef, }, }, ); @@ -371,6 +403,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('View TechDocs').closest('a')).not.toHaveAttribute('href'); @@ -414,6 +451,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('View TechDocs').closest('a')).not.toHaveAttribute('href'); diff --git a/plugins/catalog/src/components/AboutCard/AboutContent.test.tsx b/plugins/catalog/src/components/AboutCard/AboutContent.test.tsx index a1d16363a5..860ef2c532 100644 --- a/plugins/catalog/src/components/AboutCard/AboutContent.test.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutContent.test.tsx @@ -19,6 +19,7 @@ import { RELATION_OWNED_BY, RELATION_PART_OF, } from '@backstage/catalog-model'; +import { entityRouteRef } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import React from 'react'; import { AboutContent } from './AboutContent'; @@ -75,6 +76,11 @@ describe('', () => { it('renders info', async () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -103,6 +109,11 @@ describe('', () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -162,6 +173,11 @@ describe('', () => { it('renders info', async () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -193,6 +209,11 @@ describe('', () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -265,6 +286,11 @@ describe('', () => { it('renders info', async () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -299,6 +325,11 @@ describe('', () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -351,6 +382,11 @@ describe('', () => { it('renders info', async () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -374,6 +410,11 @@ describe('', () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -414,6 +455,11 @@ describe('', () => { it('renders info', async () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -438,6 +484,11 @@ describe('', () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -498,6 +549,11 @@ describe('', () => { it('renders info', async () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -525,6 +581,11 @@ describe('', () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -585,6 +646,11 @@ describe('', () => { it('renders info', async () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); @@ -610,6 +676,11 @@ describe('', () => { const { getByText, queryByText } = await renderInTestApp( , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Description')).toBeInTheDocument(); diff --git a/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx b/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx index 15f72b32ea..48ec1ef176 100644 --- a/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx +++ b/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx @@ -21,7 +21,7 @@ import { RELATION_OWNED_BY, } from '@backstage/catalog-model'; import { TableColumn, TableProps } from '@backstage/core-components'; -import { catalogApiRef } from '@backstage/plugin-catalog-react'; +import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react'; import { MockStorageApi, renderWithEffects, @@ -136,6 +136,7 @@ describe('CatalogPage', () => { { mountedRoutes: { '/create': createComponentRouteRef, + '/catalog/:namespace/:kind/:name': entityRouteRef, }, }, ), diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx index efbd6989e4..6c80e64fa9 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx @@ -24,6 +24,7 @@ import { renderInTestApp } from '@backstage/test-utils'; import * as React from 'react'; import { CatalogTable } from './CatalogTable'; import { + entityRouteRef, MockEntityListContextProvider, UserListFilter, } from '@backstage/plugin-catalog-react'; @@ -60,6 +61,11 @@ describe('CatalogTable component', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); const errorMessage = await rendered.findByText( /Could not fetch catalog entities./, @@ -83,6 +89,11 @@ describe('CatalogTable component', () => { > , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(rendered.getByText(/Owned \(3\)/)).toBeInTheDocument(); expect(rendered.getByText(/component1/)).toBeInTheDocument(); @@ -104,6 +115,11 @@ describe('CatalogTable component', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); const editButton = getByTitle('Edit'); @@ -129,6 +145,11 @@ describe('CatalogTable component', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); const viewButton = getByTitle('View'); diff --git a/plugins/catalog/src/components/CatalogTable/columns.tsx b/plugins/catalog/src/components/CatalogTable/columns.tsx index 60493d1847..89c1a23966 100644 --- a/plugins/catalog/src/components/CatalogTable/columns.tsx +++ b/plugins/catalog/src/components/CatalogTable/columns.tsx @@ -34,6 +34,7 @@ export function createNameColumn( ), }; diff --git a/plugins/catalog/src/components/DependencyOfComponentsCard/DependencyOfComponentsCard.test.tsx b/plugins/catalog/src/components/DependencyOfComponentsCard/DependencyOfComponentsCard.test.tsx index 7f703ef912..7dd823a8f0 100644 --- a/plugins/catalog/src/components/DependencyOfComponentsCard/DependencyOfComponentsCard.test.tsx +++ b/plugins/catalog/src/components/DependencyOfComponentsCard/DependencyOfComponentsCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -64,6 +65,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Dependency of components')).toBeInTheDocument(); @@ -111,6 +117,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/catalog/src/components/DependsOnComponentsCard/DependsOnComponentsCard.test.tsx b/plugins/catalog/src/components/DependsOnComponentsCard/DependsOnComponentsCard.test.tsx index f57d3c5e4d..b9fd75def9 100644 --- a/plugins/catalog/src/components/DependsOnComponentsCard/DependsOnComponentsCard.test.tsx +++ b/plugins/catalog/src/components/DependsOnComponentsCard/DependsOnComponentsCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -64,6 +65,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Depends on components')).toBeInTheDocument(); @@ -111,6 +117,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/catalog/src/components/DependsOnResourcesCard/DependsOnResourcesCard.test.tsx b/plugins/catalog/src/components/DependsOnResourcesCard/DependsOnResourcesCard.test.tsx index f9729e561c..bee759254c 100644 --- a/plugins/catalog/src/components/DependsOnResourcesCard/DependsOnResourcesCard.test.tsx +++ b/plugins/catalog/src/components/DependsOnResourcesCard/DependsOnResourcesCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -64,6 +65,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Depends on resources')).toBeInTheDocument(); @@ -111,6 +117,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx index ad0d3bceb4..7722f6ba17 100644 --- a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx +++ b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx @@ -19,6 +19,7 @@ import { catalogApiRef, EntityProvider, AsyncEntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { fireEvent } from '@testing-library/react'; @@ -54,6 +55,11 @@ describe('EntityLayout', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(rendered.getByText('my-entity')).toBeInTheDocument(); @@ -80,6 +86,11 @@ describe('EntityLayout', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(rendered.getByText('My Entity')).toBeInTheDocument(); @@ -98,6 +109,11 @@ describe('EntityLayout', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(rendered.getByText('Warning: Entity not found')).toBeInTheDocument(); @@ -130,6 +146,11 @@ describe('EntityLayout', () => { } /> , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); const secondTab = rendered.queryAllByRole('tab')[1]; @@ -172,6 +193,11 @@ describe('EntityLayout', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(rendered.queryByText('tabbed-test-title')).toBeInTheDocument(); diff --git a/plugins/catalog/src/components/HasComponentsCard/HasComponentsCard.test.tsx b/plugins/catalog/src/components/HasComponentsCard/HasComponentsCard.test.tsx index 91d9663f8d..d484ab026a 100644 --- a/plugins/catalog/src/components/HasComponentsCard/HasComponentsCard.test.tsx +++ b/plugins/catalog/src/components/HasComponentsCard/HasComponentsCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -64,6 +65,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Has components')).toBeInTheDocument(); @@ -111,6 +117,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/catalog/src/components/HasResourcesCard/HasResourcesCard.test.tsx b/plugins/catalog/src/components/HasResourcesCard/HasResourcesCard.test.tsx index 6dcf2ca9fc..45604ceb56 100644 --- a/plugins/catalog/src/components/HasResourcesCard/HasResourcesCard.test.tsx +++ b/plugins/catalog/src/components/HasResourcesCard/HasResourcesCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -111,6 +112,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx b/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx index 46281b43be..431e757656 100644 --- a/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx +++ b/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -64,6 +65,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Has subcomponents')).toBeInTheDocument(); @@ -111,6 +117,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/catalog/src/components/HasSystemsCard/HasSystemsCard.test.tsx b/plugins/catalog/src/components/HasSystemsCard/HasSystemsCard.test.tsx index b25fcaa052..3fcfed6099 100644 --- a/plugins/catalog/src/components/HasSystemsCard/HasSystemsCard.test.tsx +++ b/plugins/catalog/src/components/HasSystemsCard/HasSystemsCard.test.tsx @@ -19,6 +19,7 @@ import { CatalogApi, catalogApiRef, EntityProvider, + entityRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import { waitFor } from '@testing-library/react'; @@ -64,6 +65,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); expect(getByText('Has systems')).toBeInTheDocument(); @@ -109,6 +115,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ); await waitFor(() => { diff --git a/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx b/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx index b9edb0746a..c7fca26a3b 100644 --- a/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx +++ b/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx @@ -15,7 +15,11 @@ */ import { Entity } from '@backstage/catalog-model'; -import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react'; +import { + CatalogApi, + catalogApiRef, + entityRouteRef, +} from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import React from 'react'; import { FossaApi, fossaApiRef } from '../../api'; @@ -125,6 +129,11 @@ describe('', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + }, + }, ); expect(getAllByText(/Not configured/i)).toHaveLength(2); diff --git a/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx b/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx index 360e31cce5..743ed987fa 100644 --- a/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx +++ b/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx @@ -15,7 +15,10 @@ */ import { UserEntity } from '@backstage/catalog-model'; -import { EntityProvider } from '@backstage/plugin-catalog-react'; +import { + EntityProvider, + entityRouteRef, +} from '@backstage/plugin-catalog-react'; import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils'; import React from 'react'; import { UserProfileCard } from './UserProfileCard'; @@ -53,6 +56,11 @@ describe('UserSummary Test', () => { , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, ), ); diff --git a/plugins/techdocs/src/home/components/DocsTable.test.tsx b/plugins/techdocs/src/home/components/DocsTable.test.tsx index 2e5ada78a7..4564725db6 100644 --- a/plugins/techdocs/src/home/components/DocsTable.test.tsx +++ b/plugins/techdocs/src/home/components/DocsTable.test.tsx @@ -19,6 +19,7 @@ import { wrapInTestApp } from '@backstage/test-utils'; import { configApiRef } from '@backstage/core-plugin-api'; import { DocsTable } from './DocsTable'; import { rootDocsRouteRef } from '../../routes'; +import { entityRouteRef } from '@backstage/plugin-catalog-react'; // Hacky way to mock a specific boolean config value. const getOptionalBooleanMock = jest.fn().mockReturnValue(false); @@ -94,6 +95,7 @@ describe('DocsTable test', () => { { mountedRoutes: { '/docs/:namespace/:kind/:name/*': rootDocsRouteRef, + '/catalog/:namespace/:kind/:name': entityRouteRef, }, }, ), @@ -144,6 +146,7 @@ describe('DocsTable test', () => { { mountedRoutes: { '/techdocs/:namespace/:kind/:name/*': rootDocsRouteRef, + '/catalog/:namespace/:kind/:name': entityRouteRef, }, }, ), @@ -163,6 +166,7 @@ describe('DocsTable test', () => { wrapInTestApp(, { mountedRoutes: { '/docs/:namespace/:kind/:name/*': rootDocsRouteRef, + '/catalog/:namespace/:kind/:name': entityRouteRef, }, }), );