From 92e545c7a555ec18344ec4433e1c3abc99c18cc7 Mon Sep 17 00:00:00 2001 From: secustor Date: Fri, 21 Feb 2025 13:36:44 +0100 Subject: [PATCH] tests(techdocs-modules): move @backstage/plugin-catalog-react to dev Signed-off-by: secustor --- .../ExpandableNavigation.test.tsx | 13 ++++++++++ .../src/ReportIssue/ReportIssue.test.tsx | 25 ++++++++++++++++--- .../src/TextSize/TextSize.test.tsx | 13 ++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/plugins/techdocs-module-addons-contrib/src/ExpandableNavigation/ExpandableNavigation.test.tsx b/plugins/techdocs-module-addons-contrib/src/ExpandableNavigation/ExpandableNavigation.test.tsx index 3efc923145..a38ea600bc 100644 --- a/plugins/techdocs-module-addons-contrib/src/ExpandableNavigation/ExpandableNavigation.test.tsx +++ b/plugins/techdocs-module-addons-contrib/src/ExpandableNavigation/ExpandableNavigation.test.tsx @@ -20,6 +20,7 @@ import React from 'react'; import { fireEvent, waitFor } from '@testing-library/react'; import { ExpandableNavigation } from '../plugin'; +import { entityPresentationApiRef } from '@backstage/plugin-catalog-react'; const mockNavWithSublevels = (
@@ -84,11 +85,21 @@ const mockNavWithoutSublevels = ( ); describe('ExpandableNavigation', () => { + const entityPresentationApiMock = { + forEntity: jest.fn(), + }; + entityPresentationApiMock.forEntity.mockReturnValue({ + snapshot: { + primaryTitle: 'Test Entity', + }, + }); + it('renders without exploding', async () => { const { getByRole } = await TechDocsAddonTester.buildAddonsInTechDocs([ , ]) .withDom(mockNavWithSublevels) + .withApis([[entityPresentationApiRef, entityPresentationApiMock]]) .renderWithEffects(); expect(getByRole('button', { name: 'expand-nav' })).toBeInTheDocument(); @@ -100,6 +111,7 @@ describe('ExpandableNavigation', () => { , ]) .withDom(mockNavWithSublevels) + .withApis([[entityPresentationApiRef, entityPresentationApiMock]]) .renderWithEffects(); const toggles = @@ -137,6 +149,7 @@ describe('ExpandableNavigation', () => { , ]) .withDom(mockNavWithoutSublevels) + .withApis([[entityPresentationApiRef, entityPresentationApiMock]]) .renderWithEffects(); expect( diff --git a/plugins/techdocs-module-addons-contrib/src/ReportIssue/ReportIssue.test.tsx b/plugins/techdocs-module-addons-contrib/src/ReportIssue/ReportIssue.test.tsx index 459fa1b65e..d7dd6584c1 100644 --- a/plugins/techdocs-module-addons-contrib/src/ReportIssue/ReportIssue.test.tsx +++ b/plugins/techdocs-module-addons-contrib/src/ReportIssue/ReportIssue.test.tsx @@ -21,6 +21,7 @@ import { fireEvent, waitFor } from '@testing-library/react'; import { scmIntegrationsApiRef } from '@backstage/integration-react'; import { ReportIssue } from '../plugin'; +import { entityPresentationApiRef } from '@backstage/plugin-catalog-react'; const byUrl = jest.fn(); @@ -52,6 +53,15 @@ describe('ReportIssue', () => { containsNode: () => true, } as unknown as Selection; + const entityPresentationApiMock = { + forEntity: jest.fn(), + }; + entityPresentationApiMock.forEntity.mockReturnValue({ + snapshot: { + primaryTitle: 'Test Entity', + }, + }); + beforeEach(() => { jest.clearAllMocks(); }); @@ -93,7 +103,10 @@ describe('ReportIssue', () => { , ) - .withApis([[scmIntegrationsApiRef, { byUrl }]]) + .withApis([ + [scmIntegrationsApiRef, { byUrl }], + [entityPresentationApiRef, entityPresentationApiMock], + ]) .renderWithEffects(); (shadowRoot as ShadowRoot & Pick).getSelection = @@ -151,7 +164,10 @@ describe('ReportIssue', () => { , ) - .withApis([[scmIntegrationsApiRef, { byUrl }]]) + .withApis([ + [scmIntegrationsApiRef, { byUrl }], + [entityPresentationApiRef, entityPresentationApiMock], + ]) .renderWithEffects(); (shadowRoot as ShadowRoot & Pick).getSelection = @@ -215,7 +231,10 @@ describe('ReportIssue', () => { , ) - .withApis([[scmIntegrationsApiRef, { byUrl }]]) + .withApis([ + [scmIntegrationsApiRef, { byUrl }], + [entityPresentationApiRef, entityPresentationApiMock], + ]) .renderWithEffects(); (shadowRoot as ShadowRoot & Pick).getSelection = diff --git a/plugins/techdocs-module-addons-contrib/src/TextSize/TextSize.test.tsx b/plugins/techdocs-module-addons-contrib/src/TextSize/TextSize.test.tsx index de66889312..9a02fb12cf 100644 --- a/plugins/techdocs-module-addons-contrib/src/TextSize/TextSize.test.tsx +++ b/plugins/techdocs-module-addons-contrib/src/TextSize/TextSize.test.tsx @@ -19,6 +19,7 @@ import React from 'react'; import { act, fireEvent, waitFor } from '@testing-library/react'; import { TextSize } from '../plugin'; import { useShadowRootElements } from '@backstage/plugin-techdocs-react'; +import { entityPresentationApiRef } from '@backstage/plugin-catalog-react'; jest.mock('@backstage/plugin-techdocs-react', () => ({ ...jest.requireActual('@backstage/plugin-techdocs-react'), @@ -28,6 +29,15 @@ jest.mock('@backstage/plugin-techdocs-react', () => ({ describe('TextSize', () => { const useShadowRootElementsMock = useShadowRootElements as jest.Mock; + const entityPresentationApiMock = { + forEntity: jest.fn(), + }; + entityPresentationApiMock.forEntity.mockReturnValue({ + snapshot: { + primaryTitle: 'Test Entity', + }, + }); + beforeEach(() => { useShadowRootElementsMock.mockReturnValue([]); }); @@ -37,6 +47,7 @@ describe('TextSize', () => { , ]) .withDom(TEST_CONTENT) + .withApis([[entityPresentationApiRef, entityPresentationApiMock]]) .renderWithEffects(); expect(getByText('TEST_CONTENT')).toBeInTheDocument(); @@ -46,6 +57,7 @@ describe('TextSize', () => { const { getByTitle, getByText, getByRole, getByDisplayValue } = await TechDocsAddonTester.buildAddonsInTechDocs([]) .withDom(TEST_CONTENT) + .withApis([[entityPresentationApiRef, entityPresentationApiMock]]) .renderWithEffects(); const content = getByText('TEST_CONTENT'); @@ -103,6 +115,7 @@ describe('TextSize', () => { getByDisplayValue, } = await TechDocsAddonTester.buildAddonsInTechDocs([]) .withDom(TEST_CONTENT) + .withApis([[entityPresentationApiRef, entityPresentationApiMock]]) .renderWithEffects(); const content = getByText('TEST_CONTENT');