@@ -16,33 +16,50 @@ describe('Unit testing for SwitchApp.jsx', () => {
1616
1717 const state = {
1818 currentTab : 100 ,
19- tabs : { 100 : { snapshots : [ 1 , 2 , 3 , 4 ] , viewIndex : 1 , sliderIndex : 1 } } ,
19+ tabs : { 100 : { snapshots : [ 1 , 2 , 3 , 4 ] , viewIndex : 1 , sliderIndex : 1 , title : 'component' } } ,
2020 } ;
21- const tabsArray = [ ] ;
22- const currTab = {
21+ const tabsArray = [ { value : 100 , label : { } } ] ;
22+ const dropdownCurrTabLabel = {
2323 value : 100 ,
2424 label : { } ,
2525 } ;
26-
26+ // nate and edwin: mockImplementation creates a mock function call
2727 const dispatch = jest . fn ( ) ;
28- useStoreContext . mockImplementation ( ( ) => [ dispatch , state ] ) ;
28+ // nate and edwin: mockImplementation creates a mock state
29+ useStoreContext . mockImplementation ( ( ) => [ state , dispatch ] ) ;
2930
3031 beforeEach ( ( ) => {
3132 wrapper = shallow ( < SwitchApp /> ) ;
3233 } ) ;
3334
34- describe ( 'currentTab' , ( ) => {
35+ describe ( 'SwitchApp Component' , ( ) => {
36+ it ( 'SwitchApp component returns <Select /> from react-select library' , ( ) => {
37+ expect ( wrapper . find ( '.tab-select-container' ) . type ( ) ) . toEqual ( Select ) ;
38+ expect ( wrapper . find ( '.tab-select-container' ) . props ( ) . className ) . toBe ( 'tab-select-container' ) ;
39+ expect ( Array . isArray ( wrapper . find ( '.tab-select-container' ) . props ( ) . options ) ) . toBeTruthy ( ) ;
40+ expect ( wrapper . find ( '.tab-select-container' ) . props ( ) . options [ 0 ] ) . toHaveProperty ( 'value' ) ;
41+ expect ( wrapper . find ( '.tab-select-container' ) . props ( ) . options [ 0 ] ) . toHaveProperty ( 'label' ) ;
42+ expect ( wrapper . find ( '.tab-select-container' ) . props ( ) ) . toEqual ( state . currentTab . value ) ;
43+ } ) ;
44+ } )
45+
46+ describe ( 'dropdownCurrTabLabel' , ( ) => {
3547 it ( 'should have properties value and label' , ( ) => {
36- expect ( currTab ) . toHaveProperty ( 'value' ) ;
37- expect ( currTab ) . toHaveProperty ( 'label' ) ;
48+ expect ( dropdownCurrTabLabel ) . toHaveProperty ( 'value' ) ;
49+ expect ( dropdownCurrTabLabel ) . toHaveProperty ( 'label' ) ;
50+ } ) ;
51+ } ) ;
52+
53+ describe ( 'state' , ( ) => {
54+ it ( 'currentTab value should be a number' , ( ) => {
55+ expect ( typeof state . currentTab ) . toEqual ( 'number' ) ;
56+ } ) ;
57+ it ( 'tabs value should be an object' , ( ) => {
58+ expect ( typeof state . tabs ) . toEqual ( 'object' ) ;
3859 } ) ;
3960 } ) ;
4061
41- // check if currTab has properties value, label
42- // currentTab should be a number
43- // tab should be an object
44- // check if onChange if the function runs
45- // className should be tab-select-container
46- // options should be an array
47- // value prop should be equal to a number
62+ // options should be an array
63+ // value prop should be equal to a number
64+ // check if onChange if the function runs
4865} )
0 commit comments