|
13 | 13 | import {act, fireEvent, pointerMap, render as render_, within} from '@react-spectrum/test-utils-internal';
|
14 | 14 | import {Button} from '@react-spectrum/button';
|
15 | 15 | import {Form} from '@react-spectrum/form';
|
16 |
| -import {parseZonedDateTime, Time} from '@internationalized/date'; |
| 16 | +import {parseTime, parseZonedDateTime, Time} from '@internationalized/date'; |
17 | 17 | import {Provider} from '@react-spectrum/provider';
|
18 | 18 | import React from 'react';
|
19 | 19 | import {theme} from '@react-spectrum/theme-default';
|
@@ -167,6 +167,23 @@ describe('TimeField', function () {
|
167 | 167 | expect(onFocusSpy).toHaveBeenCalledTimes(1);
|
168 | 168 | });
|
169 | 169 |
|
| 170 | + it('should keep dayPeriod the same when hour segment that has a value >= 12 is cleared', async function () { |
| 171 | + let {getAllByRole} = render(<TimeField label="Time" defaultValue={parseTime('20:24')} />); |
| 172 | + let segments = getAllByRole('spinbutton'); |
| 173 | + |
| 174 | + await user.tab(); |
| 175 | + expect(segments[0]).toHaveFocus(); |
| 176 | + expect(segments[0]).toHaveAttribute('aria-valuetext', '8 PM'); |
| 177 | + expect(segments[2].getAttribute('aria-label')).toBe('AM/PM, '); |
| 178 | + expect(within(segments[2]).getByText('PM')).toBeInTheDocument(); |
| 179 | + |
| 180 | + fireEvent.keyDown(document.activeElement, {key: 'Backspace'}); |
| 181 | + fireEvent.keyUp(document.activeElement, {key: 'Backspace'}); |
| 182 | + expect(segments[0]).toHaveAttribute('aria-valuetext', 'Empty'); |
| 183 | + expect(segments[2].getAttribute('aria-label')).toBe('AM/PM, '); |
| 184 | + expect(within(segments[2]).getByText('PM')).toBeInTheDocument(); |
| 185 | + }); |
| 186 | + |
170 | 187 | it('should trigger right arrow key event for segment navigation', async function () {
|
171 | 188 | let {getAllByRole} = render(<TimeField label="Time" onKeyDown={onKeyDownSpy} onKeyUp={onKeyUpSpy} />);
|
172 | 189 | let segments = getAllByRole('spinbutton');
|
|
0 commit comments