@@ -3,8 +3,10 @@ import fetchIntroSteps from "../../../src/core/fetchIntroSteps";
3
3
4
4
describe ( "fetchIntroSteps" , ( ) => {
5
5
test ( "should add floating element from options.steps to the list" , ( ) => {
6
+ // Arrange
6
7
const targetElement = document . createElement ( "div" ) ;
7
8
9
+ // Act
8
10
const steps = fetchIntroSteps (
9
11
{
10
12
_options : {
@@ -22,6 +24,7 @@ describe("fetchIntroSteps", () => {
22
24
targetElement
23
25
) ;
24
26
27
+ // Assert
25
28
expect ( steps . length ) . toBe ( 2 ) ;
26
29
27
30
expect ( steps [ 0 ] . position ) . toBe ( "floating" ) ;
@@ -34,6 +37,7 @@ describe("fetchIntroSteps", () => {
34
37
} ) ;
35
38
36
39
test ( "should find and add elements from options.steps to the list" , ( ) => {
40
+ // Arrange
37
41
const targetElement = document . createElement ( "div" ) ;
38
42
39
43
const stepOne = document . createElement ( "div" ) ;
@@ -45,6 +49,7 @@ describe("fetchIntroSteps", () => {
45
49
document . body . appendChild ( stepOne ) ;
46
50
document . body . appendChild ( stepTwo ) ;
47
51
52
+ // Act
48
53
const steps = fetchIntroSteps (
49
54
{
50
55
_options : {
@@ -69,6 +74,7 @@ describe("fetchIntroSteps", () => {
69
74
targetElement
70
75
) ;
71
76
77
+ // Assert
72
78
expect ( steps . length ) . toBe ( 3 ) ;
73
79
74
80
expect ( steps [ 0 ] . element ) . toBe ( stepOne ) ;
@@ -87,6 +93,7 @@ describe("fetchIntroSteps", () => {
87
93
} ) ;
88
94
89
95
test ( "should find the data-* elements from the DOM" , ( ) => {
96
+ // Arrange
90
97
const targetElement = document . createElement ( "div" ) ;
91
98
92
99
const stepOne = document . createElement ( "div" ) ;
@@ -99,6 +106,7 @@ describe("fetchIntroSteps", () => {
99
106
targetElement . appendChild ( stepOne ) ;
100
107
targetElement . appendChild ( stepTwo ) ;
101
108
109
+ // Act
102
110
const steps = fetchIntroSteps (
103
111
{
104
112
_options : {
@@ -108,6 +116,7 @@ describe("fetchIntroSteps", () => {
108
116
targetElement
109
117
) ;
110
118
119
+ // Assert
111
120
expect ( steps . length ) . toBe ( 2 ) ;
112
121
113
122
expect ( steps [ 0 ] . position ) . toBe ( "bottom" ) ;
@@ -120,6 +129,7 @@ describe("fetchIntroSteps", () => {
120
129
} ) ;
121
130
122
131
test ( "should respect the custom step attribute (DOM)" , ( ) => {
132
+ // Arrange
123
133
const targetElement = document . createElement ( "div" ) ;
124
134
125
135
const stepOne = document . createElement ( "div" ) ;
@@ -132,6 +142,7 @@ describe("fetchIntroSteps", () => {
132
142
targetElement . appendChild ( stepOne ) ;
133
143
targetElement . appendChild ( stepTwo ) ;
134
144
145
+ // Act
135
146
const steps = fetchIntroSteps (
136
147
{
137
148
_options : {
@@ -141,6 +152,7 @@ describe("fetchIntroSteps", () => {
141
152
targetElement
142
153
) ;
143
154
155
+ // Assert
144
156
expect ( steps . length ) . toBe ( 2 ) ;
145
157
146
158
expect ( steps [ 0 ] . intro ) . toBe ( "first" ) ;
@@ -151,6 +163,7 @@ describe("fetchIntroSteps", () => {
151
163
} ) ;
152
164
153
165
test ( "should ignore DOM elements when options.steps is available" , ( ) => {
166
+ // Arrange
154
167
const targetElement = document . createElement ( "div" ) ;
155
168
156
169
const stepOne = document . createElement ( "div" ) ;
@@ -162,6 +175,7 @@ describe("fetchIntroSteps", () => {
162
175
targetElement . appendChild ( stepOne ) ;
163
176
targetElement . appendChild ( stepTwo ) ;
164
177
178
+ // Act
165
179
const steps = fetchIntroSteps (
166
180
{
167
181
_options : {
@@ -178,8 +192,56 @@ describe("fetchIntroSteps", () => {
178
192
targetElement
179
193
) ;
180
194
195
+ // Assert
181
196
expect ( steps . length ) . toBe ( 2 ) ;
182
197
expect ( steps [ 0 ] . intro ) . toBe ( "steps-first" ) ;
183
198
expect ( steps [ 1 ] . intro ) . toBe ( "steps-second" ) ;
184
199
} ) ;
200
+
201
+ it ( "should correctly sort based on data-step" , ( ) => {
202
+ // Arrange
203
+ const targetElement = document . createElement ( "div" ) ;
204
+
205
+ const stepOne = document . createElement ( "div" ) ;
206
+ stepOne . setAttribute ( "data-intro" , "one" ) ;
207
+
208
+ const stepTwo = document . createElement ( "div" ) ;
209
+ stepTwo . setAttribute ( "data-intro" , "two" ) ;
210
+
211
+ const stepThree = document . createElement ( "div" ) ;
212
+ stepThree . setAttribute ( "data-intro" , "three" ) ;
213
+ stepThree . setAttribute ( "data-step" , "3" ) ;
214
+
215
+ const stepFour = document . createElement ( "div" ) ;
216
+ stepFour . setAttribute ( "data-intro" , "four" ) ;
217
+ stepFour . setAttribute ( "data-step" , "5" ) ;
218
+
219
+ targetElement . appendChild ( stepThree ) ;
220
+ targetElement . appendChild ( stepOne ) ;
221
+ targetElement . appendChild ( stepFour ) ;
222
+ targetElement . appendChild ( stepTwo ) ;
223
+
224
+ // Act
225
+ const steps = fetchIntroSteps (
226
+ {
227
+ _options : { } ,
228
+ } as IntroJs ,
229
+ targetElement
230
+ ) ;
231
+
232
+ // Assert
233
+ expect ( steps . length ) . toBe ( 4 ) ;
234
+
235
+ expect ( steps [ 0 ] . intro ) . toBe ( "one" ) ;
236
+ expect ( steps [ 0 ] . step ) . toBe ( 1 ) ;
237
+
238
+ expect ( steps [ 1 ] . intro ) . toBe ( "two" ) ;
239
+ expect ( steps [ 1 ] . step ) . toBe ( 2 ) ;
240
+
241
+ expect ( steps [ 2 ] . intro ) . toBe ( "three" ) ;
242
+ expect ( steps [ 2 ] . step ) . toBe ( 3 ) ;
243
+
244
+ expect ( steps [ 3 ] . intro ) . toBe ( "four" ) ;
245
+ expect ( steps [ 3 ] . step ) . toBe ( 5 ) ;
246
+ } ) ;
185
247
} ) ;
0 commit comments