@@ -12,22 +12,11 @@ define([
12
12
13
13
var injector = new Squire ( ) ,
14
14
mocks = {
15
- 'Magento_Catalog/js/product/storage/ids-storage' : {
16
- name : 'IdsStorage' ,
17
- initialize : jasmine . createSpy ( ) . and . returnValue ( { } )
18
- } ,
19
15
'Magento_Catalog/js/product/storage/data-storage' : { } ,
20
16
'Magento_Catalog/js/product/storage/ids-storage-compare' : { }
21
17
} ,
22
- obj ;
23
-
24
- beforeEach ( function ( done ) {
25
- injector . mock ( mocks ) ;
26
- injector . require ( [ 'Magento_Catalog/js/product/storage/storage-service' ] , function ( insance ) {
27
- obj = insance ;
28
- done ( ) ;
29
- } ) ;
30
- } ) ;
18
+ obj ,
19
+ utils ;
31
20
32
21
describe ( 'Magento_Catalog/js/product/storage/storage-service' , function ( ) {
33
22
var config = {
@@ -36,6 +25,19 @@ define([
36
25
} ,
37
26
storage ;
38
27
28
+ beforeEach ( function ( done ) {
29
+ injector . mock ( mocks ) ;
30
+ injector . require ( [
31
+ 'Magento_Catalog/js/product/storage/ids-storage' ,
32
+ 'Magento_Catalog/js/product/storage/storage-service' ,
33
+ 'mageUtils'
34
+ ] , function ( IdsStorage , instance , mageUtils ) {
35
+ obj = instance ;
36
+ utils = mageUtils ;
37
+ done ( ) ;
38
+ } ) ;
39
+ } ) ;
40
+
39
41
describe ( '"createStorage" method' , function ( ) {
40
42
it ( 'create new storage' , function ( ) {
41
43
obj . processSubscribers = jasmine . createSpy ( ) ;
@@ -66,5 +68,54 @@ define([
66
68
expect ( typeof obj . getStorage ( config . namespace ) ) . toBe ( 'object' ) ;
67
69
} ) ;
68
70
} ) ;
71
+ describe ( '"add" method' , function ( ) {
72
+ var storageValue ;
73
+
74
+ beforeEach ( function ( ) {
75
+ storage = new obj . createStorage ( config ) ;
76
+ storageValue = {
77
+ 'property1' : 1
78
+ } ;
79
+
80
+ storage . set ( storageValue ) ;
81
+ } ) ;
82
+
83
+ it ( 'method exists' , function ( ) {
84
+ expect ( storage . add ) . toBeDefined ( ) ;
85
+ expect ( typeof storage . add ) . toEqual ( 'function' ) ;
86
+ } ) ;
87
+
88
+ it ( 'update value' , function ( ) {
89
+ spyOn ( utils , 'copy' ) . and . callThrough ( ) ;
90
+ expect ( storage . get ( ) ) . toEqual ( storageValue ) ;
91
+
92
+ storageValue = {
93
+ 'property2' : 2
94
+ } ;
95
+
96
+ storage . add ( storageValue ) ;
97
+
98
+ expect ( utils . copy ) . toHaveBeenCalled ( ) ;
99
+ expect ( storage . get ( ) ) . toEqual (
100
+ {
101
+ 'property1' : 1 ,
102
+ 'property2' : 2
103
+ }
104
+ ) ;
105
+ } ) ;
106
+
107
+ it ( 'add empty value' , function ( ) {
108
+ spyOn ( utils , 'copy' ) . and . callThrough ( ) ;
109
+
110
+ storage . add ( { } ) ;
111
+
112
+ expect ( utils . copy ) . not . toHaveBeenCalled ( ) ;
113
+ expect ( storage . get ( ) ) . toEqual (
114
+ {
115
+ 'property1' : 1
116
+ }
117
+ ) ;
118
+ } ) ;
119
+ } ) ;
69
120
} ) ;
70
121
} ) ;
0 commit comments