-
-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathrefs.spec.tsx
65 lines (55 loc) · 1.46 KB
/
refs.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { render } from '@testing-library/react';
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
import React from 'react';
import Table, { type Reference } from '../src';
describe('Table.Ref', () => {
let scrollParam: any = null;
let scrollIntoViewElement: HTMLElement = null;
beforeAll(() => {
spyElementPrototypes(HTMLElement, {
scrollTo: (_: any, param: any) => {
scrollParam = param;
},
scrollIntoView() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
scrollIntoViewElement = this;
},
});
});
beforeEach(() => {
scrollParam = null;
});
it('support reference', () => {
const ref = React.createRef<Reference>();
const { container } = render(
<Table
data={[{ key: 'light' }, { key: 'bamboo' }]}
columns={[
{
dataIndex: 'key',
},
]}
ref={ref}
scroll={{
y: 10,
}}
/>,
);
expect(ref.current.nativeElement).toBe(container.querySelector('.rc-table'));
// Scroll To number
ref.current.scrollTo({
top: 903,
});
expect(scrollParam.top).toEqual(903);
// Scroll index
ref.current.scrollTo({
index: 0,
});
expect(scrollIntoViewElement.textContent).toEqual('light');
// Scroll key
ref.current.scrollTo({
key: 'bamboo',
});
expect(scrollIntoViewElement.textContent).toEqual('bamboo');
});
});