|
1 | 1 | import assert from 'assert'; |
| 2 | +import { render, fireEvent } from '@testing-library/react'; |
| 3 | +import userEvent from '@testing-library/user-event'; |
2 | 4 | import addMonths from 'date-fns/add_months'; |
3 | 5 | import addYears from 'date-fns/add_years'; |
4 | 6 | import isSameDay from 'date-fns/is_same_day'; |
@@ -324,4 +326,35 @@ describe('<MonthInput />', () => { |
324 | 326 | assert.strictEqual('visually-hidden', prevMonthLabel.prop('className')); |
325 | 327 | }); |
326 | 328 | }); |
| 329 | + |
| 330 | + describe('RTL compatibility', () => { |
| 331 | + it('initial value should appear in the input value attribute', async () => { |
| 332 | + const screen = render(<MonthInput defaultValue="Dec 2025" />); |
| 333 | + assert.strictEqual( |
| 334 | + screen.getByTestId('react-gears-monthinput-dropdowntoggle-input').getAttribute('value'), |
| 335 | + 'Dec 2025' |
| 336 | + ); |
| 337 | + }); |
| 338 | + it('valid user typed value should appear in the input value attribute', async () => { |
| 339 | + const screen = render(<MonthInput />); |
| 340 | + |
| 341 | + const input = screen.getByTestId('react-gears-monthinput-dropdowntoggle-input'); |
| 342 | + await userEvent.type(input, 'Dec 2025'); |
| 343 | + assert.strictEqual(input.getAttribute('value'), 'Dec 2025'); |
| 344 | + }); |
| 345 | + it('invalid user typed value should appear in the input value attribute', async () => { |
| 346 | + const screen = render(<MonthInput />); |
| 347 | + |
| 348 | + const input = screen.getByTestId('react-gears-monthinput-dropdowntoggle-input'); |
| 349 | + await userEvent.type(input, 'Foo bar'); |
| 350 | + assert.strictEqual(input.getAttribute('value'), 'Foo bar'); |
| 351 | + }); |
| 352 | + it('blurring the input should update the input value to the formatted value', async () => { |
| 353 | + const screen = render(<MonthInput parse={() => 'Dec 2025'} />); |
| 354 | + const input = screen.getByTestId('react-gears-monthinput-dropdowntoggle-input'); |
| 355 | + await userEvent.type(input, '12/25/2025'); |
| 356 | + fireEvent.blur(input); |
| 357 | + assert.strictEqual(input.getAttribute('value'), 'Dec 2025'); |
| 358 | + }); |
| 359 | + }); |
327 | 360 | }); |
0 commit comments