Skip to content

Commit 8079b67

Browse files
fix: codecov
1 parent b8bb7e1 commit 8079b67

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

tests/new-range.spec.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,35 @@ describe('NewPicker.Range', () => {
995995
expect(onChange).toHaveBeenCalledWith(expect.anything(), ['20200903', '20200905']);
996996
});
997997

998+
it('blocks paste while mouse is down', () => {
999+
const onChange = jest.fn();
1000+
const { container } = render(<Demo onChange={onChange} />);
1001+
1002+
const startInput = container.querySelectorAll<HTMLInputElement>('input')[0];
1003+
1004+
// Simulate focus gained by mousedown, then paste before mouse up.
1005+
fireEvent.mouseDown(startInput);
1006+
fireEvent.focus(startInput);
1007+
1008+
fireEvent.paste(startInput, {
1009+
clipboardData: {
1010+
getData: () => '20200903',
1011+
},
1012+
});
1013+
1014+
// Guard in Input should prevent paste from taking effect
1015+
expect(onChange).not.toHaveBeenCalled();
1016+
1017+
// After mouse up, normal paste works again
1018+
fireEvent.mouseUp(startInput);
1019+
fireEvent.paste(startInput, {
1020+
clipboardData: {
1021+
getData: () => '20200903',
1022+
},
1023+
});
1024+
expect(onChange).toHaveBeenCalled();
1025+
});
1026+
9981027
it('click to change selection cell', () => {
9991028
const { container } = render(<Demo />);
10001029

@@ -1010,6 +1039,30 @@ describe('NewPicker.Range', () => {
10101039
expect(startInput.selectionEnd).toEqual(6);
10111040
});
10121041

1042+
it('blocks key input while mouse is down', () => {
1043+
const { container } = render(<Demo />);
1044+
1045+
const startInput = container.querySelectorAll<HTMLInputElement>('input')[0];
1046+
1047+
// Simulate focus gained by mousedown, then key input before mouse up.
1048+
fireEvent.mouseDown(startInput);
1049+
fireEvent.focus(startInput);
1050+
1051+
fireEvent.keyDown(startInput, {
1052+
key: '1',
1053+
});
1054+
1055+
// Guard in Input should prevent any value change before mouse up
1056+
expect(startInput).toHaveValue('YYYYMMDD');
1057+
1058+
// After mouse up, key input should be allowed and update value
1059+
fireEvent.mouseUp(startInput);
1060+
fireEvent.keyDown(startInput, {
1061+
key: '1',
1062+
});
1063+
expect(startInput).not.toHaveValue('YYYYMMDD');
1064+
});
1065+
10131066
it('focus by mousedown defers selection sync to mouseUp', () => {
10141067
const { container } = render(<Demo />);
10151068

0 commit comments

Comments
 (0)