From 0e78a00a0fe8b56d67dde53ff043cd37031a54fa Mon Sep 17 00:00:00 2001 From: tanghui Date: Fri, 15 Dec 2023 08:57:37 +0800 Subject: [PATCH 1/2] add rtl test --- tests/scroll.test.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/scroll.test.js b/tests/scroll.test.js index fb06d5d..f293a89 100644 --- a/tests/scroll.test.js +++ b/tests/scroll.test.js @@ -238,6 +238,45 @@ describe('List.Scroll', () => { }); }); + describe('scrollbar rtl', () => { + it('moving', () => { + const listRef = React.createRef(); + const wrapper = genList({ + itemHeight: 20, + height: 100, + data: genData(100), + ref: listRef, + direction: 'rtl', + }); + + // Mouse down + wrapper.find('.rc-virtual-list-scrollbar-thumb').simulate('mousedown', { + pageY: 0, + }); + + // Mouse move + act(() => { + const mouseMoveEvent = new Event('mousemove'); + mouseMoveEvent.pageY = 10; + window.dispatchEvent(mouseMoveEvent); + }); + + expect(wrapper.find('.rc-virtual-list-holder').props().style.pointerEvents).toEqual('none'); + + act(() => { + jest.runAllTimers(); + }); + + // Mouse up + act(() => { + const mouseUpEvent = new Event('mouseup'); + window.dispatchEvent(mouseUpEvent); + }); + + expect(wrapper.find('ul').instance().scrollTop > 10).toBeTruthy(); + }); + }); + it('no bubble', () => { const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100) }); From 52abee3397a1aa31c872671a88eed9a9b2391b69 Mon Sep 17 00:00:00 2001 From: tanghui Date: Fri, 15 Dec 2023 09:01:31 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8A=BD=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/scroll.test.js | 55 ++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/tests/scroll.test.js b/tests/scroll.test.js index f293a89..6381713 100644 --- a/tests/scroll.test.js +++ b/tests/scroll.test.js @@ -181,10 +181,16 @@ describe('List.Scroll', () => { expect(preventDefault).toHaveBeenCalled(); }); - describe('scrollbar', () => { - it('moving', () => { + const genScrollbarMovingTestFn = (direction) => { + return () => { const listRef = React.createRef(); - const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100), ref: listRef }); + const wrapper = genList({ + itemHeight: 20, + height: 100, + data: genData(100), + ref: listRef, + direction, + }); // Mouse down wrapper.find('.rc-virtual-list-scrollbar-thumb').simulate('mousedown', { @@ -211,7 +217,11 @@ describe('List.Scroll', () => { }); expect(wrapper.find('ul').instance().scrollTop > 10).toBeTruthy(); - }); + }; + }; + + describe('scrollbar', () => { + it('moving', genScrollbarMovingTestFn()); describe('not show scrollbar when disabled virtual', () => { [ @@ -239,42 +249,7 @@ describe('List.Scroll', () => { }); describe('scrollbar rtl', () => { - it('moving', () => { - const listRef = React.createRef(); - const wrapper = genList({ - itemHeight: 20, - height: 100, - data: genData(100), - ref: listRef, - direction: 'rtl', - }); - - // Mouse down - wrapper.find('.rc-virtual-list-scrollbar-thumb').simulate('mousedown', { - pageY: 0, - }); - - // Mouse move - act(() => { - const mouseMoveEvent = new Event('mousemove'); - mouseMoveEvent.pageY = 10; - window.dispatchEvent(mouseMoveEvent); - }); - - expect(wrapper.find('.rc-virtual-list-holder').props().style.pointerEvents).toEqual('none'); - - act(() => { - jest.runAllTimers(); - }); - - // Mouse up - act(() => { - const mouseUpEvent = new Event('mouseup'); - window.dispatchEvent(mouseUpEvent); - }); - - expect(wrapper.find('ul').instance().scrollTop > 10).toBeTruthy(); - }); + it('moving', genScrollbarMovingTestFn('rtl')); }); it('no bubble', () => {