@merchi/cart 1.4.63 → 1.4.65

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.
@@ -1,7 +1,13 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
2
3
  function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
3
4
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
4
5
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
10
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
11
  import * as React from 'react';
6
12
  import { createRoot } from 'react-dom/client';
7
13
  import { act } from 'react-dom/test-utils';
@@ -9,9 +15,10 @@ import CartProvider, { useCartContext } from './CartProvider';
9
15
  import { getCartCookie, setCartCookie } from './utilities/cookie';
10
16
  import { reportCartFailure, CART_FAILURE_SOURCES } from './utilities/reportFailure';
11
17
  import { tabIdClearCart, tabIdItems } from './utilities/tabs';
12
- import { jsx as _jsx } from "react/jsx-runtime";
18
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
19
  var mockGet = jest.fn();
14
20
  var mockPost = jest.fn();
21
+ var mockCreateItem = jest.fn();
15
22
  jest.mock('@merchi/sdk', function () {
16
23
  return {
17
24
  Merchi: jest.fn().mockImplementation(function () {
@@ -30,13 +37,22 @@ jest.mock('@merchi/sdk', function () {
30
37
  });
31
38
  jest.mock('./utilities/product', function () {
32
39
  return {
33
- makeProduct: jest.fn()
40
+ makeProduct: jest.fn(function (json) {
41
+ return json;
42
+ })
43
+ };
44
+ });
45
+ jest.mock('./utilities/job', function () {
46
+ return {
47
+ makeJob: jest.fn(function (json) {
48
+ return json;
49
+ })
34
50
  };
35
51
  });
36
52
  jest.mock('./utilities/cart', function () {
37
53
  return {
38
- makeCart: function makeCart() {
39
- return {
54
+ makeCart: function makeCart(json) {
55
+ return _objectSpread(_objectSpread({}, json), {}, {
40
56
  toFormData: function toFormData() {
41
57
  return new FormData();
42
58
  },
@@ -48,6 +64,11 @@ jest.mock('./utilities/cart', function () {
48
64
  isTest: false
49
65
  };
50
66
  }
67
+ });
68
+ },
69
+ makeCartItem: function makeCartItem() {
70
+ return {
71
+ create: mockCreateItem
51
72
  };
52
73
  },
53
74
  stripeIsValidAndActive: function stripeIsValidAndActive() {
@@ -89,6 +110,9 @@ jest.mock('./utilities/job_source', function () {
89
110
  jest.mock('./utilities/reportFailure', function () {
90
111
  return {
91
112
  reportCartFailure: jest.fn(),
113
+ reportAddCartItemFailure: jest.fn(function (error, onError) {
114
+ return onError(error);
115
+ }),
92
116
  CART_FAILURE_SOURCES: {
93
117
  load: 'cart.load',
94
118
  create: 'cart.create'
@@ -100,11 +124,41 @@ function Probe() {
100
124
  context = useCartContext();
101
125
  return null;
102
126
  }
127
+ var bindingNames = ['addCartItem', 'toggleCartOpen', 'getCart', 'getMerchiCartValues', 'isMerchiCartFetching', 'setCartComplete', 'refetchCart', 'createCartAndCookie'];
103
128
  describe('cart load and replacement failures', function () {
104
129
  var root;
105
130
  var container;
131
+ var userAgentDescriptor = Object.getOwnPropertyDescriptor(navigator, 'userAgent');
132
+ var headlessUserAgent = 'Mozilla/5.0 (X11; Linux x86_64) HeadlessChrome/153.0.8010.0 Safari/537.36';
133
+ function setUserAgent(value) {
134
+ Object.defineProperty(navigator, 'userAgent', {
135
+ configurable: true,
136
+ value: value
137
+ });
138
+ }
106
139
  beforeEach(function () {
140
+ for (var _i = 0, _bindingNames = bindingNames; _i < _bindingNames.length; _i++) {
141
+ var name = _bindingNames[_i];
142
+ delete window[name];
143
+ }
107
144
  jest.clearAllMocks();
145
+ mockGet.mockReset();
146
+ mockPost.mockReset();
147
+ mockCreateItem.mockReset();
148
+ mockCreateItem.mockImplementation(function () {
149
+ var _this = this;
150
+ return Promise.resolve({
151
+ toJson: function toJson() {
152
+ return {
153
+ id: 7,
154
+ cart: {
155
+ id: _this.cart.id
156
+ }
157
+ };
158
+ }
159
+ });
160
+ });
161
+ getCartCookie.mockReset();
108
162
  globalThis.IS_REACT_ACT_ENVIRONMENT = true;
109
163
  container = document.createElement('div');
110
164
  document.body.appendChild(container);
@@ -132,6 +186,7 @@ describe('cart load and replacement failures', function () {
132
186
  })));
133
187
  case 1:
134
188
  container.remove();
189
+ if (userAgentDescriptor) Object.defineProperty(navigator, 'userAgent', userAgentDescriptor);else delete navigator.userAgent;
135
190
  case 2:
136
191
  return _context2.a(2);
137
192
  }
@@ -141,15 +196,15 @@ describe('cart load and replacement failures', function () {
141
196
  return _mount.apply(this, arguments);
142
197
  }
143
198
  function _mount() {
144
- _mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(error) {
145
- return _regenerator().w(function (_context29) {
146
- while (1) switch (_context29.n) {
199
+ _mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(error) {
200
+ return _regenerator().w(function (_context81) {
201
+ while (1) switch (_context81.n) {
147
202
  case 0:
148
203
  mockGet.mockRejectedValue(error);
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) {
204
+ _context81.n = 1;
205
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80() {
206
+ return _regenerator().w(function (_context80) {
207
+ while (1) switch (_context80.n) {
153
208
  case 0:
154
209
  root.render(/*#__PURE__*/_jsx(CartProvider, {
155
210
  domainId: 5,
@@ -163,14 +218,14 @@ describe('cart load and replacement failures', function () {
163
218
  children: /*#__PURE__*/_jsx(Probe, {})
164
219
  }));
165
220
  case 1:
166
- return _context28.a(2);
221
+ return _context80.a(2);
167
222
  }
168
- }, _callee28);
223
+ }, _callee80);
169
224
  })));
170
225
  case 1:
171
- return _context29.a(2);
226
+ return _context81.a(2);
172
227
  }
173
- }, _callee29);
228
+ }, _callee81);
174
229
  }));
175
230
  return _mount.apply(this, arguments);
176
231
  }
@@ -178,9 +233,9 @@ describe('cart load and replacement failures', function () {
178
233
  return _mountSavedCart.apply(this, arguments);
179
234
  }
180
235
  function _mountSavedCart() {
181
- _mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32() {
182
- return _regenerator().w(function (_context32) {
183
- while (1) switch (_context32.n) {
236
+ _mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84() {
237
+ return _regenerator().w(function (_context84) {
238
+ while (1) switch (_context84.n) {
184
239
  case 0:
185
240
  mockGet.mockResolvedValue({
186
241
  toJson: function toJson() {
@@ -193,10 +248,10 @@ describe('cart load and replacement failures', function () {
193
248
  };
194
249
  }
195
250
  });
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) {
251
+ _context84.n = 1;
252
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82() {
253
+ return _regenerator().w(function (_context82) {
254
+ while (1) switch (_context82.n) {
200
255
  case 0:
201
256
  root.render(/*#__PURE__*/_jsx(CartProvider, {
202
257
  domainId: 5,
@@ -204,116 +259,118 @@ describe('cart load and replacement failures', function () {
204
259
  children: /*#__PURE__*/_jsx(Probe, {})
205
260
  }));
206
261
  case 1:
207
- return _context30.a(2);
262
+ return _context82.a(2);
208
263
  }
209
- }, _callee30);
264
+ }, _callee82);
210
265
  })));
211
266
  case 1:
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) {
267
+ _context84.n = 2;
268
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83() {
269
+ return _regenerator().w(function (_context83) {
270
+ while (1) switch (_context83.n) {
216
271
  case 0:
217
- return _context31.a(2, context.setActiveTabIndex(tabIdClearCart));
272
+ return _context83.a(2, context.setActiveTabIndex(tabIdClearCart));
218
273
  }
219
- }, _callee31);
274
+ }, _callee83);
220
275
  })));
221
276
  case 2:
222
- return _context32.a(2);
277
+ return _context84.a(2);
223
278
  }
224
- }, _callee32);
279
+ }, _callee84);
225
280
  }));
226
281
  return _mountSavedCart.apply(this, arguments);
227
282
  }
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;
283
+ it('does not expose cart operations until a suspended provider commits', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
284
+ var ready, release, gate, Suspender, _i2, _bindingNames2, name, _i3, _bindingNames3, _name, _t;
230
285
  return _regenerator().w(function (_context6) {
231
286
  while (1) switch (_context6.n) {
232
287
  case 0:
288
+ Suspender = function _Suspender() {
289
+ if (!ready) throw gate;
290
+ return null;
291
+ };
292
+ setUserAgent(headlessUserAgent);
233
293
  getCartCookie.mockResolvedValue(undefined);
234
- mockPost.mockImplementationOnce(function () {
235
- return new Promise(function (resolve) {
236
- finish = resolve;
237
- });
294
+ ready = false;
295
+ gate = new Promise(function (resolve) {
296
+ release = resolve;
238
297
  });
239
298
  _context6.n = 1;
240
299
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
241
300
  return _regenerator().w(function (_context3) {
242
301
  while (1) switch (_context3.n) {
243
302
  case 0:
244
- return _context3.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
245
- domainId: 5,
246
- createCartAndCookie: function createCartAndCookie() {},
247
- children: /*#__PURE__*/_jsx(Probe, {})
303
+ return _context3.a(2, root.render(/*#__PURE__*/_jsx(React.Suspense, {
304
+ fallback: /*#__PURE__*/_jsx("span", {
305
+ children: "Loading"
306
+ }),
307
+ children: /*#__PURE__*/_jsxs(CartProvider, {
308
+ domainId: 5,
309
+ createCartAndCookie: function createCartAndCookie() {},
310
+ children: [/*#__PURE__*/_jsx(Suspender, {}), /*#__PURE__*/_jsx(Probe, {})]
311
+ })
248
312
  })));
249
313
  }
250
314
  }, _callee3);
251
315
  })));
252
316
  case 1:
317
+ for (_i2 = 0, _bindingNames2 = bindingNames; _i2 < _bindingNames2.length; _i2++) {
318
+ name = _bindingNames2[_i2];
319
+ expect(window[name]).toBeUndefined();
320
+ }
321
+ expect(mockPost).not.toHaveBeenCalled();
253
322
  _context6.n = 2;
254
323
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
255
324
  return _regenerator().w(function (_context4) {
256
325
  while (1) switch (_context4.n) {
257
326
  case 0:
258
- context.toggleCartModal();
259
- first = window.getCart();
260
- second = window.getCart();
327
+ ready = true;
328
+ release();
261
329
  case 1:
262
330
  return _context4.a(2);
263
331
  }
264
332
  }, _callee4);
265
333
  })));
266
334
  case 2:
267
- expect(mockPost).toHaveBeenCalledTimes(1);
268
- expect(context.fetchingCart).toBe(true);
335
+ for (_i3 = 0, _bindingNames3 = bindingNames; _i3 < _bindingNames3.length; _i3++) {
336
+ _name = _bindingNames3[_i3];
337
+ expect(window[_name]).toBeInstanceOf(Function);
338
+ }
269
339
  _context6.n = 3;
270
340
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
271
341
  return _regenerator().w(function (_context5) {
272
342
  while (1) switch (_context5.n) {
273
343
  case 0:
274
- finish({
275
- cart: {
276
- id: 99,
277
- token: 'new-token'
278
- }
279
- });
280
344
  _context5.n = 1;
281
- return Promise.all([first, second]);
345
+ return window.getCart();
282
346
  case 1:
283
347
  return _context5.a(2);
284
348
  }
285
349
  }, _callee5);
286
350
  })));
287
351
  case 3:
288
- expect(context.cart.id).toBe(99);
289
- expect(context.fetchingCart).toBe(false);
290
- expect(setCartCookie).toHaveBeenCalledTimes(1);
352
+ expect(mockPost).toHaveBeenCalledTimes(1);
353
+ _t = expect;
354
+ _context6.n = 4;
355
+ return window.getMerchiCartValues();
291
356
  case 4:
357
+ _t(_context6.v.cart.id).toBe(99);
358
+ expect(context.cart.id).toBe(99);
359
+ case 5:
292
360
  return _context6.a(2);
293
361
  }
294
362
  }, _callee6);
295
363
  })));
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;
364
+ it('preserves committed operations when another provider suspends and is abandoned', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
365
+ var committed, otherRoot, gate, Suspender, _t2;
298
366
  return _regenerator().w(function (_context1) {
299
- while (1) switch (_context1.n) {
367
+ while (1) switch (_context1.p = _context1.n) {
300
368
  case 0:
301
- saved = {
302
- toJson: function toJson() {
303
- return {
304
- id: 42,
305
- isTest: false,
306
- cartItems: [{
307
- id: 7
308
- }]
309
- };
310
- }
369
+ Suspender = function _Suspender2() {
370
+ throw gate;
311
371
  };
312
- mockGet.mockImplementationOnce(function () {
313
- return new Promise(function (resolve) {
314
- finish = resolve;
315
- });
316
- }).mockResolvedValue(saved);
372
+ setUserAgent(headlessUserAgent);
373
+ getCartCookie.mockResolvedValue(undefined);
317
374
  _context1.n = 1;
318
375
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
319
376
  return _regenerator().w(function (_context7) {
@@ -328,261 +385,1158 @@ describe('cart load and replacement failures', function () {
328
385
  }, _callee7);
329
386
  })));
330
387
  case 1:
331
- _context1.n = 2;
388
+ committed = bindingNames.map(function (name) {
389
+ return window[name];
390
+ });
391
+ otherRoot = createRoot(document.createElement('div'));
392
+ gate = new Promise(function () {});
393
+ _context1.p = 2;
394
+ _context1.n = 3;
332
395
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
333
396
  return _regenerator().w(function (_context8) {
334
397
  while (1) switch (_context8.n) {
335
398
  case 0:
336
- context.toggleCartModal();
337
- read = window.getCart();
338
- case 1:
339
- return _context8.a(2);
399
+ return _context8.a(2, otherRoot.render(/*#__PURE__*/_jsx(React.Suspense, {
400
+ fallback: null,
401
+ children: /*#__PURE__*/_jsx(CartProvider, {
402
+ domainId: 6,
403
+ createCartAndCookie: function createCartAndCookie() {},
404
+ children: /*#__PURE__*/_jsx(Suspender, {})
405
+ })
406
+ })));
340
407
  }
341
408
  }, _callee8);
342
409
  })));
343
- case 2:
344
- expect(mockGet).toHaveBeenCalledTimes(1);
345
- _context1.n = 3;
410
+ case 3:
411
+ bindingNames.forEach(function (name, index) {
412
+ return expect(window[name]).toBe(committed[index]);
413
+ });
414
+ _context1.n = 4;
346
415
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
347
416
  return _regenerator().w(function (_context9) {
348
417
  while (1) switch (_context9.n) {
349
418
  case 0:
350
- finish(saved);
351
419
  _context9.n = 1;
352
- return read;
420
+ return window.getCart();
353
421
  case 1:
354
422
  return _context9.a(2);
355
423
  }
356
424
  }, _callee9);
357
425
  })));
358
- case 3:
359
- _context1.n = 4;
426
+ case 4:
427
+ expect(context.cart.id).toBe(99);
428
+ expect(mockPost).toHaveBeenCalledTimes(1);
429
+ case 5:
430
+ _context1.p = 5;
431
+ _context1.n = 6;
360
432
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
361
433
  return _regenerator().w(function (_context0) {
362
434
  while (1) switch (_context0.n) {
363
435
  case 0:
364
- _context0.n = 1;
365
- return window.getCart();
366
- case 1:
367
- return _context0.a(2);
436
+ return _context0.a(2, otherRoot.unmount());
368
437
  }
369
438
  }, _callee0);
370
439
  })));
371
- case 4:
372
- expect(mockGet).toHaveBeenCalledTimes(2);
373
- expect(mockPost).not.toHaveBeenCalled();
374
- expect(context.cart.cartItems).toHaveLength(1);
375
- case 5:
440
+ case 6:
441
+ return _context1.f(5);
442
+ case 7:
443
+ _t2 = expect;
444
+ _context1.n = 8;
445
+ return window.getMerchiCartValues();
446
+ case 8:
447
+ _t2(_context1.v.cart.id).toBe(99);
448
+ case 9:
376
449
  return _context1.a(2);
377
450
  }
378
- }, _callee1);
451
+ }, _callee1, null, [[2,, 5, 7]]);
379
452
  })));
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) {
453
+ it('removes its own global operations on unmount', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
454
+ var _i4, _bindingNames4, name;
455
+ return _regenerator().w(function (_context11) {
456
+ while (1) switch (_context11.n) {
383
457
  case 0:
384
- getCartCookie.mockResolvedValue(undefined);
385
- mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
386
- _context12.n = 1;
458
+ _context11.n = 1;
459
+ return mountSavedCart();
460
+ case 1:
461
+ _context11.n = 2;
387
462
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
388
463
  return _regenerator().w(function (_context10) {
389
464
  while (1) switch (_context10.n) {
390
465
  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
- })));
466
+ return _context10.a(2, root.render(null));
396
467
  }
397
468
  }, _callee10);
398
469
  })));
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
470
  case 2:
415
- expect(mockPost).toHaveBeenCalledTimes(2);
416
- expect(context.cart.id).toBe(99);
417
- expect(context.fetchingCart).toBe(false);
471
+ for (_i4 = 0, _bindingNames4 = bindingNames; _i4 < _bindingNames4.length; _i4++) {
472
+ name = _bindingNames4[_i4];
473
+ expect(window[name]).toBeUndefined();
474
+ }
418
475
  case 3:
419
- return _context12.a(2);
476
+ return _context11.a(2);
420
477
  }
421
- }, _callee12);
478
+ }, _callee11);
422
479
  })));
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) {
480
+ it('keeps the committed domain bindings during a suspended transition', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14() {
481
+ var gate, Suspender, tree, committed, _t3;
482
+ return _regenerator().w(function (_context14) {
483
+ while (1) switch (_context14.n) {
427
484
  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
- });
485
+ Suspender = function _Suspender3() {
486
+ throw gate;
487
+ };
488
+ setUserAgent(headlessUserAgent);
489
+ mockGet.mockResolvedValue({
490
+ toJson: function toJson() {
491
+ return {
492
+ id: 42,
493
+ cartItems: []
494
+ };
495
+ }
436
496
  });
437
- view = function view(id) {
438
- return /*#__PURE__*/_jsx(CartProvider, {
439
- domainId: id,
440
- createCartAndCookie: function createCartAndCookie() {},
441
- children: /*#__PURE__*/_jsx(Probe, {})
497
+ gate = new Promise(function () {});
498
+ tree = function tree(domainId, suspend) {
499
+ return /*#__PURE__*/_jsx(React.Suspense, {
500
+ fallback: null,
501
+ children: /*#__PURE__*/_jsx(CartProvider, {
502
+ domainId: domainId,
503
+ createCartAndCookie: function createCartAndCookie() {},
504
+ children: suspend ? /*#__PURE__*/_jsx(Suspender, {}) : /*#__PURE__*/_jsx(Probe, {})
505
+ })
442
506
  });
443
507
  };
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) {
508
+ _context14.n = 1;
509
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
510
+ return _regenerator().w(function (_context12) {
511
+ while (1) switch (_context12.n) {
448
512
  case 0:
449
- return _context13.a(2, root.render(view(5)));
513
+ return _context12.a(2, root.render(tree(5, false)));
450
514
  }
451
- }, _callee13);
515
+ }, _callee12);
452
516
  })));
453
517
  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) {
518
+ committed = bindingNames.map(function (name) {
519
+ return window[name];
520
+ });
521
+ _context14.n = 2;
522
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
523
+ return _regenerator().w(function (_context13) {
524
+ while (1) switch (_context13.n) {
458
525
  case 0:
459
- return _context14.a(2, root.render(view(6)));
526
+ React.startTransition(function () {
527
+ return root.render(tree(6, true));
528
+ });
529
+ case 1:
530
+ return _context13.a(2);
460
531
  }
461
- }, _callee14);
532
+ }, _callee13);
462
533
  })));
463
534
  case 2:
464
- expect(mockGet).toHaveBeenCalledTimes(2);
535
+ bindingNames.forEach(function (name, index) {
536
+ return expect(window[name]).toBe(committed[index]);
537
+ });
538
+ _t3 = expect;
539
+ _context14.n = 3;
540
+ return window.getMerchiCartValues();
541
+ case 3:
542
+ _t3(_context14.v.cart.id).toBe(42);
543
+ expect(mockGet).toHaveBeenCalledTimes(1);
544
+ expect(mockPost).not.toHaveBeenCalled();
545
+ case 4:
546
+ return _context14.a(2);
547
+ }
548
+ }, _callee14);
549
+ })));
550
+ it('does not remove global operations owned by another committed provider', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
551
+ var otherRoot, otherBindings, _i5, _bindingNames5, name, _t4;
552
+ return _regenerator().w(function (_context18) {
553
+ while (1) switch (_context18.p = _context18.n) {
554
+ case 0:
555
+ _context18.n = 1;
556
+ return mountSavedCart();
557
+ case 1:
558
+ otherRoot = createRoot(document.createElement('div'));
559
+ _context18.p = 2;
465
560
  _context18.n = 3;
466
561
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15() {
467
562
  return _regenerator().w(function (_context15) {
468
563
  while (1) switch (_context15.n) {
469
564
  case 0:
470
- return _context15.a(2, finish[5]({
471
- toJson: function toJson() {
472
- return {
473
- id: 5,
474
- isTest: false
475
- };
476
- }
477
- }));
565
+ return _context15.a(2, otherRoot.render(/*#__PURE__*/_jsx(CartProvider, {
566
+ domainId: 6,
567
+ createCartAndCookie: function createCartAndCookie() {},
568
+ children: /*#__PURE__*/_jsx(Probe, {})
569
+ })));
478
570
  }
479
571
  }, _callee15);
480
572
  })));
481
573
  case 3:
574
+ otherBindings = bindingNames.map(function (name) {
575
+ return window[name];
576
+ });
482
577
  _context18.n = 4;
483
578
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16() {
484
579
  return _regenerator().w(function (_context16) {
485
580
  while (1) switch (_context16.n) {
486
581
  case 0:
487
- current = window.getCart();
488
- case 1:
489
- return _context16.a(2);
582
+ return _context16.a(2, root.render(null));
490
583
  }
491
584
  }, _callee16);
492
585
  })));
493
586
  case 4:
494
- expect(mockGet).toHaveBeenCalledTimes(2);
587
+ bindingNames.forEach(function (name, index) {
588
+ return expect(window[name]).toBe(otherBindings[index]);
589
+ });
590
+ _t4 = expect;
495
591
  _context18.n = 5;
592
+ return window.getMerchiCartValues();
593
+ case 5:
594
+ _t4(_context18.v.cart.id).toBe(42);
595
+ case 6:
596
+ _context18.p = 6;
597
+ _context18.n = 7;
496
598
  return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
497
599
  return _regenerator().w(function (_context17) {
498
600
  while (1) switch (_context17.n) {
499
601
  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);
602
+ return _context17.a(2, otherRoot.unmount());
512
603
  }
513
604
  }, _callee17);
514
605
  })));
515
- case 5:
516
- expect(context.cart.id).toBe(6);
517
- case 6:
606
+ case 7:
607
+ return _context18.f(6);
608
+ case 8:
609
+ for (_i5 = 0, _bindingNames5 = bindingNames; _i5 < _bindingNames5.length; _i5++) {
610
+ name = _bindingNames5[_i5];
611
+ expect(window[name]).toBeUndefined();
612
+ }
613
+ case 9:
518
614
  return _context18.a(2);
519
615
  }
520
- }, _callee18);
616
+ }, _callee18, null, [[2,, 6, 8]]);
521
617
  })));
522
- it.each([new TypeError('Load failed'), {
523
- statusCode: 502,
524
- message: 'Gateway unavailable'
525
- }, {
526
- statusCode: 403,
527
- message: 'Forbidden'
528
- }])('preserves the saved cart and never POSTs a replacement after %s', /*#__PURE__*/function () {
529
- var _ref19 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(error) {
530
- return _regenerator().w(function (_context19) {
531
- while (1) switch (_context19.n) {
618
+ it('keeps globals usable after StrictMode setup and cleanup replay', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21() {
619
+ var _t5;
620
+ return _regenerator().w(function (_context21) {
621
+ while (1) switch (_context21.n) {
622
+ case 0:
623
+ setUserAgent(headlessUserAgent);
624
+ getCartCookie.mockResolvedValue(undefined);
625
+ _context21.n = 1;
626
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19() {
627
+ return _regenerator().w(function (_context19) {
628
+ while (1) switch (_context19.n) {
629
+ case 0:
630
+ return _context19.a(2, root.render(/*#__PURE__*/_jsx(React.StrictMode, {
631
+ children: /*#__PURE__*/_jsx(CartProvider, {
632
+ domainId: 5,
633
+ createCartAndCookie: function createCartAndCookie() {},
634
+ children: /*#__PURE__*/_jsx(Probe, {})
635
+ })
636
+ })));
637
+ }
638
+ }, _callee19);
639
+ })));
640
+ case 1:
641
+ _context21.n = 2;
642
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20() {
643
+ return _regenerator().w(function (_context20) {
644
+ while (1) switch (_context20.n) {
645
+ case 0:
646
+ _context20.n = 1;
647
+ return window.getCart();
648
+ case 1:
649
+ return _context20.a(2);
650
+ }
651
+ }, _callee20);
652
+ })));
653
+ case 2:
654
+ expect(mockPost).toHaveBeenCalledTimes(1);
655
+ _t5 = expect;
656
+ _context21.n = 3;
657
+ return window.getMerchiCartValues();
658
+ case 3:
659
+ _t5(_context21.v.cart.id).toBe(99);
660
+ case 4:
661
+ return _context21.a(2);
662
+ }
663
+ }, _callee21);
664
+ })));
665
+ it.each(['Mozilla/5.0 (X11; Linux x86_64) HeadlessChrome/153.0.8010.0 Safari/537.36', 'Mozilla/5.0 (compatible; Baiduspider-render/2.0)'])('does not create an unused cart on automated startup: %s', /*#__PURE__*/function () {
666
+ var _ref22 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23(userAgent) {
667
+ return _regenerator().w(function (_context23) {
668
+ while (1) switch (_context23.n) {
532
669
  case 0:
533
- _context19.n = 1;
534
- return mount(error);
670
+ setUserAgent(userAgent);
671
+ getCartCookie.mockResolvedValue(undefined);
672
+ _context23.n = 1;
673
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22() {
674
+ return _regenerator().w(function (_context22) {
675
+ while (1) switch (_context22.n) {
676
+ case 0:
677
+ return _context22.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
678
+ domainId: 5,
679
+ createCartAndCookie: function createCartAndCookie() {},
680
+ children: /*#__PURE__*/_jsx(Probe, {})
681
+ })));
682
+ }
683
+ }, _callee22);
684
+ })));
535
685
  case 1:
536
- expect(getCartCookie).toHaveBeenCalledWith(5);
686
+ expect(mockGet).not.toHaveBeenCalled();
537
687
  expect(mockPost).not.toHaveBeenCalled();
538
- expect(setCartCookie).not.toHaveBeenCalled();
539
- expect(context.cart).toEqual({
540
- id: 42,
541
- cartItems: [{
542
- id: 7
543
- }]
544
- });
545
- expect(context.alert.show).toBe(true);
546
688
  expect(context.fetchingCart).toBe(false);
547
- expect(reportCartFailure).toHaveBeenCalledWith(error, CART_FAILURE_SOURCES.load);
689
+ expect(reportCartFailure).not.toHaveBeenCalled();
548
690
  case 2:
549
- return _context19.a(2);
691
+ return _context23.a(2);
550
692
  }
551
- }, _callee19);
693
+ }, _callee23);
552
694
  }));
553
695
  return function (_x2) {
554
- return _ref19.apply(this, arguments);
696
+ return _ref22.apply(this, arguments);
555
697
  };
556
698
  }());
557
- it.each([404, 410])('replaces a genuinely missing cart after HTTP %s', /*#__PURE__*/function () {
558
- var _ref20 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(statusCode) {
559
- return _regenerator().w(function (_context20) {
560
- while (1) switch (_context20.n) {
561
- case 0:
562
- _context20.n = 1;
563
- return mount({
564
- statusCode: statusCode
565
- });
566
- case 1:
567
- expect(mockPost).toHaveBeenCalledTimes(1);
568
- expect(mockPost).toHaveBeenCalledWith('/carts/', expect.objectContaining({
569
- method: 'POST'
570
- }));
571
- expect(setCartCookie).toHaveBeenCalledTimes(1);
572
- case 2:
573
- return _context20.a(2);
574
- }
575
- }, _callee20);
576
- }));
577
- return function (_x3) {
578
- return _ref20.apply(this, arguments);
579
- };
699
+ it('allows explicit cart opening and concurrent callers in an automated browser', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26() {
700
+ return _regenerator().w(function (_context26) {
701
+ while (1) switch (_context26.n) {
702
+ case 0:
703
+ setUserAgent(headlessUserAgent);
704
+ getCartCookie.mockResolvedValue(undefined);
705
+ _context26.n = 1;
706
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24() {
707
+ return _regenerator().w(function (_context24) {
708
+ while (1) switch (_context24.n) {
709
+ case 0:
710
+ return _context24.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
711
+ domainId: 5,
712
+ createCartAndCookie: function createCartAndCookie() {},
713
+ children: /*#__PURE__*/_jsx(Probe, {})
714
+ })));
715
+ }
716
+ }, _callee24);
717
+ })));
718
+ case 1:
719
+ expect(mockPost).not.toHaveBeenCalled();
720
+ _context26.n = 2;
721
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25() {
722
+ return _regenerator().w(function (_context25) {
723
+ while (1) switch (_context25.n) {
724
+ case 0:
725
+ context.toggleCartModal();
726
+ _context25.n = 1;
727
+ return Promise.all([window.getCart(), window.refetchCart()]);
728
+ case 1:
729
+ return _context25.a(2);
730
+ }
731
+ }, _callee25);
732
+ })));
733
+ case 2:
734
+ expect(mockPost).toHaveBeenCalledTimes(1);
735
+ expect(context.cart.id).toBe(99);
736
+ case 3:
737
+ return _context26.a(2);
738
+ }
739
+ }, _callee26);
740
+ })));
741
+ it('creates once when explicit interaction joins a pending passive cookie lookup', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30() {
742
+ var finishCookie, first, second;
743
+ return _regenerator().w(function (_context30) {
744
+ while (1) switch (_context30.n) {
745
+ case 0:
746
+ setUserAgent(headlessUserAgent);
747
+ getCartCookie.mockImplementationOnce(function () {
748
+ return new Promise(function (resolve) {
749
+ finishCookie = resolve;
750
+ });
751
+ }).mockResolvedValue(undefined);
752
+ _context30.n = 1;
753
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27() {
754
+ return _regenerator().w(function (_context27) {
755
+ while (1) switch (_context27.n) {
756
+ case 0:
757
+ return _context27.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
758
+ domainId: 5,
759
+ createCartAndCookie: function createCartAndCookie() {},
760
+ children: /*#__PURE__*/_jsx(Probe, {})
761
+ })));
762
+ }
763
+ }, _callee27);
764
+ })));
765
+ case 1:
766
+ _context30.n = 2;
767
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28() {
768
+ return _regenerator().w(function (_context28) {
769
+ while (1) switch (_context28.n) {
770
+ case 0:
771
+ first = window.getCart();
772
+ second = window.getCart();
773
+ context.toggleCartModal();
774
+ case 1:
775
+ return _context28.a(2);
776
+ }
777
+ }, _callee28);
778
+ })));
779
+ case 2:
780
+ expect(mockPost).not.toHaveBeenCalled();
781
+ _context30.n = 3;
782
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29() {
783
+ return _regenerator().w(function (_context29) {
784
+ while (1) switch (_context29.n) {
785
+ case 0:
786
+ finishCookie(undefined);
787
+ _context29.n = 1;
788
+ return Promise.all([first, second]);
789
+ case 1:
790
+ return _context29.a(2);
791
+ }
792
+ }, _callee29);
793
+ })));
794
+ case 3:
795
+ expect(mockPost).toHaveBeenCalledTimes(1);
796
+ expect(context.cart.id).toBe(99);
797
+ case 4:
798
+ return _context30.a(2);
799
+ }
800
+ }, _callee30);
801
+ })));
802
+ it('restores saved carts for automated clients without duplicating an active read', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34() {
803
+ var finish, read;
804
+ return _regenerator().w(function (_context34) {
805
+ while (1) switch (_context34.n) {
806
+ case 0:
807
+ setUserAgent(headlessUserAgent);
808
+ mockGet.mockImplementationOnce(function () {
809
+ return new Promise(function (resolve) {
810
+ finish = resolve;
811
+ });
812
+ });
813
+ _context34.n = 1;
814
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31() {
815
+ return _regenerator().w(function (_context31) {
816
+ while (1) switch (_context31.n) {
817
+ case 0:
818
+ return _context31.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
819
+ domainId: 5,
820
+ createCartAndCookie: function createCartAndCookie() {},
821
+ children: /*#__PURE__*/_jsx(Probe, {})
822
+ })));
823
+ }
824
+ }, _callee31);
825
+ })));
826
+ case 1:
827
+ _context34.n = 2;
828
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32() {
829
+ return _regenerator().w(function (_context32) {
830
+ while (1) switch (_context32.n) {
831
+ case 0:
832
+ read = window.getCart();
833
+ context.toggleCartModal();
834
+ case 1:
835
+ return _context32.a(2);
836
+ }
837
+ }, _callee32);
838
+ })));
839
+ case 2:
840
+ expect(mockGet).toHaveBeenCalledTimes(1);
841
+ _context34.n = 3;
842
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33() {
843
+ return _regenerator().w(function (_context33) {
844
+ while (1) switch (_context33.n) {
845
+ case 0:
846
+ finish({
847
+ toJson: function toJson() {
848
+ return {
849
+ id: 42,
850
+ isTest: false,
851
+ cartItems: [{
852
+ id: 7
853
+ }]
854
+ };
855
+ }
856
+ });
857
+ _context33.n = 1;
858
+ return read;
859
+ case 1:
860
+ return _context33.a(2);
861
+ }
862
+ }, _callee33);
863
+ })));
864
+ case 3:
865
+ expect(mockPost).not.toHaveBeenCalled();
866
+ expect(context.cart.cartItems).toHaveLength(1);
867
+ case 4:
868
+ return _context34.a(2);
869
+ }
870
+ }, _callee34);
871
+ })));
872
+ it('keeps explicit retry available after an automated client creation fails', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38() {
873
+ return _regenerator().w(function (_context38) {
874
+ while (1) switch (_context38.n) {
875
+ case 0:
876
+ setUserAgent(headlessUserAgent);
877
+ getCartCookie.mockResolvedValue(undefined);
878
+ mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
879
+ _context38.n = 1;
880
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35() {
881
+ return _regenerator().w(function (_context35) {
882
+ while (1) switch (_context35.n) {
883
+ case 0:
884
+ return _context35.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
885
+ domainId: 5,
886
+ createCartAndCookie: function createCartAndCookie() {},
887
+ children: /*#__PURE__*/_jsx(Probe, {})
888
+ })));
889
+ }
890
+ }, _callee35);
891
+ })));
892
+ case 1:
893
+ expect(mockPost).not.toHaveBeenCalled();
894
+ _context38.n = 2;
895
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36() {
896
+ return _regenerator().w(function (_context36) {
897
+ while (1) switch (_context36.n) {
898
+ case 0:
899
+ _context36.n = 1;
900
+ return window.getCart();
901
+ case 1:
902
+ return _context36.a(2);
903
+ }
904
+ }, _callee36);
905
+ })));
906
+ case 2:
907
+ expect(mockPost).toHaveBeenCalledTimes(1);
908
+ expect(context.fetchingCart).toBe(false);
909
+ _context38.n = 3;
910
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37() {
911
+ return _regenerator().w(function (_context37) {
912
+ while (1) switch (_context37.n) {
913
+ case 0:
914
+ _context37.n = 1;
915
+ return window.getCart();
916
+ case 1:
917
+ return _context37.a(2);
918
+ }
919
+ }, _callee37);
920
+ })));
921
+ case 3:
922
+ expect(mockPost).toHaveBeenCalledTimes(2);
923
+ expect(context.cart.id).toBe(99);
924
+ case 4:
925
+ return _context38.a(2);
926
+ }
927
+ }, _callee38);
928
+ })));
929
+ it('initializes a cart for a direct item operation without a storefront readiness helper', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41() {
930
+ var onSuccess, onError;
931
+ return _regenerator().w(function (_context41) {
932
+ while (1) switch (_context41.n) {
933
+ case 0:
934
+ setUserAgent(headlessUserAgent);
935
+ getCartCookie.mockResolvedValue(undefined);
936
+ _context41.n = 1;
937
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39() {
938
+ return _regenerator().w(function (_context39) {
939
+ while (1) switch (_context39.n) {
940
+ case 0:
941
+ return _context39.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
942
+ domainId: 5,
943
+ createCartAndCookie: function createCartAndCookie() {},
944
+ children: /*#__PURE__*/_jsx(Probe, {})
945
+ })));
946
+ }
947
+ }, _callee39);
948
+ })));
949
+ case 1:
950
+ onSuccess = jest.fn(), onError = jest.fn();
951
+ _context41.n = 2;
952
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40() {
953
+ return _regenerator().w(function (_context40) {
954
+ while (1) switch (_context40.n) {
955
+ case 0:
956
+ _context40.n = 1;
957
+ return window.addCartItem({
958
+ product: {
959
+ id: 44
960
+ },
961
+ quantity: 100
962
+ }, onSuccess, onError);
963
+ case 1:
964
+ return _context40.a(2);
965
+ }
966
+ }, _callee40);
967
+ })));
968
+ case 2:
969
+ expect(mockPost).toHaveBeenCalledTimes(1);
970
+ expect(mockCreateItem).toHaveBeenCalledTimes(1);
971
+ expect(onSuccess).toHaveBeenCalledWith({
972
+ id: 7,
973
+ cart: {
974
+ id: 99
975
+ }
976
+ });
977
+ expect(onError).not.toHaveBeenCalled();
978
+ case 3:
979
+ return _context41.a(2);
980
+ }
981
+ }, _callee41);
982
+ })));
983
+ it('rejects a direct item operation when initialization fails without posting an item', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44() {
984
+ var onSuccess, onError;
985
+ return _regenerator().w(function (_context44) {
986
+ while (1) switch (_context44.n) {
987
+ case 0:
988
+ setUserAgent(headlessUserAgent);
989
+ getCartCookie.mockResolvedValue(undefined);
990
+ mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
991
+ _context44.n = 1;
992
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42() {
993
+ return _regenerator().w(function (_context42) {
994
+ while (1) switch (_context42.n) {
995
+ case 0:
996
+ return _context42.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
997
+ domainId: 5,
998
+ createCartAndCookie: function createCartAndCookie() {},
999
+ children: /*#__PURE__*/_jsx(Probe, {})
1000
+ })));
1001
+ }
1002
+ }, _callee42);
1003
+ })));
1004
+ case 1:
1005
+ onSuccess = jest.fn(), onError = jest.fn();
1006
+ _context44.n = 2;
1007
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43() {
1008
+ return _regenerator().w(function (_context43) {
1009
+ while (1) switch (_context43.n) {
1010
+ case 0:
1011
+ _context43.n = 1;
1012
+ return window.addCartItem({
1013
+ product: {
1014
+ id: 44
1015
+ },
1016
+ quantity: 100
1017
+ }, onSuccess, onError);
1018
+ case 1:
1019
+ return _context43.a(2);
1020
+ }
1021
+ }, _callee43);
1022
+ })));
1023
+ case 2:
1024
+ expect(mockPost).toHaveBeenCalledTimes(1);
1025
+ expect(mockCreateItem).not.toHaveBeenCalled();
1026
+ expect(onSuccess).not.toHaveBeenCalled();
1027
+ expect(onError).toHaveBeenCalledTimes(1);
1028
+ expect(context.fetchingCart).toBe(false);
1029
+ case 3:
1030
+ return _context44.a(2);
1031
+ }
1032
+ }, _callee44);
1033
+ })));
1034
+ it('waits for ordinary startup before concurrent direct item operations', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48() {
1035
+ var finish, onSuccess, onError, first, second;
1036
+ return _regenerator().w(function (_context48) {
1037
+ while (1) switch (_context48.n) {
1038
+ case 0:
1039
+ getCartCookie.mockResolvedValue(undefined);
1040
+ mockPost.mockImplementationOnce(function () {
1041
+ return new Promise(function (resolve) {
1042
+ finish = resolve;
1043
+ });
1044
+ });
1045
+ _context48.n = 1;
1046
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45() {
1047
+ return _regenerator().w(function (_context45) {
1048
+ while (1) switch (_context45.n) {
1049
+ case 0:
1050
+ return _context45.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
1051
+ domainId: 5,
1052
+ createCartAndCookie: function createCartAndCookie() {},
1053
+ children: /*#__PURE__*/_jsx(Probe, {})
1054
+ })));
1055
+ }
1056
+ }, _callee45);
1057
+ })));
1058
+ case 1:
1059
+ onSuccess = jest.fn(), onError = jest.fn();
1060
+ _context48.n = 2;
1061
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46() {
1062
+ var job;
1063
+ return _regenerator().w(function (_context46) {
1064
+ while (1) switch (_context46.n) {
1065
+ case 0:
1066
+ job = {
1067
+ product: {
1068
+ id: 44
1069
+ },
1070
+ quantity: 100
1071
+ };
1072
+ first = window.addCartItem(job, onSuccess, onError);
1073
+ second = window.addCartItem(job, onSuccess, onError);
1074
+ case 1:
1075
+ return _context46.a(2);
1076
+ }
1077
+ }, _callee46);
1078
+ })));
1079
+ case 2:
1080
+ expect(mockCreateItem).not.toHaveBeenCalled();
1081
+ _context48.n = 3;
1082
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47() {
1083
+ return _regenerator().w(function (_context47) {
1084
+ while (1) switch (_context47.n) {
1085
+ case 0:
1086
+ finish({
1087
+ cart: {
1088
+ id: 99,
1089
+ token: 'new-token'
1090
+ }
1091
+ });
1092
+ _context47.n = 1;
1093
+ return Promise.all([first, second]);
1094
+ case 1:
1095
+ return _context47.a(2);
1096
+ }
1097
+ }, _callee47);
1098
+ })));
1099
+ case 3:
1100
+ expect(mockPost).toHaveBeenCalledTimes(1);
1101
+ expect(onSuccess.mock.calls.map(function (call) {
1102
+ return call[0].cart.id;
1103
+ })).toEqual([99, 99]);
1104
+ expect(onError).not.toHaveBeenCalled();
1105
+ case 4:
1106
+ return _context48.a(2);
1107
+ }
1108
+ }, _callee48);
1109
+ })));
1110
+ it('does not automatically repeat a failed item write after explicit initialization', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52() {
1111
+ var onSuccess, onError, job;
1112
+ return _regenerator().w(function (_context52) {
1113
+ while (1) switch (_context52.n) {
1114
+ case 0:
1115
+ setUserAgent(headlessUserAgent);
1116
+ getCartCookie.mockResolvedValue(undefined);
1117
+ mockCreateItem.mockRejectedValueOnce(new TypeError('Failed to fetch'));
1118
+ _context52.n = 1;
1119
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49() {
1120
+ return _regenerator().w(function (_context49) {
1121
+ while (1) switch (_context49.n) {
1122
+ case 0:
1123
+ return _context49.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
1124
+ domainId: 5,
1125
+ createCartAndCookie: function createCartAndCookie() {},
1126
+ children: /*#__PURE__*/_jsx(Probe, {})
1127
+ })));
1128
+ }
1129
+ }, _callee49);
1130
+ })));
1131
+ case 1:
1132
+ onSuccess = jest.fn(), onError = jest.fn();
1133
+ job = {
1134
+ product: {
1135
+ id: 44
1136
+ },
1137
+ quantity: 100
1138
+ };
1139
+ _context52.n = 2;
1140
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50() {
1141
+ return _regenerator().w(function (_context50) {
1142
+ while (1) switch (_context50.n) {
1143
+ case 0:
1144
+ _context50.n = 1;
1145
+ return window.addCartItem(job, onSuccess, onError);
1146
+ case 1:
1147
+ return _context50.a(2);
1148
+ }
1149
+ }, _callee50);
1150
+ })));
1151
+ case 2:
1152
+ expect(mockPost).toHaveBeenCalledTimes(1);
1153
+ expect(mockCreateItem).toHaveBeenCalledTimes(1);
1154
+ expect(onSuccess).not.toHaveBeenCalled();
1155
+ expect(onError).toHaveBeenCalledTimes(1);
1156
+ _context52.n = 3;
1157
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51() {
1158
+ return _regenerator().w(function (_context51) {
1159
+ while (1) switch (_context51.n) {
1160
+ case 0:
1161
+ _context51.n = 1;
1162
+ return window.addCartItem(job, onSuccess, onError);
1163
+ case 1:
1164
+ return _context51.a(2);
1165
+ }
1166
+ }, _callee51);
1167
+ })));
1168
+ case 3:
1169
+ expect(mockPost).toHaveBeenCalledTimes(1);
1170
+ expect(mockCreateItem).toHaveBeenCalledTimes(2);
1171
+ expect(onSuccess).toHaveBeenCalledWith({
1172
+ id: 7,
1173
+ cart: {
1174
+ id: 99
1175
+ }
1176
+ });
1177
+ case 4:
1178
+ return _context52.a(2);
1179
+ }
1180
+ }, _callee52);
1181
+ })));
1182
+ it('shares cold initialization with opening the modal and concurrent getCart callers', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56() {
1183
+ var finish, first, second;
1184
+ return _regenerator().w(function (_context56) {
1185
+ while (1) switch (_context56.n) {
1186
+ case 0:
1187
+ getCartCookie.mockResolvedValue(undefined);
1188
+ mockPost.mockImplementationOnce(function () {
1189
+ return new Promise(function (resolve) {
1190
+ finish = resolve;
1191
+ });
1192
+ });
1193
+ _context56.n = 1;
1194
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53() {
1195
+ return _regenerator().w(function (_context53) {
1196
+ while (1) switch (_context53.n) {
1197
+ case 0:
1198
+ return _context53.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
1199
+ domainId: 5,
1200
+ createCartAndCookie: function createCartAndCookie() {},
1201
+ children: /*#__PURE__*/_jsx(Probe, {})
1202
+ })));
1203
+ }
1204
+ }, _callee53);
1205
+ })));
1206
+ case 1:
1207
+ _context56.n = 2;
1208
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54() {
1209
+ return _regenerator().w(function (_context54) {
1210
+ while (1) switch (_context54.n) {
1211
+ case 0:
1212
+ context.toggleCartModal();
1213
+ first = window.getCart();
1214
+ second = window.getCart();
1215
+ case 1:
1216
+ return _context54.a(2);
1217
+ }
1218
+ }, _callee54);
1219
+ })));
1220
+ case 2:
1221
+ expect(mockPost).toHaveBeenCalledTimes(1);
1222
+ expect(context.fetchingCart).toBe(true);
1223
+ _context56.n = 3;
1224
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55() {
1225
+ return _regenerator().w(function (_context55) {
1226
+ while (1) switch (_context55.n) {
1227
+ case 0:
1228
+ finish({
1229
+ cart: {
1230
+ id: 99,
1231
+ token: 'new-token'
1232
+ }
1233
+ });
1234
+ _context55.n = 1;
1235
+ return Promise.all([first, second]);
1236
+ case 1:
1237
+ return _context55.a(2);
1238
+ }
1239
+ }, _callee55);
1240
+ })));
1241
+ case 3:
1242
+ expect(context.cart.id).toBe(99);
1243
+ expect(context.fetchingCart).toBe(false);
1244
+ expect(setCartCookie).toHaveBeenCalledTimes(1);
1245
+ case 4:
1246
+ return _context56.a(2);
1247
+ }
1248
+ }, _callee56);
1249
+ })));
1250
+ it('shares an active saved-cart read and allows a later refresh', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61() {
1251
+ var finish, saved, read;
1252
+ return _regenerator().w(function (_context61) {
1253
+ while (1) switch (_context61.n) {
1254
+ case 0:
1255
+ saved = {
1256
+ toJson: function toJson() {
1257
+ return {
1258
+ id: 42,
1259
+ isTest: false,
1260
+ cartItems: [{
1261
+ id: 7
1262
+ }]
1263
+ };
1264
+ }
1265
+ };
1266
+ mockGet.mockImplementationOnce(function () {
1267
+ return new Promise(function (resolve) {
1268
+ finish = resolve;
1269
+ });
1270
+ }).mockResolvedValue(saved);
1271
+ _context61.n = 1;
1272
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57() {
1273
+ return _regenerator().w(function (_context57) {
1274
+ while (1) switch (_context57.n) {
1275
+ case 0:
1276
+ return _context57.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
1277
+ domainId: 5,
1278
+ createCartAndCookie: function createCartAndCookie() {},
1279
+ children: /*#__PURE__*/_jsx(Probe, {})
1280
+ })));
1281
+ }
1282
+ }, _callee57);
1283
+ })));
1284
+ case 1:
1285
+ _context61.n = 2;
1286
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58() {
1287
+ return _regenerator().w(function (_context58) {
1288
+ while (1) switch (_context58.n) {
1289
+ case 0:
1290
+ context.toggleCartModal();
1291
+ read = window.getCart();
1292
+ case 1:
1293
+ return _context58.a(2);
1294
+ }
1295
+ }, _callee58);
1296
+ })));
1297
+ case 2:
1298
+ expect(mockGet).toHaveBeenCalledTimes(1);
1299
+ _context61.n = 3;
1300
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59() {
1301
+ return _regenerator().w(function (_context59) {
1302
+ while (1) switch (_context59.n) {
1303
+ case 0:
1304
+ finish(saved);
1305
+ _context59.n = 1;
1306
+ return read;
1307
+ case 1:
1308
+ return _context59.a(2);
1309
+ }
1310
+ }, _callee59);
1311
+ })));
1312
+ case 3:
1313
+ _context61.n = 4;
1314
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60() {
1315
+ return _regenerator().w(function (_context60) {
1316
+ while (1) switch (_context60.n) {
1317
+ case 0:
1318
+ _context60.n = 1;
1319
+ return window.getCart();
1320
+ case 1:
1321
+ return _context60.a(2);
1322
+ }
1323
+ }, _callee60);
1324
+ })));
1325
+ case 4:
1326
+ expect(mockGet).toHaveBeenCalledTimes(2);
1327
+ expect(mockPost).not.toHaveBeenCalled();
1328
+ expect(context.cart.cartItems).toHaveLength(1);
1329
+ case 5:
1330
+ return _context61.a(2);
1331
+ }
1332
+ }, _callee61);
1333
+ })));
1334
+ it('releases failed initialization so an explicit retry can create the cart', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64() {
1335
+ return _regenerator().w(function (_context64) {
1336
+ while (1) switch (_context64.n) {
1337
+ case 0:
1338
+ getCartCookie.mockResolvedValue(undefined);
1339
+ mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
1340
+ _context64.n = 1;
1341
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62() {
1342
+ return _regenerator().w(function (_context62) {
1343
+ while (1) switch (_context62.n) {
1344
+ case 0:
1345
+ return _context62.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
1346
+ domainId: 5,
1347
+ createCartAndCookie: function createCartAndCookie() {},
1348
+ children: /*#__PURE__*/_jsx(Probe, {})
1349
+ })));
1350
+ }
1351
+ }, _callee62);
1352
+ })));
1353
+ case 1:
1354
+ expect(mockPost).toHaveBeenCalledTimes(1);
1355
+ expect(context.fetchingCart).toBe(false);
1356
+ _context64.n = 2;
1357
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63() {
1358
+ return _regenerator().w(function (_context63) {
1359
+ while (1) switch (_context63.n) {
1360
+ case 0:
1361
+ _context63.n = 1;
1362
+ return Promise.all([window.getCart(), window.getCart()]);
1363
+ case 1:
1364
+ return _context63.a(2);
1365
+ }
1366
+ }, _callee63);
1367
+ })));
1368
+ case 2:
1369
+ expect(mockPost).toHaveBeenCalledTimes(2);
1370
+ expect(context.cart.id).toBe(99);
1371
+ expect(context.fetchingCart).toBe(false);
1372
+ case 3:
1373
+ return _context64.a(2);
1374
+ }
1375
+ }, _callee64);
1376
+ })));
1377
+ it('initializes a changed domain independently of the previous pending domain', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70() {
1378
+ var finish, view, current;
1379
+ return _regenerator().w(function (_context70) {
1380
+ while (1) switch (_context70.n) {
1381
+ case 0:
1382
+ finish = {};
1383
+ getCartCookie.mockImplementation(function (id) {
1384
+ return Promise.resolve([String(id), 'token']);
1385
+ });
1386
+ mockGet.mockImplementation(function (id) {
1387
+ return new Promise(function (resolve) {
1388
+ finish[id] = resolve;
1389
+ });
1390
+ });
1391
+ view = function view(id) {
1392
+ return /*#__PURE__*/_jsx(CartProvider, {
1393
+ domainId: id,
1394
+ createCartAndCookie: function createCartAndCookie() {},
1395
+ children: /*#__PURE__*/_jsx(Probe, {})
1396
+ });
1397
+ };
1398
+ _context70.n = 1;
1399
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65() {
1400
+ return _regenerator().w(function (_context65) {
1401
+ while (1) switch (_context65.n) {
1402
+ case 0:
1403
+ return _context65.a(2, root.render(view(5)));
1404
+ }
1405
+ }, _callee65);
1406
+ })));
1407
+ case 1:
1408
+ _context70.n = 2;
1409
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66() {
1410
+ return _regenerator().w(function (_context66) {
1411
+ while (1) switch (_context66.n) {
1412
+ case 0:
1413
+ return _context66.a(2, root.render(view(6)));
1414
+ }
1415
+ }, _callee66);
1416
+ })));
1417
+ case 2:
1418
+ expect(mockGet).toHaveBeenCalledTimes(2);
1419
+ _context70.n = 3;
1420
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67() {
1421
+ return _regenerator().w(function (_context67) {
1422
+ while (1) switch (_context67.n) {
1423
+ case 0:
1424
+ return _context67.a(2, finish[5]({
1425
+ toJson: function toJson() {
1426
+ return {
1427
+ id: 5,
1428
+ isTest: false
1429
+ };
1430
+ }
1431
+ }));
1432
+ }
1433
+ }, _callee67);
1434
+ })));
1435
+ case 3:
1436
+ _context70.n = 4;
1437
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68() {
1438
+ return _regenerator().w(function (_context68) {
1439
+ while (1) switch (_context68.n) {
1440
+ case 0:
1441
+ current = window.getCart();
1442
+ case 1:
1443
+ return _context68.a(2);
1444
+ }
1445
+ }, _callee68);
1446
+ })));
1447
+ case 4:
1448
+ expect(mockGet).toHaveBeenCalledTimes(2);
1449
+ _context70.n = 5;
1450
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee69() {
1451
+ return _regenerator().w(function (_context69) {
1452
+ while (1) switch (_context69.n) {
1453
+ case 0:
1454
+ finish[6]({
1455
+ toJson: function toJson() {
1456
+ return {
1457
+ id: 6,
1458
+ isTest: false
1459
+ };
1460
+ }
1461
+ });
1462
+ _context69.n = 1;
1463
+ return current;
1464
+ case 1:
1465
+ return _context69.a(2);
1466
+ }
1467
+ }, _callee69);
1468
+ })));
1469
+ case 5:
1470
+ expect(context.cart.id).toBe(6);
1471
+ case 6:
1472
+ return _context70.a(2);
1473
+ }
1474
+ }, _callee70);
1475
+ })));
1476
+ it.each([new TypeError('Load failed'), {
1477
+ statusCode: 502,
1478
+ message: 'Gateway unavailable'
1479
+ }, {
1480
+ statusCode: 403,
1481
+ message: 'Forbidden'
1482
+ }])('preserves the saved cart and never POSTs a replacement after %s', /*#__PURE__*/function () {
1483
+ var _ref71 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(error) {
1484
+ return _regenerator().w(function (_context71) {
1485
+ while (1) switch (_context71.n) {
1486
+ case 0:
1487
+ _context71.n = 1;
1488
+ return mount(error);
1489
+ case 1:
1490
+ expect(getCartCookie).toHaveBeenCalledWith(5);
1491
+ expect(mockPost).not.toHaveBeenCalled();
1492
+ expect(setCartCookie).not.toHaveBeenCalled();
1493
+ expect(context.cart).toEqual({
1494
+ id: 42,
1495
+ cartItems: [{
1496
+ id: 7
1497
+ }]
1498
+ });
1499
+ expect(context.alert.show).toBe(true);
1500
+ expect(context.fetchingCart).toBe(false);
1501
+ expect(reportCartFailure).toHaveBeenCalledWith(error, CART_FAILURE_SOURCES.load);
1502
+ case 2:
1503
+ return _context71.a(2);
1504
+ }
1505
+ }, _callee71);
1506
+ }));
1507
+ return function (_x3) {
1508
+ return _ref71.apply(this, arguments);
1509
+ };
580
1510
  }());
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) {
1511
+ it.each([404, 410])('replaces a genuinely missing cart after HTTP %s', /*#__PURE__*/function () {
1512
+ var _ref72 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(statusCode) {
1513
+ return _regenerator().w(function (_context72) {
1514
+ while (1) switch (_context72.n) {
1515
+ case 0:
1516
+ _context72.n = 1;
1517
+ return mount({
1518
+ statusCode: statusCode
1519
+ });
1520
+ case 1:
1521
+ expect(mockPost).toHaveBeenCalledTimes(1);
1522
+ expect(mockPost).toHaveBeenCalledWith('/carts/', expect.objectContaining({
1523
+ method: 'POST'
1524
+ }));
1525
+ expect(setCartCookie).toHaveBeenCalledTimes(1);
1526
+ case 2:
1527
+ return _context72.a(2);
1528
+ }
1529
+ }, _callee72);
1530
+ }));
1531
+ return function (_x4) {
1532
+ return _ref72.apply(this, arguments);
1533
+ };
1534
+ }());
1535
+ it('allows an explicit retry to restore the same cart without creating another', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee74() {
1536
+ return _regenerator().w(function (_context74) {
1537
+ while (1) switch (_context74.n) {
584
1538
  case 0:
585
- _context22.n = 1;
1539
+ _context74.n = 1;
586
1540
  return mount(new TypeError('Load failed'));
587
1541
  case 1:
588
1542
  mockGet.mockResolvedValue({
@@ -596,50 +1550,50 @@ describe('cart load and replacement failures', function () {
596
1550
  };
597
1551
  }
598
1552
  });
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) {
1553
+ _context74.n = 2;
1554
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee73() {
1555
+ return _regenerator().w(function (_context73) {
1556
+ while (1) switch (_context73.n) {
603
1557
  case 0:
604
- _context21.n = 1;
1558
+ _context73.n = 1;
605
1559
  return window.getCart();
606
1560
  case 1:
607
- return _context21.a(2);
1561
+ return _context73.a(2);
608
1562
  }
609
- }, _callee21);
1563
+ }, _callee73);
610
1564
  })));
611
1565
  case 2:
612
1566
  expect(context.cart.id).toBe(42);
613
1567
  expect(context.cart.cartItems).toHaveLength(1);
614
1568
  expect(mockPost).not.toHaveBeenCalled();
615
1569
  case 3:
616
- return _context22.a(2);
1570
+ return _context74.a(2);
617
1571
  }
618
- }, _callee22);
1572
+ }, _callee74);
619
1573
  })));
620
1574
  it.each([new TypeError('Failed to fetch'), {
621
1575
  statusCode: 503,
622
1576
  message: 'Service unavailable'
623
1577
  }, null, undefined])('keeps the clear-cart panel and saved cart when replacement fails with %s', /*#__PURE__*/function () {
624
- var _ref23 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(error) {
625
- return _regenerator().w(function (_context24) {
626
- while (1) switch (_context24.n) {
1578
+ var _ref75 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee76(error) {
1579
+ return _regenerator().w(function (_context76) {
1580
+ while (1) switch (_context76.n) {
627
1581
  case 0:
628
- _context24.n = 1;
1582
+ _context76.n = 1;
629
1583
  return mountSavedCart();
630
1584
  case 1:
631
1585
  mockPost.mockRejectedValueOnce(error);
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) {
1586
+ _context76.n = 2;
1587
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee75() {
1588
+ return _regenerator().w(function (_context75) {
1589
+ while (1) switch (_context75.n) {
636
1590
  case 0:
637
- _context23.n = 1;
1591
+ _context75.n = 1;
638
1592
  return context.clearCart();
639
1593
  case 1:
640
- return _context23.a(2);
1594
+ return _context75.a(2);
641
1595
  }
642
- }, _callee23);
1596
+ }, _callee75);
643
1597
  })));
644
1598
  case 2:
645
1599
  expect(context.activeTabIndex).toBe(tabIdClearCart);
@@ -657,47 +1611,47 @@ describe('cart load and replacement failures', function () {
657
1611
  expect(context.alert.message).toBe((error === null || error === void 0 ? void 0 : error.message) || 'Unable to fetch cart.');
658
1612
  expect(context.fetchingCart).toBe(false);
659
1613
  case 3:
660
- return _context24.a(2);
1614
+ return _context76.a(2);
661
1615
  }
662
- }, _callee24);
1616
+ }, _callee76);
663
1617
  }));
664
- return function (_x4) {
665
- return _ref23.apply(this, arguments);
1618
+ return function (_x5) {
1619
+ return _ref75.apply(this, arguments);
666
1620
  };
667
1621
  }());
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) {
1622
+ it('finishes clearing only after an explicit retry successfully creates the replacement', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79() {
1623
+ return _regenerator().w(function (_context79) {
1624
+ while (1) switch (_context79.n) {
671
1625
  case 0:
672
- _context27.n = 1;
1626
+ _context79.n = 1;
673
1627
  return mountSavedCart();
674
1628
  case 1:
675
1629
  mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
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) {
1630
+ _context79.n = 2;
1631
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77() {
1632
+ return _regenerator().w(function (_context77) {
1633
+ while (1) switch (_context77.n) {
680
1634
  case 0:
681
- _context25.n = 1;
1635
+ _context77.n = 1;
682
1636
  return context.clearCart();
683
1637
  case 1:
684
- return _context25.a(2);
1638
+ return _context77.a(2);
685
1639
  }
686
- }, _callee25);
1640
+ }, _callee77);
687
1641
  })));
688
1642
  case 2:
689
1643
  expect(context.activeTabIndex).toBe(tabIdClearCart);
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) {
1644
+ _context79.n = 3;
1645
+ return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78() {
1646
+ return _regenerator().w(function (_context78) {
1647
+ while (1) switch (_context78.n) {
694
1648
  case 0:
695
- _context26.n = 1;
1649
+ _context78.n = 1;
696
1650
  return context.clearCart();
697
1651
  case 1:
698
- return _context26.a(2);
1652
+ return _context78.a(2);
699
1653
  }
700
- }, _callee26);
1654
+ }, _callee78);
701
1655
  })));
702
1656
  case 3:
703
1657
  expect(mockPost).toHaveBeenCalledTimes(2);
@@ -707,8 +1661,8 @@ describe('cart load and replacement failures', function () {
707
1661
  expect(context.alert.show).toBe(false);
708
1662
  expect(context.fetchingCart).toBe(false);
709
1663
  case 4:
710
- return _context27.a(2);
1664
+ return _context79.a(2);
711
1665
  }
712
- }, _callee27);
1666
+ }, _callee79);
713
1667
  })));
714
1668
  });