@merchi/cart 1.4.62 → 1.4.64
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 +316 -243
- package/esm/CartProvider.load.test.js +957 -95
- package/esm/utilities/automatedClient.js +5 -0
- package/esm/utilities/automatedClient.test.js +9 -0
- package/lib/CartProvider.js +317 -244
- package/lib/utilities/automatedClient.d.ts +2 -0
- package/lib/utilities/automatedClient.js +11 -0
- package/lib/utilities/automatedClient.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/CartProvider.load.test.tsx +252 -2
- package/src/CartProvider.tsx +66 -32
- package/src/utilities/automatedClient.test.ts +21 -0
- package/src/utilities/automatedClient.ts +6 -0
|
@@ -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';
|
|
@@ -12,6 +18,7 @@ import { tabIdClearCart, tabIdItems } from './utilities/tabs';
|
|
|
12
18
|
import { jsx as _jsx } 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'
|
|
@@ -103,8 +127,33 @@ function Probe() {
|
|
|
103
127
|
describe('cart load and replacement failures', function () {
|
|
104
128
|
var root;
|
|
105
129
|
var container;
|
|
130
|
+
var userAgentDescriptor = Object.getOwnPropertyDescriptor(navigator, 'userAgent');
|
|
131
|
+
var headlessUserAgent = 'Mozilla/5.0 (X11; Linux x86_64) HeadlessChrome/153.0.8010.0 Safari/537.36';
|
|
132
|
+
function setUserAgent(value) {
|
|
133
|
+
Object.defineProperty(navigator, 'userAgent', {
|
|
134
|
+
configurable: true,
|
|
135
|
+
value: value
|
|
136
|
+
});
|
|
137
|
+
}
|
|
106
138
|
beforeEach(function () {
|
|
107
139
|
jest.clearAllMocks();
|
|
140
|
+
mockGet.mockReset();
|
|
141
|
+
mockPost.mockReset();
|
|
142
|
+
mockCreateItem.mockReset();
|
|
143
|
+
mockCreateItem.mockImplementation(function () {
|
|
144
|
+
var _this = this;
|
|
145
|
+
return Promise.resolve({
|
|
146
|
+
toJson: function toJson() {
|
|
147
|
+
return {
|
|
148
|
+
id: 7,
|
|
149
|
+
cart: {
|
|
150
|
+
id: _this.cart.id
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
getCartCookie.mockReset();
|
|
108
157
|
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
109
158
|
container = document.createElement('div');
|
|
110
159
|
document.body.appendChild(container);
|
|
@@ -115,6 +164,7 @@ describe('cart load and replacement failures', function () {
|
|
|
115
164
|
token: 'new-token'
|
|
116
165
|
}
|
|
117
166
|
});
|
|
167
|
+
getCartCookie.mockResolvedValue(['42', 'saved-token']);
|
|
118
168
|
});
|
|
119
169
|
afterEach(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
120
170
|
return _regenerator().w(function (_context2) {
|
|
@@ -131,6 +181,7 @@ describe('cart load and replacement failures', function () {
|
|
|
131
181
|
})));
|
|
132
182
|
case 1:
|
|
133
183
|
container.remove();
|
|
184
|
+
if (userAgentDescriptor) Object.defineProperty(navigator, 'userAgent', userAgentDescriptor);else delete navigator.userAgent;
|
|
134
185
|
case 2:
|
|
135
186
|
return _context2.a(2);
|
|
136
187
|
}
|
|
@@ -140,15 +191,15 @@ describe('cart load and replacement failures', function () {
|
|
|
140
191
|
return _mount.apply(this, arguments);
|
|
141
192
|
}
|
|
142
193
|
function _mount() {
|
|
143
|
-
_mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
144
|
-
return _regenerator().w(function (
|
|
145
|
-
while (1) switch (
|
|
194
|
+
_mount = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(error) {
|
|
195
|
+
return _regenerator().w(function (_context60) {
|
|
196
|
+
while (1) switch (_context60.n) {
|
|
146
197
|
case 0:
|
|
147
198
|
mockGet.mockRejectedValue(error);
|
|
148
|
-
|
|
149
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
150
|
-
return _regenerator().w(function (
|
|
151
|
-
while (1) switch (
|
|
199
|
+
_context60.n = 1;
|
|
200
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59() {
|
|
201
|
+
return _regenerator().w(function (_context59) {
|
|
202
|
+
while (1) switch (_context59.n) {
|
|
152
203
|
case 0:
|
|
153
204
|
root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
154
205
|
domainId: 5,
|
|
@@ -162,14 +213,14 @@ describe('cart load and replacement failures', function () {
|
|
|
162
213
|
children: /*#__PURE__*/_jsx(Probe, {})
|
|
163
214
|
}));
|
|
164
215
|
case 1:
|
|
165
|
-
return
|
|
216
|
+
return _context59.a(2);
|
|
166
217
|
}
|
|
167
|
-
},
|
|
218
|
+
}, _callee59);
|
|
168
219
|
})));
|
|
169
220
|
case 1:
|
|
170
|
-
return
|
|
221
|
+
return _context60.a(2);
|
|
171
222
|
}
|
|
172
|
-
},
|
|
223
|
+
}, _callee60);
|
|
173
224
|
}));
|
|
174
225
|
return _mount.apply(this, arguments);
|
|
175
226
|
}
|
|
@@ -177,9 +228,9 @@ describe('cart load and replacement failures', function () {
|
|
|
177
228
|
return _mountSavedCart.apply(this, arguments);
|
|
178
229
|
}
|
|
179
230
|
function _mountSavedCart() {
|
|
180
|
-
_mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
181
|
-
return _regenerator().w(function (
|
|
182
|
-
while (1) switch (
|
|
231
|
+
_mountSavedCart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63() {
|
|
232
|
+
return _regenerator().w(function (_context63) {
|
|
233
|
+
while (1) switch (_context63.n) {
|
|
183
234
|
case 0:
|
|
184
235
|
mockGet.mockResolvedValue({
|
|
185
236
|
toJson: function toJson() {
|
|
@@ -192,10 +243,10 @@ describe('cart load and replacement failures', function () {
|
|
|
192
243
|
};
|
|
193
244
|
}
|
|
194
245
|
});
|
|
195
|
-
|
|
196
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
197
|
-
return _regenerator().w(function (
|
|
198
|
-
while (1) switch (
|
|
246
|
+
_context63.n = 1;
|
|
247
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61() {
|
|
248
|
+
return _regenerator().w(function (_context61) {
|
|
249
|
+
while (1) switch (_context61.n) {
|
|
199
250
|
case 0:
|
|
200
251
|
root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
201
252
|
domainId: 5,
|
|
@@ -203,27 +254,838 @@ describe('cart load and replacement failures', function () {
|
|
|
203
254
|
children: /*#__PURE__*/_jsx(Probe, {})
|
|
204
255
|
}));
|
|
205
256
|
case 1:
|
|
206
|
-
return
|
|
257
|
+
return _context61.a(2);
|
|
207
258
|
}
|
|
208
|
-
},
|
|
259
|
+
}, _callee61);
|
|
209
260
|
})));
|
|
210
261
|
case 1:
|
|
211
|
-
|
|
212
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
213
|
-
return _regenerator().w(function (
|
|
214
|
-
while (1) switch (
|
|
262
|
+
_context63.n = 2;
|
|
263
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62() {
|
|
264
|
+
return _regenerator().w(function (_context62) {
|
|
265
|
+
while (1) switch (_context62.n) {
|
|
215
266
|
case 0:
|
|
216
|
-
return
|
|
267
|
+
return _context62.a(2, context.setActiveTabIndex(tabIdClearCart));
|
|
217
268
|
}
|
|
218
|
-
},
|
|
269
|
+
}, _callee62);
|
|
219
270
|
})));
|
|
220
271
|
case 2:
|
|
221
|
-
return
|
|
272
|
+
return _context63.a(2);
|
|
222
273
|
}
|
|
223
|
-
},
|
|
274
|
+
}, _callee63);
|
|
224
275
|
}));
|
|
225
276
|
return _mountSavedCart.apply(this, arguments);
|
|
226
277
|
}
|
|
278
|
+
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 () {
|
|
279
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(userAgent) {
|
|
280
|
+
return _regenerator().w(function (_context4) {
|
|
281
|
+
while (1) switch (_context4.n) {
|
|
282
|
+
case 0:
|
|
283
|
+
setUserAgent(userAgent);
|
|
284
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
285
|
+
_context4.n = 1;
|
|
286
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
287
|
+
return _regenerator().w(function (_context3) {
|
|
288
|
+
while (1) switch (_context3.n) {
|
|
289
|
+
case 0:
|
|
290
|
+
return _context3.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
291
|
+
domainId: 5,
|
|
292
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
293
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
294
|
+
})));
|
|
295
|
+
}
|
|
296
|
+
}, _callee3);
|
|
297
|
+
})));
|
|
298
|
+
case 1:
|
|
299
|
+
expect(mockGet).not.toHaveBeenCalled();
|
|
300
|
+
expect(mockPost).not.toHaveBeenCalled();
|
|
301
|
+
expect(context.fetchingCart).toBe(false);
|
|
302
|
+
expect(reportCartFailure).not.toHaveBeenCalled();
|
|
303
|
+
case 2:
|
|
304
|
+
return _context4.a(2);
|
|
305
|
+
}
|
|
306
|
+
}, _callee4);
|
|
307
|
+
}));
|
|
308
|
+
return function (_x2) {
|
|
309
|
+
return _ref3.apply(this, arguments);
|
|
310
|
+
};
|
|
311
|
+
}());
|
|
312
|
+
it('allows explicit cart opening and concurrent callers in an automated browser', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
|
|
313
|
+
return _regenerator().w(function (_context7) {
|
|
314
|
+
while (1) switch (_context7.n) {
|
|
315
|
+
case 0:
|
|
316
|
+
setUserAgent(headlessUserAgent);
|
|
317
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
318
|
+
_context7.n = 1;
|
|
319
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
|
|
320
|
+
return _regenerator().w(function (_context5) {
|
|
321
|
+
while (1) switch (_context5.n) {
|
|
322
|
+
case 0:
|
|
323
|
+
return _context5.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
324
|
+
domainId: 5,
|
|
325
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
326
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
327
|
+
})));
|
|
328
|
+
}
|
|
329
|
+
}, _callee5);
|
|
330
|
+
})));
|
|
331
|
+
case 1:
|
|
332
|
+
expect(mockPost).not.toHaveBeenCalled();
|
|
333
|
+
_context7.n = 2;
|
|
334
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
|
|
335
|
+
return _regenerator().w(function (_context6) {
|
|
336
|
+
while (1) switch (_context6.n) {
|
|
337
|
+
case 0:
|
|
338
|
+
context.toggleCartModal();
|
|
339
|
+
_context6.n = 1;
|
|
340
|
+
return Promise.all([window.getCart(), window.refetchCart()]);
|
|
341
|
+
case 1:
|
|
342
|
+
return _context6.a(2);
|
|
343
|
+
}
|
|
344
|
+
}, _callee6);
|
|
345
|
+
})));
|
|
346
|
+
case 2:
|
|
347
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
348
|
+
expect(context.cart.id).toBe(99);
|
|
349
|
+
case 3:
|
|
350
|
+
return _context7.a(2);
|
|
351
|
+
}
|
|
352
|
+
}, _callee7);
|
|
353
|
+
})));
|
|
354
|
+
it('creates once when explicit interaction joins a pending passive cookie lookup', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
|
|
355
|
+
var finishCookie, first, second;
|
|
356
|
+
return _regenerator().w(function (_context1) {
|
|
357
|
+
while (1) switch (_context1.n) {
|
|
358
|
+
case 0:
|
|
359
|
+
setUserAgent(headlessUserAgent);
|
|
360
|
+
getCartCookie.mockImplementationOnce(function () {
|
|
361
|
+
return new Promise(function (resolve) {
|
|
362
|
+
finishCookie = resolve;
|
|
363
|
+
});
|
|
364
|
+
}).mockResolvedValue(undefined);
|
|
365
|
+
_context1.n = 1;
|
|
366
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
367
|
+
return _regenerator().w(function (_context8) {
|
|
368
|
+
while (1) switch (_context8.n) {
|
|
369
|
+
case 0:
|
|
370
|
+
return _context8.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
371
|
+
domainId: 5,
|
|
372
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
373
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
374
|
+
})));
|
|
375
|
+
}
|
|
376
|
+
}, _callee8);
|
|
377
|
+
})));
|
|
378
|
+
case 1:
|
|
379
|
+
_context1.n = 2;
|
|
380
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
|
|
381
|
+
return _regenerator().w(function (_context9) {
|
|
382
|
+
while (1) switch (_context9.n) {
|
|
383
|
+
case 0:
|
|
384
|
+
first = window.getCart();
|
|
385
|
+
second = window.getCart();
|
|
386
|
+
context.toggleCartModal();
|
|
387
|
+
case 1:
|
|
388
|
+
return _context9.a(2);
|
|
389
|
+
}
|
|
390
|
+
}, _callee9);
|
|
391
|
+
})));
|
|
392
|
+
case 2:
|
|
393
|
+
expect(mockPost).not.toHaveBeenCalled();
|
|
394
|
+
_context1.n = 3;
|
|
395
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
|
|
396
|
+
return _regenerator().w(function (_context0) {
|
|
397
|
+
while (1) switch (_context0.n) {
|
|
398
|
+
case 0:
|
|
399
|
+
finishCookie(undefined);
|
|
400
|
+
_context0.n = 1;
|
|
401
|
+
return Promise.all([first, second]);
|
|
402
|
+
case 1:
|
|
403
|
+
return _context0.a(2);
|
|
404
|
+
}
|
|
405
|
+
}, _callee0);
|
|
406
|
+
})));
|
|
407
|
+
case 3:
|
|
408
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
409
|
+
expect(context.cart.id).toBe(99);
|
|
410
|
+
case 4:
|
|
411
|
+
return _context1.a(2);
|
|
412
|
+
}
|
|
413
|
+
}, _callee1);
|
|
414
|
+
})));
|
|
415
|
+
it('restores saved carts for automated clients without duplicating an active read', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
|
|
416
|
+
var finish, read;
|
|
417
|
+
return _regenerator().w(function (_context13) {
|
|
418
|
+
while (1) switch (_context13.n) {
|
|
419
|
+
case 0:
|
|
420
|
+
setUserAgent(headlessUserAgent);
|
|
421
|
+
mockGet.mockImplementationOnce(function () {
|
|
422
|
+
return new Promise(function (resolve) {
|
|
423
|
+
finish = resolve;
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
_context13.n = 1;
|
|
427
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
|
|
428
|
+
return _regenerator().w(function (_context10) {
|
|
429
|
+
while (1) switch (_context10.n) {
|
|
430
|
+
case 0:
|
|
431
|
+
return _context10.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
432
|
+
domainId: 5,
|
|
433
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
434
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
435
|
+
})));
|
|
436
|
+
}
|
|
437
|
+
}, _callee10);
|
|
438
|
+
})));
|
|
439
|
+
case 1:
|
|
440
|
+
_context13.n = 2;
|
|
441
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
|
|
442
|
+
return _regenerator().w(function (_context11) {
|
|
443
|
+
while (1) switch (_context11.n) {
|
|
444
|
+
case 0:
|
|
445
|
+
read = window.getCart();
|
|
446
|
+
context.toggleCartModal();
|
|
447
|
+
case 1:
|
|
448
|
+
return _context11.a(2);
|
|
449
|
+
}
|
|
450
|
+
}, _callee11);
|
|
451
|
+
})));
|
|
452
|
+
case 2:
|
|
453
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
454
|
+
_context13.n = 3;
|
|
455
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12() {
|
|
456
|
+
return _regenerator().w(function (_context12) {
|
|
457
|
+
while (1) switch (_context12.n) {
|
|
458
|
+
case 0:
|
|
459
|
+
finish({
|
|
460
|
+
toJson: function toJson() {
|
|
461
|
+
return {
|
|
462
|
+
id: 42,
|
|
463
|
+
isTest: false,
|
|
464
|
+
cartItems: [{
|
|
465
|
+
id: 7
|
|
466
|
+
}]
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
_context12.n = 1;
|
|
471
|
+
return read;
|
|
472
|
+
case 1:
|
|
473
|
+
return _context12.a(2);
|
|
474
|
+
}
|
|
475
|
+
}, _callee12);
|
|
476
|
+
})));
|
|
477
|
+
case 3:
|
|
478
|
+
expect(mockPost).not.toHaveBeenCalled();
|
|
479
|
+
expect(context.cart.cartItems).toHaveLength(1);
|
|
480
|
+
case 4:
|
|
481
|
+
return _context13.a(2);
|
|
482
|
+
}
|
|
483
|
+
}, _callee13);
|
|
484
|
+
})));
|
|
485
|
+
it('keeps explicit retry available after an automated client creation fails', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
|
|
486
|
+
return _regenerator().w(function (_context17) {
|
|
487
|
+
while (1) switch (_context17.n) {
|
|
488
|
+
case 0:
|
|
489
|
+
setUserAgent(headlessUserAgent);
|
|
490
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
491
|
+
mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
|
|
492
|
+
_context17.n = 1;
|
|
493
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14() {
|
|
494
|
+
return _regenerator().w(function (_context14) {
|
|
495
|
+
while (1) switch (_context14.n) {
|
|
496
|
+
case 0:
|
|
497
|
+
return _context14.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
498
|
+
domainId: 5,
|
|
499
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
500
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
501
|
+
})));
|
|
502
|
+
}
|
|
503
|
+
}, _callee14);
|
|
504
|
+
})));
|
|
505
|
+
case 1:
|
|
506
|
+
expect(mockPost).not.toHaveBeenCalled();
|
|
507
|
+
_context17.n = 2;
|
|
508
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15() {
|
|
509
|
+
return _regenerator().w(function (_context15) {
|
|
510
|
+
while (1) switch (_context15.n) {
|
|
511
|
+
case 0:
|
|
512
|
+
_context15.n = 1;
|
|
513
|
+
return window.getCart();
|
|
514
|
+
case 1:
|
|
515
|
+
return _context15.a(2);
|
|
516
|
+
}
|
|
517
|
+
}, _callee15);
|
|
518
|
+
})));
|
|
519
|
+
case 2:
|
|
520
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
521
|
+
expect(context.fetchingCart).toBe(false);
|
|
522
|
+
_context17.n = 3;
|
|
523
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16() {
|
|
524
|
+
return _regenerator().w(function (_context16) {
|
|
525
|
+
while (1) switch (_context16.n) {
|
|
526
|
+
case 0:
|
|
527
|
+
_context16.n = 1;
|
|
528
|
+
return window.getCart();
|
|
529
|
+
case 1:
|
|
530
|
+
return _context16.a(2);
|
|
531
|
+
}
|
|
532
|
+
}, _callee16);
|
|
533
|
+
})));
|
|
534
|
+
case 3:
|
|
535
|
+
expect(mockPost).toHaveBeenCalledTimes(2);
|
|
536
|
+
expect(context.cart.id).toBe(99);
|
|
537
|
+
case 4:
|
|
538
|
+
return _context17.a(2);
|
|
539
|
+
}
|
|
540
|
+
}, _callee17);
|
|
541
|
+
})));
|
|
542
|
+
it('initializes a cart for a direct item operation without a storefront readiness helper', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20() {
|
|
543
|
+
var onSuccess, onError;
|
|
544
|
+
return _regenerator().w(function (_context20) {
|
|
545
|
+
while (1) switch (_context20.n) {
|
|
546
|
+
case 0:
|
|
547
|
+
setUserAgent(headlessUserAgent);
|
|
548
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
549
|
+
_context20.n = 1;
|
|
550
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
|
|
551
|
+
return _regenerator().w(function (_context18) {
|
|
552
|
+
while (1) switch (_context18.n) {
|
|
553
|
+
case 0:
|
|
554
|
+
return _context18.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
555
|
+
domainId: 5,
|
|
556
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
557
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
558
|
+
})));
|
|
559
|
+
}
|
|
560
|
+
}, _callee18);
|
|
561
|
+
})));
|
|
562
|
+
case 1:
|
|
563
|
+
onSuccess = jest.fn(), onError = jest.fn();
|
|
564
|
+
_context20.n = 2;
|
|
565
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19() {
|
|
566
|
+
return _regenerator().w(function (_context19) {
|
|
567
|
+
while (1) switch (_context19.n) {
|
|
568
|
+
case 0:
|
|
569
|
+
_context19.n = 1;
|
|
570
|
+
return window.addCartItem({
|
|
571
|
+
product: {
|
|
572
|
+
id: 44
|
|
573
|
+
},
|
|
574
|
+
quantity: 100
|
|
575
|
+
}, onSuccess, onError);
|
|
576
|
+
case 1:
|
|
577
|
+
return _context19.a(2);
|
|
578
|
+
}
|
|
579
|
+
}, _callee19);
|
|
580
|
+
})));
|
|
581
|
+
case 2:
|
|
582
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
583
|
+
expect(mockCreateItem).toHaveBeenCalledTimes(1);
|
|
584
|
+
expect(onSuccess).toHaveBeenCalledWith({
|
|
585
|
+
id: 7,
|
|
586
|
+
cart: {
|
|
587
|
+
id: 99
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
expect(onError).not.toHaveBeenCalled();
|
|
591
|
+
case 3:
|
|
592
|
+
return _context20.a(2);
|
|
593
|
+
}
|
|
594
|
+
}, _callee20);
|
|
595
|
+
})));
|
|
596
|
+
it('rejects a direct item operation when initialization fails without posting an item', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23() {
|
|
597
|
+
var onSuccess, onError;
|
|
598
|
+
return _regenerator().w(function (_context23) {
|
|
599
|
+
while (1) switch (_context23.n) {
|
|
600
|
+
case 0:
|
|
601
|
+
setUserAgent(headlessUserAgent);
|
|
602
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
603
|
+
mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
|
|
604
|
+
_context23.n = 1;
|
|
605
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21() {
|
|
606
|
+
return _regenerator().w(function (_context21) {
|
|
607
|
+
while (1) switch (_context21.n) {
|
|
608
|
+
case 0:
|
|
609
|
+
return _context21.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
610
|
+
domainId: 5,
|
|
611
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
612
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
613
|
+
})));
|
|
614
|
+
}
|
|
615
|
+
}, _callee21);
|
|
616
|
+
})));
|
|
617
|
+
case 1:
|
|
618
|
+
onSuccess = jest.fn(), onError = jest.fn();
|
|
619
|
+
_context23.n = 2;
|
|
620
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22() {
|
|
621
|
+
return _regenerator().w(function (_context22) {
|
|
622
|
+
while (1) switch (_context22.n) {
|
|
623
|
+
case 0:
|
|
624
|
+
_context22.n = 1;
|
|
625
|
+
return window.addCartItem({
|
|
626
|
+
product: {
|
|
627
|
+
id: 44
|
|
628
|
+
},
|
|
629
|
+
quantity: 100
|
|
630
|
+
}, onSuccess, onError);
|
|
631
|
+
case 1:
|
|
632
|
+
return _context22.a(2);
|
|
633
|
+
}
|
|
634
|
+
}, _callee22);
|
|
635
|
+
})));
|
|
636
|
+
case 2:
|
|
637
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
638
|
+
expect(mockCreateItem).not.toHaveBeenCalled();
|
|
639
|
+
expect(onSuccess).not.toHaveBeenCalled();
|
|
640
|
+
expect(onError).toHaveBeenCalledTimes(1);
|
|
641
|
+
expect(context.fetchingCart).toBe(false);
|
|
642
|
+
case 3:
|
|
643
|
+
return _context23.a(2);
|
|
644
|
+
}
|
|
645
|
+
}, _callee23);
|
|
646
|
+
})));
|
|
647
|
+
it('waits for ordinary startup before concurrent direct item operations', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27() {
|
|
648
|
+
var finish, onSuccess, onError, first, second;
|
|
649
|
+
return _regenerator().w(function (_context27) {
|
|
650
|
+
while (1) switch (_context27.n) {
|
|
651
|
+
case 0:
|
|
652
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
653
|
+
mockPost.mockImplementationOnce(function () {
|
|
654
|
+
return new Promise(function (resolve) {
|
|
655
|
+
finish = resolve;
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
_context27.n = 1;
|
|
659
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24() {
|
|
660
|
+
return _regenerator().w(function (_context24) {
|
|
661
|
+
while (1) switch (_context24.n) {
|
|
662
|
+
case 0:
|
|
663
|
+
return _context24.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
664
|
+
domainId: 5,
|
|
665
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
666
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
667
|
+
})));
|
|
668
|
+
}
|
|
669
|
+
}, _callee24);
|
|
670
|
+
})));
|
|
671
|
+
case 1:
|
|
672
|
+
onSuccess = jest.fn(), onError = jest.fn();
|
|
673
|
+
_context27.n = 2;
|
|
674
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25() {
|
|
675
|
+
var job;
|
|
676
|
+
return _regenerator().w(function (_context25) {
|
|
677
|
+
while (1) switch (_context25.n) {
|
|
678
|
+
case 0:
|
|
679
|
+
job = {
|
|
680
|
+
product: {
|
|
681
|
+
id: 44
|
|
682
|
+
},
|
|
683
|
+
quantity: 100
|
|
684
|
+
};
|
|
685
|
+
first = window.addCartItem(job, onSuccess, onError);
|
|
686
|
+
second = window.addCartItem(job, onSuccess, onError);
|
|
687
|
+
case 1:
|
|
688
|
+
return _context25.a(2);
|
|
689
|
+
}
|
|
690
|
+
}, _callee25);
|
|
691
|
+
})));
|
|
692
|
+
case 2:
|
|
693
|
+
expect(mockCreateItem).not.toHaveBeenCalled();
|
|
694
|
+
_context27.n = 3;
|
|
695
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26() {
|
|
696
|
+
return _regenerator().w(function (_context26) {
|
|
697
|
+
while (1) switch (_context26.n) {
|
|
698
|
+
case 0:
|
|
699
|
+
finish({
|
|
700
|
+
cart: {
|
|
701
|
+
id: 99,
|
|
702
|
+
token: 'new-token'
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
_context26.n = 1;
|
|
706
|
+
return Promise.all([first, second]);
|
|
707
|
+
case 1:
|
|
708
|
+
return _context26.a(2);
|
|
709
|
+
}
|
|
710
|
+
}, _callee26);
|
|
711
|
+
})));
|
|
712
|
+
case 3:
|
|
713
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
714
|
+
expect(onSuccess.mock.calls.map(function (call) {
|
|
715
|
+
return call[0].cart.id;
|
|
716
|
+
})).toEqual([99, 99]);
|
|
717
|
+
expect(onError).not.toHaveBeenCalled();
|
|
718
|
+
case 4:
|
|
719
|
+
return _context27.a(2);
|
|
720
|
+
}
|
|
721
|
+
}, _callee27);
|
|
722
|
+
})));
|
|
723
|
+
it('does not automatically repeat a failed item write after explicit initialization', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31() {
|
|
724
|
+
var onSuccess, onError, job;
|
|
725
|
+
return _regenerator().w(function (_context31) {
|
|
726
|
+
while (1) switch (_context31.n) {
|
|
727
|
+
case 0:
|
|
728
|
+
setUserAgent(headlessUserAgent);
|
|
729
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
730
|
+
mockCreateItem.mockRejectedValueOnce(new TypeError('Failed to fetch'));
|
|
731
|
+
_context31.n = 1;
|
|
732
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28() {
|
|
733
|
+
return _regenerator().w(function (_context28) {
|
|
734
|
+
while (1) switch (_context28.n) {
|
|
735
|
+
case 0:
|
|
736
|
+
return _context28.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
737
|
+
domainId: 5,
|
|
738
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
739
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
740
|
+
})));
|
|
741
|
+
}
|
|
742
|
+
}, _callee28);
|
|
743
|
+
})));
|
|
744
|
+
case 1:
|
|
745
|
+
onSuccess = jest.fn(), onError = jest.fn();
|
|
746
|
+
job = {
|
|
747
|
+
product: {
|
|
748
|
+
id: 44
|
|
749
|
+
},
|
|
750
|
+
quantity: 100
|
|
751
|
+
};
|
|
752
|
+
_context31.n = 2;
|
|
753
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29() {
|
|
754
|
+
return _regenerator().w(function (_context29) {
|
|
755
|
+
while (1) switch (_context29.n) {
|
|
756
|
+
case 0:
|
|
757
|
+
_context29.n = 1;
|
|
758
|
+
return window.addCartItem(job, onSuccess, onError);
|
|
759
|
+
case 1:
|
|
760
|
+
return _context29.a(2);
|
|
761
|
+
}
|
|
762
|
+
}, _callee29);
|
|
763
|
+
})));
|
|
764
|
+
case 2:
|
|
765
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
766
|
+
expect(mockCreateItem).toHaveBeenCalledTimes(1);
|
|
767
|
+
expect(onSuccess).not.toHaveBeenCalled();
|
|
768
|
+
expect(onError).toHaveBeenCalledTimes(1);
|
|
769
|
+
_context31.n = 3;
|
|
770
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30() {
|
|
771
|
+
return _regenerator().w(function (_context30) {
|
|
772
|
+
while (1) switch (_context30.n) {
|
|
773
|
+
case 0:
|
|
774
|
+
_context30.n = 1;
|
|
775
|
+
return window.addCartItem(job, onSuccess, onError);
|
|
776
|
+
case 1:
|
|
777
|
+
return _context30.a(2);
|
|
778
|
+
}
|
|
779
|
+
}, _callee30);
|
|
780
|
+
})));
|
|
781
|
+
case 3:
|
|
782
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
783
|
+
expect(mockCreateItem).toHaveBeenCalledTimes(2);
|
|
784
|
+
expect(onSuccess).toHaveBeenCalledWith({
|
|
785
|
+
id: 7,
|
|
786
|
+
cart: {
|
|
787
|
+
id: 99
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
case 4:
|
|
791
|
+
return _context31.a(2);
|
|
792
|
+
}
|
|
793
|
+
}, _callee31);
|
|
794
|
+
})));
|
|
795
|
+
it('shares cold initialization with opening the modal and concurrent getCart callers', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35() {
|
|
796
|
+
var finish, first, second;
|
|
797
|
+
return _regenerator().w(function (_context35) {
|
|
798
|
+
while (1) switch (_context35.n) {
|
|
799
|
+
case 0:
|
|
800
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
801
|
+
mockPost.mockImplementationOnce(function () {
|
|
802
|
+
return new Promise(function (resolve) {
|
|
803
|
+
finish = resolve;
|
|
804
|
+
});
|
|
805
|
+
});
|
|
806
|
+
_context35.n = 1;
|
|
807
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32() {
|
|
808
|
+
return _regenerator().w(function (_context32) {
|
|
809
|
+
while (1) switch (_context32.n) {
|
|
810
|
+
case 0:
|
|
811
|
+
return _context32.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
812
|
+
domainId: 5,
|
|
813
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
814
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
815
|
+
})));
|
|
816
|
+
}
|
|
817
|
+
}, _callee32);
|
|
818
|
+
})));
|
|
819
|
+
case 1:
|
|
820
|
+
_context35.n = 2;
|
|
821
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33() {
|
|
822
|
+
return _regenerator().w(function (_context33) {
|
|
823
|
+
while (1) switch (_context33.n) {
|
|
824
|
+
case 0:
|
|
825
|
+
context.toggleCartModal();
|
|
826
|
+
first = window.getCart();
|
|
827
|
+
second = window.getCart();
|
|
828
|
+
case 1:
|
|
829
|
+
return _context33.a(2);
|
|
830
|
+
}
|
|
831
|
+
}, _callee33);
|
|
832
|
+
})));
|
|
833
|
+
case 2:
|
|
834
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
835
|
+
expect(context.fetchingCart).toBe(true);
|
|
836
|
+
_context35.n = 3;
|
|
837
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34() {
|
|
838
|
+
return _regenerator().w(function (_context34) {
|
|
839
|
+
while (1) switch (_context34.n) {
|
|
840
|
+
case 0:
|
|
841
|
+
finish({
|
|
842
|
+
cart: {
|
|
843
|
+
id: 99,
|
|
844
|
+
token: 'new-token'
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
_context34.n = 1;
|
|
848
|
+
return Promise.all([first, second]);
|
|
849
|
+
case 1:
|
|
850
|
+
return _context34.a(2);
|
|
851
|
+
}
|
|
852
|
+
}, _callee34);
|
|
853
|
+
})));
|
|
854
|
+
case 3:
|
|
855
|
+
expect(context.cart.id).toBe(99);
|
|
856
|
+
expect(context.fetchingCart).toBe(false);
|
|
857
|
+
expect(setCartCookie).toHaveBeenCalledTimes(1);
|
|
858
|
+
case 4:
|
|
859
|
+
return _context35.a(2);
|
|
860
|
+
}
|
|
861
|
+
}, _callee35);
|
|
862
|
+
})));
|
|
863
|
+
it('shares an active saved-cart read and allows a later refresh', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40() {
|
|
864
|
+
var finish, saved, read;
|
|
865
|
+
return _regenerator().w(function (_context40) {
|
|
866
|
+
while (1) switch (_context40.n) {
|
|
867
|
+
case 0:
|
|
868
|
+
saved = {
|
|
869
|
+
toJson: function toJson() {
|
|
870
|
+
return {
|
|
871
|
+
id: 42,
|
|
872
|
+
isTest: false,
|
|
873
|
+
cartItems: [{
|
|
874
|
+
id: 7
|
|
875
|
+
}]
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
mockGet.mockImplementationOnce(function () {
|
|
880
|
+
return new Promise(function (resolve) {
|
|
881
|
+
finish = resolve;
|
|
882
|
+
});
|
|
883
|
+
}).mockResolvedValue(saved);
|
|
884
|
+
_context40.n = 1;
|
|
885
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36() {
|
|
886
|
+
return _regenerator().w(function (_context36) {
|
|
887
|
+
while (1) switch (_context36.n) {
|
|
888
|
+
case 0:
|
|
889
|
+
return _context36.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
890
|
+
domainId: 5,
|
|
891
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
892
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
893
|
+
})));
|
|
894
|
+
}
|
|
895
|
+
}, _callee36);
|
|
896
|
+
})));
|
|
897
|
+
case 1:
|
|
898
|
+
_context40.n = 2;
|
|
899
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37() {
|
|
900
|
+
return _regenerator().w(function (_context37) {
|
|
901
|
+
while (1) switch (_context37.n) {
|
|
902
|
+
case 0:
|
|
903
|
+
context.toggleCartModal();
|
|
904
|
+
read = window.getCart();
|
|
905
|
+
case 1:
|
|
906
|
+
return _context37.a(2);
|
|
907
|
+
}
|
|
908
|
+
}, _callee37);
|
|
909
|
+
})));
|
|
910
|
+
case 2:
|
|
911
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
912
|
+
_context40.n = 3;
|
|
913
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38() {
|
|
914
|
+
return _regenerator().w(function (_context38) {
|
|
915
|
+
while (1) switch (_context38.n) {
|
|
916
|
+
case 0:
|
|
917
|
+
finish(saved);
|
|
918
|
+
_context38.n = 1;
|
|
919
|
+
return read;
|
|
920
|
+
case 1:
|
|
921
|
+
return _context38.a(2);
|
|
922
|
+
}
|
|
923
|
+
}, _callee38);
|
|
924
|
+
})));
|
|
925
|
+
case 3:
|
|
926
|
+
_context40.n = 4;
|
|
927
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39() {
|
|
928
|
+
return _regenerator().w(function (_context39) {
|
|
929
|
+
while (1) switch (_context39.n) {
|
|
930
|
+
case 0:
|
|
931
|
+
_context39.n = 1;
|
|
932
|
+
return window.getCart();
|
|
933
|
+
case 1:
|
|
934
|
+
return _context39.a(2);
|
|
935
|
+
}
|
|
936
|
+
}, _callee39);
|
|
937
|
+
})));
|
|
938
|
+
case 4:
|
|
939
|
+
expect(mockGet).toHaveBeenCalledTimes(2);
|
|
940
|
+
expect(mockPost).not.toHaveBeenCalled();
|
|
941
|
+
expect(context.cart.cartItems).toHaveLength(1);
|
|
942
|
+
case 5:
|
|
943
|
+
return _context40.a(2);
|
|
944
|
+
}
|
|
945
|
+
}, _callee40);
|
|
946
|
+
})));
|
|
947
|
+
it('releases failed initialization so an explicit retry can create the cart', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43() {
|
|
948
|
+
return _regenerator().w(function (_context43) {
|
|
949
|
+
while (1) switch (_context43.n) {
|
|
950
|
+
case 0:
|
|
951
|
+
getCartCookie.mockResolvedValue(undefined);
|
|
952
|
+
mockPost.mockRejectedValueOnce(new TypeError('Failed to fetch'));
|
|
953
|
+
_context43.n = 1;
|
|
954
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41() {
|
|
955
|
+
return _regenerator().w(function (_context41) {
|
|
956
|
+
while (1) switch (_context41.n) {
|
|
957
|
+
case 0:
|
|
958
|
+
return _context41.a(2, root.render(/*#__PURE__*/_jsx(CartProvider, {
|
|
959
|
+
domainId: 5,
|
|
960
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
961
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
962
|
+
})));
|
|
963
|
+
}
|
|
964
|
+
}, _callee41);
|
|
965
|
+
})));
|
|
966
|
+
case 1:
|
|
967
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
968
|
+
expect(context.fetchingCart).toBe(false);
|
|
969
|
+
_context43.n = 2;
|
|
970
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42() {
|
|
971
|
+
return _regenerator().w(function (_context42) {
|
|
972
|
+
while (1) switch (_context42.n) {
|
|
973
|
+
case 0:
|
|
974
|
+
_context42.n = 1;
|
|
975
|
+
return Promise.all([window.getCart(), window.getCart()]);
|
|
976
|
+
case 1:
|
|
977
|
+
return _context42.a(2);
|
|
978
|
+
}
|
|
979
|
+
}, _callee42);
|
|
980
|
+
})));
|
|
981
|
+
case 2:
|
|
982
|
+
expect(mockPost).toHaveBeenCalledTimes(2);
|
|
983
|
+
expect(context.cart.id).toBe(99);
|
|
984
|
+
expect(context.fetchingCart).toBe(false);
|
|
985
|
+
case 3:
|
|
986
|
+
return _context43.a(2);
|
|
987
|
+
}
|
|
988
|
+
}, _callee43);
|
|
989
|
+
})));
|
|
990
|
+
it('initializes a changed domain independently of the previous pending domain', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49() {
|
|
991
|
+
var finish, view, current;
|
|
992
|
+
return _regenerator().w(function (_context49) {
|
|
993
|
+
while (1) switch (_context49.n) {
|
|
994
|
+
case 0:
|
|
995
|
+
finish = {};
|
|
996
|
+
getCartCookie.mockImplementation(function (id) {
|
|
997
|
+
return Promise.resolve([String(id), 'token']);
|
|
998
|
+
});
|
|
999
|
+
mockGet.mockImplementation(function (id) {
|
|
1000
|
+
return new Promise(function (resolve) {
|
|
1001
|
+
finish[id] = resolve;
|
|
1002
|
+
});
|
|
1003
|
+
});
|
|
1004
|
+
view = function view(id) {
|
|
1005
|
+
return /*#__PURE__*/_jsx(CartProvider, {
|
|
1006
|
+
domainId: id,
|
|
1007
|
+
createCartAndCookie: function createCartAndCookie() {},
|
|
1008
|
+
children: /*#__PURE__*/_jsx(Probe, {})
|
|
1009
|
+
});
|
|
1010
|
+
};
|
|
1011
|
+
_context49.n = 1;
|
|
1012
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44() {
|
|
1013
|
+
return _regenerator().w(function (_context44) {
|
|
1014
|
+
while (1) switch (_context44.n) {
|
|
1015
|
+
case 0:
|
|
1016
|
+
return _context44.a(2, root.render(view(5)));
|
|
1017
|
+
}
|
|
1018
|
+
}, _callee44);
|
|
1019
|
+
})));
|
|
1020
|
+
case 1:
|
|
1021
|
+
_context49.n = 2;
|
|
1022
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45() {
|
|
1023
|
+
return _regenerator().w(function (_context45) {
|
|
1024
|
+
while (1) switch (_context45.n) {
|
|
1025
|
+
case 0:
|
|
1026
|
+
return _context45.a(2, root.render(view(6)));
|
|
1027
|
+
}
|
|
1028
|
+
}, _callee45);
|
|
1029
|
+
})));
|
|
1030
|
+
case 2:
|
|
1031
|
+
expect(mockGet).toHaveBeenCalledTimes(2);
|
|
1032
|
+
_context49.n = 3;
|
|
1033
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46() {
|
|
1034
|
+
return _regenerator().w(function (_context46) {
|
|
1035
|
+
while (1) switch (_context46.n) {
|
|
1036
|
+
case 0:
|
|
1037
|
+
return _context46.a(2, finish[5]({
|
|
1038
|
+
toJson: function toJson() {
|
|
1039
|
+
return {
|
|
1040
|
+
id: 5,
|
|
1041
|
+
isTest: false
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
}));
|
|
1045
|
+
}
|
|
1046
|
+
}, _callee46);
|
|
1047
|
+
})));
|
|
1048
|
+
case 3:
|
|
1049
|
+
_context49.n = 4;
|
|
1050
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47() {
|
|
1051
|
+
return _regenerator().w(function (_context47) {
|
|
1052
|
+
while (1) switch (_context47.n) {
|
|
1053
|
+
case 0:
|
|
1054
|
+
current = window.getCart();
|
|
1055
|
+
case 1:
|
|
1056
|
+
return _context47.a(2);
|
|
1057
|
+
}
|
|
1058
|
+
}, _callee47);
|
|
1059
|
+
})));
|
|
1060
|
+
case 4:
|
|
1061
|
+
expect(mockGet).toHaveBeenCalledTimes(2);
|
|
1062
|
+
_context49.n = 5;
|
|
1063
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48() {
|
|
1064
|
+
return _regenerator().w(function (_context48) {
|
|
1065
|
+
while (1) switch (_context48.n) {
|
|
1066
|
+
case 0:
|
|
1067
|
+
finish[6]({
|
|
1068
|
+
toJson: function toJson() {
|
|
1069
|
+
return {
|
|
1070
|
+
id: 6,
|
|
1071
|
+
isTest: false
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
_context48.n = 1;
|
|
1076
|
+
return current;
|
|
1077
|
+
case 1:
|
|
1078
|
+
return _context48.a(2);
|
|
1079
|
+
}
|
|
1080
|
+
}, _callee48);
|
|
1081
|
+
})));
|
|
1082
|
+
case 5:
|
|
1083
|
+
expect(context.cart.id).toBe(6);
|
|
1084
|
+
case 6:
|
|
1085
|
+
return _context49.a(2);
|
|
1086
|
+
}
|
|
1087
|
+
}, _callee49);
|
|
1088
|
+
})));
|
|
227
1089
|
it.each([new TypeError('Load failed'), {
|
|
228
1090
|
statusCode: 502,
|
|
229
1091
|
message: 'Gateway unavailable'
|
|
@@ -231,11 +1093,11 @@ describe('cart load and replacement failures', function () {
|
|
|
231
1093
|
statusCode: 403,
|
|
232
1094
|
message: 'Forbidden'
|
|
233
1095
|
}])('preserves the saved cart and never POSTs a replacement after %s', /*#__PURE__*/function () {
|
|
234
|
-
var
|
|
235
|
-
return _regenerator().w(function (
|
|
236
|
-
while (1) switch (
|
|
1096
|
+
var _ref50 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50(error) {
|
|
1097
|
+
return _regenerator().w(function (_context50) {
|
|
1098
|
+
while (1) switch (_context50.n) {
|
|
237
1099
|
case 0:
|
|
238
|
-
|
|
1100
|
+
_context50.n = 1;
|
|
239
1101
|
return mount(error);
|
|
240
1102
|
case 1:
|
|
241
1103
|
expect(getCartCookie).toHaveBeenCalledWith(5);
|
|
@@ -251,20 +1113,20 @@ describe('cart load and replacement failures', function () {
|
|
|
251
1113
|
expect(context.fetchingCart).toBe(false);
|
|
252
1114
|
expect(reportCartFailure).toHaveBeenCalledWith(error, CART_FAILURE_SOURCES.load);
|
|
253
1115
|
case 2:
|
|
254
|
-
return
|
|
1116
|
+
return _context50.a(2);
|
|
255
1117
|
}
|
|
256
|
-
},
|
|
1118
|
+
}, _callee50);
|
|
257
1119
|
}));
|
|
258
|
-
return function (
|
|
259
|
-
return
|
|
1120
|
+
return function (_x3) {
|
|
1121
|
+
return _ref50.apply(this, arguments);
|
|
260
1122
|
};
|
|
261
1123
|
}());
|
|
262
1124
|
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 (
|
|
1125
|
+
var _ref51 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(statusCode) {
|
|
1126
|
+
return _regenerator().w(function (_context51) {
|
|
1127
|
+
while (1) switch (_context51.n) {
|
|
266
1128
|
case 0:
|
|
267
|
-
|
|
1129
|
+
_context51.n = 1;
|
|
268
1130
|
return mount({
|
|
269
1131
|
statusCode: statusCode
|
|
270
1132
|
});
|
|
@@ -275,19 +1137,19 @@ describe('cart load and replacement failures', function () {
|
|
|
275
1137
|
}));
|
|
276
1138
|
expect(setCartCookie).toHaveBeenCalledTimes(1);
|
|
277
1139
|
case 2:
|
|
278
|
-
return
|
|
1140
|
+
return _context51.a(2);
|
|
279
1141
|
}
|
|
280
|
-
},
|
|
1142
|
+
}, _callee51);
|
|
281
1143
|
}));
|
|
282
|
-
return function (
|
|
283
|
-
return
|
|
1144
|
+
return function (_x4) {
|
|
1145
|
+
return _ref51.apply(this, arguments);
|
|
284
1146
|
};
|
|
285
1147
|
}());
|
|
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 (
|
|
1148
|
+
it('allows an explicit retry to restore the same cart without creating another', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53() {
|
|
1149
|
+
return _regenerator().w(function (_context53) {
|
|
1150
|
+
while (1) switch (_context53.n) {
|
|
289
1151
|
case 0:
|
|
290
|
-
|
|
1152
|
+
_context53.n = 1;
|
|
291
1153
|
return mount(new TypeError('Load failed'));
|
|
292
1154
|
case 1:
|
|
293
1155
|
mockGet.mockResolvedValue({
|
|
@@ -301,50 +1163,50 @@ describe('cart load and replacement failures', function () {
|
|
|
301
1163
|
};
|
|
302
1164
|
}
|
|
303
1165
|
});
|
|
304
|
-
|
|
305
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
306
|
-
return _regenerator().w(function (
|
|
307
|
-
while (1) switch (
|
|
1166
|
+
_context53.n = 2;
|
|
1167
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52() {
|
|
1168
|
+
return _regenerator().w(function (_context52) {
|
|
1169
|
+
while (1) switch (_context52.n) {
|
|
308
1170
|
case 0:
|
|
309
|
-
|
|
1171
|
+
_context52.n = 1;
|
|
310
1172
|
return window.getCart();
|
|
311
1173
|
case 1:
|
|
312
|
-
return
|
|
1174
|
+
return _context52.a(2);
|
|
313
1175
|
}
|
|
314
|
-
},
|
|
1176
|
+
}, _callee52);
|
|
315
1177
|
})));
|
|
316
1178
|
case 2:
|
|
317
1179
|
expect(context.cart.id).toBe(42);
|
|
318
1180
|
expect(context.cart.cartItems).toHaveLength(1);
|
|
319
1181
|
expect(mockPost).not.toHaveBeenCalled();
|
|
320
1182
|
case 3:
|
|
321
|
-
return
|
|
1183
|
+
return _context53.a(2);
|
|
322
1184
|
}
|
|
323
|
-
},
|
|
1185
|
+
}, _callee53);
|
|
324
1186
|
})));
|
|
325
1187
|
it.each([new TypeError('Failed to fetch'), {
|
|
326
1188
|
statusCode: 503,
|
|
327
1189
|
message: 'Service unavailable'
|
|
328
1190
|
}, 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 (
|
|
1191
|
+
var _ref54 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(error) {
|
|
1192
|
+
return _regenerator().w(function (_context55) {
|
|
1193
|
+
while (1) switch (_context55.n) {
|
|
332
1194
|
case 0:
|
|
333
|
-
|
|
1195
|
+
_context55.n = 1;
|
|
334
1196
|
return mountSavedCart();
|
|
335
1197
|
case 1:
|
|
336
1198
|
mockPost.mockRejectedValueOnce(error);
|
|
337
|
-
|
|
338
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
339
|
-
return _regenerator().w(function (
|
|
340
|
-
while (1) switch (
|
|
1199
|
+
_context55.n = 2;
|
|
1200
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54() {
|
|
1201
|
+
return _regenerator().w(function (_context54) {
|
|
1202
|
+
while (1) switch (_context54.n) {
|
|
341
1203
|
case 0:
|
|
342
|
-
|
|
1204
|
+
_context54.n = 1;
|
|
343
1205
|
return context.clearCart();
|
|
344
1206
|
case 1:
|
|
345
|
-
return
|
|
1207
|
+
return _context54.a(2);
|
|
346
1208
|
}
|
|
347
|
-
},
|
|
1209
|
+
}, _callee54);
|
|
348
1210
|
})));
|
|
349
1211
|
case 2:
|
|
350
1212
|
expect(context.activeTabIndex).toBe(tabIdClearCart);
|
|
@@ -362,47 +1224,47 @@ describe('cart load and replacement failures', function () {
|
|
|
362
1224
|
expect(context.alert.message).toBe((error === null || error === void 0 ? void 0 : error.message) || 'Unable to fetch cart.');
|
|
363
1225
|
expect(context.fetchingCart).toBe(false);
|
|
364
1226
|
case 3:
|
|
365
|
-
return
|
|
1227
|
+
return _context55.a(2);
|
|
366
1228
|
}
|
|
367
|
-
},
|
|
1229
|
+
}, _callee55);
|
|
368
1230
|
}));
|
|
369
|
-
return function (
|
|
370
|
-
return
|
|
1231
|
+
return function (_x5) {
|
|
1232
|
+
return _ref54.apply(this, arguments);
|
|
371
1233
|
};
|
|
372
1234
|
}());
|
|
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 (
|
|
1235
|
+
it('finishes clearing only after an explicit retry successfully creates the replacement', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58() {
|
|
1236
|
+
return _regenerator().w(function (_context58) {
|
|
1237
|
+
while (1) switch (_context58.n) {
|
|
376
1238
|
case 0:
|
|
377
|
-
|
|
1239
|
+
_context58.n = 1;
|
|
378
1240
|
return mountSavedCart();
|
|
379
1241
|
case 1:
|
|
380
1242
|
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 (
|
|
1243
|
+
_context58.n = 2;
|
|
1244
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56() {
|
|
1245
|
+
return _regenerator().w(function (_context56) {
|
|
1246
|
+
while (1) switch (_context56.n) {
|
|
385
1247
|
case 0:
|
|
386
|
-
|
|
1248
|
+
_context56.n = 1;
|
|
387
1249
|
return context.clearCart();
|
|
388
1250
|
case 1:
|
|
389
|
-
return
|
|
1251
|
+
return _context56.a(2);
|
|
390
1252
|
}
|
|
391
|
-
},
|
|
1253
|
+
}, _callee56);
|
|
392
1254
|
})));
|
|
393
1255
|
case 2:
|
|
394
1256
|
expect(context.activeTabIndex).toBe(tabIdClearCart);
|
|
395
|
-
|
|
396
|
-
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
397
|
-
return _regenerator().w(function (
|
|
398
|
-
while (1) switch (
|
|
1257
|
+
_context58.n = 3;
|
|
1258
|
+
return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57() {
|
|
1259
|
+
return _regenerator().w(function (_context57) {
|
|
1260
|
+
while (1) switch (_context57.n) {
|
|
399
1261
|
case 0:
|
|
400
|
-
|
|
1262
|
+
_context57.n = 1;
|
|
401
1263
|
return context.clearCart();
|
|
402
1264
|
case 1:
|
|
403
|
-
return
|
|
1265
|
+
return _context57.a(2);
|
|
404
1266
|
}
|
|
405
|
-
},
|
|
1267
|
+
}, _callee57);
|
|
406
1268
|
})));
|
|
407
1269
|
case 3:
|
|
408
1270
|
expect(mockPost).toHaveBeenCalledTimes(2);
|
|
@@ -412,8 +1274,8 @@ describe('cart load and replacement failures', function () {
|
|
|
412
1274
|
expect(context.alert.show).toBe(false);
|
|
413
1275
|
expect(context.fetchingCart).toBe(false);
|
|
414
1276
|
case 4:
|
|
415
|
-
return
|
|
1277
|
+
return _context58.a(2);
|
|
416
1278
|
}
|
|
417
|
-
},
|
|
1279
|
+
}, _callee58);
|
|
418
1280
|
})));
|
|
419
1281
|
});
|