Skip to content

Commit

Permalink
test: rm useless test
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Aug 17, 2023
1 parent 9a8cf51 commit e6a3306
Showing 1 changed file with 42 additions and 51 deletions.
93 changes: 42 additions & 51 deletions tests/Table.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { mount } from 'enzyme';
import { resetWarned } from 'rc-util/lib/warning';
import React from 'react';
import { VariableSizeGrid as Grid } from 'react-window';
import Table, { INTERNAL_COL_DEFINE } from '../src';
import BodyRow from '../src/Body/BodyRow';
import Cell from '../src/Cell';
import { INTERNAL_HOOKS } from '../src/constant';
import { VariableSizeGrid as Grid } from "react-window";

describe('Table.Basic', () => {
const data = [
Expand Down Expand Up @@ -684,22 +684,6 @@ describe('Table.Basic', () => {
);
errSpy.mockRestore();
});

it('without scroll', () => {
resetWarned();
const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
mount(
createTable({
components: {
body: () => <h1>Bamboo</h1>,
},
}),
);
expect(errSpy).toHaveBeenCalledWith(
'Warning: `components.body` with render props is only work on `scroll.y`.',
);
errSpy.mockRestore();
});
});

it('without warning - columns is empty', () => {
Expand Down Expand Up @@ -1222,52 +1206,54 @@ describe('Table.Basic', () => {
const width = 150;
const noChildColLen = 4;
const ChildColLen = 4;
const buildChildDataIndex = (n) => `col${n}`;
const buildChildDataIndex = n => `col${n}`;
const columns = Array.from({ length: noChildColLen }, (_, i) => ({
title: `第 ${i} 列`,
dataIndex: buildChildDataIndex(i),
width,
})).concat(Array.from({ length: ChildColLen }, (_, i) => ({
title: `第 ${i} 分组`,
dataIndex: `parentCol${i}`,
width: width * 2,
children: [
{
title: `第 ${noChildColLen + i} 列`,
dataIndex: buildChildDataIndex(noChildColLen + i),
width,
},
{
title: `第 ${noChildColLen + 1 + i} 列`,
dataIndex: buildChildDataIndex(noChildColLen + 1 + i),
width,
},
]
})));
})).concat(
Array.from({ length: ChildColLen }, (_, i) => ({
title: `第 ${i} 分组`,
dataIndex: `parentCol${i}`,
width: width * 2,
children: [
{
title: `第 ${noChildColLen + i} 列`,
dataIndex: buildChildDataIndex(noChildColLen + i),
width,
},
{
title: `第 ${noChildColLen + 1 + i} 列`,
dataIndex: buildChildDataIndex(noChildColLen + 1 + i),
width,
},
],
})),
);
const data = Array.from({ length: 10000 }, (_, r) => {
const colLen = noChildColLen + ChildColLen * 2;
const record = {};
for (let c = 0; c < colLen; c ++) {
record[buildChildDataIndex(c)] = `r${r}, c${c}`
for (let c = 0; c < colLen; c++) {
record[buildChildDataIndex(c)] = `r${r}, c${c}`;
}
return record;
})
const Demo = (props) => {
});
const Demo = props => {
const gridRef = React.useRef();
const [connectObject] = React.useState(() => {
const obj = {};
Object.defineProperty(obj, "scrollLeft", {
Object.defineProperty(obj, 'scrollLeft', {
get: () => {
if (gridRef.current) {
return gridRef.current?.state?.scrollLeft;
}
return null;
},
set: (scrollLeft) => {
set: scrollLeft => {
if (gridRef.current) {
gridRef.current.scrollTo({ scrollLeft });
}
}
},
});

return obj;
Expand All @@ -1276,7 +1262,7 @@ describe('Table.Basic', () => {
React.useEffect(() => {
gridRef.current.resetAfterIndices({
columnIndex: 0,
shouldForceUpdate: false
shouldForceUpdate: false,
});
}, []);

Expand All @@ -1287,11 +1273,9 @@ describe('Table.Basic', () => {
ref={gridRef}
className="virtual-grid"
columnCount={columns.length}
columnWidth={(index) => {
columnWidth={index => {
const { width } = columns[index];
return index === columns.length - 1
? width - scrollbarSize - 1
: width;
return index === columns.length - 1 ? width - scrollbarSize - 1 : width;
}}
height={300}
rowCount={rawData.length}
Expand All @@ -1303,7 +1287,9 @@ describe('Table.Basic', () => {
>
{({ columnIndex, rowIndex, style }) => (
<div
className={`virtual-cell ${columnIndex === columns.length - 1 ? 'virtual-cell-last' : ''}`}
className={`virtual-cell ${
columnIndex === columns.length - 1 ? 'virtual-cell-last' : ''
}`}
style={style}
>
r{rowIndex}, c{columnIndex}
Expand All @@ -1321,12 +1307,17 @@ describe('Table.Basic', () => {
data={props.data}
scroll={{ y: 300, x: 300 }}
components={{
body: renderVirtualList
body: renderVirtualList,
}}
/>
);
};
const wrapper = mount(<Demo columns={columns} data={data} />);
expect(wrapper.find('col').at(noChildColLen + ChildColLen * 2 - 1).props().style.width + wrapper.find('col').last().props().style.width).toEqual(width);
})
expect(
wrapper
.find('col')
.at(noChildColLen + ChildColLen * 2 - 1)
.props().style.width + wrapper.find('col').last().props().style.width,
).toEqual(width);
});
});

0 comments on commit e6a3306

Please sign in to comment.