@merchi/cart 1.4.61 → 1.4.63
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/esm/CartProvider.js +101 -96
- package/esm/CartProvider.load.test.js +384 -89
- package/lib/CartProvider.js +101 -96
- package/package.json +3 -3
- package/src/CartProvider.load.test.tsx +77 -0
- package/src/CartProvider.tsx +19 -8
|
@@ -115,6 +115,7 @@ describe('cart load and replacement failures', function () {
|
|
|
115
115
|
token: 'new-token'
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
|
+
getCartCookie.mockResolvedValue(['42', 'saved-token']);
|
|
118
119
|
});
|
|
119
120
|
afterEach(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
120
121
|
return _regenerator().w(function (_context2) {
|
|
@@ -140,15 +141,15 @@ describe('cart load and replacement failures', function () {
|
|
|
140
141
|
return _mount.apply(this, arguments);
|
|
141
142
|
}
|
|
142
143
|
function _mount() {
|
|
143
|
-
_mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
144
|
-
return _regenerator().w(function (
|
|
145
|
-
while (1) switch (
|
|
144
|
+
_mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(error) {
|
|
145
|
+
return _regenerator().w(function (_context29) {
|
|
146
|
+
while (1) switch (_context29.n) {
|
|
146
147
|
case 0:
|
|
147
148
|
mockGet.mockRejectedValue(error);
|
|
148
|
-
|
|
149
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
150
|
-
return _regenerator().w(function (
|
|
151
|
-
while (1) switch (
|
|
149
|
+
_context29.n = 1;
|
|
150
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28() {
|
|
151
|
+
return _regenerator().w(function (_context28) {
|
|
152
|
+
while (1) switch (_context28.n) {
|
|
152
153
|
case 0:
|
|
153
154
|
root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
154
155
|
domainId: 5,
|
|
@@ -162,14 +163,14 @@ describe('cart load and replacement failures', function () {
|
|
|
162
163
|
children: /*#__PURE__*/_jsx(Probe, {})
|
|
163
164
|
}));
|
|
164
165
|
case 1:
|
|
165
|
-
return
|
|
166
|
+
return _context28.a(2);
|
|
166
167
|
}
|
|
167
|
-
},
|
|
168
|
+
}, _callee28);
|
|
168
169
|
})));
|
|
169
170
|
case 1:
|
|
170
|
-
return
|
|
171
|
+
return _context29.a(2);
|
|
171
172
|
}
|
|
172
|
-
},
|
|
173
|
+
}, _callee29);
|
|
173
174
|
}));
|
|
174
175
|
return _mount.apply(this, arguments);
|
|
175
176
|
}
|
|
@@ -177,9 +178,9 @@ describe('cart load and replacement failures', function () {
|
|
|
177
178
|
return _mountSavedCart.apply(this, arguments);
|
|
178
179
|
}
|
|
179
180
|
function _mountSavedCart() {
|
|
180
|
-
_mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
181
|
-
return _regenerator().w(function (
|
|
182
|
-
while (1) switch (
|
|
181
|
+
_mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32() {
|
|
182
|
+
return _regenerator().w(function (_context32) {
|
|
183
|
+
while (1) switch (_context32.n) {
|
|
183
184
|
case 0:
|
|
184
185
|
mockGet.mockResolvedValue({
|
|
185
186
|
toJson: function toJson() {
|
|
@@ -192,10 +193,10 @@ describe('cart load and replacement failures', function () {
|
|
|
192
193
|
};
|
|
193
194
|
}
|
|
194
195
|
});
|
|
195
|
-
|
|
196
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
197
|
-
return _regenerator().w(function (
|
|
198
|
-
while (1) switch (
|
|
196
|
+
_context32.n = 1;
|
|
197
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30() {
|
|
198
|
+
return _regenerator().w(function (_context30) {
|
|
199
|
+
while (1) switch (_context30.n) {
|
|
199
200
|
case 0:
|
|
200
201
|
root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
201
202
|
domainId: 5,
|
|
@@ -203,27 +204,321 @@ describe('cart load and replacement failures', function () {
|
|
|
203
204
|
children: /*#__PURE__*/_jsx(Probe, {})
|
|
204
205
|
}));
|
|
205
206
|
case 1:
|
|
206
|
-
return
|
|
207
|
+
return _context30.a(2);
|
|
207
208
|
}
|
|
208
|
-
},
|
|
209
|
+
}, _callee30);
|
|
209
210
|
})));
|
|
210
211
|
case 1:
|
|
211
|
-
|
|
212
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
213
|
-
return _regenerator().w(function (
|
|
214
|
-
while (1) switch (
|
|
212
|
+
_context32.n = 2;
|
|
213
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31() {
|
|
214
|
+
return _regenerator().w(function (_context31) {
|
|
215
|
+
while (1) switch (_context31.n) {
|
|
215
216
|
case 0:
|
|
216
|
-
return
|
|
217
|
+
return _context31.a(2, context.setActiveTabIndex(tabIdClearCart));
|
|
217
218
|
}
|
|
218
|
-
},
|
|
219
|
+
}, _callee31);
|
|
219
220
|
})));
|
|
220
221
|
case 2:
|
|
221
|
-
return
|
|
222
|
+
return _context32.a(2);
|
|
222
223
|
}
|
|
223
|
-
},
|
|
224
|
+
}, _callee32);
|
|
224
225
|
}));
|
|
225
226
|
return _mountSavedCart.apply(this, arguments);
|
|
226
227
|
}
|
|
228
|
+
it('shares cold initialization with opening the modal and concurrent getCart callers', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
|
|
229
|
+
var finish, first, second;
|
|
230
|
+
return _regenerator().w(function (_context6) {
|
|
231
|
+
while (1) switch (_context6.n) {
|
|
232
|
+
case 0:
|
|
233
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
234
|
+
mockPost.mockImplementationOnce(function () {
|
|
235
|
+
return new Promise(function (resolve) {
|
|
236
|
+
finish = resolve;
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
_context6.n = 1;
|
|
240
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
241
|
+
return _regenerator().w(function (_context3) {
|
|
242
|
+
while (1) switch (_context3.n) {
|
|
243
|
+
case 0:
|
|
244
|
+
return _context3.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
245
|
+
domainId: 5,
|
|
246
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
247
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
248
|
+
})));
|
|
249
|
+
}
|
|
250
|
+
}, _callee3);
|
|
251
|
+
})));
|
|
252
|
+
case 1:
|
|
253
|
+
_context6.n = 2;
|
|
254
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
255
|
+
return _regenerator().w(function (_context4) {
|
|
256
|
+
while (1) switch (_context4.n) {
|
|
257
|
+
case 0:
|
|
258
|
+
context.toggleCartModal();
|
|
259
|
+
first = window.getCart();
|
|
260
|
+
second = window.getCart();
|
|
261
|
+
case 1:
|
|
262
|
+
return _context4.a(2);
|
|
263
|
+
}
|
|
264
|
+
}, _callee4);
|
|
265
|
+
})));
|
|
266
|
+
case 2:
|
|
267
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
268
|
+
expect(context.fetchingCart).toBe(true);
|
|
269
|
+
_context6.n = 3;
|
|
270
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
|
|
271
|
+
return _regenerator().w(function (_context5) {
|
|
272
|
+
while (1) switch (_context5.n) {
|
|
273
|
+
case 0:
|
|
274
|
+
finish({
|
|
275
|
+
cart: {
|
|
276
|
+
id: 99,
|
|
277
|
+
token: 'new-token'
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
_context5.n = 1;
|
|
281
|
+
return Promise.all([first, second]);
|
|
282
|
+
case 1:
|
|
283
|
+
return _context5.a(2);
|
|
284
|
+
}
|
|
285
|
+
}, _callee5);
|
|
286
|
+
})));
|
|
287
|
+
case 3:
|
|
288
|
+
expect(context.cart.id).toBe(99);
|
|
289
|
+
expect(context.fetchingCart).toBe(false);
|
|
290
|
+
expect(setCartCookie).toHaveBeenCalledTimes(1);
|
|
291
|
+
case 4:
|
|
292
|
+
return _context6.a(2);
|
|
293
|
+
}
|
|
294
|
+
}, _callee6);
|
|
295
|
+
})));
|
|
296
|
+
it('shares an active saved-cart read and allows a later refresh', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
|
|
297
|
+
var finish, saved, read;
|
|
298
|
+
return _regenerator().w(function (_context1) {
|
|
299
|
+
while (1) switch (_context1.n) {
|
|
300
|
+
case 0:
|
|
301
|
+
saved = {
|
|
302
|
+
toJson: function toJson() {
|
|
303
|
+
return {
|
|
304
|
+
id: 42,
|
|
305
|
+
isTest: false,
|
|
306
|
+
cartItems: [{
|
|
307
|
+
id: 7
|
|
308
|
+
}]
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
mockGet.mockImplementationOnce(function () {
|
|
313
|
+
return new Promise(function (resolve) {
|
|
314
|
+
finish = resolve;
|
|
315
|
+
});
|
|
316
|
+
}).mockResolvedValue(saved);
|
|
317
|
+
_context1.n = 1;
|
|
318
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
|
|
319
|
+
return _regenerator().w(function (_context7) {
|
|
320
|
+
while (1) switch (_context7.n) {
|
|
321
|
+
case 0:
|
|
322
|
+
return _context7.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
323
|
+
domainId: 5,
|
|
324
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
325
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
326
|
+
})));
|
|
327
|
+
}
|
|
328
|
+
}, _callee7);
|
|
329
|
+
})));
|
|
330
|
+
case 1:
|
|
331
|
+
_context1.n = 2;
|
|
332
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
333
|
+
return _regenerator().w(function (_context8) {
|
|
334
|
+
while (1) switch (_context8.n) {
|
|
335
|
+
case 0:
|
|
336
|
+
context.toggleCartModal();
|
|
337
|
+
read = window.getCart();
|
|
338
|
+
case 1:
|
|
339
|
+
return _context8.a(2);
|
|
340
|
+
}
|
|
341
|
+
}, _callee8);
|
|
342
|
+
})));
|
|
343
|
+
case 2:
|
|
344
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
345
|
+
_context1.n = 3;
|
|
346
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
|
|
347
|
+
return _regenerator().w(function (_context9) {
|
|
348
|
+
while (1) switch (_context9.n) {
|
|
349
|
+
case 0:
|
|
350
|
+
finish(saved);
|
|
351
|
+
_context9.n = 1;
|
|
352
|
+
return read;
|
|
353
|
+
case 1:
|
|
354
|
+
return _context9.a(2);
|
|
355
|
+
}
|
|
356
|
+
}, _callee9);
|
|
357
|
+
})));
|
|
358
|
+
case 3:
|
|
359
|
+
_context1.n = 4;
|
|
360
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
|
|
361
|
+
return _regenerator().w(function (_context0) {
|
|
362
|
+
while (1) switch (_context0.n) {
|
|
363
|
+
case 0:
|
|
364
|
+
_context0.n = 1;
|
|
365
|
+
return window.getCart();
|
|
366
|
+
case 1:
|
|
367
|
+
return _context0.a(2);
|
|
368
|
+
}
|
|
369
|
+
}, _callee0);
|
|
370
|
+
})));
|
|
371
|
+
case 4:
|
|
372
|
+
expect(mockGet).toHaveBeenCalledTimes(2);
|
|
373
|
+
expect(mockPost).not.toHaveBeenCalled();
|
|
374
|
+
expect(context.cart.cartItems).toHaveLength(1);
|
|
375
|
+
case 5:
|
|
376
|
+
return _context1.a(2);
|
|
377
|
+
}
|
|
378
|
+
}, _callee1);
|
|
379
|
+
})));
|
|
380
|
+
it('releases failed initialization so an explicit retry can create the cart', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
|
|
381
|
+
return _regenerator().w(function (_context12) {
|
|
382
|
+
while (1) switch (_context12.n) {
|
|
383
|
+
case 0:
|
|
384
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
385
|
+
mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
|
|
386
|
+
_context12.n = 1;
|
|
387
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
|
|
388
|
+
return _regenerator().w(function (_context10) {
|
|
389
|
+
while (1) switch (_context10.n) {
|
|
390
|
+
case 0:
|
|
391
|
+
return _context10.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
392
|
+
domainId: 5,
|
|
393
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
394
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
395
|
+
})));
|
|
396
|
+
}
|
|
397
|
+
}, _callee10);
|
|
398
|
+
})));
|
|
399
|
+
case 1:
|
|
400
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
401
|
+
expect(context.fetchingCart).toBe(false);
|
|
402
|
+
_context12.n = 2;
|
|
403
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
|
|
404
|
+
return _regenerator().w(function (_context11) {
|
|
405
|
+
while (1) switch (_context11.n) {
|
|
406
|
+
case 0:
|
|
407
|
+
_context11.n = 1;
|
|
408
|
+
return Promise.all([window.getCart(), window.getCart()]);
|
|
409
|
+
case 1:
|
|
410
|
+
return _context11.a(2);
|
|
411
|
+
}
|
|
412
|
+
}, _callee11);
|
|
413
|
+
})));
|
|
414
|
+
case 2:
|
|
415
|
+
expect(mockPost).toHaveBeenCalledTimes(2);
|
|
416
|
+
expect(context.cart.id).toBe(99);
|
|
417
|
+
expect(context.fetchingCart).toBe(false);
|
|
418
|
+
case 3:
|
|
419
|
+
return _context12.a(2);
|
|
420
|
+
}
|
|
421
|
+
}, _callee12);
|
|
422
|
+
})));
|
|
423
|
+
it('initializes a changed domain independently of the previous pending domain', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
|
|
424
|
+
var finish, view, current;
|
|
425
|
+
return _regenerator().w(function (_context18) {
|
|
426
|
+
while (1) switch (_context18.n) {
|
|
427
|
+
case 0:
|
|
428
|
+
finish = {};
|
|
429
|
+
getCartCookie.mockImplementation(function (id) {
|
|
430
|
+
return Promise.resolve([String(id), 'token']);
|
|
431
|
+
});
|
|
432
|
+
mockGet.mockImplementation(function (id) {
|
|
433
|
+
return new Promise(function (resolve) {
|
|
434
|
+
finish[id] = resolve;
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
view = function view(id) {
|
|
438
|
+
return /*#__PURE__*/_jsx(CartProvider, {
|
|
439
|
+
domainId: id,
|
|
440
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
441
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
_context18.n = 1;
|
|
445
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
|
|
446
|
+
return _regenerator().w(function (_context13) {
|
|
447
|
+
while (1) switch (_context13.n) {
|
|
448
|
+
case 0:
|
|
449
|
+
return _context13.a(2, root.render(view(5)));
|
|
450
|
+
}
|
|
451
|
+
}, _callee13);
|
|
452
|
+
})));
|
|
453
|
+
case 1:
|
|
454
|
+
_context18.n = 2;
|
|
455
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14() {
|
|
456
|
+
return _regenerator().w(function (_context14) {
|
|
457
|
+
while (1) switch (_context14.n) {
|
|
458
|
+
case 0:
|
|
459
|
+
return _context14.a(2, root.render(view(6)));
|
|
460
|
+
}
|
|
461
|
+
}, _callee14);
|
|
462
|
+
})));
|
|
463
|
+
case 2:
|
|
464
|
+
expect(mockGet).toHaveBeenCalledTimes(2);
|
|
465
|
+
_context18.n = 3;
|
|
466
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15() {
|
|
467
|
+
return _regenerator().w(function (_context15) {
|
|
468
|
+
while (1) switch (_context15.n) {
|
|
469
|
+
case 0:
|
|
470
|
+
return _context15.a(2, finish[5]({
|
|
471
|
+
toJson: function toJson() {
|
|
472
|
+
return {
|
|
473
|
+
id: 5,
|
|
474
|
+
isTest: false
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
}));
|
|
478
|
+
}
|
|
479
|
+
}, _callee15);
|
|
480
|
+
})));
|
|
481
|
+
case 3:
|
|
482
|
+
_context18.n = 4;
|
|
483
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16() {
|
|
484
|
+
return _regenerator().w(function (_context16) {
|
|
485
|
+
while (1) switch (_context16.n) {
|
|
486
|
+
case 0:
|
|
487
|
+
current = window.getCart();
|
|
488
|
+
case 1:
|
|
489
|
+
return _context16.a(2);
|
|
490
|
+
}
|
|
491
|
+
}, _callee16);
|
|
492
|
+
})));
|
|
493
|
+
case 4:
|
|
494
|
+
expect(mockGet).toHaveBeenCalledTimes(2);
|
|
495
|
+
_context18.n = 5;
|
|
496
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
|
|
497
|
+
return _regenerator().w(function (_context17) {
|
|
498
|
+
while (1) switch (_context17.n) {
|
|
499
|
+
case 0:
|
|
500
|
+
finish[6]({
|
|
501
|
+
toJson: function toJson() {
|
|
502
|
+
return {
|
|
503
|
+
id: 6,
|
|
504
|
+
isTest: false
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
_context17.n = 1;
|
|
509
|
+
return current;
|
|
510
|
+
case 1:
|
|
511
|
+
return _context17.a(2);
|
|
512
|
+
}
|
|
513
|
+
}, _callee17);
|
|
514
|
+
})));
|
|
515
|
+
case 5:
|
|
516
|
+
expect(context.cart.id).toBe(6);
|
|
517
|
+
case 6:
|
|
518
|
+
return _context18.a(2);
|
|
519
|
+
}
|
|
520
|
+
}, _callee18);
|
|
521
|
+
})));
|
|
227
522
|
it.each([new TypeError('Load failed'), {
|
|
228
523
|
statusCode: 502,
|
|
229
524
|
message: 'Gateway unavailable'
|
|
@@ -231,11 +526,11 @@ describe('cart load and replacement failures', function () {
|
|
|
231
526
|
statusCode: 403,
|
|
232
527
|
message: 'Forbidden'
|
|
233
528
|
}])('preserves the saved cart and never POSTs a replacement after %s', /*#__PURE__*/function () {
|
|
234
|
-
var
|
|
235
|
-
return _regenerator().w(function (
|
|
236
|
-
while (1) switch (
|
|
529
|
+
var _ref19 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(error) {
|
|
530
|
+
return _regenerator().w(function (_context19) {
|
|
531
|
+
while (1) switch (_context19.n) {
|
|
237
532
|
case 0:
|
|
238
|
-
|
|
533
|
+
_context19.n = 1;
|
|
239
534
|
return mount(error);
|
|
240
535
|
case 1:
|
|
241
536
|
expect(getCartCookie).toHaveBeenCalledWith(5);
|
|
@@ -251,20 +546,20 @@ describe('cart load and replacement failures', function () {
|
|
|
251
546
|
expect(context.fetchingCart).toBe(false);
|
|
252
547
|
expect(reportCartFailure).toHaveBeenCalledWith(error, CART_FAILURE_SOURCES.load);
|
|
253
548
|
case 2:
|
|
254
|
-
return
|
|
549
|
+
return _context19.a(2);
|
|
255
550
|
}
|
|
256
|
-
},
|
|
551
|
+
}, _callee19);
|
|
257
552
|
}));
|
|
258
553
|
return function (_x2) {
|
|
259
|
-
return
|
|
554
|
+
return _ref19.apply(this, arguments);
|
|
260
555
|
};
|
|
261
556
|
}());
|
|
262
557
|
it.each([404, 410])('replaces a genuinely missing cart after HTTP %s', /*#__PURE__*/function () {
|
|
263
|
-
var
|
|
264
|
-
return _regenerator().w(function (
|
|
265
|
-
while (1) switch (
|
|
558
|
+
var _ref20 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(statusCode) {
|
|
559
|
+
return _regenerator().w(function (_context20) {
|
|
560
|
+
while (1) switch (_context20.n) {
|
|
266
561
|
case 0:
|
|
267
|
-
|
|
562
|
+
_context20.n = 1;
|
|
268
563
|
return mount({
|
|
269
564
|
statusCode: statusCode
|
|
270
565
|
});
|
|
@@ -275,19 +570,19 @@ describe('cart load and replacement failures', function () {
|
|
|
275
570
|
}));
|
|
276
571
|
expect(setCartCookie).toHaveBeenCalledTimes(1);
|
|
277
572
|
case 2:
|
|
278
|
-
return
|
|
573
|
+
return _context20.a(2);
|
|
279
574
|
}
|
|
280
|
-
},
|
|
575
|
+
}, _callee20);
|
|
281
576
|
}));
|
|
282
577
|
return function (_x3) {
|
|
283
|
-
return
|
|
578
|
+
return _ref20.apply(this, arguments);
|
|
284
579
|
};
|
|
285
580
|
}());
|
|
286
|
-
it('allows an explicit retry to restore the same cart without creating another', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
287
|
-
return _regenerator().w(function (
|
|
288
|
-
while (1) switch (
|
|
581
|
+
it('allows an explicit retry to restore the same cart without creating another', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22() {
|
|
582
|
+
return _regenerator().w(function (_context22) {
|
|
583
|
+
while (1) switch (_context22.n) {
|
|
289
584
|
case 0:
|
|
290
|
-
|
|
585
|
+
_context22.n = 1;
|
|
291
586
|
return mount(new TypeError('Load failed'));
|
|
292
587
|
case 1:
|
|
293
588
|
mockGet.mockResolvedValue({
|
|
@@ -301,50 +596,50 @@ describe('cart load and replacement failures', function () {
|
|
|
301
596
|
};
|
|
302
597
|
}
|
|
303
598
|
});
|
|
304
|
-
|
|
305
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
306
|
-
return _regenerator().w(function (
|
|
307
|
-
while (1) switch (
|
|
599
|
+
_context22.n = 2;
|
|
600
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21() {
|
|
601
|
+
return _regenerator().w(function (_context21) {
|
|
602
|
+
while (1) switch (_context21.n) {
|
|
308
603
|
case 0:
|
|
309
|
-
|
|
604
|
+
_context21.n = 1;
|
|
310
605
|
return window.getCart();
|
|
311
606
|
case 1:
|
|
312
|
-
return
|
|
607
|
+
return _context21.a(2);
|
|
313
608
|
}
|
|
314
|
-
},
|
|
609
|
+
}, _callee21);
|
|
315
610
|
})));
|
|
316
611
|
case 2:
|
|
317
612
|
expect(context.cart.id).toBe(42);
|
|
318
613
|
expect(context.cart.cartItems).toHaveLength(1);
|
|
319
614
|
expect(mockPost).not.toHaveBeenCalled();
|
|
320
615
|
case 3:
|
|
321
|
-
return
|
|
616
|
+
return _context22.a(2);
|
|
322
617
|
}
|
|
323
|
-
},
|
|
618
|
+
}, _callee22);
|
|
324
619
|
})));
|
|
325
620
|
it.each([new TypeError('Failed to fetch'), {
|
|
326
621
|
statusCode: 503,
|
|
327
622
|
message: 'Service unavailable'
|
|
328
623
|
}, null, undefined])('keeps the clear-cart panel and saved cart when replacement fails with %s', /*#__PURE__*/function () {
|
|
329
|
-
var
|
|
330
|
-
return _regenerator().w(function (
|
|
331
|
-
while (1) switch (
|
|
624
|
+
var _ref23 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(error) {
|
|
625
|
+
return _regenerator().w(function (_context24) {
|
|
626
|
+
while (1) switch (_context24.n) {
|
|
332
627
|
case 0:
|
|
333
|
-
|
|
628
|
+
_context24.n = 1;
|
|
334
629
|
return mountSavedCart();
|
|
335
630
|
case 1:
|
|
336
631
|
mockPost.mockRejectedValueOnce(error);
|
|
337
|
-
|
|
338
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
339
|
-
return _regenerator().w(function (
|
|
340
|
-
while (1) switch (
|
|
632
|
+
_context24.n = 2;
|
|
633
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23() {
|
|
634
|
+
return _regenerator().w(function (_context23) {
|
|
635
|
+
while (1) switch (_context23.n) {
|
|
341
636
|
case 0:
|
|
342
|
-
|
|
637
|
+
_context23.n = 1;
|
|
343
638
|
return context.clearCart();
|
|
344
639
|
case 1:
|
|
345
|
-
return
|
|
640
|
+
return _context23.a(2);
|
|
346
641
|
}
|
|
347
|
-
},
|
|
642
|
+
}, _callee23);
|
|
348
643
|
})));
|
|
349
644
|
case 2:
|
|
350
645
|
expect(context.activeTabIndex).toBe(tabIdClearCart);
|
|
@@ -362,47 +657,47 @@ describe('cart load and replacement failures', function () {
|
|
|
362
657
|
expect(context.alert.message).toBe((error === null || error === void 0 ? void 0 : error.message) || 'Unable to fetch cart.');
|
|
363
658
|
expect(context.fetchingCart).toBe(false);
|
|
364
659
|
case 3:
|
|
365
|
-
return
|
|
660
|
+
return _context24.a(2);
|
|
366
661
|
}
|
|
367
|
-
},
|
|
662
|
+
}, _callee24);
|
|
368
663
|
}));
|
|
369
664
|
return function (_x4) {
|
|
370
|
-
return
|
|
665
|
+
return _ref23.apply(this, arguments);
|
|
371
666
|
};
|
|
372
667
|
}());
|
|
373
|
-
it('finishes clearing only after an explicit retry successfully creates the replacement', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
374
|
-
return _regenerator().w(function (
|
|
375
|
-
while (1) switch (
|
|
668
|
+
it('finishes clearing only after an explicit retry successfully creates the replacement', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27() {
|
|
669
|
+
return _regenerator().w(function (_context27) {
|
|
670
|
+
while (1) switch (_context27.n) {
|
|
376
671
|
case 0:
|
|
377
|
-
|
|
672
|
+
_context27.n = 1;
|
|
378
673
|
return mountSavedCart();
|
|
379
674
|
case 1:
|
|
380
675
|
mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
|
|
381
|
-
|
|
382
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
383
|
-
return _regenerator().w(function (
|
|
384
|
-
while (1) switch (
|
|
676
|
+
_context27.n = 2;
|
|
677
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25() {
|
|
678
|
+
return _regenerator().w(function (_context25) {
|
|
679
|
+
while (1) switch (_context25.n) {
|
|
385
680
|
case 0:
|
|
386
|
-
|
|
681
|
+
_context25.n = 1;
|
|
387
682
|
return context.clearCart();
|
|
388
683
|
case 1:
|
|
389
|
-
return
|
|
684
|
+
return _context25.a(2);
|
|
390
685
|
}
|
|
391
|
-
},
|
|
686
|
+
}, _callee25);
|
|
392
687
|
})));
|
|
393
688
|
case 2:
|
|
394
689
|
expect(context.activeTabIndex).toBe(tabIdClearCart);
|
|
395
|
-
|
|
396
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
397
|
-
return _regenerator().w(function (
|
|
398
|
-
while (1) switch (
|
|
690
|
+
_context27.n = 3;
|
|
691
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26() {
|
|
692
|
+
return _regenerator().w(function (_context26) {
|
|
693
|
+
while (1) switch (_context26.n) {
|
|
399
694
|
case 0:
|
|
400
|
-
|
|
695
|
+
_context26.n = 1;
|
|
401
696
|
return context.clearCart();
|
|
402
697
|
case 1:
|
|
403
|
-
return
|
|
698
|
+
return _context26.a(2);
|
|
404
699
|
}
|
|
405
|
-
},
|
|
700
|
+
}, _callee26);
|
|
406
701
|
})));
|
|
407
702
|
case 3:
|
|
408
703
|
expect(mockPost).toHaveBeenCalledTimes(2);
|
|
@@ -412,8 +707,8 @@ describe('cart load and replacement failures', function () {
|
|
|
412
707
|
expect(context.alert.show).toBe(false);
|
|
413
708
|
expect(context.fetchingCart).toBe(false);
|
|
414
709
|
case 4:
|
|
415
|
-
return
|
|
710
|
+
return _context27.a(2);
|
|
416
711
|
}
|
|
417
|
-
},
|
|
712
|
+
}, _callee27);
|
|
418
713
|
})));
|
|
419
714
|
});
|