tests(techdocs-modules): move @backstage/plugin-catalog-react to dev

Signed-off-by: secustor <sebastian@poxhofer.at>
This commit is contained in:
secustor
2025-02-21 13:36:44 +01:00
parent 9c1cb5fe42
commit 92e545c7a5
3 changed files with 48 additions and 3 deletions
@@ -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 = (
<div data-md-component="navigation">
@@ -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([
<ExpandableNavigation />,
])
.withDom(mockNavWithSublevels)
.withApis([[entityPresentationApiRef, entityPresentationApiMock]])
.renderWithEffects();
expect(getByRole('button', { name: 'expand-nav' })).toBeInTheDocument();
@@ -100,6 +111,7 @@ describe('ExpandableNavigation', () => {
<ExpandableNavigation />,
])
.withDom(mockNavWithSublevels)
.withApis([[entityPresentationApiRef, entityPresentationApiMock]])
.renderWithEffects();
const toggles =
@@ -137,6 +149,7 @@ describe('ExpandableNavigation', () => {
<ExpandableNavigation />,
])
.withDom(mockNavWithoutSublevels)
.withApis([[entityPresentationApiRef, entityPresentationApiMock]])
.renderWithEffects();
expect(
@@ -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', () => {
</body>
</html>,
)
.withApis([[scmIntegrationsApiRef, { byUrl }]])
.withApis([
[scmIntegrationsApiRef, { byUrl }],
[entityPresentationApiRef, entityPresentationApiMock],
])
.renderWithEffects();
(shadowRoot as ShadowRoot & Pick<Document, 'getSelection'>).getSelection =
@@ -151,7 +164,10 @@ describe('ReportIssue', () => {
</body>
</html>,
)
.withApis([[scmIntegrationsApiRef, { byUrl }]])
.withApis([
[scmIntegrationsApiRef, { byUrl }],
[entityPresentationApiRef, entityPresentationApiMock],
])
.renderWithEffects();
(shadowRoot as ShadowRoot & Pick<Document, 'getSelection'>).getSelection =
@@ -215,7 +231,10 @@ describe('ReportIssue', () => {
</body>
</html>,
)
.withApis([[scmIntegrationsApiRef, { byUrl }]])
.withApis([
[scmIntegrationsApiRef, { byUrl }],
[entityPresentationApiRef, entityPresentationApiMock],
])
.renderWithEffects();
(shadowRoot as ShadowRoot & Pick<Document, 'getSelection'>).getSelection =
@@ -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', () => {
<TextSize />,
])
.withDom(<body>TEST_CONTENT</body>)
.withApis([[entityPresentationApiRef, entityPresentationApiMock]])
.renderWithEffects();
expect(getByText('TEST_CONTENT')).toBeInTheDocument();
@@ -46,6 +57,7 @@ describe('TextSize', () => {
const { getByTitle, getByText, getByRole, getByDisplayValue } =
await TechDocsAddonTester.buildAddonsInTechDocs([<TextSize />])
.withDom(<body>TEST_CONTENT</body>)
.withApis([[entityPresentationApiRef, entityPresentationApiMock]])
.renderWithEffects();
const content = getByText('TEST_CONTENT');
@@ -103,6 +115,7 @@ describe('TextSize', () => {
getByDisplayValue,
} = await TechDocsAddonTester.buildAddonsInTechDocs([<TextSize />])
.withDom(<body>TEST_CONTENT</body>)
.withApis([[entityPresentationApiRef, entityPresentationApiMock]])
.renderWithEffects();
const content = getByText('TEST_CONTENT');