Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo837 committed Dec 15, 2023
1 parent 73d83df commit a486c4d
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions tests/scroll.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import '@testing-library/jest-dom';
import { createEvent, fireEvent, render } from '@testing-library/react';
import { mount } from 'enzyme';
import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil';
import { resetWarned } from 'rc-util/lib/warning';
import React from 'react';
import { act } from 'react-dom/test-utils';
import { mount } from 'enzyme';
import { spyElementPrototypes } from './utils/domHook';
import List from '../src';
import { createEvent, fireEvent, render } from '@testing-library/react';
import { resetWarned } from 'rc-util/lib/warning';
import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil';
import '@testing-library/jest-dom';
import { spyElementPrototypes } from './utils/domHook';

function genData(count) {
return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
Expand Down Expand Up @@ -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', {
Expand All @@ -210,8 +216,12 @@ describe('List.Scroll', () => {
window.dispatchEvent(mouseUpEvent);
});

expect(wrapper.find('ul').instance().scrollTop > 10).toBeTruthy();
});
expect(wrapper.find('ul').instance().scrollTop > 100).toBeTruthy();
};
};

describe('scrollbar', () => {
it('moving', genScrollbarMovingTestFn());

describe('not show scrollbar when disabled virtual', () => {
[
Expand All @@ -238,6 +248,10 @@ describe('List.Scroll', () => {
});
});

describe('scrollbar rtl', () => {
it('moving', genScrollbarMovingTestFn('rtl'));
});

it('no bubble', () => {
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100) });

Expand Down

0 comments on commit a486c4d

Please sign in to comment.