Skip to content

Commit

Permalink
test: refactor refinedColumnDefs
Browse files Browse the repository at this point in the history
  • Loading branch information
santiago.trigo committed Dec 12, 2023
1 parent 5a2441a commit 7c2cb6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
6 changes: 2 additions & 4 deletions packages/table/src/core/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ export const Table: React.FC<TableProps> = ({

const ref = React.useRef<HTMLDivElement>();

const refinedColumnDefs: ColDef[] = getCollatedColumns(
defaultColumnDef,
columnDefs,
types,
const refinedColumnDefs: ColDef[] = columnDefs.map((column) =>
getCollatedColumns(defaultColumnDef, column, types),
);

const sizes = getSizes(theme, visualOptions?.density ?? 'default');
Expand Down
18 changes: 13 additions & 5 deletions packages/table/src/core/utils/columns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ const getColDefByIDCases: [string, ColDef[], VirtualItem, ColDef][] = [
const getCollatedColumnsCases: [
string,
DefaultColDef,
ColDef[],
ColDef,
ColumnType[],
ColDef[],
][] = [['No column definitions', DEFAULT_COLDEF, [], [], []]];
ColDef,
][] = [
[
'No column definitions',
DEFAULT_COLDEF,
{ id: 'null' },
[],
{ id: 'null', headerName: 'Column' },
],
];

describe('Table', () => {
describe('Utils', () => {
Expand All @@ -45,8 +53,8 @@ describe('Table', () => {
describe('getCollatedColumns', () => {
it.each(getCollatedColumnsCases)(
'%s',
(_title, defaultColDef, colDefs, types, expected) => {
expect(getCollatedColumns(defaultColDef, colDefs, types)).toEqual(
(_title, defaultColDef, column, types, expected) => {
expect(getCollatedColumns(defaultColDef, column, types)).toEqual(
expected,
);
},
Expand Down
12 changes: 4 additions & 8 deletions packages/table/src/core/utils/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ export const getColDefByID = (
*/
export const getCollatedColumns = (
defaultColumnDef: DefaultColDef,
columnDefs: ColDef[],
column: ColDef,
types: ColumnType[],
): ColDef[] => {
return (
columnDefs?.map((column) => {
const type = types.find((element) => element.id === column.type);
return { ...defaultColumnDef, ...type, ...column };
}) ?? []
);
): ColDef => {
const type = types.find((element) => element.id === column.type);
return { ...defaultColumnDef, ...type, ...column };
};

export const getOccupiedWidthInfo = (colDefs: ColDef[]): [number, number] =>
Expand Down

0 comments on commit 7c2cb6c

Please sign in to comment.