@@ -18,30 +18,40 @@ describe('Unit testing for SwitchApp.jsx', () => {
18
18
currentTab : 100 ,
19
19
tabs : { 100 : { snapshots : [ 1 , 2 , 3 , 4 ] , viewIndex : 1 , sliderIndex : 1 , title : 'component' } } ,
20
20
} ;
21
- const tabsArray = [ { value : 100 , label : { } } ] ;
22
21
const dropdownCurrTabLabel = {
23
22
value : 100 ,
24
- label : { } ,
23
+ label : 'component' ,
25
24
} ;
26
25
// nate and edwin: mockImplementation creates a mock function call
27
26
const dispatch = jest . fn ( ) ;
27
+
28
28
// nate and edwin: mockImplementation creates a mock state
29
29
useStoreContext . mockImplementation ( ( ) => [ state , dispatch ] ) ;
30
30
31
31
beforeEach ( ( ) => {
32
32
wrapper = shallow ( < SwitchApp /> ) ;
33
+ dispatch . mockClear ( ) ;
33
34
} ) ;
34
35
35
36
describe ( 'SwitchApp Component' , ( ) => {
37
+ beforeEach ( ( ) => {
38
+ wrapper . find ( '.tab-select-container' ) . simulate ( 'change' , { } ) ;
39
+ } ) ;
40
+ // console.log('dispatch mock calls', dispatch.mock.calls);
36
41
it ( 'SwitchApp component returns <Select /> from react-select library' , ( ) => {
37
42
expect ( wrapper . find ( '.tab-select-container' ) . type ( ) ) . toEqual ( Select ) ;
38
43
expect ( wrapper . find ( '.tab-select-container' ) . props ( ) . className ) . toBe ( 'tab-select-container' ) ;
44
+ expect ( wrapper . find ( '.tab-select-container' ) . props ( ) . value ) . toEqual ( dropdownCurrTabLabel ) ;
45
+ } ) ;
46
+ it ( 'OnChange should run dispatch function' , ( ) => {
47
+ expect ( dispatch . mock . calls . length ) . toBe ( 1 ) ;
48
+ } )
49
+ it ( 'options prop should be an array' , ( ) => {
39
50
expect ( Array . isArray ( wrapper . find ( '.tab-select-container' ) . props ( ) . options ) ) . toBeTruthy ( ) ;
40
51
expect ( wrapper . find ( '.tab-select-container' ) . props ( ) . options [ 0 ] ) . toHaveProperty ( 'value' ) ;
41
52
expect ( wrapper . find ( '.tab-select-container' ) . props ( ) . options [ 0 ] ) . toHaveProperty ( 'label' ) ;
42
- expect ( wrapper . find ( '.tab-select-container' ) . props ( ) ) . toEqual ( state . currentTab . value ) ;
43
53
} ) ;
44
- } )
54
+ } ) ;
45
55
46
56
describe ( 'dropdownCurrTabLabel' , ( ) => {
47
57
it ( 'should have properties value and label' , ( ) => {
@@ -58,8 +68,4 @@ describe('Unit testing for SwitchApp.jsx', () => {
58
68
expect ( typeof state . tabs ) . toEqual ( 'object' ) ;
59
69
} ) ;
60
70
} ) ;
61
-
62
- // options should be an array
63
- // value prop should be equal to a number
64
- // check if onChange if the function runs
65
- } )
71
+ } ) ;
0 commit comments