@@ -16,33 +16,56 @@ describe('Unit testing for SwitchApp.jsx', () => {
16
16
17
17
const state = {
18
18
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' } } ,
20
20
} ;
21
- const tabsArray = [ ] ;
22
- const currTab = {
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 ( ) ;
28
- useStoreContext . mockImplementation ( ( ) => [ dispatch , state ] ) ;
27
+
28
+ // nate and edwin: mockImplementation creates a mock state
29
+ useStoreContext . mockImplementation ( ( ) => [ state , dispatch ] ) ;
29
30
30
31
beforeEach ( ( ) => {
31
32
wrapper = shallow ( < SwitchApp /> ) ;
33
+ dispatch . mockClear ( ) ;
34
+ } ) ;
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);
41
+ it ( 'SwitchApp component returns <Select /> from react-select library' , ( ) => {
42
+ expect ( wrapper . find ( '.tab-select-container' ) . type ( ) ) . toEqual ( Select ) ;
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' , ( ) => {
50
+ expect ( Array . isArray ( wrapper . find ( '.tab-select-container' ) . props ( ) . options ) ) . toBeTruthy ( ) ;
51
+ expect ( wrapper . find ( '.tab-select-container' ) . props ( ) . options [ 0 ] ) . toHaveProperty ( 'value' ) ;
52
+ expect ( wrapper . find ( '.tab-select-container' ) . props ( ) . options [ 0 ] ) . toHaveProperty ( 'label' ) ;
53
+ } ) ;
32
54
} ) ;
33
55
34
- describe ( 'currentTab ' , ( ) => {
56
+ describe ( 'dropdownCurrTabLabel ' , ( ) => {
35
57
it ( 'should have properties value and label' , ( ) => {
36
- expect ( currTab ) . toHaveProperty ( 'value' ) ;
37
- expect ( currTab ) . toHaveProperty ( 'label' ) ;
58
+ expect ( dropdownCurrTabLabel ) . toHaveProperty ( 'value' ) ;
59
+ expect ( dropdownCurrTabLabel ) . toHaveProperty ( 'label' ) ;
38
60
} ) ;
39
61
} ) ;
40
62
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
48
- } )
63
+ describe ( 'state' , ( ) => {
64
+ it ( 'currentTab value should be a number' , ( ) => {
65
+ expect ( typeof state . currentTab ) . toEqual ( 'number' ) ;
66
+ } ) ;
67
+ it ( 'tabs value should be an object' , ( ) => {
68
+ expect ( typeof state . tabs ) . toEqual ( 'object' ) ;
69
+ } ) ;
70
+ } ) ;
71
+ } ) ;
0 commit comments