@@ -11,22 +11,26 @@ define([
11
11
'use strict' ;
12
12
13
13
describe ( 'Magento_Customer/js/customer-global-session-loader' , function ( ) {
14
- var injector = new Squire ( ) ,
14
+ var injector ,
15
15
customer = ko . observable ( { } ) ,
16
16
mocks = {
17
17
'Magento_Customer/js/customer-data' : {
18
18
get : jasmine . createSpy ( 'get' , function ( ) {
19
19
return customer ;
20
20
} ) . and . callThrough ( ) ,
21
- reload : jasmine . createSpy ( ) ,
21
+ reload : jasmine . createSpy ( 'reload' ) ,
22
22
getInitCustomerData : function ( ) { }
23
23
}
24
24
} ,
25
25
deferred ,
26
26
customerSessionLoader ;
27
27
28
- beforeEach ( function ( done ) {
28
+ beforeAll ( function ( ) {
29
29
$ ( 'body' ) . append ( '<div id="customerMenu" class="customer-menu">Customer Menu</div>' ) ;
30
+ } ) ;
31
+
32
+ beforeEach ( function ( done ) {
33
+ injector = new Squire ( ) ;
30
34
injector . mock ( mocks ) ;
31
35
injector . require ( [ 'Magento_Customer/js/customer-global-session-loader' ] , function ( instance ) {
32
36
customerSessionLoader = instance ;
@@ -38,27 +42,20 @@ define([
38
42
try {
39
43
injector . clean ( ) ;
40
44
injector . remove ( ) ;
41
- } catch ( e ) { }
45
+ injector = null ;
46
+ } catch ( e ) {
47
+ console . log ( e ) ;
48
+ }
42
49
43
50
customer ( { } ) ;
51
+ } ) ;
52
+
53
+ afterAll ( function ( ) {
44
54
$ ( '#customerMenu' ) . remove ( ) ;
45
55
} ) ;
46
56
47
57
describe ( 'Check customer data preparation process' , function ( ) {
48
- it ( 'Tests that customer data is NOT checked before initialization' , function ( ) {
49
- spyOn ( mocks [ 'Magento_Customer/js/customer-data' ] , 'getInitCustomerData' ) . and . callFake ( function ( ) {
50
- deferred = $ . Deferred ( ) ;
51
-
52
- return deferred . promise ( ) ;
53
- } ) ;
54
- expect ( customerSessionLoader ( ) ) . toBe ( undefined ) ;
55
-
56
- expect ( mocks [ 'Magento_Customer/js/customer-data' ] . get ) . toHaveBeenCalledWith ( 'customer' ) ;
57
- expect ( mocks [ 'Magento_Customer/js/customer-data' ] . getInitCustomerData ) . toHaveBeenCalled ( ) ;
58
- expect ( mocks [ 'Magento_Customer/js/customer-data' ] . reload ) . not . toHaveBeenCalled ( ) ;
59
- } ) ;
60
-
61
- it ( 'Tests that customer data reloads if customer first name is not there' , function ( ) {
58
+ it ( 'Tests that customer data does not reloads if it has first name defined' , function ( ) {
62
59
spyOn ( mocks [ 'Magento_Customer/js/customer-data' ] , 'getInitCustomerData' ) . and . callFake ( function ( ) {
63
60
deferred = $ . Deferred ( ) ;
64
61
@@ -67,22 +64,22 @@ define([
67
64
return deferred . promise ( ) ;
68
65
} ) ;
69
66
customer ( {
70
- _data : null
67
+ firstname : "First Name"
71
68
} ) ;
72
69
customerSessionLoader ( ) ;
73
70
74
71
expect ( mocks [ 'Magento_Customer/js/customer-data' ] . get ) . toHaveBeenCalledWith ( 'customer' ) ;
75
- expect ( mocks [ 'Magento_Customer/js/customer-data' ] . reload ) . toHaveBeenCalledWith ( [ ] , false ) ;
72
+ expect ( mocks [ 'Magento_Customer/js/customer-data' ] . reload ) . not . toHaveBeenCalled ( ) ;
76
73
} ) ;
77
74
78
- it ( 'Tests that customer data is checked only after initialization ' , function ( ) {
75
+ it ( 'Tests that customer data reloads if customer first name data is not there but wait until promise resolved ' , function ( ) {
79
76
spyOn ( mocks [ 'Magento_Customer/js/customer-data' ] , 'getInitCustomerData' ) . and . callFake ( function ( ) {
80
77
deferred = $ . Deferred ( ) ;
81
78
82
79
return deferred . promise ( ) ;
83
80
} ) ;
84
81
customer ( {
85
- firstname : "First Name"
82
+ _data : null
86
83
} ) ;
87
84
customerSessionLoader ( ) ;
88
85
@@ -94,21 +91,19 @@ define([
94
91
expect ( mocks [ 'Magento_Customer/js/customer-data' ] . reload ) . toHaveBeenCalledWith ( [ ] , false ) ;
95
92
} ) ;
96
93
97
- it ( 'Tests that customer data does not reloads if it has first name defined ' , function ( ) {
94
+ it ( 'Tests that customer data reloads if customer data is not there ' , function ( ) {
98
95
spyOn ( mocks [ 'Magento_Customer/js/customer-data' ] , 'getInitCustomerData' ) . and . callFake ( function ( ) {
99
96
deferred = $ . Deferred ( ) ;
100
97
101
- deferred . resolve ( ) ;
98
+ deferred . resolve ( ) ;
102
99
103
100
return deferred . promise ( ) ;
104
101
} ) ;
105
- customer ( {
106
- firstname : "First Name"
107
- } ) ;
108
- customerSessionLoader ( ) ;
102
+ expect ( customerSessionLoader ( ) ) . toBe ( undefined ) ;
109
103
110
104
expect ( mocks [ 'Magento_Customer/js/customer-data' ] . get ) . toHaveBeenCalledWith ( 'customer' ) ;
111
- expect ( mocks [ 'Magento_Customer/js/customer-data' ] . reload ) . not . toHaveBeenCalled ( ) ;
105
+ expect ( mocks [ 'Magento_Customer/js/customer-data' ] . getInitCustomerData ) . toHaveBeenCalled ( ) ;
106
+ expect ( mocks [ 'Magento_Customer/js/customer-data' ] . reload ) . toHaveBeenCalledWith ( [ ] , false ) ;
112
107
} ) ;
113
108
} ) ;
114
109
} ) ;
0 commit comments