test: add test for markdown description rendering in EntityPicker
Signed-off-by: Toby Harradine <tobyh@canva.com>
This commit is contained in:
@@ -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('<EntityPicker />', () => {
|
||||
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(
|
||||
<Wrapper>
|
||||
<EntityPicker {...props} />
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
expect(backstageCore.MarkdownContent).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
content: '**Bold text** and *italic text*',
|
||||
linkTarget: '_blank',
|
||||
}),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user