diff --git a/client/src/entrypoints/admin/telepath/__snapshots__/widgets.test.js.snap b/client/src/entrypoints/admin/telepath/__snapshots__/widgets.test.js.snap new file mode 100644 index 0000000000..694494c46a --- /dev/null +++ b/client/src/entrypoints/admin/telepath/__snapshots__/widgets.test.js.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`telepath: wagtail.widgets.RadioSelect it renders correctly 1`] = ` +"" +`; diff --git a/client/src/entrypoints/admin/telepath/widgets.test.js b/client/src/entrypoints/admin/telepath/widgets.test.js index 7c8f8a58c7..ce5a92e932 100644 --- a/client/src/entrypoints/admin/telepath/widgets.test.js +++ b/client/src/entrypoints/admin/telepath/widgets.test.js @@ -45,3 +45,58 @@ describe('telepath: wagtail.widgets.Widget', () => { expect(document.activeElement).toBe(document.querySelector('input')); }); }); + +describe('telepath: wagtail.widgets.RadioSelect', () => { + let boundWidget; + + beforeEach(() => { + // Create a placeholder to render the widget + document.body.innerHTML = '
'; + + // Unpack and render a radio select widget + const widgetDef = window.telepath.unpack({ + _type: 'wagtail.widgets.RadioSelect', + _args: [ + ``, + '__ID___0' + ] + }); + boundWidget = widgetDef.render($('#placeholder'), 'the-name', 'the-id', 'tea'); + }); + + test('it renders correctly', () => { + expect(document.body.innerHTML).toMatchSnapshot(); + expect(document.querySelector('input[value="tea"]').checked).toBe(true); + expect(document.querySelector('input[value="coffee"]').checked).toBe(false); + }); + + test('getValue() returns the current value', () => { + expect(boundWidget.getValue()).toBe('tea'); + }); + + test('getState() returns the current state', () => { + expect(boundWidget.getState()).toBe('tea'); + }); + + test('setState() changes the current state', () => { + boundWidget.setState('coffee'); + expect(document.querySelector('input[value="tea"]').checked).toBe(false); + expect(document.querySelector('input[value="coffee"]').checked).toBe(true); + }); + + test('focus() focuses the text input', () => { + boundWidget.focus(); + + // Note: This widget always focuses the last element + expect(document.activeElement).toBe(document.querySelector('input[value="coffee"]')); + }); +});