Skip to content

Commit e69955f

Browse files
author
Asad Razzaq
committed
fix(DrawerLayout): test case added
1 parent 101f501 commit e69955f

File tree

1 file changed

+123
-38
lines changed

1 file changed

+123
-38
lines changed

src/components/DrawerLayout/__tests__/DrawerLayout.test.tsx

Lines changed: 123 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DrawerActions, DrawerLayout, DrawerLayoutState } from '../';
2+
23
import { BlueBaseApp } from '@bluebase/core';
34
import Plugin from '../../../';
45
import React from 'react';
@@ -9,17 +10,14 @@ import { waitForElement } from 'enzyme-async-helpers';
910
// tslint:disable: jsx-no-lambda
1011

1112
describe('DrawerLayout', () => {
12-
1313
it('should render a simple "front" type drawer', async () => {
1414
const component = mount(
1515
<BlueBaseApp plugins={[Plugin]}>
1616
<DrawerLayout
1717
// open
1818
drawerWidth={200}
1919
// 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>}
2321
>
2422
<Text testID="drawer-layout-children">I'm DrawerLayout's children</Text>
2523
</DrawerLayout>
@@ -29,12 +27,23 @@ describe('DrawerLayout', () => {
2927
await waitForElement(component as any, DrawerLayout);
3028

3129
// 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);
3442

3543
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);
3847
});
3948

4049
it('should render an open drawer', async () => {
@@ -44,9 +53,7 @@ describe('DrawerLayout', () => {
4453
open
4554
drawerWidth={200}
4655
// 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>}
5057
>
5158
<Text testID="drawer-layout-children">I'm DrawerLayout's children</Text>
5259
</DrawerLayout>
@@ -56,7 +63,12 @@ describe('DrawerLayout', () => {
5663
await waitForElement(component as any, DrawerLayout);
5764

5865
// 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);
6072
});
6173

6274
it('should render a drawer positioned on the right', async () => {
@@ -66,9 +78,7 @@ describe('DrawerLayout', () => {
6678
// open
6779
drawerWidth={200}
6880
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>}
7282
>
7383
<Text testID="drawer-layout-children">I'm DrawerLayout's children</Text>
7484
</DrawerLayout>
@@ -78,7 +88,12 @@ describe('DrawerLayout', () => {
7888
await waitForElement(component as any, DrawerLayout);
7989

8090
// 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');
8297
});
8398

8499
it('should render a "slide" type drawer', async () => {
@@ -87,9 +102,32 @@ describe('DrawerLayout', () => {
87102
<DrawerLayout
88103
drawerType="slide"
89104
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>}
93131
>
94132
<Text testID="drawer-layout-children">I'm DrawerLayout's children</Text>
95133
</DrawerLayout>
@@ -99,7 +137,18 @@ describe('DrawerLayout', () => {
99137
await waitForElement(component as any, DrawerLayout);
100138

101139
// 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);
103152
});
104153

105154
it('should be controllable through DrawerActions', async () => {
@@ -108,58 +157,94 @@ describe('DrawerLayout', () => {
108157
<DrawerLayout
109158
drawerType="front"
110159
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>}
114161
>
115162
<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+
)}
119166
</DrawerActions>
120167
</DrawerLayout>
121168
</BlueBaseApp>
122169
);
123170

124171
await waitForElement(component as any, DrawerLayout);
125172

126-
const state: DrawerLayoutState = component.find('DrawerLayout').first().state();
173+
const state: DrawerLayoutState = component
174+
.find('DrawerLayout')
175+
.first()
176+
.state();
127177

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);
129184

130185
state.openDrawer();
131186
component.update();
132187

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);
134194

135195
state.closeDrawer();
136196
component.update();
137197

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);
139204

140205
state.toggleDrawer();
141206
component.update();
142207

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);
144214

145215
state.toggleDrawer();
146216
component.update();
147217

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);
149224

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;
151229

152230
onBackdropClick();
153231
component.update();
154232

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);
156239

157240
onBackdropClick();
158241
component.update();
159242

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);
161249
});
162-
163250
});
164-
165-

0 commit comments

Comments
 (0)