@applicaster/zapp-react-native-bridge 12.0.0-rc.7 → 12.0.0-rc.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OfflineAssets/__tests__/__snapshots__/fileManager.test.ts.snap +2 -2
- package/OfflineAssets/__tests__/fileManager.test.ts +53 -50
- package/OfflineAssets/index.ts +20 -5
- package/PushNotifications/PushTopicManager.ts +4 -6
- package/QuickBrick/__tests__/quickBrickModule.test.ts +45 -49
- package/QuickBrick/__tests__/quickBrickModule_noModule.test.ts +8 -7
- package/ZappStorage/Storage.ts +9 -1
- package/ZappStorage/StorageMultiSelectProvider.ts +45 -22
- package/ZappStorage/__tests__/__snapshots__/localStorage.test.ts.snap +12 -12
- package/ZappStorage/__tests__/__snapshots__/sessionStorage.test.ts.snap +12 -12
- package/ZappStorage/__tests__/localStorage.test.ts +383 -383
- package/ZappStorage/__tests__/localStorageAndroid.test.ts +3 -6
- package/ZappStorage/__tests__/sessionStorage.test.ts +415 -394
- package/package.json +2 -2
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { sessionStorage as NativeSessionStorage } from "../__mocks__/ios";
|
|
2
2
|
import { DEFAULT_NAMESPACE } from "../__mocks__/storageMock";
|
|
3
|
+
import { NativeModules } from "react-native";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
const RN = jest.requireActual("react-native");
|
|
6
|
-
RN.NativeModules.SessionStorage = NativeSessionStorage;
|
|
7
|
-
RN.Platform.OS = "ios";
|
|
8
|
-
|
|
9
|
-
return RN;
|
|
10
|
-
});
|
|
5
|
+
NativeModules.SessionStorage = NativeSessionStorage;
|
|
11
6
|
|
|
12
7
|
const { sessionStorage } = require("../SessionStorage");
|
|
13
8
|
|
|
@@ -31,496 +26,522 @@ function setUpStorage() {
|
|
|
31
26
|
NativeSessionStorage.setItem(obj_key, JSON.stringify(obj_value));
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
describe("sessionStorage
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
it("sets an item in storage", async () => {
|
|
40
|
-
const key = "test_key";
|
|
41
|
-
const value = "test_value";
|
|
42
|
-
const result = await sessionStorage.setItem(key, value);
|
|
43
|
-
|
|
44
|
-
expect(result).toBe(true);
|
|
45
|
-
|
|
46
|
-
expect(NativeSessionStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
|
|
47
|
-
value
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("works as a bound method", async () => {
|
|
52
|
-
const key = "test_key";
|
|
53
|
-
const value = "test_value";
|
|
54
|
-
const setItem = sessionStorage.setItem;
|
|
55
|
-
const result = await setItem(key, value);
|
|
56
|
-
|
|
57
|
-
expect(result).toBe(true);
|
|
58
|
-
|
|
59
|
-
expect(NativeSessionStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
|
|
60
|
-
value
|
|
61
|
-
);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("stringifies the value if its not a string", async () => {
|
|
65
|
-
const key = "test_key";
|
|
66
|
-
const value = { objVal: "test_value" };
|
|
67
|
-
|
|
68
|
-
const result = await sessionStorage.setItem(key, value);
|
|
69
|
-
|
|
70
|
-
expect(result).toBe(true);
|
|
71
|
-
|
|
72
|
-
expect(NativeSessionStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
|
|
73
|
-
JSON.stringify(value)
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("sets a value in a specific namespace", async () => {
|
|
78
|
-
const key = "test_key";
|
|
79
|
-
const value = "test_value";
|
|
80
|
-
const namespace = "test_namespace";
|
|
81
|
-
const result = await sessionStorage.setItem(key, value, namespace);
|
|
82
|
-
|
|
83
|
-
expect(result).toBe(true);
|
|
84
|
-
|
|
85
|
-
expect(NativeSessionStorage.items.get(namespace).get(key)).toEqual(value);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("throws if key is null", async () => {
|
|
89
|
-
const value = "test_value";
|
|
90
|
-
|
|
91
|
-
expect(() =>
|
|
92
|
-
sessionStorage.setItem(null, value)
|
|
93
|
-
).rejects.toThrowErrorMatchingSnapshot();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("throws if key is undefined", async () => {
|
|
97
|
-
const value = "test_value";
|
|
98
|
-
|
|
99
|
-
expect(() =>
|
|
100
|
-
sessionStorage.setItem(undefined, value)
|
|
101
|
-
).rejects.toThrowErrorMatchingSnapshot();
|
|
102
|
-
});
|
|
29
|
+
describe("sessionStorage", () => {
|
|
30
|
+
describe("setItem", () => {
|
|
31
|
+
beforeEach(async () => {
|
|
32
|
+
NativeSessionStorage.__clear();
|
|
33
|
+
});
|
|
103
34
|
|
|
104
|
-
|
|
105
|
-
|
|
35
|
+
it("sets an item in storage", async () => {
|
|
36
|
+
const key = "test_key";
|
|
37
|
+
const value = "test_value";
|
|
38
|
+
const result = await sessionStorage.setItem(key, value);
|
|
106
39
|
|
|
107
|
-
|
|
108
|
-
sessionStorage.setItem(key, null)
|
|
109
|
-
).rejects.toThrowErrorMatchingSnapshot();
|
|
110
|
-
});
|
|
40
|
+
expect(result).toBe(true);
|
|
111
41
|
|
|
112
|
-
|
|
113
|
-
|
|
42
|
+
expect(
|
|
43
|
+
NativeSessionStorage.items.get(DEFAULT_NAMESPACE).get(key)
|
|
44
|
+
).toEqual(value);
|
|
45
|
+
});
|
|
114
46
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
47
|
+
it("works as a bound method", async () => {
|
|
48
|
+
const key = "test_key";
|
|
49
|
+
const value = "test_value";
|
|
50
|
+
const setItem = sessionStorage.setItem;
|
|
51
|
+
const result = await setItem(key, value);
|
|
119
52
|
|
|
120
|
-
|
|
121
|
-
const key = "fail";
|
|
122
|
-
const value = "value";
|
|
53
|
+
expect(result).toBe(true);
|
|
123
54
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
55
|
+
expect(
|
|
56
|
+
NativeSessionStorage.items.get(DEFAULT_NAMESPACE).get(key)
|
|
57
|
+
).toEqual(value);
|
|
58
|
+
});
|
|
128
59
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
const new_value = "new_value";
|
|
133
|
-
let removeListener;
|
|
60
|
+
it("stringifies the value if its not a string", async () => {
|
|
61
|
+
const key = "test_key";
|
|
62
|
+
const value = { objVal: "test_value" };
|
|
134
63
|
|
|
135
|
-
|
|
136
|
-
setUpStorage();
|
|
137
|
-
listener.mockClear();
|
|
64
|
+
const result = await sessionStorage.setItem(key, value);
|
|
138
65
|
|
|
139
|
-
|
|
140
|
-
{ key: namespaced_key, namespace: test_namespace },
|
|
141
|
-
listener
|
|
142
|
-
);
|
|
143
|
-
});
|
|
66
|
+
expect(result).toBe(true);
|
|
144
67
|
|
|
145
|
-
|
|
146
|
-
|
|
68
|
+
expect(
|
|
69
|
+
NativeSessionStorage.items.get(DEFAULT_NAMESPACE).get(key)
|
|
70
|
+
).toEqual(JSON.stringify(value));
|
|
71
|
+
});
|
|
147
72
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
})
|
|
154
|
-
);
|
|
155
|
-
});
|
|
73
|
+
it("sets a value in a specific namespace", async () => {
|
|
74
|
+
const key = "test_key";
|
|
75
|
+
const value = "test_value";
|
|
76
|
+
const namespace = "test_namespace";
|
|
77
|
+
const result = await sessionStorage.setItem(key, value, namespace);
|
|
156
78
|
|
|
157
|
-
|
|
158
|
-
const setItem = sessionStorage.setItem;
|
|
159
|
-
await setItem(namespaced_key, new_value, test_namespace);
|
|
160
|
-
|
|
161
|
-
expect(listener).toHaveBeenCalledWith(
|
|
162
|
-
expect.objectContaining({
|
|
163
|
-
key: namespaced_key,
|
|
164
|
-
namespace: test_namespace,
|
|
165
|
-
value: new_value,
|
|
166
|
-
})
|
|
167
|
-
);
|
|
168
|
-
});
|
|
79
|
+
expect(result).toBe(true);
|
|
169
80
|
|
|
170
|
-
|
|
171
|
-
|
|
81
|
+
expect(NativeSessionStorage.items.get(namespace).get(key)).toEqual(value);
|
|
82
|
+
});
|
|
172
83
|
|
|
173
|
-
|
|
174
|
-
|
|
84
|
+
it("throws if key is null", async () => {
|
|
85
|
+
const value = "test_value";
|
|
175
86
|
|
|
176
|
-
|
|
177
|
-
|
|
87
|
+
expect(() =>
|
|
88
|
+
sessionStorage.setItem(null, value)
|
|
89
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
90
|
+
});
|
|
178
91
|
|
|
179
|
-
|
|
92
|
+
it("throws if key is undefined", async () => {
|
|
93
|
+
const value = "test_value";
|
|
180
94
|
|
|
181
|
-
|
|
182
|
-
|
|
95
|
+
expect(() =>
|
|
96
|
+
sessionStorage.setItem(undefined, value)
|
|
97
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
183
98
|
});
|
|
184
99
|
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
const new_value = "new_value";
|
|
188
|
-
let removeListener;
|
|
100
|
+
it("throws if value is null", async () => {
|
|
101
|
+
const key = "test_key";
|
|
189
102
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
103
|
+
expect(() =>
|
|
104
|
+
sessionStorage.setItem(key, null)
|
|
105
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
106
|
+
});
|
|
193
107
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
listener
|
|
197
|
-
);
|
|
198
|
-
});
|
|
108
|
+
it("throws if value is undefined", async () => {
|
|
109
|
+
const key = "test_key";
|
|
199
110
|
|
|
200
|
-
|
|
201
|
-
|
|
111
|
+
expect(() =>
|
|
112
|
+
sessionStorage.setItem(key, undefined)
|
|
113
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
114
|
+
});
|
|
202
115
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
value: new_value,
|
|
207
|
-
namespace: test_namespace,
|
|
208
|
-
})
|
|
209
|
-
);
|
|
210
|
-
});
|
|
116
|
+
it("throws if there is an error in the native module", async () => {
|
|
117
|
+
const key = "fail";
|
|
118
|
+
const value = "value";
|
|
211
119
|
|
|
212
|
-
|
|
213
|
-
|
|
120
|
+
expect(() =>
|
|
121
|
+
sessionStorage.setItem(key, value)
|
|
122
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
123
|
+
});
|
|
214
124
|
|
|
215
|
-
|
|
125
|
+
describe("listeners", () => {
|
|
126
|
+
describe("listening for a specific key and namespace change", () => {
|
|
127
|
+
const listener = jest.fn();
|
|
128
|
+
const new_value = "new_value";
|
|
129
|
+
let removeListener;
|
|
130
|
+
|
|
131
|
+
beforeEach(() => {
|
|
132
|
+
setUpStorage();
|
|
133
|
+
listener.mockClear();
|
|
134
|
+
|
|
135
|
+
removeListener = sessionStorage.addListener(
|
|
136
|
+
{ key: namespaced_key, namespace: test_namespace },
|
|
137
|
+
listener
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("invokes the listener when this key is changed", async () => {
|
|
142
|
+
await sessionStorage.setItem(
|
|
143
|
+
namespaced_key,
|
|
144
|
+
new_value,
|
|
145
|
+
test_namespace
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
expect(listener).toHaveBeenCalledWith(
|
|
149
|
+
expect.objectContaining({
|
|
150
|
+
key: namespaced_key,
|
|
151
|
+
namespace: test_namespace,
|
|
152
|
+
value: new_value,
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("works as a bound method", async () => {
|
|
158
|
+
const setItem = sessionStorage.setItem;
|
|
159
|
+
await setItem(namespaced_key, new_value, test_namespace);
|
|
160
|
+
|
|
161
|
+
expect(listener).toHaveBeenCalledWith(
|
|
162
|
+
expect.objectContaining({
|
|
163
|
+
key: namespaced_key,
|
|
164
|
+
namespace: test_namespace,
|
|
165
|
+
value: new_value,
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("is not invoked when another key is changed", async () => {
|
|
171
|
+
await sessionStorage.setItem(test_key, new_value);
|
|
172
|
+
|
|
173
|
+
expect(listener).not.toHaveBeenCalled();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("removes the listener when invoking the remove function", async () => {
|
|
177
|
+
removeListener();
|
|
178
|
+
|
|
179
|
+
await sessionStorage.setItem(
|
|
180
|
+
namespaced_key,
|
|
181
|
+
new_value,
|
|
182
|
+
test_namespace
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
expect(listener).not.toHaveBeenCalled();
|
|
186
|
+
});
|
|
216
187
|
});
|
|
217
188
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
189
|
+
describe("listening for any key change in a namespace", () => {
|
|
190
|
+
const listener = jest.fn();
|
|
191
|
+
const new_value = "new_value";
|
|
192
|
+
let removeListener;
|
|
193
|
+
|
|
194
|
+
beforeEach(() => {
|
|
195
|
+
setUpStorage();
|
|
196
|
+
listener.mockClear();
|
|
197
|
+
|
|
198
|
+
removeListener = sessionStorage.addListener(
|
|
199
|
+
{ namespace: test_namespace },
|
|
200
|
+
listener
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("is invoked when a key in the namespace is changed", async () => {
|
|
205
|
+
await sessionStorage.setItem(
|
|
206
|
+
namespaced_key,
|
|
207
|
+
new_value,
|
|
208
|
+
test_namespace
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
expect(listener).toHaveBeenCalledWith(
|
|
212
|
+
expect.objectContaining({
|
|
213
|
+
key: namespaced_key,
|
|
214
|
+
value: new_value,
|
|
215
|
+
namespace: test_namespace,
|
|
216
|
+
})
|
|
217
|
+
);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("is not invoked when a key in a different namespace is changed", async () => {
|
|
221
|
+
await sessionStorage.setItem(test_key, new_value, DEFAULT_NAMESPACE);
|
|
222
|
+
|
|
223
|
+
expect(listener).not.toHaveBeenCalled();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("is not invoked after being removed", async () => {
|
|
227
|
+
removeListener();
|
|
228
|
+
|
|
229
|
+
await sessionStorage.setItem(
|
|
230
|
+
namespaced_key,
|
|
231
|
+
new_value,
|
|
232
|
+
test_namespace
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
expect(listener).not.toHaveBeenCalled();
|
|
236
|
+
});
|
|
224
237
|
});
|
|
225
|
-
});
|
|
226
238
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
239
|
+
describe("listening for key changes in the default namespace", () => {
|
|
240
|
+
const listener = jest.fn();
|
|
241
|
+
const new_value = "new_value";
|
|
242
|
+
let removeListener;
|
|
231
243
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
244
|
+
beforeEach(() => {
|
|
245
|
+
setUpStorage();
|
|
246
|
+
listener.mockClear();
|
|
235
247
|
|
|
236
|
-
|
|
237
|
-
|
|
248
|
+
removeListener = sessionStorage.addListener({}, listener);
|
|
249
|
+
});
|
|
238
250
|
|
|
239
|
-
|
|
240
|
-
|
|
251
|
+
it("is invoked when a key is changed in the default namespace", async () => {
|
|
252
|
+
await sessionStorage.setItem(test_key, new_value);
|
|
241
253
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
expect(listener).toHaveBeenCalledWith(
|
|
255
|
+
expect.objectContaining({
|
|
256
|
+
key: test_key,
|
|
257
|
+
value: new_value,
|
|
258
|
+
namespace: DEFAULT_NAMESPACE,
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
});
|
|
250
262
|
|
|
251
|
-
|
|
252
|
-
|
|
263
|
+
it("is not invoked when a key in a nother namespace is changed", async () => {
|
|
264
|
+
await sessionStorage.setItem(
|
|
265
|
+
namespaced_key,
|
|
266
|
+
new_value,
|
|
267
|
+
test_namespace
|
|
268
|
+
);
|
|
253
269
|
|
|
254
|
-
|
|
255
|
-
|
|
270
|
+
expect(listener).not.toHaveBeenCalled();
|
|
271
|
+
});
|
|
256
272
|
|
|
257
|
-
|
|
258
|
-
|
|
273
|
+
it("is not invoked after having been removed", async () => {
|
|
274
|
+
removeListener();
|
|
259
275
|
|
|
260
|
-
|
|
276
|
+
await sessionStorage.setItem(test_key, new_value);
|
|
261
277
|
|
|
262
|
-
|
|
278
|
+
expect(listener).not.toHaveBeenCalled();
|
|
279
|
+
});
|
|
263
280
|
});
|
|
264
281
|
});
|
|
265
282
|
});
|
|
266
|
-
});
|
|
267
283
|
|
|
268
|
-
describe("
|
|
269
|
-
|
|
284
|
+
describe("getItem", () => {
|
|
285
|
+
beforeAll(setUpStorage);
|
|
270
286
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
287
|
+
it("retrieves a value from storage", async () => {
|
|
288
|
+
const result = await sessionStorage.getItem(test_key);
|
|
289
|
+
expect(result).toBe(test_value);
|
|
290
|
+
});
|
|
275
291
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
292
|
+
it("works as a bound method", async () => {
|
|
293
|
+
const getItem = sessionStorage.getItem;
|
|
294
|
+
const result = await getItem(test_key);
|
|
295
|
+
expect(result).toBe(test_value);
|
|
296
|
+
});
|
|
281
297
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
298
|
+
it("retrieves a value in a namespace", async () => {
|
|
299
|
+
const result = await sessionStorage.getItem(
|
|
300
|
+
namespaced_key,
|
|
301
|
+
test_namespace
|
|
302
|
+
);
|
|
286
303
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
expect(result).toEqual(obj_value);
|
|
290
|
-
});
|
|
304
|
+
expect(result).toBe(namespaced_value);
|
|
305
|
+
});
|
|
291
306
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
)
|
|
296
|
-
});
|
|
307
|
+
it("retrieves non string values", async () => {
|
|
308
|
+
const result = await sessionStorage.getItem(obj_key);
|
|
309
|
+
expect(result).toEqual(obj_value);
|
|
310
|
+
});
|
|
297
311
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
312
|
+
it("throws if key is null", async () => {
|
|
313
|
+
expect(() =>
|
|
314
|
+
sessionStorage.getItem(null)
|
|
315
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("throws if key is undefined", async () => {
|
|
319
|
+
expect(() =>
|
|
320
|
+
sessionStorage.getItem()
|
|
321
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
322
|
+
});
|
|
303
323
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
324
|
+
it("throws if there is an error on the native side", async () => {
|
|
325
|
+
expect(() =>
|
|
326
|
+
sessionStorage.getItem("fail")
|
|
327
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
328
|
+
});
|
|
308
329
|
});
|
|
309
|
-
});
|
|
310
330
|
|
|
311
|
-
describe("
|
|
312
|
-
|
|
331
|
+
describe("removeItem", () => {
|
|
332
|
+
beforeEach(setUpStorage);
|
|
313
333
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
334
|
+
it("removes a value from storage", async () => {
|
|
335
|
+
const result = await sessionStorage.removeItem(test_key);
|
|
336
|
+
expect(result).toBe(true);
|
|
317
337
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
338
|
+
expect(
|
|
339
|
+
NativeSessionStorage.items.get(DEFAULT_NAMESPACE).get(test_key)
|
|
340
|
+
).toBeUndefined();
|
|
341
|
+
});
|
|
322
342
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
343
|
+
it("works as a bound method", async () => {
|
|
344
|
+
const removeItem = sessionStorage.removeItem;
|
|
345
|
+
const result = await removeItem(test_key);
|
|
346
|
+
expect(result).toBe(true);
|
|
327
347
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
348
|
+
expect(
|
|
349
|
+
NativeSessionStorage.items.get(DEFAULT_NAMESPACE).get(test_key)
|
|
350
|
+
).toBeUndefined();
|
|
351
|
+
});
|
|
332
352
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
353
|
+
it("removes a value in a namespace", async () => {
|
|
354
|
+
const result = await sessionStorage.removeItem(
|
|
355
|
+
namespaced_key,
|
|
356
|
+
test_namespace
|
|
357
|
+
);
|
|
338
358
|
|
|
339
|
-
|
|
359
|
+
expect(result).toBe(true);
|
|
340
360
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
361
|
+
expect(
|
|
362
|
+
NativeSessionStorage.items.get(test_namespace).get(namespaced_key)
|
|
363
|
+
).toBeUndefined();
|
|
364
|
+
});
|
|
345
365
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
366
|
+
it("throws if key is null", async () => {
|
|
367
|
+
expect(() =>
|
|
368
|
+
sessionStorage.removeItem(null)
|
|
369
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
370
|
+
});
|
|
351
371
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
372
|
+
it("throws if key is undefined", async () => {
|
|
373
|
+
expect(() =>
|
|
374
|
+
sessionStorage.removeItem()
|
|
375
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
376
|
+
});
|
|
357
377
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
378
|
+
it("throws if a native error is thrown", async () => {
|
|
379
|
+
expect(() =>
|
|
380
|
+
sessionStorage.removeItem("fail")
|
|
381
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
382
|
+
});
|
|
363
383
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
384
|
+
describe("listeners", () => {
|
|
385
|
+
describe("listening for a specific key and namespace change", () => {
|
|
386
|
+
const listener = jest.fn();
|
|
387
|
+
let removeListener;
|
|
368
388
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
389
|
+
beforeEach(() => {
|
|
390
|
+
setUpStorage();
|
|
391
|
+
listener.mockClear();
|
|
372
392
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
393
|
+
removeListener = sessionStorage.addListener(
|
|
394
|
+
{ key: namespaced_key, namespace: test_namespace },
|
|
395
|
+
listener
|
|
396
|
+
);
|
|
397
|
+
});
|
|
378
398
|
|
|
379
|
-
|
|
380
|
-
|
|
399
|
+
it("invokes the listener when this key is changed", async () => {
|
|
400
|
+
await sessionStorage.removeItem(namespaced_key, test_namespace);
|
|
381
401
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
402
|
+
expect(listener).toHaveBeenCalledWith(
|
|
403
|
+
expect.objectContaining({
|
|
404
|
+
key: namespaced_key,
|
|
405
|
+
namespace: test_namespace,
|
|
406
|
+
value: null,
|
|
407
|
+
})
|
|
408
|
+
);
|
|
409
|
+
});
|
|
390
410
|
|
|
391
|
-
|
|
392
|
-
|
|
411
|
+
it("is not invoked when another key is changed", async () => {
|
|
412
|
+
await sessionStorage.removeItem(test_key);
|
|
393
413
|
|
|
394
|
-
|
|
395
|
-
|
|
414
|
+
expect(listener).not.toHaveBeenCalled();
|
|
415
|
+
});
|
|
396
416
|
|
|
397
|
-
|
|
398
|
-
|
|
417
|
+
it("removes the listener when invoking the remove function", async () => {
|
|
418
|
+
removeListener();
|
|
399
419
|
|
|
400
|
-
|
|
420
|
+
await sessionStorage.removeItem(namespaced_key, test_namespace);
|
|
401
421
|
|
|
402
|
-
|
|
422
|
+
expect(listener).not.toHaveBeenCalled();
|
|
423
|
+
});
|
|
403
424
|
});
|
|
404
|
-
});
|
|
405
425
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
426
|
+
describe("listening for any key change in a namespace", () => {
|
|
427
|
+
const listener = jest.fn();
|
|
428
|
+
let removeListener;
|
|
409
429
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
430
|
+
beforeEach(() => {
|
|
431
|
+
setUpStorage();
|
|
432
|
+
listener.mockClear();
|
|
413
433
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
434
|
+
removeListener = sessionStorage.addListener(
|
|
435
|
+
{ namespace: test_namespace },
|
|
436
|
+
listener
|
|
437
|
+
);
|
|
438
|
+
});
|
|
419
439
|
|
|
420
|
-
|
|
421
|
-
|
|
440
|
+
it("is invoked when a key in the namespace is changed", async () => {
|
|
441
|
+
await sessionStorage.removeItem(namespaced_key, test_namespace);
|
|
422
442
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
443
|
+
expect(listener).toHaveBeenCalledWith(
|
|
444
|
+
expect.objectContaining({
|
|
445
|
+
key: namespaced_key,
|
|
446
|
+
value: null,
|
|
447
|
+
namespace: test_namespace,
|
|
448
|
+
})
|
|
449
|
+
);
|
|
450
|
+
});
|
|
431
451
|
|
|
432
|
-
|
|
433
|
-
|
|
452
|
+
it("is not invoked when a key in a different namespace is changed", async () => {
|
|
453
|
+
await sessionStorage.removeItem(test_key, DEFAULT_NAMESPACE);
|
|
434
454
|
|
|
435
|
-
|
|
436
|
-
|
|
455
|
+
expect(listener).not.toHaveBeenCalled();
|
|
456
|
+
});
|
|
437
457
|
|
|
438
|
-
|
|
439
|
-
|
|
458
|
+
it("is not invoked after being removed", async () => {
|
|
459
|
+
removeListener();
|
|
440
460
|
|
|
441
|
-
|
|
461
|
+
await sessionStorage.removeItem(namespaced_key, test_namespace);
|
|
442
462
|
|
|
443
|
-
|
|
463
|
+
expect(listener).not.toHaveBeenCalled();
|
|
464
|
+
});
|
|
444
465
|
});
|
|
445
|
-
});
|
|
446
466
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
467
|
+
describe("listening for key changes in the default namespace", () => {
|
|
468
|
+
const listener = jest.fn();
|
|
469
|
+
let removeListener;
|
|
450
470
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
471
|
+
beforeEach(() => {
|
|
472
|
+
setUpStorage();
|
|
473
|
+
listener.mockClear();
|
|
454
474
|
|
|
455
|
-
|
|
456
|
-
|
|
475
|
+
removeListener = sessionStorage.addListener({}, listener);
|
|
476
|
+
});
|
|
457
477
|
|
|
458
|
-
|
|
459
|
-
|
|
478
|
+
it("is invoked when a key is changed in the default namespace", async () => {
|
|
479
|
+
await sessionStorage.removeItem(test_key);
|
|
460
480
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
481
|
+
expect(listener).toHaveBeenCalledWith(
|
|
482
|
+
expect.objectContaining({
|
|
483
|
+
key: test_key,
|
|
484
|
+
value: null,
|
|
485
|
+
namespace: DEFAULT_NAMESPACE,
|
|
486
|
+
})
|
|
487
|
+
);
|
|
488
|
+
});
|
|
469
489
|
|
|
470
|
-
|
|
471
|
-
|
|
490
|
+
it("is not invoked when a key in a nother namespace is changed", async () => {
|
|
491
|
+
await sessionStorage.removeItem(namespaced_key, test_namespace);
|
|
472
492
|
|
|
473
|
-
|
|
474
|
-
|
|
493
|
+
expect(listener).not.toHaveBeenCalled();
|
|
494
|
+
});
|
|
475
495
|
|
|
476
|
-
|
|
477
|
-
|
|
496
|
+
it("is not invoked after having been removed", async () => {
|
|
497
|
+
removeListener();
|
|
478
498
|
|
|
479
|
-
|
|
499
|
+
await sessionStorage.removeItem(test_key);
|
|
480
500
|
|
|
481
|
-
|
|
501
|
+
expect(listener).not.toHaveBeenCalled();
|
|
502
|
+
});
|
|
482
503
|
});
|
|
483
504
|
});
|
|
484
505
|
});
|
|
485
|
-
});
|
|
486
506
|
|
|
487
|
-
describe("
|
|
488
|
-
|
|
507
|
+
describe("getAllItems", () => {
|
|
508
|
+
beforeAll(setUpStorage);
|
|
489
509
|
|
|
490
|
-
|
|
491
|
-
|
|
510
|
+
it("retrieves all values", async () => {
|
|
511
|
+
const result = await sessionStorage.getAllItems();
|
|
492
512
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
513
|
+
expect(result).toEqual(
|
|
514
|
+
expect.objectContaining({
|
|
515
|
+
[test_key]: test_value,
|
|
516
|
+
[obj_key]: obj_value,
|
|
517
|
+
})
|
|
518
|
+
);
|
|
519
|
+
});
|
|
500
520
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
521
|
+
it("works as a bound method", async () => {
|
|
522
|
+
const getAllItems = sessionStorage.getAllItems;
|
|
523
|
+
const result = await getAllItems();
|
|
504
524
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
525
|
+
expect(result).toEqual(
|
|
526
|
+
expect.objectContaining({
|
|
527
|
+
[test_key]: test_value,
|
|
528
|
+
[obj_key]: obj_value,
|
|
529
|
+
})
|
|
530
|
+
);
|
|
531
|
+
});
|
|
512
532
|
|
|
513
|
-
|
|
514
|
-
|
|
533
|
+
it("retrieves all values in a namespace", async () => {
|
|
534
|
+
const result = await sessionStorage.getAllItems(test_namespace);
|
|
515
535
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
536
|
+
expect(result).toEqual(
|
|
537
|
+
expect.objectContaining({ [namespaced_key]: namespaced_value })
|
|
538
|
+
);
|
|
539
|
+
});
|
|
520
540
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
541
|
+
it("throws if an error happen on native side", async () => {
|
|
542
|
+
expect(() =>
|
|
543
|
+
sessionStorage.getAllItems("undefined_namespace")
|
|
544
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
545
|
+
});
|
|
525
546
|
});
|
|
526
547
|
});
|