/
Section.spec.tsx
122 lines (116 loc) · 2.63 KB
/
Section.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
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
113
114
115
116
117
118
119
120
121
122
import React from 'react';
import { render } from '@testing-library/react';
import Section from 'rsg-components/Section';
import Context from '../Context';
import slots from '../slots';
import { DisplayModes } from '../../consts';
const context = {
config: {
pagePerSection: false,
},
displayMode: DisplayModes.all,
slots: slots(),
} as any;
const Provider = (props: any) => <Context.Provider value={context} {...props} />;
test('should render nested sections', () => {
const { getByTestId } = render(
<Provider>
<Section
section={{
name: 'Outer section',
slug: 'outer-section',
usageMode: 'collapse',
exampleMode: 'collapse',
sections: [
{
name: 'Nested section',
slug: 'nested-section',
usageMode: 'collapse',
exampleMode: 'collapse',
},
],
}}
depth={3}
/>
</Provider>
);
expect(getByTestId('section-outer-section')).toContainElement(
getByTestId('section-nested-section')
);
});
test('should render components inside a section', () => {
const { getByTestId, getByText } = render(
<Provider>
<Section
section={{
name: 'Components',
slug: 'components',
usageMode: 'collapse',
exampleMode: 'collapse',
components: [
{
name: 'Foo',
visibleName: 'Foo',
slug: 'foo',
pathLine: 'components/foo.js',
filepath: 'components/foo.js',
props: {
description: 'Foo foo',
},
},
{
name: 'Bar',
visibleName: 'Bar',
slug: 'bar',
pathLine: 'components/bar.js',
filepath: 'components/bar.js',
props: {
description: 'Bar bar',
},
},
],
}}
depth={3}
/>
</Provider>
);
expect(getByTestId('section-components')).toContainElement(getByText('components/foo.js'));
expect(getByTestId('section-components')).toContainElement(getByText('components/bar.js'));
});
test('should not render section in isolation mode by default', () => {
const { getByLabelText } = render(
<Provider>
<Section
section={{
name: 'A',
slug: 'a',
usageMode: 'collapse',
exampleMode: 'collapse',
}}
depth={3}
/>
</Provider>
);
expect(getByLabelText(/open isolated/i)).toBeInTheDocument();
});
test('should render section in isolation mode', () => {
const { queryByLabelText } = render(
<Provider
value={{
...context,
displayMode: DisplayModes.section,
}}
>
<Section
section={{
name: 'A',
slug: 'a',
usageMode: 'collapse',
exampleMode: 'collapse',
}}
depth={3}
/>
</Provider>
);
expect(queryByLabelText(/open isolated/i)).toBeNull();
});