11import React from 'react' ;
2- import { shallow } from 'enzyme' ;
2+ import { shallow , mount } from 'enzyme' ;
33import { Progress } from '../' ;
44
55describe ( 'Progress' , ( ) => {
6- it ( 'should render with "progress " tag by default' , ( ) => {
6+ it ( 'should render with "div " tag by default' , ( ) => {
77 const wrapper = shallow ( < Progress /> ) ;
88
9- expect ( wrapper . type ( ) ) . toBe ( 'progress ' ) ;
9+ expect ( wrapper . type ( ) ) . toBe ( 'div ' ) ;
1010 } ) ;
1111
1212 it ( 'should render with "progress" class' , ( ) => {
@@ -18,56 +18,56 @@ describe('Progress', () => {
1818 it ( 'should render with "value" 0 by default' , ( ) => {
1919 const wrapper = shallow ( < Progress /> ) ;
2020
21- expect ( wrapper . prop ( 'value' ) ) . toBe ( 0 ) ;
21+ expect ( wrapper . instance ( ) . props [ 'value' ] ) . toBe ( 0 ) ;
2222 } ) ;
2323
2424 it ( 'should render with "max" 100 by default' , ( ) => {
2525 const wrapper = shallow ( < Progress /> ) ;
2626
27- expect ( wrapper . prop ( 'max' ) ) . toBe ( 100 ) ;
27+ expect ( wrapper . instance ( ) . props [ 'max' ] ) . toBe ( 100 ) ;
2828 } ) ;
2929
3030 it ( 'should render with the given "value" when passed as string prop' , ( ) => {
3131 const wrapper = shallow ( < Progress value = "10" /> ) ;
3232
33- expect ( wrapper . prop ( 'value' ) ) . toBe ( '10' ) ;
33+ expect ( wrapper . instance ( ) . props [ 'value' ] ) . toBe ( '10' ) ;
3434 } ) ;
3535
3636 it ( 'should render with the given "value" when passed as number prop' , ( ) => {
3737 const wrapper = shallow ( < Progress value = { 10 } /> ) ;
3838
39- expect ( wrapper . prop ( 'value' ) ) . toBe ( 10 ) ;
39+ expect ( wrapper . instance ( ) . props [ 'value' ] ) . toBe ( 10 ) ;
4040 } ) ;
4141
4242 it ( 'should render with the given "max" when passed as string prop' , ( ) => {
4343 const wrapper = shallow ( < Progress max = "10" /> ) ;
4444
45- expect ( wrapper . prop ( 'max' ) ) . toBe ( '10' ) ;
45+ expect ( wrapper . instance ( ) . props [ 'max' ] ) . toBe ( '10' ) ;
4646 } ) ;
4747
4848 it ( 'should render with the given "max" when passed as number prop' , ( ) => {
4949 const wrapper = shallow ( < Progress max = { 10 } /> ) ;
5050
51- expect ( wrapper . prop ( 'max' ) ) . toBe ( 10 ) ;
51+ expect ( wrapper . instance ( ) . props [ 'max' ] ) . toBe ( 10 ) ;
5252 } ) ;
5353
54- it ( 'should render with "progress-striped" class when striped prop is truthy' , ( ) => {
54+ it ( 'should render with "progress-bar- striped" class when striped prop is truthy' , ( ) => {
5555 const wrapper = shallow ( < Progress striped /> ) ;
5656
57- expect ( wrapper . hasClass ( 'progress-striped' ) ) . toBe ( true ) ;
57+ expect ( wrapper . find ( '.progress-bar' ) . hasClass ( 'progress-bar -striped' ) ) . toBe ( true ) ;
5858 } ) ;
5959
60- it ( 'should render with "progress-striped" and "progress-animated" classes when animated prop is truthy' , ( ) => {
60+ it ( 'should render with "progress-bar- striped" and "progress-bar -animated" classes when animated prop is truthy' , ( ) => {
6161 const wrapper = shallow ( < Progress animated /> ) ;
6262
63- expect ( wrapper . hasClass ( 'progress-striped' ) ) . toBe ( true ) ;
64- expect ( wrapper . hasClass ( 'progress-animated' ) ) . toBe ( true ) ;
63+ expect ( wrapper . find ( '.progress-bar' ) . hasClass ( 'progress-bar -striped' ) ) . toBe ( true ) ;
64+ expect ( wrapper . find ( '.progress-bar' ) . hasClass ( 'progress-bar -animated' ) ) . toBe ( true ) ;
6565 } ) ;
6666
67- it ( 'should render with "progress -${color}" class when color prop is defined' , ( ) => {
67+ it ( 'should render with "bg -${color}" class when color prop is defined' , ( ) => {
6868 const wrapper = shallow ( < Progress color = "yo" /> ) ;
6969
70- expect ( wrapper . hasClass ( ' progress-yo') ) . toBe ( true ) ;
70+ expect ( wrapper . find ( '. progress-bar' ) . hasClass ( 'bg -yo') ) . toBe ( true ) ;
7171 } ) ;
7272
7373 it ( 'should render additional classes' , ( ) => {
@@ -77,114 +77,31 @@ describe('Progress', () => {
7777 expect ( wrapper . hasClass ( 'progress' ) ) . toBe ( true ) ;
7878 } ) ;
7979
80- it ( 'should have div fallback for IE9 ' , ( ) => {
81- const wrapper = shallow ( < Progress /> ) ;
80+ it ( 'should render custom tag ' , ( ) => {
81+ const wrapper = shallow ( < Progress tag = "main" /> ) ;
8282
83- expect ( wrapper . childAt ( 0 ) . type ( ) ) . toBe ( 'div ' ) ;
83+ expect ( wrapper . type ( ) ) . toBe ( 'main ' ) ;
8484 } ) ;
8585
86- describe ( 'div fallback' , ( ) => {
87- it ( 'should render with "progress" class' , ( ) => {
88- const div = shallow ( < Progress /> ) . childAt ( 0 ) ;
89-
90- expect ( div . hasClass ( 'progress' ) ) . toBe ( true ) ;
91- } ) ;
92-
93- it ( 'should render with "progress-animated" class when animated is truthy' , ( ) => {
94- const div = shallow ( < Progress animated /> ) . childAt ( 0 ) ;
95-
96- expect ( div . hasClass ( 'progress-animated' ) ) . toBe ( true ) ;
97- } ) ;
98-
99- it ( 'should render additional classes' , ( ) => {
100- const div = shallow ( < Progress className = "other" /> ) . childAt ( 0 ) ;
101-
102- expect ( div . hasClass ( 'other' ) ) . toBe ( true ) ;
103- expect ( div . hasClass ( 'progress' ) ) . toBe ( true ) ;
104- } ) ;
105-
106- it ( 'should have a span' , ( ) => {
107- const div = shallow ( < Progress /> ) . childAt ( 0 ) ;
108-
109- expect ( div . childAt ( 0 ) . type ( ) ) . toBe ( 'span' ) ;
110- } ) ;
111-
112- describe ( 'the span' , ( ) => {
113- it ( 'should render with "progress-bar" class' , ( ) => {
114- const span = shallow ( < Progress /> ) . childAt ( 0 ) . childAt ( 0 ) ;
115-
116- expect ( span . hasClass ( 'progress-bar' ) ) . toBe ( true ) ;
117- } ) ;
118-
119- it ( 'should render with "progress-bar-striped" class when striped is truthy' , ( ) => {
120- const span = shallow ( < Progress striped /> ) . childAt ( 0 ) . childAt ( 0 ) ;
121-
122- expect ( span . hasClass ( 'progress-bar-striped' ) ) . toBe ( true ) ;
123- } ) ;
124-
125- it ( 'should render with "progress-bar-striped" class when animated is truthy' , ( ) => {
126- const span = shallow ( < Progress animated /> ) . childAt ( 0 ) . childAt ( 0 ) ;
127-
128- expect ( span . hasClass ( 'progress-bar-striped' ) ) . toBe ( true ) ;
129- } ) ;
130-
131- it ( 'should render with a style width matching the percent of the fill' , ( ) => {
132- const span = shallow ( < Progress value = "25" /> ) . childAt ( 0 ) . childAt ( 0 ) ;
86+ it ( 'should render only the .progress-bar when "bar" is passed' , ( ) => {
87+ const wrapper = shallow ( < Progress bar /> ) ;
13388
134- expect ( span . prop ( 'style' ) . width ) . toBe ( '25%' ) ;
135- } ) ;
136-
137- it ( 'should render with a style width matching the percent of the fill (with max)' , ( ) => {
138- const span = shallow ( < Progress value = "25" max = "50" /> ) . childAt ( 0 ) . childAt ( 0 ) ;
139-
140- expect ( span . prop ( 'style' ) . width ) . toBe ( '50%' ) ;
141- } ) ;
142- } ) ;
89+ expect ( wrapper . type ( ) ) . toBe ( 'div' ) ;
90+ expect ( wrapper . hasClass ( 'progress-bar' ) ) . toBe ( true ) ;
14391 } ) ;
14492
145- describe ( 'with a custom tag' , ( ) => {
146- it ( 'should render custom tag' , ( ) => {
147- const wrapper = shallow ( < Progress tag = "main" /> ) ;
148-
149- expect ( wrapper . type ( ) ) . toBe ( 'main' ) ;
150- } ) ;
151-
152- it ( 'should have a span' , ( ) => {
153- const span = shallow ( < Progress tag = "main" /> ) . childAt ( 0 ) ;
154-
155- expect ( span . type ( ) ) . toBe ( 'span' ) ;
156- } ) ;
157-
158- describe ( 'the span' , ( ) => {
159- it ( 'should render with "progress-bar" class' , ( ) => {
160- const span = shallow ( < Progress tag = "main" /> ) . childAt ( 0 ) ;
161-
162- expect ( span . hasClass ( 'progress-bar' ) ) . toBe ( true ) ;
163- } ) ;
164-
165- it ( 'should render with "progress-bar-striped" class when striped is truthy' , ( ) => {
166- const span = shallow ( < Progress tag = "main" striped /> ) . childAt ( 0 ) ;
167-
168- expect ( span . hasClass ( 'progress-bar-striped' ) ) . toBe ( true ) ;
169- } ) ;
170-
171- it ( 'should render with "progress-bar-striped" class when animated is truthy' , ( ) => {
172- const span = shallow ( < Progress tag = "main" animated /> ) . childAt ( 0 ) ;
173-
174- expect ( span . hasClass ( 'progress-bar-striped' ) ) . toBe ( true ) ;
175- } ) ;
176-
177- it ( 'should render with a style width matching the percent of the fill' , ( ) => {
178- const span = shallow ( < Progress tag = "main" value = "25" /> ) . childAt ( 0 ) ;
179-
180- expect ( span . prop ( 'style' ) . width ) . toBe ( '25%' ) ;
181- } ) ;
182-
183- it ( 'should render with a style width matching the percent of the fill (with max)' , ( ) => {
184- const span = shallow ( < Progress tag = "main" value = "25" max = "50" /> ) . childAt ( 0 ) ;
185-
186- expect ( span . prop ( 'style' ) . width ) . toBe ( '50%' ) ;
187- } ) ;
188- } ) ;
93+ it ( 'should render nested progress bars' , ( ) => {
94+ const wrapper = mount (
95+ < Progress >
96+ < Progress value = "15" />
97+ < Progress color = "success" value = "30" />
98+ < Progress color = "info" value = "25" />
99+ < Progress color = "warning" value = "20" />
100+ < Progress color = "danger" value = "5" />
101+ </ Progress >
102+ ) ;
103+
104+ expect ( wrapper . find ( '.progress' ) . length ) . toBe ( 1 ) ;
105+ expect ( wrapper . find ( '.progress-bar' ) . length ) . toBe ( 5 ) ;
189106 } ) ;
190107} ) ;
0 commit comments