diff --git a/packages/ra-ui-materialui/src/input/NullableBooleanInput.spec.tsx b/packages/ra-ui-materialui/src/input/NullableBooleanInput.spec.tsx index adeb7069fc7..d13515c56ce 100644 --- a/packages/ra-ui-materialui/src/input/NullableBooleanInput.spec.tsx +++ b/packages/ra-ui-materialui/src/input/NullableBooleanInput.spec.tsx @@ -77,6 +77,35 @@ describe('', () => { ).toBeNull(); }); + it('should select the option "true" if defaultValue is true', () => { + const { container, getByRole, getByText, getAllByText } = render( +
( + + )} + /> + ); + expect(container.querySelector('input').getAttribute('value')).toBe( + 'true' + ); + const select = getByRole('button'); + fireEvent.mouseDown(select); + expect( + getAllByText('ra.boolean.true')[1].getAttribute('aria-selected') + ).toBe('true'); + expect( + getByText('ra.boolean.false').getAttribute('aria-selected') + ).toBeNull(); + expect( + getByText('ra.boolean.null').getAttribute('aria-selected') + ).toBeNull(); + }); + it('should select the option "false" if value is false', () => { const { getByRole, getByText, getAllByText, container } = render( ', () => { ).toBeNull(); }); + it('should select the option "false" if defaultValue is false', () => { + const { getByRole, getByText, getAllByText, container } = render( + ( + + )} + /> + ); + expect(container.querySelector('input').getAttribute('value')).toBe( + 'false' + ); + const select = getByRole('button'); + fireEvent.mouseDown(select); + expect( + getByText('ra.boolean.true').getAttribute('aria-selected') + ).toBeNull(); + expect( + getAllByText('ra.boolean.false')[1].getAttribute('aria-selected') + ).toBe('true'); + expect( + getByText('ra.boolean.null').getAttribute('aria-selected') + ).toBeNull(); + }); + it('should select the option "null" if value is null', () => { const { getByRole, getByText, container } = render( ', () => { ); }); + it('should select the option "null" if defaultValue is null', () => { + const { getByRole, getByText, container } = render( + ( + + )} + /> + ); + expect(container.querySelector('input').getAttribute('value')).toBe(''); + const select = getByRole('button'); + fireEvent.mouseDown(select); + expect( + getByText('ra.boolean.true').getAttribute('aria-selected') + ).toBeNull(); + expect( + getByText('ra.boolean.false').getAttribute('aria-selected') + ).toBeNull(); + expect(getByText('ra.boolean.null').getAttribute('aria-selected')).toBe( + 'true' + ); + }); + it('should allow to customize the label of the null option', () => { const { getByRole, getByText, container } = render( = props resource, source, validate, + ...rest, }); return (