1
1
import { DrawerActions , DrawerLayout , DrawerLayoutState } from '../' ;
2
+
2
3
import { BlueBaseApp } from '@bluebase/core' ;
3
4
import Plugin from '../../../' ;
4
5
import React from 'react' ;
@@ -9,17 +10,14 @@ import { waitForElement } from 'enzyme-async-helpers';
9
10
// tslint:disable: jsx-no-lambda
10
11
11
12
describe ( 'DrawerLayout' , ( ) => {
12
-
13
13
it ( 'should render a simple "front" type drawer' , async ( ) => {
14
14
const component = mount (
15
15
< BlueBaseApp plugins = { [ Plugin ] } >
16
16
< DrawerLayout
17
17
// open
18
18
drawerWidth = { 200 }
19
19
// drawerPosition="left"
20
- renderNavigationView = { ( ) => (
21
- < Text testID = "navigation-view" > I'm inside drawer</ Text >
22
- ) }
20
+ renderNavigationView = { ( ) => < Text testID = "navigation-view" > I'm inside drawer</ Text > }
23
21
>
24
22
< Text testID = "drawer-layout-children" > I'm DrawerLayout's children</ Text >
25
23
</ DrawerLayout >
@@ -29,12 +27,23 @@ describe('DrawerLayout', () => {
29
27
await waitForElement ( component as any , DrawerLayout ) ;
30
28
31
29
// expect(component).toMatchSnapshot();
32
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'anchor' ) ) . toBe ( 'left' ) ;
33
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'open' ) ) . toBe ( false ) ;
30
+ expect (
31
+ component
32
+ . find ( 'Drawer' )
33
+ . first ( )
34
+ . prop ( 'anchor' )
35
+ ) . toBe ( 'left' ) ;
36
+ expect (
37
+ component
38
+ . find ( 'Drawer' )
39
+ . first ( )
40
+ . prop ( 'open' )
41
+ ) . toBe ( false ) ;
34
42
35
43
expect ( component . find ( 'Drawer Text[testID="navigation-view"]' ) ) . toHaveLength ( 0 ) ;
36
- expect ( component . find ( 'DrawerLayout Text[testID="drawer-layout-children"]' ) . length ) . toBeGreaterThan ( 0 ) ;
37
-
44
+ expect (
45
+ component . find ( 'DrawerLayout Text[testID="drawer-layout-children"]' ) . length
46
+ ) . toBeGreaterThan ( 0 ) ;
38
47
} ) ;
39
48
40
49
it ( 'should render an open drawer' , async ( ) => {
@@ -44,9 +53,7 @@ describe('DrawerLayout', () => {
44
53
open
45
54
drawerWidth = { 200 }
46
55
// drawerPosition="left"
47
- renderNavigationView = { ( ) => (
48
- < Text testID = "navigation-view" > I'm inside drawer</ Text >
49
- ) }
56
+ renderNavigationView = { ( ) => < Text testID = "navigation-view" > I'm inside drawer</ Text > }
50
57
>
51
58
< Text testID = "drawer-layout-children" > I'm DrawerLayout's children</ Text >
52
59
</ DrawerLayout >
@@ -56,7 +63,12 @@ describe('DrawerLayout', () => {
56
63
await waitForElement ( component as any , DrawerLayout ) ;
57
64
58
65
// expect(component).toMatchSnapshot();
59
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'open' ) ) . toBe ( true ) ;
66
+ expect (
67
+ component
68
+ . find ( 'Drawer' )
69
+ . first ( )
70
+ . prop ( 'open' )
71
+ ) . toBe ( true ) ;
60
72
} ) ;
61
73
62
74
it ( 'should render a drawer positioned on the right' , async ( ) => {
@@ -66,9 +78,7 @@ describe('DrawerLayout', () => {
66
78
// open
67
79
drawerWidth = { 200 }
68
80
drawerPosition = "right"
69
- renderNavigationView = { ( ) => (
70
- < Text testID = "navigation-view" > I'm inside drawer</ Text >
71
- ) }
81
+ renderNavigationView = { ( ) => < Text testID = "navigation-view" > I'm inside drawer</ Text > }
72
82
>
73
83
< Text testID = "drawer-layout-children" > I'm DrawerLayout's children</ Text >
74
84
</ DrawerLayout >
@@ -78,7 +88,12 @@ describe('DrawerLayout', () => {
78
88
await waitForElement ( component as any , DrawerLayout ) ;
79
89
80
90
// expect(component).toMatchSnapshot();
81
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'anchor' ) ) . toBe ( 'right' ) ;
91
+ expect (
92
+ component
93
+ . find ( 'Drawer' )
94
+ . first ( )
95
+ . prop ( 'anchor' )
96
+ ) . toBe ( 'right' ) ;
82
97
} ) ;
83
98
84
99
it ( 'should render a "slide" type drawer' , async ( ) => {
@@ -87,9 +102,32 @@ describe('DrawerLayout', () => {
87
102
< DrawerLayout
88
103
drawerType = "slide"
89
104
drawerWidth = { 200 }
90
- renderNavigationView = { ( ) => (
91
- < Text testID = "navigation-view" > I'm inside drawer</ Text >
92
- ) }
105
+ renderNavigationView = { ( ) => < Text testID = "navigation-view" > I'm inside drawer</ Text > }
106
+ >
107
+ < Text testID = "drawer-layout-children" > I'm DrawerLayout's children</ Text >
108
+ </ DrawerLayout >
109
+ </ BlueBaseApp >
110
+ ) ;
111
+
112
+ await waitForElement ( component as any , DrawerLayout ) ;
113
+
114
+ // expect(component).toMatchSnapshot();
115
+ expect (
116
+ component
117
+ . find ( 'Drawer' )
118
+ . first ( )
119
+ . prop ( 'variant' )
120
+ ) . toBe ( 'persistent' ) ;
121
+ } ) ;
122
+
123
+ it ( 'should render a "slide" type drawer with open prop' , async ( ) => {
124
+ const component = mount (
125
+ < BlueBaseApp plugins = { [ Plugin ] } >
126
+ < DrawerLayout
127
+ drawerType = "slide"
128
+ drawerWidth = { 200 }
129
+ open = { true }
130
+ renderNavigationView = { ( ) => < Text testID = "navigation-view" > I'm inside drawer</ Text > }
93
131
>
94
132
< Text testID = "drawer-layout-children" > I'm DrawerLayout's children</ Text >
95
133
</ DrawerLayout >
@@ -99,7 +137,18 @@ describe('DrawerLayout', () => {
99
137
await waitForElement ( component as any , DrawerLayout ) ;
100
138
101
139
// expect(component).toMatchSnapshot();
102
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'variant' ) ) . toBe ( 'persistent' ) ;
140
+ expect (
141
+ component
142
+ . find ( 'Drawer' )
143
+ . first ( )
144
+ . prop ( 'variant' )
145
+ ) . toBe ( 'persistent' ) ;
146
+ expect (
147
+ component
148
+ . find ( 'Drawer' )
149
+ . first ( )
150
+ . prop ( 'open' )
151
+ ) . toBe ( true ) ;
103
152
} ) ;
104
153
105
154
it ( 'should be controllable through DrawerActions' , async ( ) => {
@@ -108,58 +157,94 @@ describe('DrawerLayout', () => {
108
157
< DrawerLayout
109
158
drawerType = "front"
110
159
drawerWidth = { 200 }
111
- renderNavigationView = { ( ) => (
112
- < Text testID = "navigation-view" > I'm inside drawer</ Text >
113
- ) }
160
+ renderNavigationView = { ( ) => < Text testID = "navigation-view" > I'm inside drawer</ Text > }
114
161
>
115
162
< DrawerActions >
116
- { ( _navigation ) => (
117
- < Text testID = "drawer-layout-children" > I'm DrawerLayout's children</ Text >
118
- ) }
163
+ { _navigation => (
164
+ < Text testID = "drawer-layout-children" > I'm DrawerLayout's children</ Text >
165
+ ) }
119
166
</ DrawerActions >
120
167
</ DrawerLayout >
121
168
</ BlueBaseApp >
122
169
) ;
123
170
124
171
await waitForElement ( component as any , DrawerLayout ) ;
125
172
126
- const state : DrawerLayoutState = component . find ( 'DrawerLayout' ) . first ( ) . state ( ) ;
173
+ const state : DrawerLayoutState = component
174
+ . find ( 'DrawerLayout' )
175
+ . first ( )
176
+ . state ( ) ;
127
177
128
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'open' ) ) . toBe ( false ) ;
178
+ expect (
179
+ component
180
+ . find ( 'Drawer' )
181
+ . first ( )
182
+ . prop ( 'open' )
183
+ ) . toBe ( false ) ;
129
184
130
185
state . openDrawer ( ) ;
131
186
component . update ( ) ;
132
187
133
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'open' ) ) . toBe ( true ) ;
188
+ expect (
189
+ component
190
+ . find ( 'Drawer' )
191
+ . first ( )
192
+ . prop ( 'open' )
193
+ ) . toBe ( true ) ;
134
194
135
195
state . closeDrawer ( ) ;
136
196
component . update ( ) ;
137
197
138
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'open' ) ) . toBe ( false ) ;
198
+ expect (
199
+ component
200
+ . find ( 'Drawer' )
201
+ . first ( )
202
+ . prop ( 'open' )
203
+ ) . toBe ( false ) ;
139
204
140
205
state . toggleDrawer ( ) ;
141
206
component . update ( ) ;
142
207
143
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'open' ) ) . toBe ( true ) ;
208
+ expect (
209
+ component
210
+ . find ( 'Drawer' )
211
+ . first ( )
212
+ . prop ( 'open' )
213
+ ) . toBe ( true ) ;
144
214
145
215
state . toggleDrawer ( ) ;
146
216
component . update ( ) ;
147
217
148
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'open' ) ) . toBe ( false ) ;
218
+ expect (
219
+ component
220
+ . find ( 'Drawer' )
221
+ . first ( )
222
+ . prop ( 'open' )
223
+ ) . toBe ( false ) ;
149
224
150
- const onBackdropClick = component . find ( 'Drawer' ) . first ( ) . prop ( 'onBackdropClick' ) as any ;
225
+ const onBackdropClick = component
226
+ . find ( 'Drawer' )
227
+ . first ( )
228
+ . prop ( 'onBackdropClick' ) as any ;
151
229
152
230
onBackdropClick ( ) ;
153
231
component . update ( ) ;
154
232
155
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'open' ) ) . toBe ( true ) ;
233
+ expect (
234
+ component
235
+ . find ( 'Drawer' )
236
+ . first ( )
237
+ . prop ( 'open' )
238
+ ) . toBe ( true ) ;
156
239
157
240
onBackdropClick ( ) ;
158
241
component . update ( ) ;
159
242
160
- expect ( component . find ( 'Drawer' ) . first ( ) . prop ( 'open' ) ) . toBe ( false ) ;
243
+ expect (
244
+ component
245
+ . find ( 'Drawer' )
246
+ . first ( )
247
+ . prop ( 'open' )
248
+ ) . toBe ( false ) ;
161
249
} ) ;
162
-
163
250
} ) ;
164
-
165
-
0 commit comments