@@ -2,19 +2,21 @@ import React from 'react';
2
2
import { configure , shallow } from 'enzyme' ;
3
3
import Adapter from 'enzyme-adapter-react-16' ;
4
4
import Action from '../components/Action' ;
5
+ import { changeView , changeSlider } from '../actions/actions' ;
5
6
6
7
configure ( { adapter : new Adapter ( ) } ) ;
7
8
8
9
describe ( 'unit testing for Action.jsx' , ( ) => {
9
10
let wrapper ;
10
11
const props = {
11
12
selected : true ,
12
- handleChangeSnapshot : jest . fn ( ) ,
13
- handleJumpSnapshot : jest . fn ( ) ,
13
+ sliderIndex : 1 ,
14
14
index : 1 ,
15
+ dispatch : jest . fn ( ) ,
15
16
} ;
16
17
beforeEach ( ( ) => {
17
18
wrapper = shallow ( < Action { ...props } /> ) ;
19
+ props . dispatch . mockClear ( ) ;
18
20
} ) ;
19
21
20
22
describe ( 'Component' , ( ) => {
@@ -32,9 +34,14 @@ describe('unit testing for Action.jsx', () => {
32
34
expect ( wrapper . find ( '.action-component-text' ) . text ( ) ) . toEqual ( props . index . toString ( ) ) ;
33
35
} ) ;
34
36
35
- test ( 'should invoke changeSnapshot method when clicked' , ( ) => {
37
+ test ( 'should invoke dispatch method when clicked' , ( ) => {
36
38
wrapper . find ( '.action-component' ) . simulate ( 'click' ) ;
37
- expect ( props . handleChangeSnapshot ) . toHaveBeenCalled ( ) ;
39
+ expect ( props . dispatch ) . toHaveBeenCalled ( ) ;
40
+ } ) ;
41
+
42
+ test ( 'dispatch should send a changeView action' , ( ) => {
43
+ wrapper . find ( '.action-component' ) . simulate ( 'click' ) ;
44
+ expect ( props . dispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( changeView ( props . index ) ) ;
38
45
} ) ;
39
46
} ) ;
40
47
@@ -48,13 +55,14 @@ describe('unit testing for Action.jsx', () => {
48
55
) . toHaveLength ( 1 ) ;
49
56
} ) ;
50
57
51
- test ( 'should invoke jumpSnapshot method when clicked' , ( ) => {
52
- wrapper
53
- . find ( '.action-component' )
54
- . children ( )
55
- . find ( '.jump-button' )
56
- . simulate ( 'click' ) ;
57
- expect ( props . handleJumpSnapshot ) . toHaveBeenCalled ( ) ;
58
+ test ( 'should invoke dispatch method when clicked' , ( ) => {
59
+ wrapper . find ( '.jump-button' ) . simulate ( 'click' , { stopPropagation ( ) { } } ) ;
60
+ expect ( props . dispatch ) . toHaveBeenCalled ( ) ;
61
+ } ) ;
62
+
63
+ test ( 'dispatch should send a changeSlider action' , ( ) => {
64
+ wrapper . find ( '.jump-button' ) . simulate ( 'click' , { stopPropagation ( ) { } } ) ;
65
+ expect ( props . dispatch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( changeSlider ( props . index ) ) ;
58
66
} ) ;
59
67
} ) ;
60
68
} ) ;
0 commit comments