Skip to content

Commit 341c634

Browse files
author
刘欢
committed
test: add coverage for all handles disabled scenario
1 parent a7db356 commit 341c634

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

tests/Range.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,5 +981,27 @@ describe('Range', () => {
981981

982982
expect(onChange).not.toHaveBeenCalled();
983983
});
984+
985+
it('all handles disabled: find nearest enabled returns -1', () => {
986+
// This test specifically covers line 426 in Slider.tsx
987+
// When all handles are disabled and clicking near one,
988+
// the nearestIndex search returns -1 and returns early
989+
const onChange = jest.fn();
990+
const { container } = render(
991+
<Slider range defaultValue={[0, 50, 100]} disabled={[true, true, true]} onChange={onChange} />,
992+
);
993+
994+
// Click at position 10 (near first disabled handle)
995+
const rail = container.querySelector('.rc-slider-rail');
996+
const mouseDown = createEvent.mouseDown(rail);
997+
Object.defineProperties(mouseDown, {
998+
clientX: { get: () => 10 },
999+
clientY: { get: () => 10 },
1000+
});
1001+
fireEvent(rail, mouseDown);
1002+
1003+
// Should not trigger onChange because all handles are disabled
1004+
expect(onChange).not.toHaveBeenCalled();
1005+
});
9841006
});
9851007
});

0 commit comments

Comments
 (0)