@@ -2,9 +2,9 @@ import expect from 'expect'
22import React from 'react'
33import { renderToStaticMarkup as render } from 'react-dom/server'
44
5- import { configure , mount } from 'enzyme'
5+ import { configure , mount , shallow } from 'enzyme'
66import Adapter from 'enzyme-adapter-react-16'
7- import { spy } from 'sinon'
7+ import { spy , mock } from 'sinon'
88
99import AppSwitch from 'src/Switch'
1010
@@ -15,14 +15,60 @@ describe('AppSwitch', () => {
1515 expect ( render ( < AppSwitch /> ) )
1616 . toContain ( '<label class="switch' )
1717 } ) ;
18- it ( 'should call toggle' , ( ) => {
19- const onChange = spy ( AppSwitch . prototype , 'toggle' ) ;
20- const event = { target : { checked : true } } ;
21- const wrapper = mount ( < AppSwitch outlineAlt label pill size = "lg" /> ) ;
22- expect ( wrapper . find ( 'input' ) . props ( ) . checked ) . toBe ( false ) ;
23- wrapper . find ( 'input' ) . simulate ( 'change' , event )
24- expect ( onChange . called ) . toBe ( true ) ;
25- expect ( wrapper . find ( 'input' ) . props ( ) . checked ) . toBe ( true ) ;
18+ it ( 'should render with switch class' , ( ) => {
19+ const wrapper = shallow ( < AppSwitch /> ) ;
20+ expect ( wrapper . hasClass ( 'switch' ) ) . toBe ( true ) ;
21+ } ) ;
22+ it ( 'should render with outline class' , ( ) => {
23+ const wrapper = shallow ( < AppSwitch outline /> ) ;
24+ expect ( wrapper . hasClass ( 'switch-outline-secondary' ) ) . toBe ( true ) ;
25+ } ) ;
26+ it ( 'should render with outline alt class' , ( ) => {
27+ const wrapper = shallow ( < AppSwitch outline = { 'alt' } /> ) ;
28+ expect ( wrapper . hasClass ( 'switch-outline-secondary-alt' ) ) . toBe ( true ) ;
29+ } ) ;
30+ it ( 'should render with outline alt class' , ( ) => {
31+ const wrapper = shallow ( < AppSwitch outline color = "primary-alt" /> ) ;
32+ expect ( wrapper . hasClass ( 'switch-outline-primary-alt' ) ) . toBe ( true ) ;
33+ } ) ;
34+ it ( 'should render with info class' , ( ) => {
35+ const wrapper = shallow ( < AppSwitch color = "info" /> ) ;
36+ expect ( wrapper . hasClass ( 'switch-info' ) ) . toBe ( true ) ;
37+ } ) ;
38+ it ( 'should render with pill class' , ( ) => {
39+ const wrapper = shallow ( < AppSwitch variant = "pill" /> ) ;
40+ expect ( wrapper . hasClass ( 'switch-pill' ) ) . toBe ( true ) ;
41+ } ) ;
42+ it ( 'should render with 3d class' , ( ) => {
43+ const wrapper = shallow ( < AppSwitch variant = "3d" /> ) ;
44+ expect ( wrapper . hasClass ( 'switch-3d' ) ) . toBe ( true ) ;
45+ } ) ;
46+ it ( 'should render with lg class' , ( ) => {
47+ const wrapper = shallow ( < AppSwitch size = "lg" /> ) ;
48+ expect ( wrapper . hasClass ( 'switch-lg' ) ) . toBe ( true ) ;
49+ } ) ;
50+ it ( 'should render with label class' , ( ) => {
51+ const wrapper = shallow ( < AppSwitch label /> ) ;
52+ expect ( wrapper . hasClass ( 'switch-label' ) ) . toBe ( true ) ;
53+ } ) ;
54+
55+ describe ( 'onChange' , ( ) => {
56+ it ( 'calls props.onChange if it exists' , ( ) => {
57+ const onChangeMock = mock ( )
58+ const wrapper = mount ( < AppSwitch onChange = { onChangeMock } /> ) ;
59+ wrapper . find ( 'input' ) . hostNodes ( ) . simulate ( 'change' ) ;
60+ expect ( onChangeMock . called ) . toBe ( true ) ;
61+ } ) ;
2662
27- } )
63+ it ( 'should call onChange()' , ( ) => {
64+ const onChange = spy ( AppSwitch . prototype , 'onChange' ) ;
65+ const event = { target : { checked : true } } ;
66+ const wrapper = shallow ( < AppSwitch label size = "lg" /> ) ;
67+ expect ( wrapper . find ( 'input' ) . props ( ) . checked ) . toBe ( false ) ;
68+ wrapper . find ( 'input' ) . simulate ( 'change' , event )
69+ expect ( onChange . called ) . toBe ( true ) ;
70+ expect ( wrapper . find ( 'input' ) . props ( ) . checked ) . toBe ( true ) ;
71+ } )
72+ }
73+ )
2874} )
0 commit comments