1
1
import introJs from "../src" ;
2
- import { find , content , className } from "./helper" ;
2
+ import { content , className , skipButton , nextButton , prevButton , doneButton , tooltipText } from "./helper" ;
3
3
4
4
describe ( "intro" , ( ) => {
5
5
beforeEach ( ( ) => {
@@ -17,11 +17,11 @@ describe("intro", () => {
17
17
} )
18
18
. start ( ) ;
19
19
20
- expect ( content ( ".introjs-tooltiptext" ) ) . toBe ( "hello world" ) ;
20
+ expect ( content ( tooltipText ( ) ) ) . toBe ( "hello world" ) ;
21
21
22
- expect ( content ( ".introjs-donebutton" ) ) . toBe ( "Done" ) ;
22
+ expect ( content ( doneButton ( ) ) ) . toBe ( "Done" ) ;
23
23
24
- expect ( find ( ".introjs-prevbutton" ) ) . toBeNull ( ) ;
24
+ expect ( prevButton ( ) ) . toBeNull ( ) ;
25
25
26
26
expect ( className ( ".introjs-showElement" ) ) . toContain (
27
27
"introjsFloatingElement"
@@ -31,6 +31,75 @@ describe("intro", () => {
31
31
) ;
32
32
} ) ;
33
33
34
+ test ( "should call onexit and oncomplete when there is one step" , ( ) => {
35
+ const onexitMock = jest . fn ( ) ;
36
+ const oncompleteMMock = jest . fn ( ) ;
37
+
38
+ introJs ( )
39
+ . setOptions ( {
40
+ steps : [
41
+ {
42
+ intro : "hello world" ,
43
+ } ,
44
+ ] ,
45
+ } )
46
+ . onexit ( onexitMock )
47
+ . oncomplete ( oncompleteMMock )
48
+ . start ( ) ;
49
+
50
+ nextButton ( ) . click ( ) ;
51
+
52
+ expect ( onexitMock ) . toBeCalledTimes ( 1 ) ;
53
+ expect ( oncompleteMMock ) . toBeCalledTimes ( 1 ) ;
54
+ } ) ;
55
+
56
+ test ( "should call onexit when skip is clicked" , ( ) => {
57
+ const onexitMock = jest . fn ( ) ;
58
+ const oncompleteMMock = jest . fn ( ) ;
59
+
60
+ introJs ( )
61
+ . setOptions ( {
62
+ steps : [
63
+ {
64
+ intro : "hello world" ,
65
+ } ,
66
+ ] ,
67
+ } )
68
+ . onexit ( onexitMock )
69
+ . oncomplete ( oncompleteMMock )
70
+ . start ( ) ;
71
+
72
+ skipButton ( ) . click ( ) ;
73
+
74
+ expect ( onexitMock ) . toBeCalledTimes ( 1 ) ;
75
+ expect ( oncompleteMMock ) . toBeCalledTimes ( 1 ) ;
76
+ } ) ;
77
+
78
+ test ( "should call not oncomplete when skip is clicked and there are two steps" , ( ) => {
79
+ const onexitMock = jest . fn ( ) ;
80
+ const oncompleteMMock = jest . fn ( ) ;
81
+
82
+ introJs ( )
83
+ . setOptions ( {
84
+ steps : [
85
+ {
86
+ intro : "first" ,
87
+ } ,
88
+ {
89
+ intro : "second" ,
90
+ } ,
91
+ ] ,
92
+ } )
93
+ . onexit ( onexitMock )
94
+ . oncomplete ( oncompleteMMock )
95
+ . start ( ) ;
96
+
97
+ skipButton ( ) . click ( ) ;
98
+
99
+ expect ( onexitMock ) . toBeCalledTimes ( 1 ) ;
100
+ expect ( oncompleteMMock ) . toBeCalledTimes ( 0 ) ;
101
+ } ) ;
102
+
34
103
test ( "should start floating intro with two steps" , ( ) => {
35
104
introJs ( )
36
105
. setOptions ( {
@@ -45,15 +114,15 @@ describe("intro", () => {
45
114
} )
46
115
. start ( ) ;
47
116
48
- expect ( content ( ".introjs-tooltiptext" ) ) . toBe ( "step one" ) ;
117
+ expect ( content ( tooltipText ( ) ) ) . toBe ( "step one" ) ;
49
118
50
- expect ( find ( ".introjs-donebutton" ) ) . toBeNull ( ) ;
119
+ expect ( doneButton ( ) ) . toBeNull ( ) ;
51
120
52
- expect ( find ( ".introjs-prevbutton" ) ) . not . toBeNull ( ) ;
53
- expect ( className ( ".introjs-prevbutton" ) ) . toContain ( "introjs-disabled" ) ;
121
+ expect ( prevButton ( ) ) . not . toBeNull ( ) ;
122
+ expect ( className ( prevButton ( ) ) ) . toContain ( "introjs-disabled" ) ;
54
123
55
- expect ( find ( ".introjs-nextbutton" ) ) . not . toBeNull ( ) ;
56
- expect ( className ( ".introjs-nextbutton" ) ) . not . toContain ( "introjs-disabled" ) ;
124
+ expect ( nextButton ( ) ) . not . toBeNull ( ) ;
125
+ expect ( className ( nextButton ( ) ) ) . not . toContain ( "introjs-disabled" ) ;
57
126
58
127
expect ( className ( ".introjs-showElement" ) ) . toContain (
59
128
"introjsFloatingElement"
0 commit comments