diff --git a/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx b/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx index a4e284a0eb..9990277da3 100644 --- a/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx +++ b/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx @@ -14,14 +14,24 @@ * limitations under the License. */ -import { EntityProvider } from '@backstage/plugin-catalog-react'; +import { + CatalogApi, + catalogApiRef, + EntityProvider, +} from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import React from 'react'; import { EntityProcessingErrorsPanel } from './EntityProcessingErrorsPanel'; -import { Entity } from '@backstage/catalog-model'; +import { Entity, getEntityName } from '@backstage/catalog-model'; +import { ApiProvider, ApiRegistry } from '@backstage/core-app-api'; describe('', () => { + const catalogClient: jest.Mocked = { + getEntityAncestors: jest.fn(), + } as any; + const apis = ApiRegistry.with(catalogApiRef, catalogClient); + it('renders EntityProcessErrors if the entity has errors', async () => { const entity: Entity = { apiVersion: 'v1', @@ -86,10 +96,16 @@ describe('', () => { }, }; + catalogClient.getEntityAncestors.mockResolvedValue({ + root: getEntityName(entity), + items: [{ entity, parents: [] }], + }); const { getByText, queryByText } = await renderInTestApp( - - - , + + + + + , ); expect( @@ -99,5 +115,110 @@ describe('', () => { ).toBeInTheDocument(); expect(getByText('Error: Foo')).toBeInTheDocument(); expect(queryByText('Error: This should not be rendered')).toBeNull(); + expect( + queryByText('The error below originates from'), + ).not.toBeInTheDocument(); + }); + + it('renders EntityProcessErrors if the parent entity has errors', async () => { + const entity: Entity = { + apiVersion: 'v1', + kind: 'Component', + metadata: { + name: 'software', + description: 'This is the description', + }, + spec: { + owner: 'guest', + type: 'service', + lifecycle: 'production', + }, + }; + + const parent: Entity = { + apiVersion: 'v1', + kind: 'Component', + metadata: { + name: 'parent', + description: 'This is the description', + }, + + spec: { + owner: 'guest', + type: 'service', + lifecycle: 'production', + }, + status: { + items: [ + { + type: 'backstage.io/catalog-processing', + level: 'error', + message: + 'InputError: Policy check failed; caused by Error: Malformed envelope, /metadata/labels should be object', + error: { + name: 'InputError', + message: + 'Policy check failed; caused by Error: Malformed envelope, /metadata/labels should be object', + cause: { + name: 'Error', + message: + 'Malformed envelope, /metadata/labels should be object', + }, + }, + }, + { + type: 'foo', + level: 'error', + message: 'InputError: This should not be rendered', + error: { + name: 'InputError', + message: 'Foo', + cause: { + name: 'Error', + message: + 'Malformed envelope, /metadata/labels should be object', + }, + }, + }, + { + type: 'backstage.io/catalog-processing', + level: 'error', + message: 'InputError: Foo', + error: { + name: 'InputError', + message: 'Foo', + cause: { + name: 'Error', + message: + 'Malformed envelope, /metadata/labels should be object', + }, + }, + }, + ], + }, + }; + catalogClient.getEntityAncestors.mockResolvedValue({ + root: getEntityName(entity), + items: [ + { entity, parents: [getEntityName(parent)] }, + { entity: parent, parents: [] }, + ], + }); + const { getByText, queryByText } = await renderInTestApp( + + + + + , + ); + + expect( + getByText( + 'Error: Policy check failed; caused by Error: Malformed envelope, /metadata/labels should be object', + ), + ).toBeInTheDocument(); + expect(getByText('Error: Foo')).toBeInTheDocument(); + expect(queryByText('Error: This should not be rendered')).toBeNull(); + expect(queryByText('The error below originates from')).toBeInTheDocument(); }); });