1
1
import * as React from 'react' ;
2
2
import { expect } from 'chai' ;
3
- import CheckCircle from '../internal/svg-icons/CheckCircle' ;
4
3
import { createShallow , getClasses } from '@material-ui/core/test-utils' ;
5
4
import createMount from 'test/utils/createMount' ;
6
5
import describeConformance from '../test-utils/describeConformance' ;
6
+ import { createClientRender } from 'test/utils/createClientRender' ;
7
7
import Paper from '../Paper' ;
8
8
import Step from '../Step' ;
9
9
import StepLabel from '../StepLabel' ;
@@ -16,6 +16,7 @@ describe('<Stepper />', () => {
16
16
let shallow ;
17
17
// StrictModeViolation: test uses StepContent
18
18
const mount = createMount ( { strict : false } ) ;
19
+ const render = createClientRender ( { strict : false } ) ;
19
20
20
21
before ( ( ) => {
21
22
classes = getClasses ( < Stepper /> ) ;
@@ -45,20 +46,17 @@ describe('<Stepper />', () => {
45
46
} ) ;
46
47
47
48
describe ( 'rendering children' , ( ) => {
48
- it ( 'renders 3 children with connectors as separators ' , ( ) => {
49
- const wrapper = shallow (
49
+ it ( 'renders 3 Step and 2 StepConnector components ' , ( ) => {
50
+ const wrapper = mount (
50
51
< Stepper >
51
- < div />
52
- < div />
53
- < div />
52
+ < Step />
53
+ < Step />
54
+ < Step />
54
55
</ Stepper > ,
55
56
) ;
56
57
57
- const children = wrapper . children ( ) ;
58
-
59
- expect ( children . length ) . to . equal ( 5 ) ;
60
- expect ( wrapper . childAt ( 1 ) . find ( StepConnector ) . length ) . to . equal ( 1 ) ;
61
- expect ( wrapper . childAt ( 3 ) . find ( StepConnector ) . length ) . to . equal ( 1 ) ;
58
+ expect ( wrapper . find ( StepConnector ) . length ) . to . equal ( 2 ) ;
59
+ expect ( wrapper . find ( Step ) . length ) . to . equal ( 3 ) ;
62
60
} ) ;
63
61
} ) ;
64
62
@@ -122,7 +120,7 @@ describe('<Stepper />', () => {
122
120
123
121
describe ( 'step connector' , ( ) => {
124
122
it ( 'should have a default step connector' , ( ) => {
125
- const wrapper = shallow (
123
+ const wrapper = mount (
126
124
< Stepper >
127
125
< Step />
128
126
< Step />
@@ -133,14 +131,15 @@ describe('<Stepper />', () => {
133
131
} ) ;
134
132
135
133
it ( 'should allow the developer to specify a custom step connector' , ( ) => {
136
- const wrapper = shallow (
137
- < Stepper connector = { < CheckCircle /> } >
134
+ const CustomConnector = ( ) => null ;
135
+ const wrapper = mount (
136
+ < Stepper connector = { < CustomConnector /> } >
138
137
< Step />
139
138
< Step />
140
139
</ Stepper > ,
141
140
) ;
142
141
143
- expect ( wrapper . find ( CheckCircle ) . length ) . to . equal ( 1 ) ;
142
+ expect ( wrapper . find ( CustomConnector ) . length ) . to . equal ( 1 ) ;
144
143
expect ( wrapper . find ( StepConnector ) . length ) . to . equal ( 0 ) ;
145
144
} ) ;
146
145
@@ -156,7 +155,7 @@ describe('<Stepper />', () => {
156
155
} ) ;
157
156
158
157
it ( 'should pass active prop to connector when second step is active' , ( ) => {
159
- const wrapper = shallow (
158
+ const wrapper = mount (
160
159
< Stepper activeStep = { 1 } >
161
160
< Step />
162
161
< Step />
@@ -167,7 +166,7 @@ describe('<Stepper />', () => {
167
166
} ) ;
168
167
169
168
it ( 'should pass completed prop to connector when second step is completed' , ( ) => {
170
- const wrapper = shallow (
169
+ const wrapper = mount (
171
170
< Stepper activeStep = { 2 } >
172
171
< Step />
173
172
< Step />
@@ -176,6 +175,29 @@ describe('<Stepper />', () => {
176
175
const connectors = wrapper . find ( StepConnector ) ;
177
176
expect ( connectors . first ( ) . props ( ) . completed ) . to . equal ( true ) ;
178
177
} ) ;
178
+
179
+ it ( 'should pass correct active and completed props to the StepConnector with nonLinear prop' , ( ) => {
180
+ const steps = [ 'Step1' , 'Step2' , 'Step3' ] ;
181
+
182
+ const { container } = render (
183
+ < Stepper orientation = "horizontal" nonLinear connector = { < StepConnector /> } >
184
+ { steps . map ( ( label , index ) => (
185
+ < Step key = { label } active completed = { index === 2 } >
186
+ < StepLabel > { label } </ StepLabel >
187
+ </ Step >
188
+ ) ) }
189
+ </ Stepper > ,
190
+ ) ;
191
+
192
+ const connectors = container . querySelectorAll ( '.MuiStepConnector-root' ) ;
193
+
194
+ expect ( connectors ) . to . have . length ( 2 ) ;
195
+ expect ( connectors [ 0 ] ) . to . have . class ( 'MuiStepConnector-active' ) ;
196
+ expect ( connectors [ 0 ] ) . to . not . have . class ( 'MuiStepConnector-completed' ) ;
197
+
198
+ expect ( connectors [ 1 ] ) . to . have . class ( 'MuiStepConnector-active' ) ;
199
+ expect ( connectors [ 1 ] ) . to . have . class ( 'MuiStepConnector-completed' ) ;
200
+ } ) ;
179
201
} ) ;
180
202
181
203
it ( 'renders with a null child' , ( ) => {
0 commit comments