Skip to content

Commit bfd138a

Browse files
committed
Add unit tests for rich text block chooser initialisation based on capabilities
1 parent 3a4ff1e commit bfd138a

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

client/src/entrypoints/admin/telepath/widgets.test.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,28 @@ describe('telepath: wagtail.widgets.DraftailRichTextArea', () => {
526526
});
527527
parentCapabilities = new Map();
528528
parentCapabilities.set('split', { enabled: true, fn: jest.fn() });
529+
parentCapabilities.set('addSibling', {
530+
enabled: true,
531+
getBlockMax: () => 5,
532+
blockGroups: [
533+
[
534+
'Media',
535+
[
536+
{
537+
name: 'image_block',
538+
meta: {
539+
icon: 'image',
540+
label: 'Image',
541+
blockDefId: 'blockdef-1234',
542+
isPreviewable: true,
543+
description: 'Full-width image',
544+
},
545+
},
546+
],
547+
],
548+
],
549+
fn: jest.fn(),
550+
});
529551
const inputId = 'the-id';
530552
boundWidget = widgetDef.render(
531553
document.getElementById('placeholder'),
@@ -616,11 +638,23 @@ describe('telepath: wagtail.widgets.DraftailRichTextArea', () => {
616638
ReactTestUtils.act(() =>
617639
boundWidget.setCapabilityOptions('split', { enabled: true }),
618640
);
619-
expect(inputElement.draftailEditor.props.commands).toHaveLength(3);
620-
expect(inputElement.draftailEditor.props.commands[2].items[0].type).toBe(
641+
expect(inputElement.draftailEditor.props.commands).toHaveLength(4);
642+
expect(inputElement.draftailEditor.props.commands[3].items[0].type).toBe(
621643
'split',
622644
);
623645
});
646+
647+
test('configures the block chooser based on siblings capability', () => {
648+
expect(inputElement.draftailEditor.props.commands[2].items[0]).toEqual(
649+
expect.objectContaining({
650+
icon: 'image',
651+
label: 'Image',
652+
blockDefId: 'blockdef-1234',
653+
isPreviewable: true,
654+
description: 'Full-width image',
655+
}),
656+
);
657+
});
624658
});
625659

626660
describe('telepath: wagtail.widgets.DateInput', () => {

0 commit comments

Comments
 (0)