@shopgate/pwa-ui-shared 7.32.0-beta.2 → 7.32.0-beta.21

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 (68) hide show
  1. package/ActionButton/index.js +4 -0
  2. package/AddToCartButton/index.js +4 -1
  3. package/Button/index.js +10 -3
  4. package/ButtonLink/index.js +4 -0
  5. package/Card/index.js +13 -34
  6. package/CardList/components/Item/index.js +26 -20
  7. package/CardList/index.js +2 -1
  8. package/CartTotalLine/index.js +1 -1
  9. package/Dialog/components/PipelineErrorDialog/index.js +2 -1
  10. package/DiscountBadge/index.js +1 -1
  11. package/FavoritesButton/FavoritesButton.d.ts +74 -0
  12. package/FavoritesButton/FavoritesButton.d.ts.map +1 -0
  13. package/FavoritesButton/FavoritesButton.js +87 -0
  14. package/FavoritesButton/connector.d.ts +3 -0
  15. package/FavoritesButton/connector.d.ts.map +1 -0
  16. package/FavoritesButton/index.d.ts +3 -0
  17. package/FavoritesButton/index.d.ts.map +1 -0
  18. package/FavoritesButton/index.js +1 -134
  19. package/Glow/index.js +4 -3
  20. package/NoResults/components/Icon/index.js +4 -1
  21. package/NoResults/index.js +1 -1
  22. package/Price/index.js +11 -4
  23. package/PriceStriked/index.js +7 -1
  24. package/RatingStars/index.js +16 -5
  25. package/RippleButton/index.js +5 -1
  26. package/Sheet/index.js +11 -1
  27. package/TaxDisclaimer/index.js +0 -1
  28. package/package.json +5 -5
  29. package/AccordionContainer/spec.js +0 -35
  30. package/ActionButton/spec.js +0 -66
  31. package/AddToCartButton/spec.js +0 -68
  32. package/Availability/spec.js +0 -42
  33. package/Button/spec.js +0 -38
  34. package/ButtonLink/spec.js +0 -29
  35. package/Chip/spec.js +0 -27
  36. package/ContextMenu/spec.js +0 -113
  37. package/Dialog/components/HtmlContentDialog/spec.js +0 -107
  38. package/Dialog/components/PipelineErrorDialog/spec.js +0 -89
  39. package/Dialog/components/TextMessageDialog/spec.js +0 -62
  40. package/Dialog/components/VariantSelectModal/spec.js +0 -55
  41. package/Dialog/spec.js +0 -84
  42. package/DiscountBadge/spec.js +0 -20
  43. package/FavoritesButton/spec.js +0 -131
  44. package/Form/Builder/classes/ActionListener/spec.js +0 -323
  45. package/Form/Builder/spec.js +0 -309
  46. package/Form/InfoField/spec.js +0 -12
  47. package/Form/Password/spec.js +0 -39
  48. package/Form/RadioGroup/spec.js +0 -97
  49. package/Form/Select/spec.js +0 -39
  50. package/Form/SelectContextChoices/spec.js +0 -36
  51. package/Form/TextField/spec.js +0 -124
  52. package/FormElement/spec.js +0 -68
  53. package/Glow/spec.js +0 -14
  54. package/IndicatorCircle/spec.js +0 -26
  55. package/PlaceholderLabel/spec.js +0 -26
  56. package/PlaceholderParagraph/spec.js +0 -26
  57. package/ProgressBar/spec.js +0 -14
  58. package/RadioButton/spec.js +0 -22
  59. package/RatingStars/spec.js +0 -91
  60. package/RippleButton/spec.js +0 -58
  61. package/Sheet/components/Header/components/SearchBar/spec.js +0 -22
  62. package/Sheet/components/Header/spec.js +0 -17
  63. package/Sheet/spec.js +0 -100
  64. package/TaxDisclaimer/spec.js +0 -44
  65. package/TextField/spec.js +0 -146
  66. package/ToggleIcon/spec.js +0 -39
  67. package/tsconfig.build.json +0 -16
  68. package/tsconfig.json +0 -3
@@ -24,8 +24,14 @@ const calcAngle = element => {
24
24
  };
25
25
  const useStyles = makeStyles()(theme => ({
26
26
  root: {
27
+ '--font-size': `calc(${theme.typography.price.fontSize} * 0.75)`,
28
+ '--font-family': theme.typography.price.fontFamily,
29
+ '--font-weight': theme.typography.price.fontWeight,
30
+ fontSize: 'var(--font-size)',
31
+ fontFamily: 'var(--font-family)',
32
+ fontWeight: 'var(--font-weight)',
27
33
  whiteSpace: 'nowrap',
28
- color: theme.palette.grey.dark,
34
+ color: theme.components.price.strikedColor,
29
35
  '& span': {
30
36
  position: 'relative',
31
37
  '&::before': {
@@ -15,7 +15,7 @@ const ICON_SIZES = {
15
15
  const useStyles = makeStyles()(theme => ({
16
16
  container: {
17
17
  position: 'relative',
18
- display: 'inline-block',
18
+ display: 'inline-flex',
19
19
  verticalAlign: 'middle',
20
20
  maxWidth: '100%'
21
21
  },
@@ -43,6 +43,11 @@ const useStyles = makeStyles()(theme => ({
43
43
  position: 'absolute',
44
44
  left: 0,
45
45
  top: 0,
46
+ // Purely decorative overlay: let every pointer event fall through to the
47
+ // empty-star buttons underneath, which span all slots and handle selection.
48
+ // Without this, the invisible spacers/half-stars cover the higher-index
49
+ // buttons and swallow clicks in selectable mode.
50
+ pointerEvents: 'none',
46
51
  color: theme.components.ratingStars.filled,
47
52
  display: 'inline-flex',
48
53
  alignItems: 'center',
@@ -107,10 +112,10 @@ const RatingStars = ({
107
112
  const starProps = {
108
113
  className: iconClassName,
109
114
  key: numStars + pos,
115
+ // Decorative duplicate of the underlying empty-star button; hidden from
116
+ // assistive tech and non-interactive (the empty layer handles clicks).
110
117
  ...(isSelectable && {
111
- 'aria-hidden': true,
112
- role: 'button',
113
- onClick: e => handleSelection(e, pos)
118
+ 'aria-hidden': true
114
119
  })
115
120
  };
116
121
  return /*#__PURE__*/_jsx("div", {
@@ -124,7 +129,13 @@ const RatingStars = ({
124
129
  children: /*#__PURE__*/_jsx(StarHalfIcon, {
125
130
  size: size
126
131
  })
127
- }, i + numFullStars))), [iconClassName, numFullStars, numHalfStars, size, handleSelection, isSelectable]);
132
+ }, i + numFullStars)), times(Math.max(numStars - numFullStars - numHalfStars, 0), i => /*#__PURE__*/_jsx("div", {
133
+ className: iconClassName,
134
+ style: {
135
+ width: size
136
+ },
137
+ "aria-hidden": true
138
+ }, `placeholder-${i}`))), [iconClassName, numFullStars, numHalfStars, size, isSelectable]);
128
139
  return /*#__PURE__*/_jsxs("div", {
129
140
  role: isSelectable ? undefined : 'img',
130
141
  className: rootClassName,
@@ -14,6 +14,10 @@ const useStyles = makeStyles()(theme => ({
14
14
  /**
15
15
  * The ripple button component is a special derivation of the basic button component
16
16
  * that adds a ripple effect when clicked.
17
+ * @deprecated Use `Button` from `@shopgate/engage/components/v2` instead — it ripples by default,
18
+ * so `rippleClassName` and `rippleSize` are gone and `disableRipple` turns the effect off. Map
19
+ * `flat` to `variant="text"`, `type="secondary"` to `color="primary"`, and `type="primary"` or the
20
+ * default to `color="secondary"`.
17
21
  * @param {Object} props Props.
18
22
  * @returns {JSX.Element}
19
23
  */
@@ -34,7 +38,7 @@ const RippleButton = ({
34
38
  classes
35
39
  } = useStyles();
36
40
  const buttonProps = {
37
- className: `${className} ui-shared__ripple-button`,
41
+ className: cx(className, 'ui-shared__ripple-button'),
38
42
  disabled,
39
43
  onClick,
40
44
  flat,
package/Sheet/index.js CHANGED
@@ -106,7 +106,17 @@ const useStyles = makeStyles()(theme => ({
106
106
  },
107
107
  paddingBottom: [theme.layout.safeArea.bottom],
108
108
  overflowY: 'scroll',
109
- WebkitOverflowScrolling: 'touch'
109
+ WebkitOverflowScrolling: 'touch',
110
+ '@media (hover: hover) and (pointer: fine)': {
111
+ '::-webkit-scrollbar': {
112
+ width: 6,
113
+ background: 'transparent'
114
+ },
115
+ '::-webkit-scrollbar-thumb': {
116
+ background: theme.components.border.medium,
117
+ borderRadius: 4
118
+ }
119
+ }
110
120
  },
111
121
  drawerAnimIn: {
112
122
  [responsiveMediaQuery('<=sm', {
@@ -8,7 +8,6 @@ import { makeStyles } from '@shopgate/engage/styles';
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  const useStyles = makeStyles()(theme => ({
10
10
  text: {
11
- background: theme.palette.background.surface,
12
11
  padding: theme.spacing(2.5, 2)
13
12
  }
14
13
  }));
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-ui-shared",
3
- "version": "7.32.0-beta.2",
3
+ "version": "7.32.0-beta.21",
4
4
  "description": "Shopgate's shared UI components.",
5
5
  "main": "index.js",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
8
- "@shopgate/pwa-ui-ios": "7.32.0-beta.2",
9
- "@shopgate/pwa-ui-material": "7.32.0-beta.2"
8
+ "@shopgate/pwa-ui-ios": "7.32.0-beta.21",
9
+ "@shopgate/pwa-ui-material": "7.32.0-beta.21"
10
10
  },
11
11
  "devDependencies": {
12
- "@shopgate/pwa-common": "7.32.0-beta.2",
13
- "@shopgate/pwa-common-commerce": "7.32.0-beta.2",
12
+ "@shopgate/pwa-common": "7.32.0-beta.21",
13
+ "@shopgate/pwa-common-commerce": "7.32.0-beta.21",
14
14
  "classnames": "2.5.1",
15
15
  "react": "^17.0.2"
16
16
  },
@@ -1,35 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import AccordionContainer from "./index";
4
-
5
- /**
6
- * @returns {JSX}
7
- */
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- const Child = () => /*#__PURE__*/_jsx("div", {});
10
- describe('<AccordionContainer />', () => {
11
- it('should render children with props', () => {
12
- const wrapper = shallow(/*#__PURE__*/_jsx(AccordionContainer, {
13
- children: props => /*#__PURE__*/_jsx(Child, {
14
- ...props
15
- })
16
- }));
17
- const props = wrapper.find('Child').props();
18
- expect(wrapper).toMatchSnapshot();
19
- expect(props.open).toEqual(false);
20
- expect(typeof props.handleOpen).toEqual('function');
21
- expect(typeof props.handleClose).toEqual('function');
22
- });
23
- it('should update children props when state changes', () => {
24
- const wrapper = shallow(/*#__PURE__*/_jsx(AccordionContainer, {
25
- children: props => /*#__PURE__*/_jsx(Child, {
26
- ...props
27
- })
28
- }));
29
- wrapper.setState({
30
- open: true
31
- });
32
- expect(wrapper).toMatchSnapshot();
33
- expect(wrapper.find('Child').props().open).toEqual(true);
34
- });
35
- });
@@ -1,66 +0,0 @@
1
- import React from 'react';
2
- import { fireEvent, render, screen } from '@testing-library/react';
3
- import ActionButton from "./index";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- describe('<ActionButton />', () => {
6
- const renderComponent = (props = {}) => render(/*#__PURE__*/_jsx(ActionButton, {
7
- ...props,
8
- children: "Action Button"
9
- }));
10
- describe('Given the component was mounted to the DOM', () => {
11
- let renderedElement;
12
- let mockOnClick;
13
- beforeEach(() => {
14
- jest.useFakeTimers();
15
- mockOnClick = jest.fn();
16
- renderedElement = renderComponent({
17
- onClick: mockOnClick
18
- });
19
- });
20
- afterEach(() => {
21
- jest.clearAllTimers();
22
- jest.useRealTimers();
23
- });
24
- it('should match snapshot', () => {
25
- expect(renderedElement.container.firstChild).toMatchSnapshot();
26
- });
27
- it('should not show the loading indicator by default', () => {
28
- const indicator = renderedElement.container.querySelector('[data-test-id="loadingIndicator"]');
29
- expect(indicator).toBeNull();
30
- });
31
- describe('Given the loading prop is set to true', () => {
32
- beforeEach(() => {
33
- renderedElement.rerender(/*#__PURE__*/_jsx(ActionButton, {
34
- onClick: mockOnClick,
35
- loading: true,
36
- children: "Action Button"
37
- }));
38
- });
39
- it('should match snapshot', () => {
40
- expect(renderedElement.container.firstChild).toMatchSnapshot();
41
- });
42
- it('should show the loading indicator', () => {
43
- const indicator = renderedElement.container.querySelector('[data-test-id="loadingIndicator"]');
44
- expect(indicator).toBeTruthy();
45
- });
46
- });
47
- describe('Given the component gets clicked', () => {
48
- let timeoutSpy;
49
- beforeEach(() => {
50
- timeoutSpy = jest.spyOn(global, 'setTimeout');
51
- fireEvent.click(screen.getByRole('button'));
52
- });
53
- afterEach(() => {
54
- timeoutSpy.mockRestore();
55
- });
56
- it('should use setTimeout for delaying the onClick handler', () => {
57
- expect(timeoutSpy).toHaveBeenCalledTimes(1);
58
- expect(timeoutSpy.mock.calls[0][1]).toBe(ActionButton.clickDelay);
59
- });
60
- it('should eventually call the onClick handler', () => {
61
- jest.runOnlyPendingTimers();
62
- expect(mockOnClick).toHaveBeenCalledTimes(1);
63
- });
64
- });
65
- });
66
- });
@@ -1,68 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import { act } from 'react-dom/test-utils';
4
- import AddToCartButton from "./index";
5
-
6
- /**
7
- * Flushes the promise queue.
8
- * @returns {Promise}
9
- */
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- const flushMicrotasks = () => Promise.resolve();
12
- describe('<AddToCartButton />', () => {
13
- it('should render in loading state and should not be clickable', () => {
14
- const spy = jest.fn(() => Promise.resolve());
15
- const wrapper = mount(/*#__PURE__*/_jsx(AddToCartButton, {
16
- onClick: spy,
17
- isLoading: true,
18
- isOrderable: true,
19
- isDisabled: false
20
- }));
21
-
22
- // Click shouldn’t fire when loading
23
- wrapper.find('button').prop('onClick')();
24
- expect(wrapper).toMatchSnapshot();
25
- expect(spy).toHaveBeenCalledTimes(0);
26
- });
27
- it('should render with checkmark icon and should not be clickable the second time', async () => {
28
- const spy = jest.fn(() => Promise.resolve());
29
- const wrapper = mount(/*#__PURE__*/_jsx(AddToCartButton, {
30
- onClick: spy,
31
- isLoading: false,
32
- isOrderable: true,
33
- isDisabled: false
34
- }));
35
-
36
- // First click triggers async work
37
- await act(async () => {
38
- wrapper.find('button').prop('onClick')();
39
- await flushMicrotasks();
40
- });
41
- wrapper.update();
42
-
43
- // Second click should be ignored
44
- await act(async () => {
45
- wrapper.find('button').prop('onClick')();
46
- await flushMicrotasks();
47
- });
48
- wrapper.update();
49
- expect(wrapper).toMatchSnapshot();
50
- expect(spy).toHaveBeenCalledTimes(1);
51
- });
52
- it('should render with cart icon and should be clickable', async () => {
53
- const spy = jest.fn(() => Promise.resolve());
54
- const wrapper = mount(/*#__PURE__*/_jsx(AddToCartButton, {
55
- onClick: spy,
56
- isLoading: false,
57
- isOrderable: true,
58
- isDisabled: false
59
- }));
60
- await act(async () => {
61
- wrapper.find('button').prop('onClick')();
62
- await flushMicrotasks();
63
- });
64
- wrapper.update();
65
- expect(wrapper).toMatchSnapshot();
66
- expect(spy).toHaveBeenCalledTimes(1);
67
- });
68
- });
@@ -1,42 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import { AVAILABILITY_STATE_OK, AVAILABILITY_STATE_WARNING, AVAILABILITY_STATE_ALERT } from '@shopgate/pwa-common-commerce/product/constants';
4
- import Availability from "./index";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- describe('<Availability />', () => {
7
- it('should not render when text is empty', () => {
8
- const wrapper = render(/*#__PURE__*/_jsx(Availability, {
9
- text: ""
10
- }));
11
- expect(wrapper.asFragment()).toMatchSnapshot();
12
- });
13
- it('should not render by default if state is "ok"', () => {
14
- const wrapper = render(/*#__PURE__*/_jsx(Availability, {
15
- state: AVAILABILITY_STATE_OK,
16
- text: "Available"
17
- }));
18
- expect(wrapper.asFragment()).toMatchSnapshot();
19
- });
20
- it('should render if state is "ok" when "showWhenAvailable" is set', () => {
21
- const wrapper = render(/*#__PURE__*/_jsx(Availability, {
22
- state: AVAILABILITY_STATE_OK,
23
- text: "Available",
24
- showWhenAvailable: true
25
- }));
26
- expect(wrapper.asFragment()).toMatchSnapshot();
27
- });
28
- it('should render if state is "warning"', () => {
29
- const wrapper = render(/*#__PURE__*/_jsx(Availability, {
30
- state: AVAILABILITY_STATE_WARNING,
31
- text: "Only 5 left"
32
- }));
33
- expect(wrapper.asFragment()).toMatchSnapshot();
34
- });
35
- it('should render if state is "warning"', () => {
36
- const wrapper = render(/*#__PURE__*/_jsx(Availability, {
37
- state: AVAILABILITY_STATE_ALERT,
38
- text: "Out of stock"
39
- }));
40
- expect(wrapper.asFragment()).toMatchSnapshot();
41
- });
42
- });
package/Button/spec.js DELETED
@@ -1,38 +0,0 @@
1
- import trim from 'lodash/trim';
2
- import React from 'react';
3
- import { shallow } from 'enzyme';
4
- import Button from "./index";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- describe('<Button />', () => {
7
- it('should render as a regular button if type is omitted', () => {
8
- const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
9
- children: "Press me"
10
- }));
11
- expect(wrapper).toMatchSnapshot();
12
- expect(wrapper.render().text()).toEqual('Press me');
13
- });
14
- it('should render as a regular button if type is explicitly defined', () => {
15
- const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
16
- type: "regular",
17
- children: "Press me"
18
- }));
19
- expect(wrapper).toMatchSnapshot();
20
- expect(trim(wrapper.prop('className'))).toMatch(/^ui-shared__button\s+/);
21
- });
22
- it('should render as a primary button', () => {
23
- const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
24
- type: "primary",
25
- children: "Press me"
26
- }));
27
- expect(trim(wrapper.prop('className'))).toMatch(/^ui-shared__button\s+/);
28
- expect(wrapper).toMatchSnapshot();
29
- });
30
- it('should render as a secondary button', () => {
31
- const wrapper = shallow(/*#__PURE__*/_jsx(Button, {
32
- type: "secondary",
33
- children: "Press me"
34
- }));
35
- expect(trim(wrapper.prop('className'))).toMatch(/^ui-shared__button\s+/);
36
- expect(wrapper).toMatchSnapshot();
37
- });
38
- });
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import { fireEvent, render } from '@testing-library/react';
3
- import { UnwrappedButtonLink as ButtonLink } from "./index";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- describe('<ButtonLink>', () => {
6
- describe('On click action', () => {
7
- beforeEach(() => {
8
- jest.useFakeTimers();
9
- });
10
- afterEach(() => {
11
- jest.runOnlyPendingTimers();
12
- jest.useRealTimers();
13
- });
14
- it('should create component and open page on click', () => {
15
- const mockedNavigate = jest.fn();
16
- const link = 'https://example.com';
17
- const component = render(/*#__PURE__*/_jsx(ButtonLink, {
18
- href: link,
19
- navigate: mockedNavigate,
20
- children: "Text inside"
21
- }));
22
- expect(component.container.firstChild).toMatchSnapshot();
23
- fireEvent.click(component.container.querySelector('button'));
24
- jest.runOnlyPendingTimers();
25
- expect(mockedNavigate).toHaveBeenCalledTimes(1);
26
- expect(mockedNavigate).toHaveBeenCalledWith(link);
27
- });
28
- });
29
- });
package/Chip/spec.js DELETED
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- import { mount } from 'enzyme';
3
- import Chip from '.';
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- describe('<Chip />', () => {
6
- it('should render a tag', () => {
7
- const wrapper = mount(/*#__PURE__*/_jsx(Chip, {
8
- id: "some-id",
9
- children: "text"
10
- }));
11
- expect(wrapper).toMatchSnapshot();
12
- expect(wrapper.find('button').length).toEqual(2);
13
- expect(wrapper.find('button').at(1).text()).toEqual('text');
14
- });
15
- });
16
- describe('<Chip />', () => {
17
- it('should render a without removable icon', () => {
18
- const wrapper = mount(/*#__PURE__*/_jsx(Chip, {
19
- id: "some-id",
20
- removable: false,
21
- children: "text"
22
- }));
23
- expect(wrapper).toMatchSnapshot();
24
- expect(wrapper.find('button').length).toEqual(1);
25
- expect(wrapper.find('button').at(0).text()).toEqual('text');
26
- });
27
- });
@@ -1,113 +0,0 @@
1
- import React from 'react';
2
- import { mount, shallow } from 'enzyme';
3
- import { act } from 'react-dom/test-utils';
4
- import Backdrop from '@shopgate/pwa-common/components/Backdrop';
5
- import ContextMenu from "./index";
6
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
- jest.mock('@shopgate/engage/components');
8
- jest.mock('@shopgate/engage/a11y/components');
9
- global.requestAnimationFrame = fn => fn();
10
- jest.useFakeTimers();
11
- describe('<ContextMenu />', () => {
12
- const mockItemAClick = jest.fn();
13
- const mockItemBClick = jest.fn();
14
- const numMenuItems = 2;
15
- describe('Snapshot test', () => {
16
- it('should match snapshot', () => {
17
- const wrapper = shallow(/*#__PURE__*/_jsxs(ContextMenu, {
18
- isOpened: true,
19
- children: [/*#__PURE__*/_jsx(ContextMenu.Item, {
20
- onClick: mockItemAClick,
21
- className: "menu-active-item",
22
- children: "Item A"
23
- }), /*#__PURE__*/_jsx(ContextMenu.Item, {
24
- onClick: mockItemBClick,
25
- className: "menu-active-item",
26
- children: "Item B"
27
- })]
28
- }));
29
- expect(wrapper).toMatchSnapshot();
30
- });
31
- it('should match snapshot without toggle', () => {
32
- const wrapper = shallow(/*#__PURE__*/_jsx(ContextMenu, {
33
- isOpened: true,
34
- showToggle: false,
35
- children: /*#__PURE__*/_jsx(ContextMenu.Item, {
36
- onClick: mockItemAClick,
37
- className: "menu-active-item",
38
- children: "Item A"
39
- })
40
- }));
41
- expect(wrapper).toMatchSnapshot();
42
- });
43
- });
44
- describe('Given the component was mounted to the DOM', () => {
45
- let renderedElement;
46
-
47
- /**
48
- * The view component
49
- */
50
- const renderComponent = () => {
51
- renderedElement = mount(/*#__PURE__*/_jsxs(ContextMenu, {
52
- children: [/*#__PURE__*/_jsx(ContextMenu.Item, {
53
- onClick: mockItemAClick,
54
- children: "Item A"
55
- }), /*#__PURE__*/_jsx(ContextMenu.Item, {
56
- onClick: mockItemBClick,
57
- children: "Item B"
58
- })]
59
- }));
60
- };
61
- beforeEach(renderComponent);
62
- it('should match snapshot', () => {
63
- expect(renderedElement).toMatchSnapshot();
64
- });
65
- it('should have active state set to false', () => {
66
- expect(renderedElement.find('ConnectedReactPortal').prop('isOpened')).toBe(null);
67
- });
68
- it('should render the toggle button', () => {
69
- expect(renderedElement.find('button').length).toBe(1);
70
- });
71
- it('should not render any context menu items', () => {
72
- expect(renderedElement.find(ContextMenu.Item).length).toBe(0);
73
- });
74
- describe('Given toggle button gets clicked', () => {
75
- beforeEach(() => {
76
- renderedElement.find('button').simulate('click');
77
- renderedElement.update();
78
- });
79
- it('should have active state set to true', () => {
80
- expect(renderedElement.find('ConnectedReactPortal').prop('isOpened')).toBe(true);
81
- });
82
- it('should render the actual context menu w/ items', () => {
83
- expect(renderedElement.find(ContextMenu.Item).length).toBe(numMenuItems);
84
- });
85
- describe('Given the first item gets clicked', () => {
86
- beforeEach(() => {
87
- act(() => {
88
- renderedElement.find(ContextMenu.Item).first().children().find('[data-test-id="contextMenuButton"]').first().simulate('click');
89
- jest.runAllTimers();
90
- });
91
- });
92
- it('should call the related click handler', () => {
93
- expect(mockItemAClick).toBeCalled();
94
- });
95
- it('should close the context menu', () => {
96
- renderedElement.update();
97
- expect(renderedElement.find(ContextMenu.Item).length).toBe(0);
98
- });
99
- });
100
- describe('Given the backdrop gets clicked', () => {
101
- beforeEach(() => {
102
- renderedElement.find(Backdrop).children().find('[onClick]').simulate('click');
103
- });
104
- it('should have active state reset to false', () => {
105
- expect(renderedElement.find('ConnectedReactPortal').prop('isOpened')).toBe(false);
106
- });
107
- it('should close the context menu', () => {
108
- expect(renderedElement.find(ContextMenu.Item).length).toBe(0);
109
- });
110
- });
111
- });
112
- });
113
- });
@@ -1,107 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from 'enzyme';
3
- import HtmlContentDialog from "./index";
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- const message = '<p><i>This is a html message.</i></p>';
6
- const title = 'This is the title.';
7
- jest.mock('@shopgate/engage/a11y/components');
8
- jest.mock('@shopgate/engage/components', () => {
9
- const mockReact = jest.requireActual('react');
10
- function Text({
11
- string
12
- }) {
13
- return mockReact.createElement('span', null, string);
14
- }
15
- Text.propTypes = {
16
- params: () => null
17
- };
18
- Text.defaultProps = {
19
- params: {}
20
- };
21
- const I18n = {
22
- Text
23
- };
24
- function Ellipsis({
25
- children
26
- }) {
27
- return mockReact.createElement('span', null, children);
28
- }
29
- function Button({
30
- children,
31
- onClick,
32
- disabled,
33
- className
34
- }) {
35
- return mockReact.createElement('button', {
36
- onClick,
37
- disabled,
38
- className
39
- }, children);
40
- }
41
- function Typography({
42
- children
43
- }) {
44
- return mockReact.createElement('span', null, children);
45
- }
46
- return {
47
- I18n,
48
- Ellipsis,
49
- Button,
50
- Typography
51
- };
52
- });
53
- describe('<HtmlContentDialog />', () => {
54
- it('should render with minimal props', () => {
55
- const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
56
- message: message,
57
- actions: []
58
- }));
59
- expect(wrapper).toMatchSnapshot();
60
- expect(wrapper.html()).toMatch(message);
61
- });
62
- it('should render with title and html message', () => {
63
- const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
64
- title: title,
65
- message: message,
66
- actions: []
67
- }));
68
- expect(wrapper).toMatchSnapshot();
69
- expect(wrapper.html()).toMatch(title);
70
- });
71
- it('should render with title, html message and messageParams', () => {
72
- const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
73
- title: title,
74
- message: "Message with {name}",
75
- params: {
76
- name: 'Placeholder'
77
- },
78
- actions: []
79
- }));
80
- expect(wrapper).toMatchSnapshot();
81
- });
82
- it('should render the actions', () => {
83
- const actions = [{
84
- label: 'fooAction',
85
- action: () => {}
86
- }];
87
- const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
88
- title: title,
89
- message: message,
90
- actions: actions
91
- }));
92
- expect(wrapper).toMatchSnapshot();
93
- expect(wrapper.html()).toMatch(actions[0].label);
94
- });
95
- it('should pass title through', () => {
96
- const customTitle = /*#__PURE__*/_jsx("div", {
97
- children: "Title"
98
- });
99
- const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
100
- title: customTitle,
101
- message: message,
102
- params: {},
103
- actions: []
104
- }));
105
- expect(wrapper.find('BasicDialog').prop('title')).toEqual(customTitle);
106
- });
107
- });