@@ -3,8 +3,10 @@ import fetchIntroSteps from "../../../src/core/fetchIntroSteps";
33
44describe ( "fetchIntroSteps" , ( ) => {
55 test ( "should add floating element from options.steps to the list" , ( ) => {
6+ // Arrange
67 const targetElement = document . createElement ( "div" ) ;
78
9+ // Act
810 const steps = fetchIntroSteps (
911 {
1012 _options : {
@@ -22,6 +24,7 @@ describe("fetchIntroSteps", () => {
2224 targetElement
2325 ) ;
2426
27+ // Assert
2528 expect ( steps . length ) . toBe ( 2 ) ;
2629
2730 expect ( steps [ 0 ] . position ) . toBe ( "floating" ) ;
@@ -34,6 +37,7 @@ describe("fetchIntroSteps", () => {
3437 } ) ;
3538
3639 test ( "should find and add elements from options.steps to the list" , ( ) => {
40+ // Arrange
3741 const targetElement = document . createElement ( "div" ) ;
3842
3943 const stepOne = document . createElement ( "div" ) ;
@@ -45,6 +49,7 @@ describe("fetchIntroSteps", () => {
4549 document . body . appendChild ( stepOne ) ;
4650 document . body . appendChild ( stepTwo ) ;
4751
52+ // Act
4853 const steps = fetchIntroSteps (
4954 {
5055 _options : {
@@ -69,6 +74,7 @@ describe("fetchIntroSteps", () => {
6974 targetElement
7075 ) ;
7176
77+ // Assert
7278 expect ( steps . length ) . toBe ( 3 ) ;
7379
7480 expect ( steps [ 0 ] . element ) . toBe ( stepOne ) ;
@@ -87,6 +93,7 @@ describe("fetchIntroSteps", () => {
8793 } ) ;
8894
8995 test ( "should find the data-* elements from the DOM" , ( ) => {
96+ // Arrange
9097 const targetElement = document . createElement ( "div" ) ;
9198
9299 const stepOne = document . createElement ( "div" ) ;
@@ -99,6 +106,7 @@ describe("fetchIntroSteps", () => {
99106 targetElement . appendChild ( stepOne ) ;
100107 targetElement . appendChild ( stepTwo ) ;
101108
109+ // Act
102110 const steps = fetchIntroSteps (
103111 {
104112 _options : {
@@ -108,6 +116,7 @@ describe("fetchIntroSteps", () => {
108116 targetElement
109117 ) ;
110118
119+ // Assert
111120 expect ( steps . length ) . toBe ( 2 ) ;
112121
113122 expect ( steps [ 0 ] . position ) . toBe ( "bottom" ) ;
@@ -120,6 +129,7 @@ describe("fetchIntroSteps", () => {
120129 } ) ;
121130
122131 test ( "should respect the custom step attribute (DOM)" , ( ) => {
132+ // Arrange
123133 const targetElement = document . createElement ( "div" ) ;
124134
125135 const stepOne = document . createElement ( "div" ) ;
@@ -132,6 +142,7 @@ describe("fetchIntroSteps", () => {
132142 targetElement . appendChild ( stepOne ) ;
133143 targetElement . appendChild ( stepTwo ) ;
134144
145+ // Act
135146 const steps = fetchIntroSteps (
136147 {
137148 _options : {
@@ -141,6 +152,7 @@ describe("fetchIntroSteps", () => {
141152 targetElement
142153 ) ;
143154
155+ // Assert
144156 expect ( steps . length ) . toBe ( 2 ) ;
145157
146158 expect ( steps [ 0 ] . intro ) . toBe ( "first" ) ;
@@ -151,6 +163,7 @@ describe("fetchIntroSteps", () => {
151163 } ) ;
152164
153165 test ( "should ignore DOM elements when options.steps is available" , ( ) => {
166+ // Arrange
154167 const targetElement = document . createElement ( "div" ) ;
155168
156169 const stepOne = document . createElement ( "div" ) ;
@@ -162,6 +175,7 @@ describe("fetchIntroSteps", () => {
162175 targetElement . appendChild ( stepOne ) ;
163176 targetElement . appendChild ( stepTwo ) ;
164177
178+ // Act
165179 const steps = fetchIntroSteps (
166180 {
167181 _options : {
@@ -178,8 +192,56 @@ describe("fetchIntroSteps", () => {
178192 targetElement
179193 ) ;
180194
195+ // Assert
181196 expect ( steps . length ) . toBe ( 2 ) ;
182197 expect ( steps [ 0 ] . intro ) . toBe ( "steps-first" ) ;
183198 expect ( steps [ 1 ] . intro ) . toBe ( "steps-second" ) ;
184199 } ) ;
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+ } ) ;
185247} ) ;
0 commit comments