Add unit tests for rich text block chooser initialisation based on capabilities

stable/6.4.x
Thibaud Colas 2025-01-24 13:39:53 +00:00 zatwierdzone przez Sage Abdullah
rodzic 32011394e8
commit 7e451f2116
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: EB1A33CC51CC0217
1 zmienionych plików z 36 dodań i 2 usunięć

Wyświetl plik

@ -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', () => {