-
Notifications
You must be signed in to change notification settings - Fork 32
/
Accordion.test.tsx
112 lines (85 loc) · 2.44 KB
/
Accordion.test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React, {ReactElement} from 'react';
import {RenderAPI, fireEvent, render} from '@testing-library/react-native';
import {createComponent, createTestProps} from '../../test/testUtils';
import {Accordion} from '../../main';
let props: any;
let component: ReactElement;
let testingLib: RenderAPI;
const data = [
{
title: 'title1',
bodies: ['body1', 'body2', 'body3'],
},
{
title: 'title2',
bodies: ['body1', 'body2', 'body3'],
},
{
title: 'title3',
bodies: ['body1', 'body2', 'body3'],
},
];
describe('[Accordion] render test', () => {
it('should render without crashing', () => {
props = createTestProps({data: data});
component = createComponent(<Accordion {...props} />);
testingLib = render(component);
const json = testingLib.toJSON();
expect(json).toMatchSnapshot();
});
it('should render collapsed when collapseOnStart props is true', () => {
props = createTestProps({
collapseOnStart: true,
data: data,
});
component = <Accordion {...props} />;
testingLib = render(component);
const json = testingLib.toJSON();
expect(json).toMatchSnapshot();
});
it('should operate animation when isAnimated props is true', () => {
jest.useFakeTimers();
props = createTestProps({
isAnimated: true,
data: data,
});
component = <Accordion {...props} />;
jest.runAllTimers();
testingLib = render(component);
const json = testingLib.toJSON();
expect(json).toMatchSnapshot();
});
it('should adjust duration of animation depends on animDuration props value', () => {
props = createTestProps({
animDuration: 500,
data: data,
});
component = <Accordion {...props} />;
testingLib = render(component);
const json = testingLib.toJSON();
expect(json).toMatchSnapshot();
});
});
describe('[Accordion] event test', () => {
beforeEach(() => {
props = createTestProps({
data: data,
});
component = <Accordion {...props} />;
testingLib = render(component);
});
it('should trigger onLayout event when itemBody rendered', () => {
const {getByTestId} = testingLib;
const itemTitle = getByTestId('body_0');
fireEvent(itemTitle, 'layout', {
nativeEvent: {
layout: {
height: 300,
},
},
});
});
it('should trigger press event when clicking title', () => {
fireEvent.press(testingLib.getByTestId('title_0'));
});
});