Account for case when builder is external, entity exists, but docs do not.

Co-authored-by: Jeremy Guarini <jguarini@paloaltonetworks.com>
Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2022-04-25 09:52:02 +02:00
parent bed0d64ce9
commit f3dc243432
2 changed files with 28 additions and 4 deletions
@@ -148,6 +148,28 @@ describe('<TechDocsReaderPageHeader />', () => {
});
});
it('should not render a techdocs page header if techdocs metadata is missing', async () => {
getTechDocsMetadata.mockResolvedValue(undefined);
await act(async () => {
const rendered = await renderInTestApp(
<Wrapper>
<TechDocsReaderPageHeader />
</Wrapper>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name/*': entityRouteRef,
'/docs': rootRouteRef,
},
},
);
await waitFor(() => {
expect(rendered.container.innerHTML).not.toContain('header');
});
});
});
it('should render a link back to the component page', async () => {
getTechDocsMetadata.mockResolvedValue(mockTechDocsMetadata);
@@ -71,7 +71,7 @@ export const TechDocsReaderPageHeader = (
subtitle,
setSubtitle,
entityRef,
metadata: { value: metadata },
metadata: { value: metadata, loading: metadataLoading },
entityMetadata: { value: entityMetadata, loading: entityMetadataLoading },
} = useTechDocsReaderPage();
@@ -146,9 +146,11 @@ export const TechDocsReaderPageHeader = (
</>
);
// If there is no entity metadata, there's no reason to show the header.
if (entityMetadataLoading === false && entityMetadata === undefined)
return null;
// If there is no entity or techdocs metadata, there's no reason to show the
// header (hides the header on 404 error pages).
const noEntMetadata = !entityMetadataLoading && entityMetadata === undefined;
const noTdMetadata = !metadataLoading && metadata === undefined;
if (noEntMetadata || noTdMetadata) return null;
return (
<Header