Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 4c76ec2

Browse files
committed
refactor(groups): update all typings for groups and clean up methods
1 parent 27825bf commit 4c76ec2

File tree

15 files changed

+309
-242
lines changed

15 files changed

+309
-242
lines changed

src/Column.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/DataScroller.test.tsx

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import * as faker from 'faker';
22
import React from 'react';
33
import { act, fireEvent, render } from 'react-testing-library';
4+
import Column, { Props as ColumnProps } from './components/Column';
5+
import Group from './components/Group';
46
import DataScroller from './DataScroller';
57

6-
import {
7-
CellRendererArgs,
8-
Column,
9-
HeaderRendererArgs,
10-
RowGetterArgs,
11-
} from './types';
8+
import { CellRendererArgs, HeaderRendererArgs, RowGetterArgs } from './types';
129

1310
const initialColumns = [
1411
{
@@ -62,7 +59,7 @@ const rows = generateRows(rowCount);
6259

6360
const rowGetter = ({ index }: RowGetterArgs) => rows[index];
6461

65-
let columns: Column[] = [];
62+
let columns: ColumnProps[] = [];
6663
for (let counter = 0; counter < 10; counter += 1) {
6764
columns = [...initialColumns, ...(columns || [])];
6865
}
@@ -72,7 +69,7 @@ columns = columns.map((column, index) => ({
7269
columnData: { ...(column.columnData || {}), columnIndex: index },
7370
}));
7471

75-
let frozenColumns: Column[] = [];
72+
let frozenColumns: ColumnProps[] = [];
7673
for (let counter = 0; counter < 2; counter += 1) {
7774
frozenColumns = [...initialColumns, ...(frozenColumns || [])];
7875
}
@@ -82,43 +79,58 @@ frozenColumns = frozenColumns.map((column, index) => ({
8279
columnData: { ...(column.columnData || {}), columnIndex: index },
8380
}));
8481

82+
const GroupHeaderA = (props: { width: number }) => {
83+
return (
84+
<div style={{ backgroundColor: 'blue', width: props.width }}>
85+
First Group
86+
</div>
87+
);
88+
};
89+
90+
const GroupHeaderB = (props: { width: number }) => {
91+
return (
92+
<div style={{ backgroundColor: 'red', width: props.width }}>
93+
Second Group
94+
</div>
95+
);
96+
};
97+
8598
describe('DataScroller', () => {
99+
const { container, getByTestId } = render(
100+
<DataScroller
101+
rowCount={rowCount}
102+
rowGetter={rowGetter}
103+
rowHeight={100}
104+
height={100}
105+
headerHeight={0}
106+
width={500}
107+
columns={[
108+
<Group key="groupa" headerRenderer={GroupHeaderA}>
109+
{columns.map((column, index) => (
110+
<Column key={index} {...column} />
111+
))}
112+
</Group>,
113+
<Group key="groupb" headerRenderer={GroupHeaderB}>
114+
{columns.map((column, index) => (
115+
<Column key={index} {...column} />
116+
))}
117+
</Group>,
118+
]}
119+
frozenColumns={frozenColumns.map((column, index) => (
120+
<Column key={index} {...column} />
121+
))}
122+
/>,
123+
);
86124
it('renders only one row', () => {
87-
const { container } = render(
88-
<DataScroller
89-
rowCount={rowCount}
90-
rowGetter={rowGetter}
91-
rowHeight={100}
92-
height={100}
93-
headerHeight={0}
94-
width={500}
95-
columns={columns}
96-
frozenColumns={frozenColumns}
97-
/>,
98-
);
99-
100125
expect(container.textContent).toMatch(rows[0].firstName);
101126
expect(container.textContent).not.toMatch(rows[1].firstName);
102127
});
103128

104129
it('loads one additional row when scrolling', () => {
105-
const { container, debug, getByTestId } = render(
106-
<DataScroller
107-
rowCount={rowCount}
108-
rowGetter={rowGetter}
109-
rowHeight={100}
110-
height={100}
111-
headerHeight={0}
112-
width={500}
113-
columns={columns}
114-
frozenColumns={frozenColumns}
115-
/>,
116-
);
117-
118130
const scrollContainer = getByTestId('scroll-container');
119131

120132
act(() => {
121-
scrollContainer.scrollTop = 50;
133+
scrollContainer.scrollTop = 100;
122134
fireEvent.scroll(scrollContainer);
123135
});
124136

0 commit comments

Comments
 (0)