@shopgate/pwa-common 7.32.0-beta.2 → 7.32.0-beta.20

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.
Files changed (64) hide show
  1. package/components/Button/index.js +6 -0
  2. package/components/Image/Image.d.ts +78 -0
  3. package/components/Image/Image.d.ts.map +1 -0
  4. package/components/Image/Image.js +123 -91
  5. package/components/Image/ImageInner.d.ts +45 -0
  6. package/components/Image/ImageInner.d.ts.map +1 -0
  7. package/components/Image/ImageInner.js +23 -29
  8. package/components/Image/index.d.ts +3 -0
  9. package/components/Image/index.d.ts.map +1 -0
  10. package/components/Swiper/index.js +17 -2
  11. package/constants/Configuration.js +7 -0
  12. package/helpers/mocks/mockRenderOptions.js +21 -0
  13. package/package.json +3 -3
  14. package/providers/toast/index.js +54 -40
  15. package/subscriptions/error.js +50 -27
  16. package/subscriptions/helpers/pipeline.js +68 -0
  17. package/subscriptions/router.js +2 -2
  18. package/action-creators/app/spec.js +0 -96
  19. package/action-creators/client/spec.js +0 -44
  20. package/action-creators/menu/spec.js +0 -37
  21. package/action-creators/modal/spec.js +0 -26
  22. package/action-creators/page/spec.js +0 -38
  23. package/action-creators/url/spec.js +0 -45
  24. package/action-creators/user/spec.js +0 -186
  25. package/components/Backdrop/spec.js +0 -24
  26. package/components/Button/spec.js +0 -42
  27. package/components/Checkbox/spec.js +0 -111
  28. package/components/CountdownTimer/spec.js +0 -141
  29. package/components/Drawer/spec.js +0 -79
  30. package/components/Ellipsis/spec.js +0 -15
  31. package/components/EmbeddedMedia/spec.js +0 -61
  32. package/components/Grid/components/Item/spec.js +0 -24
  33. package/components/Grid/spec.js +0 -24
  34. package/components/HtmlSanitizer/spec.js +0 -229
  35. package/components/I18n/components/FormatDate/spec.js +0 -54
  36. package/components/I18n/components/FormatNumber/spec.js +0 -51
  37. package/components/I18n/components/FormatPrice/spec.js +0 -54
  38. package/components/I18n/components/FormatTime/spec.js +0 -51
  39. package/components/I18n/components/I18nProvider/spec.js +0 -40
  40. package/components/I18n/components/Placeholder/spec.js +0 -37
  41. package/components/I18n/components/Translate/spec.js +0 -33
  42. package/components/InfiniteContainer/spec.js +0 -204
  43. package/components/Input/spec.js +0 -123
  44. package/components/Link/spec.js +0 -60
  45. package/components/List/spec.js +0 -26
  46. package/components/ModalContainer/spec.js +0 -115
  47. package/components/Select/spec.js +0 -122
  48. package/components/SelectBox/spec.js +0 -68
  49. package/components/Swiper/components/SwiperItem/spec.js +0 -26
  50. package/components/Widgets/components/Widget/spec.js +0 -75
  51. package/components/Widgets/components/WidgetGrid/spec.js +0 -53
  52. package/components/Widgets/spec.js +0 -234
  53. package/helpers/data/spec.js +0 -194
  54. package/helpers/date/spec.js +0 -92
  55. package/helpers/style/spec.js +0 -108
  56. package/helpers/validation/spec.js +0 -10
  57. package/styles/reset/form.js +0 -58
  58. package/styles/reset/index.js +0 -8
  59. package/styles/reset/media.js +0 -26
  60. package/styles/reset/root.js +0 -37
  61. package/styles/reset/table.js +0 -14
  62. package/styles/reset/typography.js +0 -30
  63. package/tsconfig.build.json +0 -16
  64. package/tsconfig.json +0 -3
@@ -32,47 +32,41 @@ let ToastProvider = /*#__PURE__*/function (_Component) {
32
32
  if (!toast.message) {
33
33
  return;
34
34
  }
35
- const {
36
- toasts
37
- } = _this.state;
38
-
39
- // Check if the toast id already is present.
40
- const found = toasts.find(({
41
- id
42
- }) => toast.id === id);
35
+ const nextToast = {
36
+ id: toast.id,
37
+ action: toast.action,
38
+ actionLabel: toast.actionLabel,
39
+ onLongPress: toast.onLongPress,
40
+ message: toast.message,
41
+ messageParams: toast.messageParams,
42
+ duration: toast.duration || _this.props.theme.transitions.duration.toast
43
+ };
43
44
 
44
- // If found, update the toast with the new data.
45
- if (found) {
46
- found.action = toast.action;
47
- found.actionLabel = toast.actionLabel;
48
- found.message = toast.message;
49
- found.messageParams = toast.messageParams;
50
- found.duration = toast.duration || _this.props.theme.transitions.duration.toast;
51
- } else {
52
- toasts.push({
53
- id: toast.id,
54
- action: toast.action,
55
- actionLabel: toast.actionLabel,
56
- message: toast.message,
57
- messageParams: toast.messageParams,
58
- duration: toast.duration || _this.props.theme.transitions.duration.toast
59
- });
60
- }
61
- _this.setState({
45
+ // Update the queue immutably: consumers rely on the array reference changing to re-render
46
+ // (e.g. the SnackBar memoizes the currently shown toast on this reference). A toast whose id
47
+ // is already queued replaces that entry with the new data; otherwise it is appended.
48
+ _this.setState(({
62
49
  toasts
50
+ }) => {
51
+ const exists = toasts.some(({
52
+ id
53
+ }) => id === toast.id);
54
+ return {
55
+ toasts: exists ? toasts.map(item => item.id === toast.id ? nextToast : item) : [].concat(toasts, [nextToast])
56
+ };
63
57
  });
64
58
  };
65
59
  /**
66
60
  * Removes the first toast from the list.
67
61
  */
68
62
  _this.removeToast = () => {
69
- const {
70
- toasts
71
- } = _this.state;
72
- toasts.shift();
73
- _this.setState({
63
+ // Drop the first toast immutably so the array reference changes and the SnackBar advances to
64
+ // the next queued toast (rather than re-rendering the same, now-stale, memoized toast).
65
+ _this.setState(({
74
66
  toasts
75
- });
67
+ }) => ({
68
+ toasts: toasts.slice(1)
69
+ }));
76
70
  };
77
71
  _this.flushToasts = () => {
78
72
  if (_this.state.toasts.length) {
@@ -90,11 +84,21 @@ let ToastProvider = /*#__PURE__*/function (_Component) {
90
84
  }
91
85
 
92
86
  /**
93
- * Returns the context value to be passed to consumers.
94
- * @returns {Object}
87
+ * Removes the UIEvents listeners registered in the constructor.
95
88
  */
96
89
  _inheritsLoose(ToastProvider, _Component);
97
90
  var _proto = ToastProvider.prototype;
91
+ _proto.componentWillUnmount = function componentWillUnmount() {
92
+ UIEvents.removeListener(this.constructor.ADD, this.addToast);
93
+ UIEvents.removeListener(this.constructor.FLUSH, this.flushToasts);
94
+ }
95
+
96
+ /**
97
+ * Returns the context value to be passed to consumers. The object reference is cached and only
98
+ * rebuilt when `toasts` changes, so consumers (Toaster → SnackBarContainer → SnackBar) don't
99
+ * re-render on every unrelated ToastProvider render.
100
+ * @returns {Object}
101
+ */;
98
102
  /**
99
103
  * @returns {JSX}
100
104
  */
@@ -107,14 +111,24 @@ let ToastProvider = /*#__PURE__*/function (_Component) {
107
111
  return _createClass(ToastProvider, [{
108
112
  key: "provided",
109
113
  get: function () {
110
- return {
111
- addToast: this.addToast,
112
- removeToast: this.removeToast,
113
- toasts: this.state.toasts
114
- };
114
+ if (!this.providedCache || this.providedCache.toasts !== this.state.toasts) {
115
+ this.providedCache = {
116
+ addToast: this.addToast,
117
+ removeToast: this.removeToast,
118
+ toasts: this.state.toasts
119
+ };
120
+ }
121
+ return this.providedCache;
115
122
  }
116
123
  }]);
117
124
  }(Component);
118
125
  ToastProvider.ADD = 'toast_add';
119
126
  ToastProvider.FLUSH = 'toast_flush';
120
- export default withTheme(ToastProvider);
127
+ const ThemedToastProvider = withTheme(ToastProvider);
128
+
129
+ // The HOC returns a new component which doesn't carry over the statics of the wrapped class. They
130
+ // are part of the public API of this module (consumers emit UIEvents on ToastProvider.ADD), so they
131
+ // are re-attached explicitly.
132
+ ThemedToastProvider.ADD = ToastProvider.ADD;
133
+ ThemedToastProvider.FLUSH = ToastProvider.FLUSH;
134
+ export default ThemedToastProvider;
@@ -1,7 +1,4 @@
1
1
  import "core-js/modules/es.array.includes.js";
2
- import after from 'lodash/after';
3
- import before from 'lodash/before';
4
- import over from 'lodash/over';
5
2
  import { isAvailable } from '@shopgate/native-modules';
6
3
  import { init, addBreadcrumb, configureScope, captureException, captureMessage, captureEvent, withScope, Severity as SentrySeverity } from '@sentry/browser';
7
4
  import { EBIGAPI, emitter, errorManager, ETIMEOUT, ENETUNREACH, EUNKNOWN, EFAVORITE } from '@shopgate/pwa-core';
@@ -12,7 +9,7 @@ import {
12
9
  // eslint-disable-next-line import/no-named-default
13
10
  default as appConfig, themeName, pckVersion } from "../helpers/config";
14
11
  import { env } from "../helpers/environment";
15
- import { transformGeneralPipelineError } from "./helpers/pipeline";
12
+ import { transformGeneralPipelineError, getDisplayErrorMessage } from "./helpers/pipeline";
16
13
  import { historyPop } from "../actions/router";
17
14
  import showModal from "../actions/modal/showModal";
18
15
  import { getUserData } from "../selectors/user";
@@ -24,6 +21,9 @@ import { getRouterStack } from "../selectors/router";
24
21
  import { MODAL_PIPELINE_ERROR } from "../constants/ModalTypes";
25
22
  import ToastProvider from "../providers/toast";
26
23
 
24
+ // Generic, translated fallback shown when a backend error carries no code we can map to a message.
25
+ const GENERIC_ERROR_MESSAGE = 'modal.body_error';
26
+
27
27
  /**
28
28
  * App errors subscriptions.
29
29
  * @param {Function} subscribe The subscribe function.
@@ -60,15 +60,35 @@ export default subscribe => {
60
60
  error
61
61
  } = action;
62
62
  const {
63
- message,
64
63
  code,
65
64
  context,
66
65
  meta = {}
67
66
  } = error;
68
67
  const {
69
- behavior
68
+ behavior,
69
+ message: originalMessage
70
70
  } = meta;
71
- if (behavior) {
71
+
72
+ // Never surface a raw backend message to the user: show the extension's own translated
73
+ // message, a code-mapped translated message, or a generic fallback. The resolver is the single
74
+ // source of truth for both the text and whether it is ready-to-display (`displayTranslated`) or
75
+ // a locale key that must still go through I18n.Text.
76
+ const {
77
+ message: displayMessage,
78
+ translated: displayTranslated
79
+ } = getDisplayErrorMessage(error, GENERIC_ERROR_MESSAGE);
80
+
81
+ // Unknown/generic and connection-style backend errors are treated as general platform issues.
82
+ // EUNKNOWN is always treated as general — even when the backend supplied a translated message —
83
+ // so it is shown as a toast with its translated message or generic fallback, never a modal.
84
+ const isConnectionError = displayMessage === 'error.general' || [ETIMEOUT, ENETUNREACH].includes(code);
85
+ const isGeneralError = isConnectionError || displayMessage === GENERIC_ERROR_MESSAGE || code === EUNKNOWN;
86
+
87
+ // Some pipeline actions (e.g. fetchCategory) register an error behavior for *every* error via
88
+ // `setResponseBehavior`. Those behaviors are only meaningful for the specific errors they
89
+ // expect; when the platform fails with an unexpected/unmappable message we skip the behavior
90
+ // and fall through to the generic toast handling instead of, for example, showing a modal.
91
+ if (behavior && !isGeneralError) {
72
92
  behavior({
73
93
  dispatch,
74
94
  getState,
@@ -78,38 +98,41 @@ export default subscribe => {
78
98
  return;
79
99
  }
80
100
 
81
- /** Show modal thunk */
82
- const showModalError = () => {
101
+ /**
102
+ * Shows the pipeline error modal. When openWithDetails is set, the modal opens directly on the
103
+ * developer detail view (pipeline, code, raw message, params) — used for the toast long-press.
104
+ * @param {boolean} [openWithDetails=false] Whether to open the modal in developer detail mode.
105
+ */
106
+ const showModalError = (openWithDetails = false) => {
83
107
  dispatch(showModal({
84
108
  confirm: 'modal.ok',
85
109
  dismiss: null,
86
110
  title: null,
87
- message,
111
+ message: displayMessage,
88
112
  type: MODAL_PIPELINE_ERROR,
89
113
  params: {
90
114
  pipeline: context,
91
115
  request: meta.input,
92
- message: meta.message,
93
- code
116
+ message: originalMessage,
117
+ code,
118
+ translated: displayTranslated,
119
+ messageParams: meta.additionalParams,
120
+ openWithDetails
94
121
  }
95
122
  }));
96
123
  };
97
- let shouldShowToast = message === 'error.general';
98
- if ([ETIMEOUT, ENETUNREACH].includes(code) && message === 'modal.body_error') {
99
- shouldShowToast = true;
100
- }
101
- // It was transformed general error. let it popup after 10 toast clicks
102
- if (shouldShowToast) {
103
- const showToastAfter = after(9, showModalError);
104
- // Recursively show same toast message until clicked 10 times
105
- const showToast = before(10, () => {
106
- events.emit(ToastProvider.ADD, {
107
- id: 'pipeline.error',
108
- message: 'error.general',
109
- action: over([showToast, showToastAfter])
110
- });
124
+
125
+ // General platform errors surface as a toast instead of a modal.
126
+ // Long-pressing the toast opens the error modal in developer detail mode.
127
+ if (isGeneralError) {
128
+ // Connection-style errors show the generic connection message, but never override a message
129
+ // an extension already translated for us.
130
+ const useGenericConnectionText = isConnectionError && !displayTranslated;
131
+ events.emit(ToastProvider.ADD, {
132
+ id: 'pipeline.error',
133
+ message: useGenericConnectionText ? 'error.general' : displayMessage,
134
+ onLongPress: () => showModalError(true)
111
135
  });
112
- showToast();
113
136
  return;
114
137
  }
115
138
  showModalError();
@@ -1,3 +1,5 @@
1
+ import { i18n } from '@shopgate/engage/core/helpers';
2
+
1
3
  /**
2
4
  * @param {Object} error error
3
5
  * @returns {string|*}
@@ -12,4 +14,70 @@ export function transformGeneralPipelineError(error) {
12
14
  return 'error.general';
13
15
  }
14
16
  return message;
17
+ }
18
+
19
+ /**
20
+ * @typedef {Object} DisplayErrorMessage
21
+ * @property {string} message The text to display — an already-translated string or a locale key.
22
+ * @property {boolean} translated Whether `message` is ready-to-display text (`true`) or a locale
23
+ * key that still needs to go through I18n.Text (`false`).
24
+ */
25
+
26
+ /**
27
+ * Resolves the message to display for a pipeline error, without ever surfacing raw backend text.
28
+ * Also reports whether the result is ready-to-display text or a locale key
29
+ * Precedence:
30
+ * 1. An extension's own message when it is explicitly flagged as already translated.
31
+ * 2. A resolvable i18n key — safe to surface even when errorManager did not remap it, because a
32
+ * translation key (e.g. `cart.error_out_of_stock`) is not raw backend text. `i18n.has` confirms
33
+ * the key actually resolves in the loaded locales, rather than merely looking like a key.
34
+ * 3. The code-mapped message. When errorManager maps the error code it resolves a message that
35
+ * differs from the raw backend text (`error.meta.message`).
36
+ * 4. A generic, translated fallback otherwise — including when nothing mapped and errorManager fell
37
+ * back to the raw backend message (`error.message === error.meta.message`).
38
+ * @param {Object} error The queued pipeline error.
39
+ * @param {string} error.message The message resolved by errorManager (code-mapped or raw fallback).
40
+ * @param {Object} [error.meta] The error meta data.
41
+ * @param {boolean} [error.meta.translated] Whether the backend message is already translated.
42
+ * @param {string} [error.meta.message] The original, raw backend message.
43
+ * @param {string} genericMessage The generic fallback message key.
44
+ * @returns {DisplayErrorMessage}
45
+ */
46
+ export function getDisplayErrorMessage(error, genericMessage) {
47
+ const {
48
+ message,
49
+ meta = {}
50
+ } = error;
51
+ const {
52
+ translated,
53
+ message: originalMessage
54
+ } = meta;
55
+ if (translated && originalMessage) {
56
+ return {
57
+ message: originalMessage,
58
+ translated: true
59
+ };
60
+ }
61
+
62
+ // A translation key is never raw backend text, so surface it even when errorManager left it
63
+ // untouched (`message === originalMessage`).
64
+ if (typeof message === 'string' && i18n.has(message)) {
65
+ return {
66
+ message,
67
+ translated: false
68
+ };
69
+ }
70
+
71
+ // Only trust `message` when we have the raw backend message to compare against and a mapping
72
+ // actually replaced it. Without the raw message we cannot rule out that `message` is raw text.
73
+ if (originalMessage !== undefined && message !== originalMessage) {
74
+ return {
75
+ message,
76
+ translated: false
77
+ };
78
+ }
79
+ return {
80
+ message: genericMessage,
81
+ translated: false
82
+ };
15
83
  }
@@ -9,7 +9,7 @@ import Route from '@virtuous/conductor/Route';
9
9
  import { Linking } from '@shopgate/native-modules';
10
10
  import { HISTORY_RESET_TO } from '@shopgate/pwa-common/constants/ActionTypes';
11
11
  import { logger } from '@shopgate/pwa-core';
12
- import { isPageAdminPreviewActive } from '@shopgate/engage/admin-preview/helpers';
12
+ import { isNavigationBlocked } from '@shopgate/engage/admin-preview/helpers';
13
13
  import addCouponsToCart from '@shopgate/pwa-common-commerce/cart/actions/addCouponsToCart';
14
14
  import { getCurrentRoute, getRouterStackIndex } from "../selectors/router";
15
15
  import { LoadingProvider } from "../providers";
@@ -31,7 +31,7 @@ import ToastProvider from "../providers/toast";
31
31
  */
32
32
  export default function routerSubscriptions(subscribe) {
33
33
  subscribe(navigate$, async params => {
34
- if (isPageAdminPreviewActive()) {
34
+ if (isNavigationBlocked()) {
35
35
  // No navigation is allowed in page preview mode.
36
36
  return;
37
37
  }
@@ -1,96 +0,0 @@
1
- import { APP_WILL_START, APP_DID_START, PWA_DID_APPEAR, PWA_DID_DISAPPEAR, WILL_REGISTER_LINK_EVENTS, DID_REGISTER_LINK_EVENTS, OPEN_DEEP_LINK, OPEN_PUSH_NOTIFICATION, OPEN_UNIVERSAL_LINK } from "../../constants/ActionTypes";
2
- import { appWillStart, appDidStart, pwaDidAppear, pwaDidDisappear, willRegisterLinkEvents, didRegisterLinkEvents, openDeepLink, openPushNotification, openUniversalLink } from "./index";
3
- const dataMock = {
4
- some: 'data'
5
- };
6
- describe('Action Creators: app', () => {
7
- describe('appWillStart()', () => {
8
- it('should work as expected', () => {
9
- const expected = {
10
- type: APP_WILL_START,
11
- location: dataMock
12
- };
13
- expect(appWillStart(dataMock)).toEqual(expected);
14
- });
15
- });
16
- describe('appDidStart()', () => {
17
- it('should work as expected', () => {
18
- const expected = {
19
- type: APP_DID_START
20
- };
21
- expect(appDidStart()).toEqual(expected);
22
- });
23
- });
24
- describe('pwaDidAppear()', () => {
25
- it('should work as expected', () => {
26
- const expected = {
27
- type: PWA_DID_APPEAR
28
- };
29
- expect(pwaDidAppear()).toEqual(expected);
30
- });
31
- });
32
- describe('pwaDidDisappear()', () => {
33
- it('should work as expected', () => {
34
- const expected = {
35
- type: PWA_DID_DISAPPEAR
36
- };
37
- expect(pwaDidDisappear()).toEqual(expected);
38
- });
39
- });
40
- describe('willRegisterLinkEvents()', () => {
41
- it('should work as expected', () => {
42
- const expected = {
43
- type: WILL_REGISTER_LINK_EVENTS
44
- };
45
- expect(willRegisterLinkEvents()).toEqual(expected);
46
- });
47
- });
48
- describe('didRegisterLinkEvents()', () => {
49
- it('should work as expected', () => {
50
- const expected = {
51
- type: DID_REGISTER_LINK_EVENTS
52
- };
53
- expect(didRegisterLinkEvents()).toEqual(expected);
54
- });
55
- });
56
- describe('openDeepLink()', () => {
57
- it('should work as expected', () => {
58
- const expected = {
59
- type: OPEN_DEEP_LINK,
60
- payload: dataMock
61
- };
62
- expect(openDeepLink(dataMock)).toEqual(expected);
63
- });
64
- });
65
- describe('openPushNotification()', () => {
66
- const notificationId = 'abc123';
67
- const link = '/link/to/somewhere';
68
- it('should work as expected', () => {
69
- const expected = {
70
- type: OPEN_PUSH_NOTIFICATION,
71
- notificationId,
72
- link
73
- };
74
- expect(openPushNotification(notificationId, link)).toEqual(expected);
75
- });
76
- it('should work as expected when the link is empty', () => {
77
- const expected = {
78
- type: OPEN_PUSH_NOTIFICATION,
79
- notificationId,
80
- link: ''
81
- };
82
- expect(openPushNotification(notificationId)).toEqual(expected);
83
- });
84
- });
85
- describe('openUniversalLink()', () => {
86
- const expected = {
87
- type: OPEN_UNIVERSAL_LINK,
88
- payload: {
89
- link: 'https://testshop.shopgate.com/item/313131313132',
90
- wasOpenedFromSearchIndex: true,
91
- linkSerial: 1003
92
- }
93
- };
94
- expect(openUniversalLink(expected.payload)).toEqual(expected);
95
- });
96
- });
@@ -1,44 +0,0 @@
1
- import { requestClientInformation, receiveClientInformation, errorClientInformation, receiveClientConnectivity } from "./index";
2
- import { REQUEST_CLIENT_INFORMATION, RECEIVE_CLIENT_INFORMATION, ERROR_CLIENT_INFORMATION, RECEIVE_CLIENT_CONNECTIVITY } from "../../constants/ActionTypes";
3
- describe('Action Creators: client', () => {
4
- describe('requestClientInformation()', () => {
5
- it('should work as expected', () => {
6
- const expected = {
7
- type: REQUEST_CLIENT_INFORMATION
8
- };
9
- expect(requestClientInformation()).toEqual(expected);
10
- });
11
- });
12
- describe('receiveClientInformation()', () => {
13
- it('should work as expected', () => {
14
- const data = {
15
- some: 'data'
16
- };
17
- const expected = {
18
- type: RECEIVE_CLIENT_INFORMATION,
19
- data
20
- };
21
- expect(receiveClientInformation(data)).toEqual(expected);
22
- });
23
- });
24
- describe('errorClientInformation()', () => {
25
- it('should work as expected', () => {
26
- const expected = {
27
- type: ERROR_CLIENT_INFORMATION
28
- };
29
- expect(errorClientInformation()).toEqual(expected);
30
- });
31
- });
32
- describe('receiveClientConnectivity()', () => {
33
- it('should work as expected', () => {
34
- const data = {
35
- some: 'data'
36
- };
37
- const expected = {
38
- type: RECEIVE_CLIENT_CONNECTIVITY,
39
- data
40
- };
41
- expect(receiveClientConnectivity(data)).toEqual(expected);
42
- });
43
- });
44
- });
@@ -1,37 +0,0 @@
1
- import { REQUEST_MENU, RECEIVE_MENU, ERROR_MENU } from "../../constants/ActionTypes";
2
- import { requestMenu, receiveMenu, errorMenu } from "./index";
3
- const entries = [{
4
- url: '/',
5
- label: 'Page Label'
6
- }];
7
- const id = 'quicklinks';
8
- describe('Action Creators: menu', () => {
9
- describe('requestMenu()', () => {
10
- it('should work as expected', () => {
11
- const expected = {
12
- type: REQUEST_MENU,
13
- id
14
- };
15
- expect(requestMenu(id)).toEqual(expected);
16
- });
17
- });
18
- describe('receiveMenu()', () => {
19
- it('should work as expected', () => {
20
- const expected = {
21
- type: RECEIVE_MENU,
22
- id,
23
- entries
24
- };
25
- expect(receiveMenu(id, entries)).toEqual(expected);
26
- });
27
- });
28
- describe('errorMenu()', () => {
29
- it('should work as expected', () => {
30
- const expected = {
31
- type: ERROR_MENU,
32
- id
33
- };
34
- expect(errorMenu(id)).toEqual(expected);
35
- });
36
- });
37
- });
@@ -1,26 +0,0 @@
1
- import { CREATE_MODAL, REMOVE_MODAL } from "../../constants/ActionTypes";
2
- import { createModal, removeModal } from "./index";
3
- const options = {
4
- some: 'data'
5
- };
6
- const id = 'modalId';
7
- describe('Action Creators: modal', () => {
8
- describe('createModal()', () => {
9
- it('should work as expected', () => {
10
- const expected = {
11
- type: CREATE_MODAL,
12
- options
13
- };
14
- expect(createModal(options)).toEqual(expected);
15
- });
16
- });
17
- describe('removeModal()', () => {
18
- it('should work as expected', () => {
19
- const expected = {
20
- type: REMOVE_MODAL,
21
- id
22
- };
23
- expect(removeModal(id)).toEqual(expected);
24
- });
25
- });
26
- });
@@ -1,38 +0,0 @@
1
- import { REQUEST_PAGE_CONFIG, RECEIVE_PAGE_CONFIG, ERROR_PAGE_CONFIG } from "../../constants/ActionTypes";
2
- import { requestPageConfig, receivePageConfig, errorPageConfig } from "./index";
3
- const pageId = 'index';
4
- const config = {
5
- some: 'data'
6
- };
7
- describe('Action Creators: page', () => {
8
- describe('requestPageConfig()', () => {
9
- it('should work as expected', () => {
10
- const expected = {
11
- type: REQUEST_PAGE_CONFIG,
12
- pageId
13
- };
14
- expect(requestPageConfig(pageId)).toEqual(expected);
15
- });
16
- });
17
- describe('receivePageConfig()', () => {
18
- it('should work as expected', () => {
19
- const expected = {
20
- type: RECEIVE_PAGE_CONFIG,
21
- pageId,
22
- config
23
- };
24
- expect(receivePageConfig(pageId, config)).toEqual(expected);
25
- });
26
- });
27
- describe('errorPageConfig()', () => {
28
- it('should work as expected', () => {
29
- const errorCode = 'error';
30
- const expected = {
31
- type: ERROR_PAGE_CONFIG,
32
- errorCode,
33
- pageId
34
- };
35
- expect(errorPageConfig(pageId, errorCode)).toEqual(expected);
36
- });
37
- });
38
- });
@@ -1,45 +0,0 @@
1
- import { RECEIVE_URL, REQUEST_URL, ERROR_URL } from "../../constants/ActionTypes";
2
- import { receiveUrl, requestUrl, errorUrl } from "./index";
3
- const url = 'https://www.myshop.com/checkout';
4
- const urlType = 'checkout';
5
- const expires = 123456;
6
- describe('Action Creators: url', () => {
7
- describe('receiveUrl()', () => {
8
- it('should work as expected', () => {
9
- const expected = {
10
- type: RECEIVE_URL,
11
- url,
12
- urlType,
13
- expires
14
- };
15
- expect(receiveUrl(urlType, url, expires)).toEqual(expected);
16
- });
17
- it('should work as expected when no expires parameter is passed', () => {
18
- const expected = {
19
- type: RECEIVE_URL,
20
- url,
21
- urlType,
22
- expires: null
23
- };
24
- expect(receiveUrl(urlType, url)).toEqual(expected);
25
- });
26
- });
27
- describe('requestUrl()', () => {
28
- it('should work as expected', () => {
29
- const expected = {
30
- type: REQUEST_URL,
31
- urlType
32
- };
33
- expect(requestUrl(urlType)).toEqual(expected);
34
- });
35
- });
36
- describe('errorUrl()', () => {
37
- it('should work as expected', () => {
38
- const expected = {
39
- type: ERROR_URL,
40
- urlType
41
- };
42
- expect(errorUrl(urlType)).toEqual(expected);
43
- });
44
- });
45
- });