Skip to content

Commit

Permalink
test(react/table): correct table test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
travor20814 committed Dec 5, 2023
1 parent 8ed6368 commit 7747328
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/react/src/Table/Table.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const defaultSources: DataType[] = [{
}];

const defaultColumns: TableColumn<DataType>[] = [{
key: 'foo',
dataIndex: 'foo',
title: 'foo',
}];
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/Table/TableBody.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const defaultSources: DataType[] = [{
}];

const defaultColumns: TableColumn<DataType>[] = [{
key: 'foo',
dataIndex: 'foo',
title: 'foo',
}];
Expand Down
12 changes: 11 additions & 1 deletion packages/react/src/Table/TableBodyRow.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,16 @@ describe('<TableBodyRow />', () => {

it('ellipsis control should set to true by default, and false when no data/disabled', () => {
const columns: TableColumn<DataType>[] = [{
key: 'name',
dataIndex: 'name',
title: 'name',
}, {
key: 'not-existed',
dataIndex: 'not-existed',
title: 'bar',
ellipsis: true,
}, {
key: 'name',
dataIndex: 'name',
title: 'foo',
ellipsis: false,
Expand Down Expand Up @@ -118,6 +121,7 @@ describe('<TableBodyRow />', () => {

describe('columns are given', () => {
const columns: TableColumn<DataType>[] = [{
key: 'name',
dataIndex: 'name',
title: 'foo',
headerClassName: undefined,
Expand All @@ -127,11 +131,12 @@ describe('<TableBodyRow />', () => {
width: 80,
align: 'center',
}, {
dataIndex: 'bar',
key: 'bar',
title: 'bar',
align: 'start',
render: () => 'bar-render',
}, {
key: 'foo.bar',
dataIndex: 'foo.bar',
title: 'foo',
}];
Expand Down Expand Up @@ -301,8 +306,10 @@ describe('<TableBodyRow />', () => {
name: 'bar',
}],
columns: [{
key: 'name',
dataIndex: 'name',
}, {
key: 'name2',
dataIndex: 'name',
}],
}),
Expand Down Expand Up @@ -351,8 +358,10 @@ describe('<TableBodyRow />', () => {
expandedRowRender: () => ({
dataSource: [],
columns: [{
key: 'name',
dataIndex: 'name',
}, {
key: 'name2',
dataIndex: 'name',
}],
}),
Expand Down Expand Up @@ -391,6 +400,7 @@ describe('<TableBodyRow />', () => {
describe('exceptions handle', () => {
it('column.width/column.align not given', () => {
const columns: TableColumn<DataType>[] = [{
key: 'name',
dataIndex: 'name',
title: 'name',
}];
Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/Table/TableExpandedTable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ const dataSource: DataType[] = [{
}];

const columns: TableColumn<DataType>[] = [{
key: 'name',
dataIndex: 'name',
title: 'name',
width: 80,
align: 'center',
}, {
key: 'age',
dataIndex: 'age',
title: 'foo',
ellipsis: false,
Expand All @@ -49,9 +51,12 @@ const expandedSources: DataType[] = [{
}];

const expandedColumns: TableColumn<DataType>[] = [{
key: 'name',
dataIndex: 'name',
title: '',
}, {
dataIndex: 'name',
key: 'name',
title: '',
render: () => 'render name',
}];

Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/Table/TableHeader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('<TableHeader />', () => {

describe('columns are given', () => {
const columns: TableColumn<DataType>[] = [{
key: 'foo',
dataIndex: 'foo',
title: 'foo',
headerClassName: undefined,
Expand All @@ -44,8 +45,8 @@ describe('<TableHeader />', () => {
width: 80,
align: 'center',
}, {
key: 'bar',
dataIndex: 'bar',
title: 'bar',
align: 'start',
renderTitle: () => 'bar',
sorter: () => 1,
Expand Down Expand Up @@ -158,6 +159,7 @@ describe('<TableHeader />', () => {
describe('exceptions handle', () => {
it('column.width/column.align not given', () => {
const columns: TableColumn<DataType>[] = [{
key: 'foo',
dataIndex: 'foo',
title: 'foo',
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('<TableEditRenderWrapper />', () => {
}}
>
<TableEditRenderWrapper
key="edit"
dataIndex={defaultDataIndex}
rowData={defaultRowData}
setCellProps={setCellProps}
Expand Down
21 changes: 11 additions & 10 deletions packages/react/src/Table/sorting/TableSortingIcon.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ type DataType = {
key: string;
};

const dataIndex = 'foo';
const key = 'foo';
const defaultColumn = { key: 'foo', title: '', dataIndex: '' };

describe('<TableSortingIcon />', () => {
afterEach(cleanupHook);

it('should bind host class', () => {
const { getHostHTMLElement } = render(<TableSortingIcon column={{ dataIndex: 'foo' }} />);
const { getHostHTMLElement } = render(<TableSortingIcon column={defaultColumn} />);
const element = getHostHTMLElement();

expect(element.classList.contains('mzn-table__icon')).toBeTruthy();
Expand All @@ -47,12 +48,12 @@ describe('<TableSortingIcon />', () => {
...defaultMockingContextValue,
sorting: {
...defaultMockingContextValue.sorting,
sortedOn: dataIndex,
sortedOn: key,
sortedType: mode,
},
}}
>
<TableSortingIcon column={{ dataIndex }} />
<TableSortingIcon column={defaultColumn} />
</TableContext.Provider>,
);
const element = getHostHTMLElement();
Expand Down Expand Up @@ -89,12 +90,12 @@ describe('<TableSortingIcon />', () => {
sorting: {
...defaultMockingContextValue.sorting,
onSort,
sortedOn: dataIndex,
sortedOn: key,
sortedType: 'none',
},
}}
>
<TableSortingIcon column={{ dataIndex }} />
<TableSortingIcon column={defaultColumn} />
</TableContext.Provider>,
);
const element = getHostHTMLElement();
Expand All @@ -103,7 +104,7 @@ describe('<TableSortingIcon />', () => {
fireEvent.click(element);
});

expect(valueGetFromOnSort).toStrictEqual({ dataIndex });
expect(valueGetFromOnSort).toStrictEqual(defaultColumn);
});

it('should icon remain default state when is not sorting on its column', () => {
Expand All @@ -113,12 +114,12 @@ describe('<TableSortingIcon />', () => {
...defaultMockingContextValue,
sorting: {
...defaultMockingContextValue.sorting,
sortedOn: `${dataIndex}-bar`,
sortedOn: `${key}-bar`,
sortedType: 'asc',
},
}}
>
<TableSortingIcon column={{ dataIndex }} />
<TableSortingIcon column={defaultColumn} />
</TableContext.Provider>,
);
const element = getHostHTMLElement();
Expand All @@ -137,7 +138,7 @@ describe('<TableSortingIcon />', () => {
beforeEach(() => {
const { getHostHTMLElement } = render(
<TableContext.Provider value={{}}>
<TableSortingIcon column={{ dataIndex: 'foo' }} />
<TableSortingIcon column={defaultColumn} />
</TableContext.Provider>,
);
const element = getHostHTMLElement();
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/Table/sorting/useTableSorting.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('useTableSorting()', () => {

TestRenderer.act(() => {
onChange({
key: 'age',
dataIndex: 'age',
sorter: numberSorter,
});
Expand All @@ -70,6 +71,7 @@ describe('useTableSorting()', () => {

TestRenderer.act(() => {
onChange({
key: 'age',
dataIndex: 'age',
sorter: numberSorter,
});
Expand All @@ -83,6 +85,7 @@ describe('useTableSorting()', () => {

TestRenderer.act(() => {
onChange({
key: 'age',
dataIndex: 'age',
sorter: numberSorter,
});
Expand All @@ -109,6 +112,7 @@ describe('useTableSorting()', () => {

TestRenderer.act(() => {
onChange({
key: 'age',
dataIndex: 'age',
sorter: numberSorter,
});
Expand All @@ -121,6 +125,7 @@ describe('useTableSorting()', () => {

TestRenderer.act(() => {
onChange({
key: 'count',
dataIndex: 'count',
sorter: numberSorter,
});
Expand Down Expand Up @@ -154,6 +159,7 @@ describe('useTableSorting()', () => {

TestRenderer.act(() => {
onChange({
key: 'age',
dataIndex: 'age',
sorter: numberSorter,
onSorted: onAgeSorted,
Expand Down Expand Up @@ -208,6 +214,7 @@ describe('useTableSorting()', () => {

TestRenderer.act(() => {
onChange({
key: 'age',
dataIndex: 'age',
});
});
Expand Down

0 comments on commit 7747328

Please sign in to comment.