From 5dd5cc81932dcf7b647e76e52125394854ab0e8a Mon Sep 17 00:00:00 2001 From: "Storm B. Heg" Date: Thu, 3 Aug 2023 14:17:42 +0200 Subject: [PATCH] FieldBlock: add test proving options are constructed and passed down --- .../StreamField/blocks/FieldBlock.test.js | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/client/src/components/StreamField/blocks/FieldBlock.test.js b/client/src/components/StreamField/blocks/FieldBlock.test.js index adb3fb341a8d..a2db80f62c7f 100644 --- a/client/src/components/StreamField/blocks/FieldBlock.test.js +++ b/client/src/components/StreamField/blocks/FieldBlock.test.js @@ -8,7 +8,14 @@ window.comments = { }; // Define some callbacks in global scope that can be mocked in tests -let constructor = (_widgetName, _name, _id, _initialState) => {}; +let constructor = ( + _widgetName, + _name, + _id, + _initialState, + _parentCapabilities, + _options, +) => {}; let setState = (_widgetName, _state) => {}; let getState = (_widgetName) => {}; let getValue = (_widgetName) => {}; @@ -20,13 +27,19 @@ class DummyWidgetDefinition { this.throwErrorOnRender = throwErrorOnRender; } - render(placeholder, name, id, initialState) { + render(placeholder, name, id, initialState, parentCapabilities, options) { if (this.throwErrorOnRender) { throw new Error('Mock rendering error'); } const widgetName = this.widgetName; - constructor(widgetName, { name, id, initialState }); + constructor(widgetName, { + name, + id, + initialState, + parentCapabilities, + options, + }); $(placeholder).replaceWith( `

${widgetName}

`, @@ -100,6 +113,24 @@ describe('telepath: wagtail.blocks.FieldBlock', () => { name: 'the-prefix', id: 'the-prefix', initialState: 'Test initial state', + options: { + // Options should have been passed to the block definition + attributes: { + 'aria-describedby': 'the-prefix-helptext', + 'required': '', + }, + }, + parentCapabilities: new Map(), + }); + }); + + test('getAttributes() returns aria-describedby and required attributes', () => { + const attributes = boundBlock.getAttributes(); + expect(attributes).toEqual({ + // Added because FieldBlockDefinition has a helpText in its meta options + 'aria-describedby': 'the-prefix-helptext', + // Added because FieldBlockDefinition has required set in its meta options + 'required': '', }); });