@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
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import Grid from "./index";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- describe('<Grid />', () => {
6
- it('should render without any further props', () => {
7
- const wrapper = shallow(/*#__PURE__*/_jsx(Grid, {}));
8
- expect(wrapper).toMatchSnapshot();
9
- });
10
- it('should be able to render a custom tag', () => {
11
- const wrapper = shallow(/*#__PURE__*/_jsx(Grid, {
12
- component: "article"
13
- }));
14
- expect(wrapper).toMatchSnapshot();
15
- expect(wrapper.type()).toEqual('article');
16
- });
17
- it('should add custom classes on demand', () => {
18
- const wrapper = shallow(/*#__PURE__*/_jsx(Grid, {
19
- className: "custom-class-name"
20
- }));
21
- expect(wrapper).toMatchSnapshot();
22
- expect(wrapper.hasClass('custom-class-name')).toEqual(true);
23
- });
24
- });
@@ -1,229 +0,0 @@
1
- /** @jest-environment jsdom */
2
-
3
- import React from 'react';
4
- import { mount } from 'enzyme';
5
- import { embeddedMedia } from '@shopgate/pwa-common/collections';
6
- import HtmlSanitizer from "./index";
7
- import { jsx as _jsx } from "react/jsx-runtime";
8
- jest.mock("../EmbeddedMedia", () => ({
9
- children
10
- }) => children);
11
- jest.mock("./connector", () => Cmp => Cmp);
12
-
13
- /**
14
- * @param {string} html HTML markup.
15
- * @param {Object} props Component props.
16
- * @returns {JSX.Element}
17
- */
18
- const createWrapper = (html, props = {}) => mount(/*#__PURE__*/_jsx(HtmlSanitizer, {
19
- navigate: () => {},
20
- ...props,
21
- children: html
22
- }));
23
- describe('<HtmlSanitizer />', () => {
24
- let embeddedMediaAddSpy;
25
- let embeddedMediaRemoveSpy;
26
- let embeddedMediaHandleCookieConsentSpy;
27
- beforeEach(() => {
28
- jest.clearAllMocks();
29
- embeddedMediaAddSpy = jest.spyOn(embeddedMedia, 'add');
30
- embeddedMediaRemoveSpy = jest.spyOn(embeddedMedia, 'remove');
31
- embeddedMediaHandleCookieConsentSpy = jest.spyOn(embeddedMedia, 'handleCookieConsent');
32
- });
33
- it('should render the HtmlSanitizer', () => {
34
- /**
35
- * The value for html is the HTML-escaped equivalent of the following:
36
- * <h1>Hello World!</h1>
37
- * @type {string}
38
- */
39
- const html = '&lt;h1&gt;Hello World!&lt;/h1&gt;';
40
- const wrapper = createWrapper(html, {
41
- decode: true
42
- });
43
-
44
- // Test result of dangerouslySetInnerHTML.
45
- expect(wrapper.html()).toEqual('<div class="common__html-sanitizer"><h1>Hello World!</h1></div>');
46
- expect(wrapper.render()).toMatchSnapshot();
47
- });
48
- it('should add and remove handlers for embedded media', () => {
49
- const wrapper = createWrapper('<div></div>', {
50
- decode: true
51
- });
52
- const ref = wrapper.instance().htmlContainer.current;
53
- expect(embeddedMediaAddSpy).toHaveBeenCalledTimes(1);
54
- expect(embeddedMediaAddSpy).toHaveBeenCalledWith(ref);
55
- expect(embeddedMediaRemoveSpy).toHaveBeenCalledTimes(0);
56
- wrapper.setProps({
57
- children: '<span></span>'
58
- });
59
- expect(embeddedMediaAddSpy).toHaveBeenCalledTimes(2);
60
- expect(embeddedMediaAddSpy).toHaveBeenCalledWith(ref);
61
- expect(embeddedMediaRemoveSpy).toHaveBeenCalledTimes(0);
62
- wrapper.unmount();
63
- expect(embeddedMediaAddSpy).toHaveBeenCalledTimes(2);
64
- expect(embeddedMediaRemoveSpy).toHaveBeenCalledTimes(1);
65
- expect(embeddedMediaRemoveSpy).toHaveBeenCalledWith(ref);
66
- });
67
- it('strips out images with relative paths', () => {
68
- const html = `
69
- <div>
70
- <style>a { color: red }</style>
71
- <a href="foo">
72
- <img src="bar.jpg" />
73
- </a>
74
- </div>
75
- `;
76
- const wrapper = createWrapper(html);
77
- expect(wrapper.html()).not.toContain('<img');
78
- expect(wrapper.html()).toContain('<style>');
79
- expect(wrapper.render()).toMatchSnapshot();
80
- });
81
- it('should move style blocks out of the content', () => {
82
- const html = `
83
- <div>
84
- <style>a { color: red }</style>
85
- <a href="foo">
86
- <img src="bar.jpg" />
87
- </a>
88
- </div>
89
- `;
90
- const wrapper = createWrapper(html, {
91
- processStyles: true
92
- });
93
- expect(wrapper.html()).not.toContain('<style>');
94
- });
95
- it('does not strip out images with absolute paths', () => {
96
- const html = `
97
- <div>
98
- <a href="foo">
99
- <img src="http://google.de/bar.jpg" />
100
- </a>
101
- </div>
102
- `;
103
- const wrapper = createWrapper(html);
104
- expect(wrapper.html()).toContain('<img');
105
- expect(wrapper.render()).toMatchSnapshot();
106
- });
107
- it('strips out the script tags', () => {
108
- /**
109
- * The value for html is the HTML-escaped equivalent of the following:
110
- * <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
111
- * <script type="text/javascript">var x = 42;</script>
112
- * <p>Foo Bar</p>
113
- * <script>var y = 23;</script>
114
- * @type {string}
115
- */
116
- const html = '&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt;var x = 42;&lt;/script&gt; &lt;p&gt;Foo Bar&lt;/p&gt; &lt;script&gt;var y = 23;&lt;/script&gt;';
117
- const wrapper = createWrapper(html, {
118
- decode: true
119
- });
120
-
121
- // Test result of dangerouslySetInnerHTML.
122
- expect(wrapper.html()).toEqual('<div class="common__html-sanitizer"> <p>Foo Bar</p> </div>');
123
- expect(wrapper).toMatchSnapshot();
124
- });
125
- describe('Link handling', () => {
126
- const mockedHandleClick = jest.fn();
127
- beforeEach(() => {
128
- mockedHandleClick.mockClear();
129
- });
130
- it('follows a link from a plain <a>', () => {
131
- // Create a real container element in the current document
132
- const attachNode = document.createElement('div');
133
- document.body.appendChild(attachNode);
134
- const html = '&lt;a id=&quot;link&quot; href=&quot;#follow-me-and-everything-is-alright&quot;&gt;Plain Link&lt;/a&gt;';
135
- const wrapper = mount(/*#__PURE__*/_jsx(HtmlSanitizer, {
136
- decode: true,
137
- settings: {
138
- handleClick: mockedHandleClick
139
- },
140
- navigate: () => {},
141
- children: html
142
- }), {
143
- attachTo: attachNode
144
- });
145
- const aTag = attachNode.getElementsByTagName('a')[0];
146
- aTag.closest = () => aTag;
147
- const event = {
148
- target: aTag,
149
- preventDefault: () => {}
150
- };
151
- wrapper.instance().handleClick(event);
152
- expect(mockedHandleClick).toHaveBeenCalledTimes(1);
153
- expect(mockedHandleClick).toHaveBeenCalledWith('#follow-me-and-everything-is-alright', '');
154
- wrapper.unmount();
155
- attachNode.remove();
156
- });
157
- it('follows a link from a <a> with other HTML inside', () => {
158
- const attachNode = document.createElement('div');
159
- document.body.appendChild(attachNode);
160
- const html = '&lt;a id=&quot;link&quot; target=&quot;_blank&quot; href=&quot;#I-ll-be-the-one-to-tuck-you-in-at-night&quot;&gt;&lt;span&gt;Span Link&lt;/span&gt;&lt;/a&gt;';
161
- const wrapper = mount(/*#__PURE__*/_jsx(HtmlSanitizer, {
162
- decode: true,
163
- settings: {
164
- handleClick: mockedHandleClick
165
- },
166
- navigate: () => {},
167
- children: html
168
- }), {
169
- attachTo: attachNode
170
- });
171
- const aTag = attachNode.getElementsByTagName('a')[0];
172
- const spanTag = attachNode.getElementsByTagName('span')[0];
173
- spanTag.closest = () => aTag;
174
- const event = {
175
- target: spanTag,
176
- preventDefault: () => {}
177
- };
178
- wrapper.instance().handleClick(event);
179
- expect(mockedHandleClick).toHaveBeenCalledTimes(1);
180
- expect(mockedHandleClick).toHaveBeenCalledWith('#I-ll-be-the-one-to-tuck-you-in-at-night', '_blank');
181
- });
182
- });
183
- describe('Cookie consent handling', () => {
184
- it('should invoke handleCookieConsent method of embedded media with default cookie consent settings', () => {
185
- createWrapper('<div></div>', {
186
- decode: true
187
- });
188
- expect(embeddedMediaHandleCookieConsentSpy).toHaveBeenCalledTimes(1);
189
- expect(embeddedMediaHandleCookieConsentSpy).toHaveBeenCalledWith(expect.any(Document), {
190
- comfortCookiesAccepted: false,
191
- statisticsCookiesAccepted: false
192
- });
193
- });
194
- it('should invoke handleCookieConsent method of embedded media with accepted comfort cookies', () => {
195
- createWrapper('<div></div>', {
196
- decode: true,
197
- comfortCookiesAccepted: true
198
- });
199
- expect(embeddedMediaHandleCookieConsentSpy).toHaveBeenCalledTimes(1);
200
- expect(embeddedMediaHandleCookieConsentSpy).toHaveBeenCalledWith(expect.any(Document), {
201
- comfortCookiesAccepted: true,
202
- statisticsCookiesAccepted: false
203
- });
204
- });
205
- it('should invoke handleCookieConsent method of embedded media with accepted statistics cookies', () => {
206
- createWrapper('<div></div>', {
207
- decode: true,
208
- statisticsCookiesAccepted: true
209
- });
210
- expect(embeddedMediaHandleCookieConsentSpy).toHaveBeenCalledTimes(1);
211
- expect(embeddedMediaHandleCookieConsentSpy).toHaveBeenCalledWith(expect.any(Document), {
212
- comfortCookiesAccepted: false,
213
- statisticsCookiesAccepted: true
214
- });
215
- });
216
- it('should invoke handleCookieConsent method of embedded media with all cookies accepted', () => {
217
- createWrapper('<div></div>', {
218
- decode: true,
219
- comfortCookiesAccepted: true,
220
- statisticsCookiesAccepted: true
221
- });
222
- expect(embeddedMediaHandleCookieConsentSpy).toHaveBeenCalledTimes(1);
223
- expect(embeddedMediaHandleCookieConsentSpy).toHaveBeenCalledWith(expect.any(Document), {
224
- comfortCookiesAccepted: true,
225
- statisticsCookiesAccepted: true
226
- });
227
- });
228
- });
229
- });
@@ -1,54 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { i18n } from '@shopgate/engage/core';
4
- import I18n from "../../index";
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<FormatDate />', () => {
8
- const locales = {
9
- greeting: 'Hello {date}'
10
- };
11
- const lang = 'en-US';
12
- const timestamp = 123456789000;
13
- const formattedDate = 'Nov 29, 1973';
14
- const format = 'medium';
15
- i18n.init({
16
- locales,
17
- lang
18
- });
19
- describe('Given the component was mounted to the DOM', () => {
20
- let renderedElement;
21
- it('should match snapshot', () => {
22
- renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
23
- children: /*#__PURE__*/_jsxs("div", {
24
- children: [/*#__PURE__*/_jsx("span", {
25
- className: "only-date",
26
- children: /*#__PURE__*/_jsx(I18n.Date, {
27
- timestamp: timestamp,
28
- format: format
29
- })
30
- }), /*#__PURE__*/_jsx("span", {
31
- className: "text-with-date",
32
- children: /*#__PURE__*/_jsx(I18n.Text, {
33
- string: "greeting",
34
- children: /*#__PURE__*/_jsx(I18n.Date, {
35
- forKey: "date",
36
- timestamp: timestamp,
37
- format: format
38
- })
39
- })
40
- })]
41
- })
42
- }));
43
- expect(renderedElement).toMatchSnapshot();
44
- });
45
- it('should render formatted date', () => {
46
- const text = renderedElement.find('.only-date').text();
47
- expect(text).toBe(formattedDate);
48
- });
49
- it('should render within translated text', () => {
50
- const text = renderedElement.find('.text-with-date').text();
51
- expect(text).toBe(`Hello ${formattedDate}`);
52
- });
53
- });
54
- });
@@ -1,51 +0,0 @@
1
- import "core-js/modules/es.array.includes.js";
2
- import React from 'react';
3
- import { mount } from 'enzyme';
4
- import { i18n } from '@shopgate/engage/core';
5
- import I18n from "../../index";
6
- import FormatNumber from "./index";
7
- import { jsx as _jsx } from "react/jsx-runtime";
8
- jest.unmock('@shopgate/engage/core/helpers/i18n');
9
- describe('<FormatNumber>', () => {
10
- describe('i18n not ready', () => {
11
- it('should return same number and className when i18n is not ready', () => {
12
- const component = mount(/*#__PURE__*/_jsx(FormatNumber, {
13
- number: 1,
14
- fractions: 2,
15
- className: "some-class"
16
- }));
17
- expect(component.html().includes('some-class')).toBe(true);
18
- expect(component.text().includes('1')).toBe(true);
19
- expect(component).toMatchSnapshot();
20
- });
21
- });
22
- describe('i18n ready', () => {
23
- i18n.init({
24
- locales: {},
25
- lang: 'en-US'
26
- });
27
- const pairs = [[1, '1.00', 2], [0.1, '0.10', 2], [1, '1.000', 3], [1, '1', 0]];
28
-
29
- /**
30
- * Makes a component.
31
- * @param {number} number Number
32
- * @param {number} fractions Decimal points.
33
- * @returns {Object}
34
- */
35
- const makeComponent = (number, fractions) => mount(/*#__PURE__*/_jsx(I18n.Provider, {
36
- children: /*#__PURE__*/_jsx("div", {
37
- children: /*#__PURE__*/_jsx(FormatNumber, {
38
- number: number,
39
- fractions: fractions
40
- })
41
- })
42
- }));
43
- pairs.forEach(([input, expexted, fractions]) => {
44
- it(`should format ${input} into ${expexted}`, () => {
45
- const component = makeComponent(input, fractions);
46
- expect(component.text().includes(`${expexted}`)).toBe(true);
47
- expect(component).toMatchSnapshot();
48
- });
49
- });
50
- });
51
- });
@@ -1,54 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { i18n } from '@shopgate/engage/core';
4
- import I18n from "../../index";
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<FormatPrice />', () => {
8
- const locales = {
9
- greeting: 'Hello {price}'
10
- };
11
- const price = 1234.56;
12
- const formattedPrice = '€1,234.56';
13
- const currency = 'EUR';
14
- const lang = 'en-US';
15
- i18n.init({
16
- locales,
17
- lang
18
- });
19
- describe('Given the component was mounted to the DOM', () => {
20
- let renderedElement;
21
- it('should match snapshot', () => {
22
- renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
23
- children: /*#__PURE__*/_jsxs("div", {
24
- children: [/*#__PURE__*/_jsx("span", {
25
- className: "only-price",
26
- children: /*#__PURE__*/_jsx(I18n.Price, {
27
- price: price,
28
- currency: currency
29
- })
30
- }), /*#__PURE__*/_jsx("span", {
31
- className: "text-with-price",
32
- children: /*#__PURE__*/_jsx(I18n.Text, {
33
- string: "greeting",
34
- children: /*#__PURE__*/_jsx(I18n.Price, {
35
- forKey: "price",
36
- price: price,
37
- currency: currency
38
- })
39
- })
40
- })]
41
- })
42
- }));
43
- expect(renderedElement).toMatchSnapshot();
44
- });
45
- it('should render formatted price', () => {
46
- const text = renderedElement.find('.only-price').text();
47
- expect(text).toBe(formattedPrice);
48
- });
49
- it('should render within translated text', () => {
50
- const text = renderedElement.find('.text-with-price').text();
51
- expect(text).toBe(`Hello ${formattedPrice}`);
52
- });
53
- });
54
- });
@@ -1,51 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { i18n } from '@shopgate/engage/core';
4
- import I18n from "../../index";
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<FormatTime />', () => {
8
- const locales = {
9
- greeting: 'Hello {time}'
10
- };
11
- const timestamp = new Date('Dec 25, 1999 04:25:45').getTime();
12
- const formattedTime = '4:25:45 AM';
13
- const format = 'medium';
14
- const lang = 'en-US';
15
- i18n.init({
16
- locales,
17
- lang
18
- });
19
- describe('Given the component was mounted to the DOM', () => {
20
- // TODO: Handle snapshot test.
21
- const renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
22
- children: /*#__PURE__*/_jsxs("div", {
23
- children: [/*#__PURE__*/_jsx("span", {
24
- className: "only-time",
25
- children: /*#__PURE__*/_jsx(I18n.Time, {
26
- timestamp: timestamp,
27
- format: format
28
- })
29
- }), /*#__PURE__*/_jsx("span", {
30
- className: "text-with-time",
31
- children: /*#__PURE__*/_jsx(I18n.Text, {
32
- string: "greeting",
33
- children: /*#__PURE__*/_jsx(I18n.Time, {
34
- forKey: "time",
35
- timestamp: timestamp,
36
- format: format
37
- })
38
- })
39
- })]
40
- })
41
- }));
42
- it('should render formatted time', () => {
43
- const text = renderedElement.find('.only-time').text();
44
- expect(text).toBe(formattedTime);
45
- });
46
- it('should render within translated text', () => {
47
- const text = renderedElement.find('.text-with-time').text();
48
- expect(text).toBe(`Hello ${formattedTime}`);
49
- });
50
- });
51
- });
@@ -1,40 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import { i18n as i18nHelper } from '@shopgate/engage/core';
4
- import I18nProvider from "./index";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<I18nProvider />', () => {
8
- const locales = {
9
- greeting: 'Guten Tag {name}'
10
- };
11
- const lang = 'de-DE';
12
- i18nHelper.init({
13
- locales,
14
- lang
15
- });
16
- describe('Given the component was mounted to the DOM', () => {
17
- let renderedElement;
18
- let renderedInstance;
19
- it('should match snapshot', () => {
20
- renderedElement = shallow(/*#__PURE__*/_jsx(I18nProvider, {}));
21
- renderedInstance = renderedElement.instance();
22
- expect(renderedElement).toMatchSnapshot();
23
- });
24
- it('should provide access to i18n via context', () => {
25
- const {
26
- i18n
27
- } = renderedInstance.getChildContext();
28
- expect(i18n).toEqual(renderedInstance.getI18nInstance);
29
- });
30
- it('should translate when calling an instance method', () => {
31
- const {
32
- __
33
- } = renderedInstance.getI18nInstance();
34
- const translated = __('greeting', {
35
- name: 'Test'
36
- });
37
- expect(translated).toBe('Guten Tag Test');
38
- });
39
- });
40
- });
@@ -1,37 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { i18n } from '@shopgate/engage/core';
4
- import I18n from "../../index";
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<Placeholder />', () => {
8
- const locales = {
9
- greeting: 'Hello {world}'
10
- };
11
- const lang = 'en-US';
12
- i18n.init({
13
- locales,
14
- lang
15
- });
16
- describe('Given the component was mounted to the DOM', () => {
17
- let renderedElement;
18
- it('should render', () => {
19
- renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
20
- children: /*#__PURE__*/_jsxs(I18n.Text, {
21
- string: "greeting",
22
- children: [/*#__PURE__*/_jsx(I18n.Placeholder, {
23
- forKey: "world",
24
- children: /*#__PURE__*/_jsx("strong", {
25
- children: "WORLD"
26
- })
27
- }), "/"]
28
- })
29
- }));
30
- expect(renderedElement).toMatchSnapshot();
31
- });
32
- it('should render with a placeholder text', () => {
33
- const text = renderedElement.find('strong').text();
34
- expect(text).toBe('WORLD');
35
- });
36
- });
37
- });
@@ -1,33 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { i18n } from '@shopgate/engage/core';
4
- import I18n from "../../index";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- jest.unmock('@shopgate/engage/core/helpers/i18n');
7
- describe('<Translate />', () => {
8
- const locales = {
9
- greeting: 'Hello {name}'
10
- };
11
- i18n.init({
12
- locales,
13
- lang: 'en-US'
14
- });
15
- describe('Given the component was mounted to the DOM', () => {
16
- let renderedElement;
17
- it('should match snapshot', () => {
18
- renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
19
- children: /*#__PURE__*/_jsx(I18n.Text, {
20
- string: "greeting",
21
- params: {
22
- name: 'Test'
23
- }
24
- })
25
- }));
26
- expect(renderedElement).toMatchSnapshot();
27
- });
28
- it('should render translated text', () => {
29
- const text = renderedElement.find(I18n.Text).text();
30
- expect(text).toBe('Hello Test');
31
- });
32
- });
33
- });