Skip to content

Commit 0172a1a

Browse files
committed
test: add coverage for formatted input manual clear
- Added test case for mask format inputs to cover onFormatKeyDown path - Ensures handleManualClear return statement is covered by tests - Increases test coverage to 456 tests total
1 parent acb8fdb commit 0172a1a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/manual-clear.spec.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,30 @@ describe('Picker.ManualClear', () => {
156156
// Input should be empty
157157
expect(input.value).toBe('');
158158
});
159+
160+
it('should clear formatted input with mask format', async () => {
161+
const onChange = jest.fn();
162+
const { container } = render(
163+
<Picker
164+
generateConfig={dayGenerateConfig}
165+
value={getDay('2023-08-01')}
166+
onChange={onChange}
167+
locale={enUS}
168+
format={{ type: 'mask', format: 'YYYY-MM-DD' }}
169+
/>,
170+
);
171+
172+
const input = container.querySelector('input') as HTMLInputElement;
173+
174+
openPicker(container);
175+
input.setSelectionRange(0, input.value.length);
176+
fireEvent.keyDown(input, { key: 'Delete', code: 'Delete' });
177+
178+
await waitFakeTimer();
179+
180+
expect(onChange).toHaveBeenCalledWith(null, null);
181+
expect(input.value).toBe('');
182+
});
159183
});
160184

161185
describe('Range Picker', () => {

0 commit comments

Comments
 (0)