From 6ccee05f4689c990df2c740eb1cf1ec0885e56c7 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Tue, 23 Mar 2021 11:16:12 -0400 Subject: [PATCH] Fix tests Signed-off-by: Adam Harvey --- .../SystemDiagram/SystemDiagram.test.tsx | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/plugins/catalog/src/components/SystemDiagram/SystemDiagram.test.tsx b/plugins/catalog/src/components/SystemDiagram/SystemDiagram.test.tsx index bca8d97b05..cd38384645 100644 --- a/plugins/catalog/src/components/SystemDiagram/SystemDiagram.test.tsx +++ b/plugins/catalog/src/components/SystemDiagram/SystemDiagram.test.tsx @@ -22,6 +22,15 @@ import React from 'react'; import { SystemDiagram } from './SystemDiagram'; describe('', () => { + beforeAll(() => { + Object.defineProperty(window.SVGElement.prototype, 'getBBox', { + value: () => ({ width: 100, height: 100 }), + configurable: true, + }); + }); + + afterEach(() => jest.resetAllMocks()); + const catalogApi: Partial = { getEntities: () => Promise.resolve({ @@ -41,7 +50,7 @@ describe('', () => { apiVersion: 'backstage.io/v1alpha1', kind: 'Component', metadata: { - name: 'Entity2', + name: 'my-entity', namespace: 'my-namespace', }, spec: { @@ -50,35 +59,43 @@ describe('', () => { system: 'my-system', }, }, + { + apiVersion: 'backstage.io/v1alpha1', + kind: 'System', + metadata: { + name: 'my-system2', + namespace: 'my-namespace2', + }, + spec: { + owner: 'tools@example.com', + }, + }, ] as Entity[], }), - // need to mock this? - // getEntityRelations: (Entity, string) => - // Promise.resolve({ - - // }), }; - afterEach(() => jest.resetAllMocks()); - it('shows empty list if no relations', async () => { const entity: Entity = { apiVersion: 'v1', kind: 'System', metadata: { - name: 'my-system', + name: 'my-system2', + namespace: 'my-namespace2', }, relations: [], }; - const { getByText } = await renderInTestApp( + const { queryByText } = await renderInTestApp( , ); - expect(getByText('System Diagram')).toBeInTheDocument(); - // expect(getByText('my-system')).not.toBeInTheDocument(); + expect(queryByText(/System Diagram/)).toBeInTheDocument(); + expect(queryByText(/system:my-namespace2\/my-system2/)).toBeInTheDocument(); + expect( + queryByText(/component:my-namespace\/my-entity/), + ).not.toBeInTheDocument(); }); it('shows related systems', async () => { @@ -108,6 +125,7 @@ describe('', () => { ); expect(getByText('System Diagram')).toBeInTheDocument(); - expect(getByText('my-system')).toBeInTheDocument(); + expect(getByText('system:my-namespace/my-system')).toBeInTheDocument(); + expect(getByText('component:my-namespace/my-entity')).toBeInTheDocument(); }); });