From 7e451f21168d82f4f90ec06b1fd91e1423504eac Mon Sep 17 00:00:00 2001 From: Thibaud Colas <thibaudcolas@gmail.com> Date: Fri, 24 Jan 2025 13:39:53 +0000 Subject: [PATCH] Add unit tests for rich text block chooser initialisation based on capabilities --- .../admin/telepath/widgets.test.js | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/client/src/entrypoints/admin/telepath/widgets.test.js b/client/src/entrypoints/admin/telepath/widgets.test.js index cc2fd88917..4e0aee5987 100644 --- a/client/src/entrypoints/admin/telepath/widgets.test.js +++ b/client/src/entrypoints/admin/telepath/widgets.test.js @@ -526,6 +526,28 @@ describe('telepath: wagtail.widgets.DraftailRichTextArea', () => { }); parentCapabilities = new Map(); parentCapabilities.set('split', { enabled: true, fn: jest.fn() }); + parentCapabilities.set('addSibling', { + enabled: true, + getBlockMax: () => 5, + blockGroups: [ + [ + 'Media', + [ + { + name: 'image_block', + meta: { + icon: 'image', + label: 'Image', + blockDefId: 'blockdef-1234', + isPreviewable: true, + description: 'Full-width image', + }, + }, + ], + ], + ], + fn: jest.fn(), + }); const inputId = 'the-id'; boundWidget = widgetDef.render( document.getElementById('placeholder'), @@ -616,11 +638,23 @@ describe('telepath: wagtail.widgets.DraftailRichTextArea', () => { ReactTestUtils.act(() => boundWidget.setCapabilityOptions('split', { enabled: true }), ); - expect(inputElement.draftailEditor.props.commands).toHaveLength(3); - expect(inputElement.draftailEditor.props.commands[2].items[0].type).toBe( + expect(inputElement.draftailEditor.props.commands).toHaveLength(4); + expect(inputElement.draftailEditor.props.commands[3].items[0].type).toBe( 'split', ); }); + + test('configures the block chooser based on siblings capability', () => { + expect(inputElement.draftailEditor.props.commands[2].items[0]).toEqual( + expect.objectContaining({ + icon: 'image', + label: 'Image', + blockDefId: 'blockdef-1234', + isPreviewable: true, + description: 'Full-width image', + }), + ); + }); }); describe('telepath: wagtail.widgets.DateInput', () => {