Skip to content

Commit

Permalink
fix: supplementary test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yezhonghu0503 committed Oct 28, 2024
1 parent f31d159 commit 7bf2a08
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/hooks/useColumns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ function useColumns<RecordType>(
// >>> Insert expand column if not exist
if (!cloneColumns.includes(EXPAND_COLUMN)) {
const expandColIndex = expandIconColumnIndex || 0;
console.log(expandColIndex);
if (expandColIndex >= 0 && (expandColIndex || fixed === 'left' || !fixed)) {
cloneColumns.splice(expandColIndex, 0, EXPAND_COLUMN);
}
Expand Down Expand Up @@ -245,6 +244,7 @@ function useColumns<RecordType>(
}

return baseColumns.filter(col => col !== EXPAND_COLUMN);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [expandable, baseColumns, getRowKey, expandedKeys, expandIcon, direction]);

// ========================= Transform ========================
Expand All @@ -263,6 +263,7 @@ function useColumns<RecordType>(
];
}
return finalColumns;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [transformColumns, withExpandColumns, direction]);

// ========================== Flatten =========================
Expand All @@ -271,6 +272,7 @@ function useColumns<RecordType>(
return revertForRtl(flatColumns(mergedColumns));
}
return flatColumns(mergedColumns);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mergedColumns, direction, scrollWidth]);

// ========================= Gap Fixed ========================
Expand Down
30 changes: 30 additions & 0 deletions tests/ExpandRow.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,36 @@ describe('Table.Expand', () => {
expect(wrapper2.find('.rc-table-has-fix-right').length).toBe(0);
});

it('fixed in expandable Fixed in expandable', () => {
const columns = [
{ title: 'Name', dataIndex: 'name', key: 'name' },
{ title: 'Age', dataIndex: 'age', key: 'age' },
{ title: 'Gender', dataIndex: 'gender', key: 'gender' },
];
const data = [
{ key: 0, name: 'Lucy', age: 27, gender: 'F' },
{ key: 1, name: 'Jack', age: 28, gender: 'M' },
];
const wrapper = mount(
createTable({
columns,
data,
scroll: { x: 903 },
expandable: { expandedRowRender, fixed: 'left' },
}),
);
const wrapper2 = mount(
createTable({
columns,
data,
scroll: { x: 903 },
expandable: { expandedRowRender, fixed: 'right' },
}),
);
expect(wrapper.find('.rc-table-has-fix-left').length).toBe(1);
expect(wrapper2.find('.rc-table-has-fix-right').length).toBe(1);
});

describe('config expand column index', () => {
it('not show EXPAND_COLUMN if expandable is false', () => {
resetWarned();
Expand Down

0 comments on commit 7bf2a08

Please sign in to comment.