@@ -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
afterEach ( function ( ) {
33
22
try {
@@ -43,6 +32,19 @@ define([
43
32
} ,
44
33
storage ;
45
34
35
+ beforeEach ( function ( done ) {
36
+ injector . mock ( mocks ) ;
37
+ injector . require ( [
38
+ 'Magento_Catalog/js/product/storage/ids-storage' ,
39
+ 'Magento_Catalog/js/product/storage/storage-service' ,
40
+ 'mageUtils'
41
+ ] , function ( IdsStorage , instance , mageUtils ) {
42
+ obj = instance ;
43
+ utils = mageUtils ;
44
+ done ( ) ;
45
+ } ) ;
46
+ } ) ;
47
+
46
48
describe ( '"createStorage" method' , function ( ) {
47
49
it ( 'create new storage' , function ( ) {
48
50
obj . processSubscribers = jasmine . createSpy ( ) ;
@@ -73,5 +75,54 @@ define([
73
75
expect ( typeof obj . getStorage ( config . namespace ) ) . toBe ( 'object' ) ;
74
76
} ) ;
75
77
} ) ;
78
+ describe ( '"add" method' , function ( ) {
79
+ var storageValue ;
80
+
81
+ beforeEach ( function ( ) {
82
+ storage = new obj . createStorage ( config ) ;
83
+ storageValue = {
84
+ 'property1' : 1
85
+ } ;
86
+
87
+ storage . set ( storageValue ) ;
88
+ } ) ;
89
+
90
+ it ( 'method exists' , function ( ) {
91
+ expect ( storage . add ) . toBeDefined ( ) ;
92
+ expect ( typeof storage . add ) . toEqual ( 'function' ) ;
93
+ } ) ;
94
+
95
+ it ( 'update value' , function ( ) {
96
+ spyOn ( utils , 'copy' ) . and . callThrough ( ) ;
97
+ expect ( storage . get ( ) ) . toEqual ( storageValue ) ;
98
+
99
+ storageValue = {
100
+ 'property2' : 2
101
+ } ;
102
+
103
+ storage . add ( storageValue ) ;
104
+
105
+ expect ( utils . copy ) . toHaveBeenCalled ( ) ;
106
+ expect ( storage . get ( ) ) . toEqual (
107
+ {
108
+ 'property1' : 1 ,
109
+ 'property2' : 2
110
+ }
111
+ ) ;
112
+ } ) ;
113
+
114
+ it ( 'add empty value' , function ( ) {
115
+ spyOn ( utils , 'copy' ) . and . callThrough ( ) ;
116
+
117
+ storage . add ( { } ) ;
118
+
119
+ expect ( utils . copy ) . not . toHaveBeenCalled ( ) ;
120
+ expect ( storage . get ( ) ) . toEqual (
121
+ {
122
+ 'property1' : 1
123
+ }
124
+ ) ;
125
+ } ) ;
126
+ } ) ;
76
127
} ) ;
77
128
} ) ;
0 commit comments