6
6
/* eslint max-nested-callbacks: 0 */
7
7
8
8
define ( [
9
- 'squire'
10
- ] , function ( Squire ) {
9
+ 'squire' ,
10
+ 'jquery' ,
11
+ 'jquery/jquery-storageapi'
12
+ ] , function ( Squire , $ ) {
11
13
'use strict' ;
12
14
13
15
var injector = new Squire ( ) ,
14
- originalGetJSON ,
15
- storage ,
16
- storageInvalidation = { } ,
16
+ sectionConfig ,
17
17
obj ;
18
18
19
- beforeEach ( function ( done ) {
20
- injector . require ( [ 'Magento_Customer/js/customer-data' ] , function ( Constr ) {
21
- originalGetJSON = $ . getJSON ;
22
- obj = Constr ;
23
- done ( ) ;
24
- } ) ;
25
- } ) ;
19
+ describe ( 'Magento_Customer/js/customer-data' , function ( ) {
26
20
27
- afterEach ( function ( ) {
28
- try {
29
- injector . clean ( ) ;
30
- injector . remove ( ) ;
31
- $ . getJSON = originalGetJSON ;
32
- } catch ( e ) {
33
- }
34
- } ) ;
21
+ beforeEach ( function ( done ) {
22
+ injector . require ( [
23
+ 'Magento_Customer/js/customer-data' ,
24
+ 'Magento_Customer/js/section-config'
25
+ ] , function ( Constr , sectionConfiguration ) {
26
+ obj = Constr ;
27
+ sectionConfig = sectionConfiguration ;
28
+ done ( ) ;
29
+ } ) ;
30
+ } ) ;
35
31
36
- describe ( 'Magento_Customer/js/customer-data' , function ( ) {
32
+ afterEach ( function ( ) {
33
+ try {
34
+ injector . clean ( ) ;
35
+ injector . remove ( ) ;
36
+ } catch ( e ) {
37
+ }
38
+ } ) ;
37
39
38
40
describe ( '"init" method' , function ( ) {
39
- beforeEach ( function ( ) {
40
- spyOn ( obj , "reload" ) . and . returnValue ( true ) ;
41
-
42
- storageInvalidation = {
41
+ var storageInvalidation = {
43
42
keys : function ( ) {
44
43
return [ 'section' ] ;
45
44
}
46
- }
47
-
48
- var dataProvider = {
49
- getFromStorage : function ( sections ) {
45
+ } ,
46
+ dataProvider = {
47
+ getFromStorage : function ( ) {
50
48
return [ 'section' ] ;
51
49
}
52
- } ;
53
-
50
+ } ,
54
51
storage = {
55
52
keys : function ( ) {
56
53
return [ 'section' ] ;
57
54
}
58
55
} ;
59
56
57
+ beforeEach ( function ( ) {
58
+ spyOn ( obj , "reload" ) . and . returnValue ( true ) ;
59
+ spyOn ( $ , 'initNamespaceStorage' ) . and . returnValue ( true ) ;
60
60
spyOn ( dataProvider , "getFromStorage" ) ;
61
61
spyOn ( storage , "keys" ) . and . returnValue ( [ 'section' ] ) ;
62
62
spyOn ( storageInvalidation , "keys" ) . and . returnValue ( [ 'section' ] ) ;
@@ -124,15 +124,17 @@ define([
124
124
} ) ;
125
125
126
126
it ( 'Does not throw before component is initialized' , function ( ) {
127
+ _ . each = jasmine . createSpy ( ) . and . returnValue ( true ) ;
128
+
127
129
expect ( function ( ) {
128
- obj . set ( 'cart' , { } ) ;
130
+ obj . set ( ) ;
129
131
} ) . not . toThrow ( ) ;
130
132
} ) ;
131
133
} ) ;
132
134
133
135
describe ( '"reload" method' , function ( ) {
134
136
beforeEach ( function ( ) {
135
- $ . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
137
+ jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
136
138
var deferred = $ . Deferred ( ) ;
137
139
138
140
deferred . promise ( ) . done = function ( ) {
@@ -160,7 +162,9 @@ define([
160
162
it ( 'Returns proper sections object when passed array with a single section name' , function ( ) {
161
163
var result ;
162
164
163
- $ . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
165
+ spyOn ( sectionConfig , 'filterClientSideSections' ) . and . returnValue ( [ 'section' ] ) ;
166
+
167
+ jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
164
168
var deferred = $ . Deferred ( ) ;
165
169
166
170
deferred . promise ( ) . done = function ( ) {
@@ -190,7 +194,9 @@ define([
190
194
it ( 'Returns proper sections object when passed array with a multiple section names' , function ( ) {
191
195
var result ;
192
196
193
- $ . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
197
+ spyOn ( sectionConfig , 'filterClientSideSections' ) . and . returnValue ( [ 'cart,customer,messages' ] ) ;
198
+
199
+ jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
194
200
var deferred = $ . Deferred ( ) ;
195
201
196
202
expect ( parameters ) . toEqual ( jasmine . objectContaining ( {
@@ -224,7 +230,7 @@ define([
224
230
it ( 'Returns all sections when passed wildcard string' , function ( ) {
225
231
var result ;
226
232
227
- $ . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
233
+ jQuery . getJSON = jasmine . createSpy ( ) . and . callFake ( function ( url , parameters ) {
228
234
var deferred = $ . Deferred ( ) ;
229
235
230
236
expect ( parameters ) . toEqual ( jasmine . objectContaining ( {
@@ -246,7 +252,7 @@ define([
246
252
247
253
result = obj . reload ( '*' , true ) ;
248
254
249
- expect ( $ . getJSON ) . toHaveBeenCalled ( ) ;
255
+ expect ( jQuery . getJSON ) . toHaveBeenCalled ( ) ;
250
256
expect ( result ) . toEqual ( jasmine . objectContaining ( {
251
257
responseJSON : {
252
258
cart : { } ,
@@ -261,6 +267,12 @@ define([
261
267
it ( 'Should be defined' , function ( ) {
262
268
expect ( obj . hasOwnProperty ( 'invalidate' ) ) . toBeDefined ( ) ;
263
269
} ) ;
270
+
271
+ it ( 'Does not throw before component is initialized' , function ( ) {
272
+ expect ( function ( ) {
273
+ obj . invalidate ( ) ;
274
+ } ) . not . toThrow ( ) ;
275
+ } ) ;
264
276
} ) ;
265
277
266
278
describe ( '"Magento_Customer/js/customer-data" method' , function ( ) {
0 commit comments