@@ -2,7 +2,7 @@ import { spy } from 'sinon';
2
2
import { Step } from '../../../src/js/step.js' ;
3
3
import { getPopperOptions , parseAttachTo , shouldCenterStep } from '../../../src/js/utils/general.js' ;
4
4
5
- describe ( 'General Utils' , function ( ) {
5
+ describe ( 'General Utils' , function ( ) {
6
6
let optionsElement ;
7
7
8
8
beforeEach ( ( ) => {
@@ -15,8 +15,8 @@ describe('General Utils', function() {
15
15
document . body . removeChild ( optionsElement ) ;
16
16
} ) ;
17
17
18
- describe ( 'parseAttachTo()' , function ( ) {
19
- it ( 'fails if element does not exist' , function ( ) {
18
+ describe ( 'parseAttachTo()' , function ( ) {
19
+ it ( 'fails if element does not exist' , function ( ) {
20
20
const step = new Step ( { } , {
21
21
attachTo : { element : '.element-does-not-exist' , on : 'center' }
22
22
} ) ;
@@ -25,7 +25,7 @@ describe('General Utils', function() {
25
25
expect ( element ) . toBeFalsy ( ) ;
26
26
} ) ;
27
27
28
- it ( 'accepts callback function as element' , function ( ) {
28
+ it ( 'accepts callback function as element' , function ( ) {
29
29
const callback = spy ( ) ;
30
30
31
31
const step = new Step ( { } , {
@@ -36,7 +36,7 @@ describe('General Utils', function() {
36
36
expect ( callback . called ) . toBe ( true ) ;
37
37
} ) ;
38
38
39
- it ( 'correctly resolves elements when given function that returns a selector' , function ( ) {
39
+ it ( 'correctly resolves elements when given function that returns a selector' , function ( ) {
40
40
const step = new Step ( { } , {
41
41
attachTo : { element : ( ) => 'body' , on : 'center' }
42
42
} ) ;
@@ -45,7 +45,7 @@ describe('General Utils', function() {
45
45
expect ( element [ 0 ] ) . toBe ( document . body ) ;
46
46
} ) ;
47
47
48
- it ( 'binds element callback to step' , function ( ) {
48
+ it ( 'binds element callback to step' , function ( ) {
49
49
const step = new Step ( { } , {
50
50
attachTo : {
51
51
element ( ) {
@@ -57,10 +57,36 @@ describe('General Utils', function() {
57
57
58
58
parseAttachTo ( step ) ;
59
59
} ) ;
60
+
61
+ it ( 'returns all selected elements if multiple flag enabled' , function ( ) {
62
+ const elements = [ ] ;
63
+ const addNode = ( ) => {
64
+ const el = document . createElement ( 'div' ) ;
65
+ el . className = 'multiple-item' ;
66
+ document . body . appendChild ( el ) ;
67
+ return el ;
68
+ } ;
69
+
70
+ elements . push ( addNode ( ) ) ;
71
+ elements . push ( addNode ( ) ) ;
72
+
73
+ const step = new Step ( { } , {
74
+ attachTo : {
75
+ element : '.multiple-item' ,
76
+ on : 'center' ,
77
+ multiple : true
78
+ }
79
+ } ) ;
80
+
81
+ const { element } = parseAttachTo ( step ) ;
82
+ elements . forEach ( ( el , index ) => {
83
+ expect ( element [ index ] ) . toBe ( el ) ;
84
+ } )
85
+ } ) ;
60
86
} ) ;
61
87
62
- describe ( 'getPopperOptions' , function ( ) {
63
- it ( 'modifiers can be overridden' , function ( ) {
88
+ describe ( 'getPopperOptions' , function ( ) {
89
+ it ( 'modifiers can be overridden' , function ( ) {
64
90
const step = new Step ( { } , {
65
91
attachTo : { element : '.options-test' , on : 'right' } ,
66
92
popperOptions : {
@@ -79,7 +105,7 @@ describe('General Utils', function() {
79
105
expect ( popperOptions . modifiers [ 1 ] . options . altAxis ) . toBe ( false ) ;
80
106
} ) ;
81
107
82
- it ( 'positioning strategy is explicitly set' , function ( ) {
108
+ it ( 'positioning strategy is explicitly set' , function ( ) {
83
109
const step = new Step ( { } , {
84
110
attachTo : { element : '.options-test' , on : 'center' } ,
85
111
options : {
@@ -138,7 +164,7 @@ describe('General Utils', function() {
138
164
} )
139
165
140
166
it ( 'Returns true when element property is null' , ( ) => {
141
- const elementAttachTo = { element : null } ; // FAILS
167
+ const elementAttachTo = { element : null } ; // FAILS
142
168
143
169
expect ( shouldCenterStep ( elementAttachTo ) ) . toBe ( true )
144
170
} )
0 commit comments