Skip to content

Commit d2a99f6

Browse files
committed
update scrollTo test
1 parent 5bf6b01 commit d2a99f6

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

packages/main/src/components/AnalyticalTable/AnalyticalTable.test.tsx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,29 +289,54 @@ describe('AnalyticalTable', () => {
289289
const UsingTable = (props) => {
290290
tableRef = useRef(null);
291291
return (
292-
<AnalyticalTable ref={tableRef} title="Table Title" data={data} columns={columns} visibleRows={1} minRows={1} />
292+
<AnalyticalTable
293+
style={{ width: '170px' }}
294+
ref={tableRef}
295+
title="Table Title"
296+
data={data}
297+
columns={columns}
298+
visibleRows={1}
299+
minRows={1}
300+
/>
293301
);
294302
};
295303

296-
render(<UsingTable />);
304+
const { getByRole, container } = render(<UsingTable />);
297305

298306
// Check existence + type
299307
expect(typeof tableRef.current.scrollTo).toBe('function');
300308
expect(typeof tableRef.current.scrollToItem).toBe('function');
309+
expect(typeof tableRef.current.horizontalScrollTo).toBe('function');
310+
expect(typeof tableRef.current.horizontalScrollToItem).toBe('function');
301311

302312
// call functions
303-
const tableInnerRef = tableRef.current.querySelector("div[class^='AnalyticalTable-table'] > div");
313+
const tableBodyRef = tableRef.current.querySelector("div[class^='AnalyticalTable-tbody']");
314+
const tableContainerRef = getByRole('grid', { hidden: true });
315+
304316
act(() => {
305317
tableRef.current.scrollToItem(1, 'start');
306318
});
307319

308-
expect(tableInnerRef.scrollTop).toBe(44);
320+
expect(tableBodyRef.scrollTop).toBe(44);
309321

310322
act(() => {
311323
tableRef.current.scrollTo(2);
312324
});
313325

314-
expect(tableInnerRef.scrollTop).toBe(2);
326+
expect(tableBodyRef.scrollTop).toBe(2);
327+
328+
screen.debug(tableContainerRef, 9999999);
329+
act(() => {
330+
tableRef.current.horizontalScrollToItem(1, 'start');
331+
});
332+
333+
expect(tableContainerRef.scrollLeft).toBe(150);
334+
335+
act(() => {
336+
tableRef.current.horizontalScrollTo(2);
337+
});
338+
339+
expect(tableContainerRef.scrollLeft).toBe(2);
315340
});
316341

317342
test('with highlight row', () => {

0 commit comments

Comments
 (0)