From e1a861821609e7c7b301d48bf4bca7a09a7d8b9e Mon Sep 17 00:00:00 2001
From: Dunqing );
diff --git a/tests/ExpandRow.spec.js b/tests/ExpandRow.spec.jsx
similarity index 96%
rename from tests/ExpandRow.spec.js
rename to tests/ExpandRow.spec.jsx
index 7dbb9593d..0fd701f7f 100644
--- a/tests/ExpandRow.spec.js
+++ b/tests/ExpandRow.spec.jsx
@@ -1,8 +1,8 @@
-import React from 'react';
import { mount } from 'enzyme';
-import { act } from 'react-dom/test-utils';
-import { resetWarned } from 'rc-util/lib/warning';
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
+import { resetWarned } from 'rc-util/lib/warning';
+import React from 'react';
+import { act } from 'react-dom/test-utils';
import Table from '../src';
describe('Table.Expand', () => {
@@ -22,7 +22,7 @@ describe('Table.Expand', () => {
it('renders expand row correctly', () => {
resetWarned();
- const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const wrapper = mount(createTable({ expandedRowRender }));
expect(wrapper.find('tbody tr')).toHaveLength(2);
expect(errorSpy).toHaveBeenCalledWith(
@@ -32,7 +32,7 @@ describe('Table.Expand', () => {
});
it('pass proper parameters to expandedRowRender', () => {
- const rowRender = jest.fn(() =>
);
act(() => {
@@ -59,7 +59,7 @@ describe('Table.FixedColumn', () => {
});
await act(async () => {
- jest.runAllTimers();
+ vi.runAllTimers();
await Promise.resolve();
wrapper.update();
});
diff --git a/tests/FixedColumn.spec.js b/tests/FixedColumn.spec.jsx
similarity index 97%
rename from tests/FixedColumn.spec.js
rename to tests/FixedColumn.spec.jsx
index 18eb60451..a0f7eb47a 100644
--- a/tests/FixedColumn.spec.js
+++ b/tests/FixedColumn.spec.jsx
@@ -3,13 +3,13 @@ import RcResizeObserver from 'rc-resize-observer';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
import { resetWarned } from 'rc-util/lib/warning';
import { act } from 'react-dom/test-utils';
-import { safeAct } from './utils';
import Table from '../src';
+import { safeAct } from './utils';
describe('Table.FixedColumn', () => {
let domSpy;
beforeEach(() => {
- jest.useFakeTimers();
+ vi.useFakeTimers();
});
beforeAll(() => {
domSpy = spyElementPrototypes(HTMLElement, {
@@ -70,7 +70,7 @@ describe('Table.FixedColumn', () => {
{ name: 'without data', data: [] },
].forEach(({ name, data: testData }) => {
it(`${scrollName} - ${name}`, async () => {
- jest.useFakeTimers();
+ vi.useFakeTimers();
const wrapper = mount(
);
act(() => {
@@ -91,7 +91,7 @@ describe('Table.FixedColumn', () => {
});
await safeAct(wrapper);
expect(wrapper.render()).toMatchSnapshot();
- jest.useRealTimers();
+ vi.useRealTimers();
});
});
});
@@ -107,7 +107,7 @@ describe('Table.FixedColumn', () => {
scroll={{ x: 'max-content' }}
/>,
);
-
+
await safeAct(wrapper);
expect(wrapper.find('colgroup').render()).toMatchSnapshot();
@@ -193,7 +193,7 @@ describe('Table.FixedColumn', () => {
let errorSpy;
beforeAll(() => {
- errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
});
beforeEach(() => {
diff --git a/tests/FixedHeader.spec.js b/tests/FixedHeader.spec.jsx
similarity index 95%
rename from tests/FixedHeader.spec.js
rename to tests/FixedHeader.spec.jsx
index 842c9f45e..a4dbbfa8d 100644
--- a/tests/FixedHeader.spec.js
+++ b/tests/FixedHeader.spec.jsx
@@ -3,8 +3,8 @@ import RcResizeObserver from 'rc-resize-observer';
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
import React from 'react';
import { act } from 'react-dom/test-utils';
-import { safeAct } from './utils';
import Table, { INTERNAL_COL_DEFINE } from '../src';
+import { safeAct } from './utils';
describe('Table.FixedHeader', () => {
let domSpy;
@@ -17,7 +17,7 @@ describe('Table.FixedHeader', () => {
});
beforeEach(() => {
- jest.useFakeTimers();
+ vi.useFakeTimers();
visible = true;
});
@@ -58,9 +58,9 @@ describe('Table.FixedHeader', () => {
expect(wrapper.find('.rc-table-header table').props().style.visibility).toBeFalsy();
- expect();
expect(wrapper.find('colgroup col').at(0).props().style.width).toEqual(100);
expect(wrapper.find('colgroup col').at(1).props().style.width).toEqual(200);
+ console.log(wrapper.find('colgroup col').at(1).props());
expect(wrapper.find('colgroup col').at(2).props().style.width).toEqual(0);
// Update columns
@@ -70,7 +70,7 @@ describe('Table.FixedHeader', () => {
expect(wrapper.find('colgroup col').at(0).props().style.width).toEqual(200);
expect(wrapper.find('colgroup col').at(1).props().style.width).toEqual(100);
- jest.useRealTimers();
+ vi.useRealTimers();
});
it('INTERNAL_COL_DEFINE', async () => {
@@ -121,7 +121,7 @@ describe('Table.FixedHeader', () => {
}}
/>,
);
-
+
await safeAct(wrapper);
expect(wrapper.find('.rc-table-header table').props().style).toEqual(
expect.objectContaining({ visibility: null }),
@@ -190,7 +190,7 @@ describe('Table.FixedHeader', () => {
]);
act(() => {
- jest.runAllTimers();
+ vi.runAllTimers();
wrapper.update();
});
@@ -198,7 +198,7 @@ describe('Table.FixedHeader', () => {
expect.objectContaining({ width: 93 }),
);
- jest.useRealTimers();
+ vi.useRealTimers();
});
it('do not mask as ant-table-cell-fix-left-last in nested table parent cell', async () => {
@@ -247,16 +247,11 @@ describe('Table.FixedHeader', () => {
name: 'Jack1',
},
];
- const wrapper = mount(
-
,
- );
+ const wrapper = mount(
);
await safeAct(wrapper);
expect(wrapper.find('td').at(9).props().className).toContain('rc-table-cell-fix-left-last');
- expect(wrapper.find('th').first().props().className).not.toContain('rc-table-cell-fix-left-last');
-
+ expect(wrapper.find('th').first().props().className).not.toContain(
+ 'rc-table-cell-fix-left-last',
+ );
});
});
diff --git a/tests/GroupingColumns.spec.js b/tests/GroupingColumns.spec.jsx
similarity index 100%
rename from tests/GroupingColumns.spec.js
rename to tests/GroupingColumns.spec.jsx
index 2f69d74e5..7300265f7 100644
--- a/tests/GroupingColumns.spec.js
+++ b/tests/GroupingColumns.spec.jsx
@@ -1,5 +1,5 @@
-import React from 'react';
import { mount } from 'enzyme';
+import React from 'react';
import Table from '../src';
describe('Table with grouping columns', () => {
diff --git a/tests/Hover.spec.tsx b/tests/Hover.spec.tsx
index 7f49160c3..01162e7b1 100644
--- a/tests/Hover.spec.tsx
+++ b/tests/Hover.spec.tsx
@@ -1,7 +1,7 @@
-import React from 'react';
import { mount } from 'enzyme';
-import { resetWarned } from 'rc-util/lib/warning';
import toArray from 'rc-util/lib/Children/toArray';
+import { resetWarned } from 'rc-util/lib/warning';
+import React from 'react';
import Table from '../src';
import type { TableProps } from '../src/Table';
@@ -41,7 +41,7 @@ describe('Table.Hover', () => {
it('warning if use `render` for rowSpan', () => {
resetWarned();
- const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const wrapper = mount(
createTable({
diff --git a/tests/Internal.spec.js b/tests/Internal.spec.jsx
similarity index 100%
rename from tests/Internal.spec.js
rename to tests/Internal.spec.jsx
diff --git a/tests/Scroll.spec.js b/tests/Scroll.spec.jsx
similarity index 91%
rename from tests/Scroll.spec.js
rename to tests/Scroll.spec.jsx
index c5e243658..a4511d6cb 100644
--- a/tests/Scroll.spec.js
+++ b/tests/Scroll.spec.jsx
@@ -1,11 +1,14 @@
-import React from 'react';
import { mount } from 'enzyme';
-import { act } from 'react-dom/test-utils';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
+import React from 'react';
+import { act } from 'react-dom/test-utils';
import Table from '../src';
describe('Table.Scroll', () => {
- const data = [{ key: 'key0', name: 'Lucy' }, { key: 'key1', name: 'Jack' }];
+ const data = [
+ { key: 'key0', name: 'Lucy' },
+ { key: 'key1', name: 'Jack' },
+ ];
const createTable = props => {
const columns = [{ title: 'Name', dataIndex: 'name', key: 'name' }];
@@ -36,14 +39,14 @@ describe('Table.Scroll', () => {
});
it('fire scroll event', () => {
- jest.useFakeTimers();
+ vi.useFakeTimers();
let scrollLeft = 0;
let scrollTop = 0;
- const setScrollLeft = jest.fn((_, val) => {
+ const setScrollLeft = vi.fn((_, val) => {
scrollLeft = val;
});
- const setScrollTop = jest.fn((_, val) => {
+ const setScrollTop = vi.fn((_, val) => {
scrollTop = val;
});
@@ -85,7 +88,7 @@ describe('Table.Scroll', () => {
/>,
);
- jest.runAllTimers();
+ vi.runAllTimers();
// Use `onScroll` directly since simulate not support `currentTarget`
act(() => {
const headerDiv = wrapper.find('div.rc-table-header').instance();
@@ -96,7 +99,7 @@ describe('Table.Scroll', () => {
});
headerDiv.dispatchEvent(wheelEvent);
- jest.runAllTimers();
+ vi.runAllTimers();
});
expect(setScrollLeft).toHaveBeenCalledWith(undefined, 10);
@@ -114,11 +117,11 @@ describe('Table.Scroll', () => {
},
});
});
- jest.runAllTimers();
+ vi.runAllTimers();
expect(setScrollLeft).toHaveBeenCalledWith(undefined, 33);
setScrollLeft.mockReset();
domSpy.mockRestore();
- jest.useRealTimers();
+ vi.useRealTimers();
});
});
diff --git a/tests/Sticky.spec.js b/tests/Sticky.spec.jsx
similarity index 96%
rename from tests/Sticky.spec.js
rename to tests/Sticky.spec.jsx
index f1ccbda2c..fee181c9f 100644
--- a/tests/Sticky.spec.js
+++ b/tests/Sticky.spec.jsx
@@ -1,13 +1,13 @@
-import React from 'react';
-import { act } from 'react-dom/test-utils';
import { mount } from 'enzyme';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
+import React from 'react';
+import { act } from 'react-dom/test-utils';
import Table from '../src';
import { safeAct } from './utils';
describe('Table.Sticky', () => {
beforeEach(() => {
- jest.useFakeTimers();
+ vi.useFakeTimers();
});
it('Sticky Header', async () => {
const col1 = { dataIndex: 'light', width: 100 };
@@ -53,7 +53,7 @@ describe('Table.Sticky', () => {
top: 10,
});
- jest.useRealTimers();
+ vi.useRealTimers();
});
it('Sticky scroll', async () => {
@@ -120,10 +120,11 @@ describe('Table.Sticky', () => {
);
await act(async () => {
- jest.runAllTimers();
+ vi.runAllTimers();
await Promise.resolve();
});
+ console.log(wrapper.find('.rc-table-sticky-scroll').get(0), 'shouldUndefined');
expect(wrapper.find('.rc-table-sticky-scroll').get(0)).not.toBeUndefined();
const oldInnerHeight = global.innerHeight;
@@ -133,7 +134,7 @@ describe('Table.Sticky', () => {
await act(async () => {
global.dispatchEvent(resizeEvent);
- jest.runAllTimers();
+ vi.runAllTimers();
await Promise.resolve();
wrapper.update();
});
@@ -143,12 +144,12 @@ describe('Table.Sticky', () => {
await act(async () => {
global.innerHeight = oldInnerHeight;
global.dispatchEvent(resizeEvent);
- jest.runAllTimers();
+ vi.runAllTimers();
await Promise.resolve();
wrapper.update();
});
- const mockFn = jest.fn();
+ const mockFn = vi.fn();
wrapper
.find('.rc-table-sticky-scroll-bar')
@@ -165,7 +166,7 @@ describe('Table.Sticky', () => {
await act(async () => {
document.body.dispatchEvent(mousemoveEvent);
- jest.runAllTimers();
+ vi.runAllTimers();
await Promise.resolve();
wrapper.update();
});
@@ -179,7 +180,7 @@ describe('Table.Sticky', () => {
mousemoveEvent.pageX = -50;
document.body.dispatchEvent(mousemoveEvent);
- jest.runAllTimers();
+ vi.runAllTimers();
await Promise.resolve();
wrapper.update();
});
@@ -193,7 +194,7 @@ describe('Table.Sticky', () => {
mousemoveEvent.buttons = 0;
document.body.dispatchEvent(mousemoveEvent);
- jest.runAllTimers();
+ vi.runAllTimers();
await Promise.resolve();
wrapper.update();
});
@@ -209,11 +210,10 @@ describe('Table.Sticky', () => {
window.pageYOffset = 0;
mockFn.mockRestore();
domSpy.mockRestore();
- jest.useRealTimers();
+ vi.useRealTimers();
});
it('Sticky Header with border classname', async () => {
-
const TableDemo = props => {
return (
{
describe('dataIndex', () => {
it("pass record to render when it's falsy", () => {
[null, undefined, '', []].forEach(dataIndex => {
- const cellRender = jest.fn();
+ const cellRender = vi.fn();
const columns = [
{
title: 'Name',
@@ -504,7 +504,7 @@ describe('Table.Basic', () => {
});
it('shows error if no rowKey specify', () => {
- const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
const localData = [{ name: 'Lucy' }, { name: 'Jack' }];
mount(createTable({ data: localData }));
expect(spy.mock.calls[0][0]).toMatch(
@@ -595,7 +595,7 @@ describe('Table.Basic', () => {
});
it('renders onHeaderRow correctly', () => {
- const onHeaderRow = jest.fn((columns, index) => ({
+ const onHeaderRow = vi.fn((columns, index) => ({
id: `header-row-${index}`,
}));
const wrapper = mount(createTable({ onHeaderRow }));
@@ -666,7 +666,7 @@ describe('Table.Basic', () => {
describe('scroll content', () => {
it('with scroll', () => {
resetWarned();
- const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
const wrapper = mount(
createTable({
columns: [{ dataIndex: 'a' }, { dataIndex: 'b', width: 903 }],
@@ -686,7 +686,7 @@ describe('Table.Basic', () => {
it('without scroll', () => {
resetWarned();
- const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
mount(
createTable({
components: {
@@ -703,7 +703,7 @@ describe('Table.Basic', () => {
it('without warning - columns is empty', () => {
resetWarned();
- const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
mount(
createTable({
columns: [],
@@ -775,7 +775,7 @@ describe('Table.Basic', () => {
let spy;
beforeAll(() => {
- spy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ spy = vi.spyOn(console, 'error').mockImplementation(() => {});
});
afterEach(() => {
@@ -787,7 +787,7 @@ describe('Table.Basic', () => {
});
it('fires row click event', () => {
- const onClick = jest.fn();
+ const onClick = vi.fn();
const wrapper = mount(createTable({ onRow: () => ({ onClick }) }));
const tr = wrapper.find('tbody tr').first();
@@ -800,7 +800,7 @@ describe('Table.Basic', () => {
});
it('fires double row click event', () => {
- const onDoubleClick = jest.fn();
+ const onDoubleClick = vi.fn();
const wrapper = mount(createTable({ onRow: () => ({ onDoubleClick }) }));
const tr = wrapper.find('tbody tr').first();
@@ -813,7 +813,7 @@ describe('Table.Basic', () => {
});
it('fires row contextmenu event', () => {
- const onContextMenu = jest.fn();
+ const onContextMenu = vi.fn();
const wrapper = mount(createTable({ onRow: () => ({ onContextMenu }) }));
const tr = wrapper.find('tbody tr').first();
@@ -826,7 +826,7 @@ describe('Table.Basic', () => {
});
it('fires onRowMouseEnter', () => {
- const onMouseEnter = jest.fn();
+ const onMouseEnter = vi.fn();
const wrapper = mount(
createTable({
onRow: () => ({ onMouseEnter }),
@@ -844,7 +844,7 @@ describe('Table.Basic', () => {
});
it('fires onRowMouseLeave', () => {
- const onMouseLeave = jest.fn();
+ const onMouseLeave = vi.fn();
const wrapper = mount(
createTable({
onRow: () => ({ onMouseLeave }),
@@ -1055,7 +1055,7 @@ describe('Table.Basic', () => {
});
it('not block nest children', () => {
- const onExpandedRowsChange = jest.fn();
+ const onExpandedRowsChange = vi.fn();
const wrapper = mount(
+ ,
+ ],
+ "endIndex": null,
+ "next": null,
+ "parent": null,
+ "prev": null,
+ "startIndex": null,
+ "type": "root",
+ "x-mode": "quirks",
+ },
+ "_root": [Circular],
+ "length": 1,
+ "options": {
+ "decodeEntities": true,
+ "xml": false,
+ },
+ },
+ "length": 1,
+ "options": {
+ "decodeEntities": true,
+ "xml": false,
+ },
+}
+`;
+
+exports[`Table.Expand > does not crash if scroll is not set 1`] = `
+LoadedCheerio {
+ "0":
-
+
-
-
-
-
-
-
- Name
-
-
- Age
-
-
-
-
-
-
- Lucy
-
-
- 27
-
-
-
-
-
-
- Jim
-
-
- 1
-
-
-
-
-
-
-
- Jack
-
-
- 28
-
-
-
-
-
-
-
-
- Name
-
-
- Age
-
-
-
-
- Jack
-
-
- 28
-
-
-
-
- Jack
-
-
- 28
-
-
-
-
-
- Jack
-
-
- 28
-
-
-
-
-
-
-
-
- Name
-
-
- Age
-
-
-
-
-
-
- Lucy
-
-
- 27
-
-
-
-
-
-
- Jim
-
-
- 1
-
-
-
-
-
-
-
- Jack
-
-
- 28
-
-
-
-
-
-
-
-
- Name
-
-
- Age
-
-
-
-
-
-
- Lucy
-
-
- 27
-
-
-
-
-
-
- Jack
-
-
- 28
-
-
-
-
-
-
- Jack
-
-
- 28
-
-
-
-
-
-
- Jack
-
-
- 28
-
-
-
-
-
-
- Jack
-
-
- 28
-
-
-
-
-
-
-
- Jack
-
-
- 28
-
-
+
+
+
+
+
+
+ Name
+
+
+ Age
+
+
+
+
+
+
+ Lucy
+
+
+ 27
+
+
+
+
+
+
+ Jim
+
+
+ 1
+
+
+
+
+
+
+
+ Jack
+
+
+ 28
+
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > not use nest when children is invalidate 1`] = ` +LoadedCheerio { + "0":
+ Name + | ++ Age + | +
---|---|
+ Jack + | ++ 28 + | +
+ Jack + | ++ 28 + | +
+ Jack + | ++ 28 + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > renders fixed column correctly > work 1`] = ` +LoadedCheerio { + "0":
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > renders tree row correctly 1`] = ` +LoadedCheerio { + "0":
+ Name + | ++ Age + | +
---|---|
+ + + Lucy + | ++ 27 + | +
+ + + Jim + | ++ 1 + | +
+ + + Jack + | ++ 28 + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > renders tree row correctly with different children 1`] = ` +LoadedCheerio { + "0":
+ Name + | ++ Age + | +
---|---|
+ + + Lucy + | ++ 27 + | +
+ + + Jack + | ++ 28 + | +
+ + + Jack + | ++ 28 + | +
+ + + Jack + | ++ 28 + | +
+ + + Jack + | ++ 28 + | +
+ + + Jack + | ++ 28 + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > work in expandable fix 1`] = ` +LoadedCheerio { + "0":
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Expand > work in expandable fix 2`] = ` +LoadedCheerio { + "0":
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; diff --git a/tests/__snapshots__/FixedColumn.spec.js.snap b/tests/__snapshots__/FixedColumn.spec.js.snap deleted file mode 100644 index 99648e662..000000000 --- a/tests/__snapshots__/FixedColumn.spec.js.snap +++ /dev/null @@ -1,2965 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` -
-`; - -exports[`Table.FixedColumn renders correctly all column has width should use it 1`] = ` -
-`; - -exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = ` -
-`; - -exports[`Table.FixedColumn renders correctly scrollX - without data 1`] = ` -
-`; - -exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = ` -
- 123 - | -- - - 1111 - - - | -- | - xxxxxxxx - | -- xxxxxxxx - | -- xxxxxxxx - | -- xxxxxxxx - | -- xxxxxxxx - | -- xxxxxxxx - | -- xxxxxxxx - | -- xxxxxxxx - | -- xxxxxxxx - | -
- cdd - | -- - - 1111 - - - | -- | - edd12221 - | -- edd12221 - | -- edd12221 - | -- edd12221 - | -- edd12221 - | -- edd12221 - | -- edd12221 - | -- edd12221 - | -- edd12221 - | -
- 133 - | -- - - 1111 - - - | -- edd12221 - | -- | - | - | - | - | - | - | - | - |
- 133 - | -- - - 1111 - - - | -- edd12221 - | -- | - | - | - | - | - | - | - | - |
- 133 - | -- - - 1111 - - - | -- edd12221 - | -- | - | - | - | - | - | - | - | - |
- 133 - | -- - - 1111 - - - | -- edd12221 - | -- | - | - | - | - | - | - | - | - |
- 133 - | -- - - 1111 - - - | -- edd12221 - | -- | - | - | - | - | - | - | - | - |
- 133 - | -- - - 1111 - - - | -- edd12221 - | -- | - | - | - | - | - | - | - | - |
- 133 - | -- - - 1111 - - - | -- edd12221 - | -- | - | - | - | - | - | - | - | - |
-`; - -exports[`Table.FixedColumn renders correctly scrollXY - without data 1`] = ` -
- | - -
-`; diff --git a/tests/__snapshots__/FixedColumn.spec.jsx.snap b/tests/__snapshots__/FixedColumn.spec.jsx.snap new file mode 100644 index 000000000..1fe978969 --- /dev/null +++ b/tests/__snapshots__/FixedColumn.spec.jsx.snap @@ -0,0 +1,3145 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Table.FixedColumn > fixed column renders correctly RTL 1`] = ` +LoadedCheerio { + "0":
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > all column has width should use it 1`] = ` +LoadedCheerio { + "0":
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > scrollX - with data 1`] = ` +LoadedCheerio { + "0":
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > scrollX - without data 1`] = ` +LoadedCheerio { + "0":
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > scrollXY - with data 1`] = ` +LoadedCheerio { + "0":
+ 123 + | ++ + + 1111 + + + | ++ | + xxxxxxxx + | ++ xxxxxxxx + | ++ xxxxxxxx + | ++ xxxxxxxx + | ++ xxxxxxxx + | ++ xxxxxxxx + | ++ xxxxxxxx + | ++ xxxxxxxx + | ++ xxxxxxxx + | +
+ cdd + | ++ + + 1111 + + + | ++ | + edd12221 + | ++ edd12221 + | ++ edd12221 + | ++ edd12221 + | ++ edd12221 + | ++ edd12221 + | ++ edd12221 + | ++ edd12221 + | ++ edd12221 + | +
+ 133 + | ++ + + 1111 + + + | ++ edd12221 + | ++ | + | + | + | + | + | + | + | + |
+ 133 + | ++ + + 1111 + + + | ++ edd12221 + | ++ | + | + | + | + | + | + | + | + |
+ 133 + | ++ + + 1111 + + + | ++ edd12221 + | ++ | + | + | + | + | + | + | + | + |
+ 133 + | ++ + + 1111 + + + | ++ edd12221 + | ++ | + | + | + | + | + | + | + | + |
+ 133 + | ++ + + 1111 + + + | ++ edd12221 + | ++ | + | + | + | + | + | + | + | + |
+ 133 + | ++ + + 1111 + + + | ++ edd12221 + | ++ | + | + | + | + | + | + | + | + |
+ 133 + | ++ + + 1111 + + + | ++ edd12221 + | ++ | + | + | + | + | + | + | + | + |
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.FixedColumn > renders correctly > scrollXY - without data 1`] = ` +LoadedCheerio { + "0":
+ | + +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; diff --git a/tests/__snapshots__/Summary.spec.tsx.snap b/tests/__snapshots__/Summary.spec.tsx.snap index e72a20741..40aec2575 100644 --- a/tests/__snapshots__/Summary.spec.tsx.snap +++ b/tests/__snapshots__/Summary.spec.tsx.snap @@ -1,28 +1,58 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Table.Summary support data type 1`] = ` -
-+exports[`Table.Summary > support data type 1`] = ` +LoadedCheerio { + "0":
+, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} `; diff --git a/tests/__snapshots__/Table.spec.js.snap b/tests/__snapshots__/Table.spec.js.snap deleted file mode 100644 index 13d03fd8c..000000000 --- a/tests/__snapshots__/Table.spec.js.snap +++ /dev/null @@ -1,918 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Table.Basic columns support JSX condition 1`] = ` -[ - , -
- title - | -- title3 - | -
---|---|
- 2 - | -- 3 - | -
- 2 - | -- 3 - | -
, -] -`; - -exports[`Table.Basic custom components renders correctly 1`] = ` -
- Name - | -
---|
- Lucy - | -
- Jack - | -
-`; - -exports[`Table.Basic custom components renders fixed column and header correctly 1`] = ` -
- Lucy - | -- 27 - | -- F - | -
-`; - -exports[`Table.Basic custom components scroll content with scroll 1`] = ` -
-`; - -exports[`Table.Basic internal api transformColumns basic 1`] = ` -
- before - | -- Name - | -- after - | -
---|---|---|
- | - Lucy - | -- |
- | - Jack - | -- |
-`; - -exports[`Table.Basic renders colSpan correctly 1`] = ` -
- Name - | -|
---|---|
- John - | -|
- Terry - | -- Garner - | -
-`; - -exports[`Table.Basic renders correctly RTL 1`] = ` -
- Name - | -
---|
- Lucy - | -
- Jack - | -
-`; - -exports[`Table.Basic renders correctly basic 1`] = ` -
- Name - | -
---|
- Lucy - | -
- Jack - | -
-`; - -exports[`Table.Basic renders correctly column children undefined 1`] = ` -
- 姓名 - | -- 年龄 - | -
---|---|
- Lucy - | -- |
- Jack - | -- |
-`; - -exports[`Table.Basic renders correctly falsy columns 1`] = ` -
- 姓名 - | -
---|
- Lucy - | -
- Jack - | -
-`; - -exports[`Table.Basic renders correctly no columns 1`] = ` -
- |
- |
- |
-`; - -exports[`Table.Basic renders rowSpan correctly 1`] = ` -
- First Name - | -- Last Name - | -
---|---|
- John - | -- Doe - | -
- Terry - | -
-`; - -exports[`Table.Basic should get scrollbar size 1`] = ` -
-`; - -exports[`Table.Basic syntactic sugar 1`] = ` -
- total - | -
---|
- Name - | -
- No Data - | -
-`; diff --git a/tests/__snapshots__/Table.spec.jsx.snap b/tests/__snapshots__/Table.spec.jsx.snap new file mode 100644 index 000000000..ba16fd958 --- /dev/null +++ b/tests/__snapshots__/Table.spec.jsx.snap @@ -0,0 +1,1319 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Table.Basic > columns support JSX condition 1`] = ` +LoadedCheerio { + "0": , + "1":
+ title + | ++ title3 + | +
---|---|
+ 2 + | ++ 3 + | +
+ 2 + | ++ 3 + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 2, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > custom components > renders correctly 1`] = ` +LoadedCheerio { + "0":
+ Name + | +
---|
+ Lucy + | +
+ Jack + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > custom components > renders fixed column and header correctly 1`] = ` +LoadedCheerio { + "0":
+ Lucy + | ++ 27 + | ++ F + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > custom components > scroll content > with scroll 1`] = ` +LoadedCheerio { + "0":
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > internal api > transformColumns > basic 1`] = ` +LoadedCheerio { + "0":
+ before + | ++ Name + | ++ after + | +
---|---|---|
+ | + Lucy + | ++ |
+ | + Jack + | ++ |
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders colSpan correctly 1`] = ` +LoadedCheerio { + "0":
+ Name + | +|
---|---|
+ John + | +|
+ Terry + | ++ Garner + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > RTL 1`] = ` +LoadedCheerio { + "0":
+ Name + | +
---|
+ Lucy + | +
+ Jack + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > basic 1`] = ` +LoadedCheerio { + "0":
+ Name + | +
---|
+ Lucy + | +
+ Jack + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > column children undefined 1`] = ` +LoadedCheerio { + "0":
+ 姓名 + | ++ 年龄 + | +
---|---|
+ Lucy + | ++ |
+ Jack + | ++ |
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > falsy columns 1`] = ` +LoadedCheerio { + "0":
+ 姓名 + | +
---|
+ Lucy + | +
+ Jack + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders correctly > no columns 1`] = ` +LoadedCheerio { + "0":
+ |
+ |
+ |
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > renders rowSpan correctly 1`] = ` +LoadedCheerio { + "0":
+ First Name + | ++ Last Name + | +
---|---|
+ John + | ++ Doe + | +
+ Terry + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > should get scrollbar size 1`] = ` +LoadedCheerio { + "0":
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ , + ], + "endIndex": null, + "next": null, + "parent": null, + "prev": null, + "startIndex": null, + "type": "root", + "x-mode": "quirks", + }, + "_root": [Circular], + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, + }, + "length": 1, + "options": { + "decodeEntities": true, + "xml": false, + }, +} +`; + +exports[`Table.Basic > syntactic sugar 1`] = ` +LoadedCheerio { + "0":
+ total + | +
---|
+ Name + | +
+ No Data + | +
, + "_root": LoadedCheerio { + "0": Document { + "children": [ + +
+
+ ,
+ ],
+ "endIndex": null,
+ "next": null,
+ "parent": null,
+ "prev": null,
+ "startIndex": null,
+ "type": "root",
+ "x-mode": "quirks",
+ },
+ "_root": [Circular],
+ "length": 1,
+ "options": {
+ "decodeEntities": true,
+ "xml": false,
+ },
+ },
+ "length": 1,
+ "options": {
+ "decodeEntities": true,
+ "xml": false,
+ },
+}
+`;
diff --git a/tests/setup.js b/tests/setup.js
deleted file mode 100644
index 154da504f..000000000
--- a/tests/setup.js
+++ /dev/null
@@ -1,7 +0,0 @@
-global.requestAnimationFrame = cb => setTimeout(cb, 0);
-require('regenerator-runtime');
-
-const Enzyme = require('enzyme');
-const Adapter = require('enzyme-adapter-react-16');
-
-Enzyme.configure({ adapter: new Adapter() });
diff --git a/tests/setup.ts b/tests/setup.ts
new file mode 100644
index 000000000..cd26964fc
--- /dev/null
+++ b/tests/setup.ts
@@ -0,0 +1,21 @@
+import type { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers';
+import matchers from '@testing-library/jest-dom/matchers';
+import { expect } from 'vitest';
+
+declare module 'vitest' {
+ interface Assertion {
x: 10000,
}}
sticky={{
- getContainer: () => container,
+ getContainer: () => ol,
}}
/>,
{
- attachTo: container,
+ container: ol,
},
);
- await act(async () => {
+ await act(() => {
vi.runAllTimers();
- await Promise.resolve();
});
- expect(wrapper.find('.rc-table-sticky-scroll').get(0)).toBeTruthy();
- expect(wrapper.find('.rc-table-sticky-scroll-bar').get(0)).toBeTruthy();
-
- expect(wrapper.find('.rc-table-sticky-scroll-bar').prop('style')).toEqual({
+ expect(container.querySelector('.rc-table-sticky-scroll')).toBeTruthy();
+ expect(container.querySelector('.rc-table-sticky-scroll-bar')).toBeTruthy();
+ expect(container.querySelector('.rc-table-sticky-scroll-bar').style).toContain({
width: '50px',
- transform: 'translate3d(0px, 0, 0)',
+ transform: 'translate3d(50px, 0, 0)',
});
const mockFn = vi.fn();
+ const node = container.querySelector('.rc-table-sticky-scroll-bar');
+ const event = createEvent.mouseDown(node);
+ event.preventDefault = mockFn;
+ fireEvent(node, event);
- wrapper
- .find('.rc-table-sticky-scroll-bar')
- .simulate('mousedown', { persist: mockFn, preventDefault: mockFn, pageX: 0 });
-
- expect(mockFn).toHaveBeenCalledTimes(2);
+ expect(mockFn).toHaveBeenCalledTimes(1);
- const mousemoveEvent = new Event('mousemove');
-
- mousemoveEvent.buttons = 1;
- mousemoveEvent.pageX = 50;
-
- await act(async () => {
- document.body.dispatchEvent(mousemoveEvent);
+ await act(() => {
+ fireEvent.mouseMove(container, {
+ buttons: 1,
+ pageX: 50,
+ });
vi.runAllTimers();
- await Promise.resolve();
- wrapper.update();
});
- expect(wrapper.find('.rc-table-sticky-scroll-bar').prop('style')).toEqual({
+ expect(container.querySelector('.rc-table-sticky-scroll-bar').style).toContain({
width: '50px',
transform: 'translate3d(50.5px, 0, 0)',
});
- wrapper.unmount();
+ unmount();
window.pageYOffset = 0;
domSpy.mockRestore();
From 7c3c9e41017a6a6df567a87c2550591e5d695668 Mon Sep 17 00:00:00 2001
From: Dunqing
@@ -1185,7 +1196,10 @@ exports[`Table.Basic > should get scrollbar size 1`] = `
>
{
/>,
);
- await act(async () => {
+ await act(() => {
vi.runAllTimers();
- await Promise.resolve();
});
- expect(wrapper.find('.rc-table-sticky-scroll').get(0)).not.toBeUndefined();
+ expect(container.querySelector('.rc-table-sticky-scroll')).toBeTruthy();
+ // const oldInnerHeight = document.body.innerHeight;
const oldInnerHeight = global.innerHeight;
const resizeEvent = new Event('resize');
global.innerHeight = 10000;
- await act(async () => {
+ await act(() => {
global.dispatchEvent(resizeEvent);
vi.runAllTimers();
- await Promise.resolve();
- wrapper.update();
});
- expect(wrapper.find('.rc-table-sticky-scroll').get(0)).toBeFalsy();
+ expect(container.querySelector('.rc-table-sticky-scroll')).toBeNull();
- await act(async () => {
+ await act(() => {
global.innerHeight = oldInnerHeight;
global.dispatchEvent(resizeEvent);
vi.runAllTimers();
- await Promise.resolve();
- wrapper.update();
});
const mockFn = vi.fn();
+ const node = container.querySelector('.rc-table-sticky-scroll-bar');
+ const event = createEvent.mouseDown(node, { clientX: 0 });
+ event.preventDefault = mockFn;
+ fireEvent(node, event);
- wrapper
- .find('.rc-table-sticky-scroll-bar')
- .simulate('mousedown', { persist: mockFn, preventDefault: mockFn, pageX: 0 });
-
- console.log(mockFn.mock.calls);
-
- expect(mockFn).toHaveBeenCalledTimes(2);
-
- expect(wrapper.find('.rc-table-sticky-scroll-bar-active').length).toBe(1);
-
- const mousemoveEvent = new Event('mousemove');
+ expect(mockFn).toHaveBeenCalledTimes(1);
- mousemoveEvent.buttons = 1;
- mousemoveEvent.pageX = 50;
+ expect(container.querySelector('.rc-table-sticky-scroll-bar-active')).toBeTruthy();
- await act(async () => {
- document.body.dispatchEvent(mousemoveEvent);
+ await act(() => {
+ fireEvent.mouseMove(container, {
+ buttons: 1,
+ clientX: 50,
+ });
vi.runAllTimers();
- await Promise.resolve();
- wrapper.update();
});
- expect(wrapper.find('.rc-table-sticky-scroll-bar').prop('style')).toEqual({
+ expect(container.querySelector('.rc-table-sticky-scroll-bar').style).toContain({
width: '50px',
transform: 'translate3d(50.5px, 0, 0)',
});
- await act(async () => {
- mousemoveEvent.pageX = -50;
- document.body.dispatchEvent(mousemoveEvent);
-
+ await act(() => {
+ fireEvent.mouseMove(container, {
+ buttons: 1,
+ clientX: -50,
+ });
vi.runAllTimers();
- await Promise.resolve();
- wrapper.update();
});
- expect(wrapper.find('.rc-table-sticky-scroll-bar').prop('style')).toEqual({
+ expect(container.querySelector('.rc-table-sticky-scroll-bar').style).toContain({
width: '50px',
transform: 'translate3d(0px, 0, 0)',
});
- await act(async () => {
- mousemoveEvent.buttons = 0;
- document.body.dispatchEvent(mousemoveEvent);
-
+ await act(() => {
+ fireEvent.mouseMove(container, {
+ buttons: 0,
+ clientX: -50,
+ });
vi.runAllTimers();
- await Promise.resolve();
- wrapper.update();
});
- expect(wrapper.find('.rc-table-sticky-scroll-bar-active').length).toBe(0);
+ expect(container.querySelector('.rc-table-sticky-scroll-bar-active')).toBeFalsy();
- const mouseupEvent = new Event('mouseup');
+ fireEvent.mouseUp(container);
- document.body.dispatchEvent(mouseupEvent);
-
- wrapper.unmount();
+ unmount();
window.pageYOffset = 0;
mockFn.mockRestore();
@@ -286,13 +272,17 @@ describe('Table.Sticky', () => {
);
};
- const wrapper = mount(
@@ -379,7 +384,10 @@ LoadedCheerio {
style="width: 0px;"
/>
diff --git a/tests/setup.ts b/tests/setup.ts
index cd26964fc..8597c2d9b 100644
--- a/tests/setup.ts
+++ b/tests/setup.ts
@@ -15,6 +15,8 @@ window.getComputedStyle = elt => getComputedStyle(elt);
global.requestAnimationFrame = cb => setTimeout(cb, 0);
require('regenerator-runtime');
+vi.mock('rc-util/lib/getScrollBarSize');
+
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
From a8283c6e2cd1425f55e8758893d20f8afd7cd35b Mon Sep 17 00:00:00 2001
From: Dunqing {
/>,
);
- await act(() => {
+ await act(async () => {
vi.runAllTimers();
+ await Promise.resolve();
});
- expect(container.querySelector('.rc-table-sticky-scroll')).toBeTruthy();
+ expect(wrapper.find('.rc-table-sticky-scroll').get(0)).not.toBeUndefined();
const oldInnerHeight = global.innerHeight;
const resizeEvent = new Event('resize');
global.innerHeight = 10000;
- await act(() => {
+ await act(async () => {
global.dispatchEvent(resizeEvent);
vi.runAllTimers();
+ await Promise.resolve();
+ wrapper.update();
});
- expect(container.querySelector('.rc-table-sticky-scroll')).toBeNull();
+ expect(wrapper.find('.rc-table-sticky-scroll').get(0)).toBeFalsy();
- await act(() => {
+ await act(async () => {
global.innerHeight = oldInnerHeight;
global.dispatchEvent(resizeEvent);
vi.runAllTimers();
+ await Promise.resolve();
+ wrapper.update();
});
const mockFn = vi.fn();
- const node = container.querySelector('.rc-table-sticky-scroll-bar');
- const event = createEvent.mouseDown(node, { clientX: 0 });
- event.preventDefault = mockFn;
- fireEvent(node, event);
- expect(mockFn).toHaveBeenCalledTimes(1);
+ wrapper
+ .find('.rc-table-sticky-scroll-bar')
+ .simulate('mousedown', { persist: mockFn, preventDefault: mockFn, pageX: 0 });
- expect(container.querySelector('.rc-table-sticky-scroll-bar-active')).toBeTruthy();
+ expect(mockFn).toHaveBeenCalledTimes(2);
- await act(() => {
- fireEvent.mouseMove(container, {
- buttons: 1,
- clientX: 50,
- });
+ expect(wrapper.find('.rc-table-sticky-scroll-bar-active').length).toBe(1);
+
+ const mousemoveEvent = new Event('mousemove');
+
+ mousemoveEvent.buttons = 1;
+ mousemoveEvent.pageX = 50;
+
+ await act(async () => {
+ document.body.dispatchEvent(mousemoveEvent);
vi.runAllTimers();
+ await Promise.resolve();
+ wrapper.update();
});
- expect(container.querySelector('.rc-table-sticky-scroll-bar').style).toContain({
+ expect(wrapper.find('.rc-table-sticky-scroll-bar').prop('style')).toEqual({
width: '50px',
transform: 'translate3d(50.5px, 0, 0)',
});
- await act(() => {
- fireEvent.mouseMove(container, {
- buttons: 1,
- clientX: -50,
- });
+ await act(async () => {
+ mousemoveEvent.pageX = -50;
+ document.body.dispatchEvent(mousemoveEvent);
+
vi.runAllTimers();
+ await Promise.resolve();
+ wrapper.update();
});
- expect(container.querySelector('.rc-table-sticky-scroll-bar').style).toContain({
+ expect(wrapper.find('.rc-table-sticky-scroll-bar').prop('style')).toEqual({
width: '50px',
transform: 'translate3d(0px, 0, 0)',
});
- await act(() => {
- fireEvent.mouseMove(container, {
- buttons: 0,
- clientX: -50,
- });
+ await act(async () => {
+ mousemoveEvent.buttons = 0;
+ document.body.dispatchEvent(mousemoveEvent);
+
vi.runAllTimers();
+ await Promise.resolve();
+ wrapper.update();
});
- expect(container.querySelector('.rc-table-sticky-scroll-bar-active')).toBeFalsy();
+ expect(wrapper.find('.rc-table-sticky-scroll-bar-active').length).toBe(0);
+
+ const mouseupEvent = new Event('mouseup');
- fireEvent.mouseUp(container);
+ document.body.dispatchEvent(mouseupEvent);
- unmount();
+ wrapper.unmount();
window.pageYOffset = 0;
mockFn.mockRestore();
@@ -271,17 +282,13 @@ describe('Table.Sticky', () => {
);
};
- const { container } = render(
{
x: 10000,
}}
sticky={{
- getContainer: () => ol,
+ getContainer: () => container,
}}
/>,
{
- container: ol,
+ attachTo: container,
},
);
- await act(() => {
+ await act(async () => {
vi.runAllTimers();
+ await Promise.resolve();
});
- expect(container.querySelector('.rc-table-sticky-scroll')).toBeTruthy();
- expect(container.querySelector('.rc-table-sticky-scroll-bar')).toBeTruthy();
- expect(container.querySelector('.rc-table-sticky-scroll-bar').style).toContain({
+ expect(wrapper.find('.rc-table-sticky-scroll').get(0)).toBeTruthy();
+ expect(wrapper.find('.rc-table-sticky-scroll-bar').get(0)).toBeTruthy();
+
+ expect(wrapper.find('.rc-table-sticky-scroll-bar').prop('style')).toEqual({
width: '50px',
- transform: 'translate3d(50px, 0, 0)',
+ transform: 'translate3d(0px, 0, 0)',
});
const mockFn = vi.fn();
- const node = container.querySelector('.rc-table-sticky-scroll-bar');
- const event = createEvent.mouseDown(node, { clientX: 0 });
- event.preventDefault = mockFn;
- fireEvent(node, event);
- expect(mockFn).toHaveBeenCalledTimes(1);
+ wrapper
+ .find('.rc-table-sticky-scroll-bar')
+ .simulate('mousedown', { persist: mockFn, preventDefault: mockFn, pageX: 0 });
- await act(() => {
- fireEvent.mouseMove(container, {
- buttons: 1,
- clientX: 50,
- });
+ expect(mockFn).toHaveBeenCalledTimes(2);
+
+ const mousemoveEvent = new Event('mousemove');
+
+ mousemoveEvent.buttons = 1;
+ mousemoveEvent.pageX = 50;
+
+ await act(async () => {
+ document.body.dispatchEvent(mousemoveEvent);
vi.runAllTimers();
+ await Promise.resolve();
+ wrapper.update();
});
- expect(container.querySelector('.rc-table-sticky-scroll-bar').style).toContain({
+ expect(wrapper.find('.rc-table-sticky-scroll-bar').prop('style')).toEqual({
width: '50px',
transform: 'translate3d(50.5px, 0, 0)',
});
- unmount();
+ wrapper.unmount();
window.pageYOffset = 0;
domSpy.mockRestore();