From 205df8bd61aa239d956ac5e75bf729c446d3a2b6 Mon Sep 17 00:00:00 2001 From: Toby Harradine Date: Wed, 16 Apr 2025 13:00:54 +1000 Subject: [PATCH] test: add test for markdown description rendering in EntityPicker Signed-off-by: Toby Harradine --- .../fields/EntityPicker/EntityPicker.test.tsx | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx index ab3092e3ed..2522283230 100644 --- a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx +++ b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx @@ -28,6 +28,13 @@ import { EntityPickerProps } from './schema'; import { ScaffolderRJSFFieldProps as FieldProps } from '@backstage/plugin-scaffolder-react'; import { DefaultEntityPresentationApi } from '@backstage/plugin-catalog'; import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils'; +import * as backstageCore from '@backstage/core-components'; + +// Mock MarkdownContent to test that it's called with the right props +jest.mock('@backstage/core-components', () => ({ + ...jest.requireActual('@backstage/core-components'), + MarkdownContent: jest.fn(() => null), +})); const makeEntity = (kind: string, namespace: string, name: string): Entity => ({ apiVersion: 'scaffolder.backstage.io/v1beta3', @@ -812,4 +819,39 @@ describe('', () => { expect(onChange).toHaveBeenCalledWith(undefined); }); }); + + describe('with markdown description', () => { + beforeEach(() => { + jest.clearAllMocks(); + uiSchema = { 'ui:options': {} }; + props = { + onChange, + schema: { + description: '**Bold text** and *italic text*', + }, + required, + uiSchema, + rawErrors, + formData, + } as unknown as FieldProps; + + catalogApi.getEntities.mockResolvedValue({ items: entities }); + }); + + it('renders description as markdown', async () => { + await renderInTestApp( + + + , + ); + + expect(backstageCore.MarkdownContent).toHaveBeenCalledWith( + expect.objectContaining({ + content: '**Bold text** and *italic text*', + linkTarget: '_blank', + }), + expect.anything(), + ); + }); + }); });