@riosst100/pwa-marketplace 1.2.4 → 1.2.5

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 (70) hide show
  1. package/package.json +1 -1
  2. package/src/componentOverrideMapping.js +2 -1
  3. package/src/components/Filter/index.js +7 -7
  4. package/src/components/OperatingHours/index.js +1 -0
  5. package/src/components/OperatingHours/operatingHours.js +32 -0
  6. package/src/components/Pagination/index.js +26 -17
  7. package/src/components/Search/index.js +1 -1
  8. package/src/components/Seller/seller.js +137 -46
  9. package/src/components/Seller/sellerAddressCard.js +48 -0
  10. package/src/components/SellerDetail/index.js +1 -0
  11. package/src/components/SellerDetail/sellerDetail.js +158 -0
  12. package/src/components/SellerInformation/sellerInformation.js +51 -26
  13. package/src/components/SellerLocation/sellerLocation.js +6 -2
  14. package/src/components/SellerLocation/sellerLocationItem.js +6 -8
  15. package/src/components/SellerProducts/sellerProducts.js +33 -12
  16. package/src/components/SellerReview/sellerReview.js +29 -29
  17. package/src/components/SellerReviewItem/sellerReviewItem.js +8 -8
  18. package/src/components/SortBy/index.js +13 -5
  19. package/src/components/commons/Tabs/index.js +11 -9
  20. package/src/overwrites/venia-ui/lib/components/Header/header.js +46 -34
  21. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenu.spec.js +91 -0
  22. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenuItem.spec.js +123 -0
  23. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/Submenu.spec.js +61 -0
  24. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/SubmenuColumn.spec.js +50 -0
  25. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenu.spec.js.snap +114 -0
  26. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenuItem.spec.js.snap +71 -0
  27. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/Submenu.spec.js.snap +59 -0
  28. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/SubmenuColumn.spec.js.snap +34 -0
  29. package/src/overwrites/venia-ui/lib/components/MegaMenu/index.js +1 -0
  30. package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.js +90 -0
  31. package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.module.css +12 -0
  32. package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.js +156 -0
  33. package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.module.css +31 -0
  34. package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.js +89 -0
  35. package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.module.css +43 -0
  36. package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.js +99 -0
  37. package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.module.css +28 -0
  38. package/src/overwrites/venia-ui/lib/components/SearchBar/__stories__/searchBar.js +11 -0
  39. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/searchField.spec.js.snap +72 -0
  40. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedCategories.spec.js.snap +30 -0
  41. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProduct.spec.js.snap +69 -0
  42. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProducts.spec.js.snap +7 -0
  43. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestions.spec.js.snap +12 -0
  44. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/autocomplete.spec.js +52 -0
  45. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchBar.spec.js +82 -0
  46. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchField.spec.js +87 -0
  47. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedCategories.spec.js +45 -0
  48. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProduct.spec.js +43 -0
  49. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProducts.spec.js +45 -0
  50. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestions.spec.js +110 -0
  51. package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.js +172 -0
  52. package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.module.css +62 -0
  53. package/src/overwrites/venia-ui/lib/components/SearchBar/index.js +1 -0
  54. package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.js +74 -0
  55. package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.module.css +50 -0
  56. package/src/overwrites/venia-ui/lib/components/SearchBar/searchField.js +40 -0
  57. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.js +48 -0
  58. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.module.css +13 -0
  59. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategory.js +49 -0
  60. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategory.module.css +0 -0
  61. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.js +97 -0
  62. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.module.css +24 -0
  63. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.js +43 -0
  64. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.module.css +13 -0
  65. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.js +75 -0
  66. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.module.css +6 -0
  67. package/src/talons/Seller/seller.gql.js +70 -5
  68. package/src/talons/Seller/useSeller.js +6 -1
  69. package/src/talons/SellerProducts/useSellerProducts.js +129 -0
  70. package/src/theme/vars.js +7 -0
@@ -0,0 +1,99 @@
1
+ import React from 'react';
2
+ import { Link } from 'react-router-dom';
3
+
4
+ import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
5
+
6
+ import { useStyle } from '@magento/venia-ui/lib/classify';
7
+ import defaultClasses from './submenuColumn.module.css';
8
+ import PropTypes from 'prop-types';
9
+
10
+ /**
11
+ * The SubmenuColumn component displays columns with categories in submenu
12
+ *
13
+ * @param {MegaMenuCategory} props.category
14
+ * @param {function} props.onNavigate - function called when clicking on Link
15
+ */
16
+ const SubmenuColumn = props => {
17
+ const {
18
+ category,
19
+ categoryUrlSuffix,
20
+ onNavigate,
21
+ handleCloseSubMenu
22
+ } = props;
23
+ const classes = useStyle(defaultClasses, props.classes);
24
+
25
+ const categoryUrl = resourceUrl(
26
+ `/${category.url_path}${categoryUrlSuffix || ''}`
27
+ );
28
+ let children = null;
29
+
30
+ if (category.children.length) {
31
+ const childrenItems = category.children.map((subCategory, index) => {
32
+ const { url_path, isActive, name } = subCategory;
33
+ const categoryUrl = resourceUrl(
34
+ `/${url_path}${categoryUrlSuffix || ''}`
35
+ );
36
+
37
+ // setting keyboardProps if it is last child of that category
38
+ const keyboardProps =
39
+ index === category.children.length - 1
40
+ ? props.keyboardProps
41
+ : {};
42
+
43
+ return (
44
+ <li key={index} className={classes.submenuChildItem}>
45
+ <Link
46
+ {...keyboardProps}
47
+ className={isActive ? classes.linkActive : classes.link}
48
+ data-cy="MegaMenu-SubmenuColumn-link"
49
+ to={categoryUrl}
50
+ onClick={onNavigate}
51
+ >
52
+ {name}
53
+ </Link>
54
+ </li>
55
+ );
56
+ });
57
+
58
+ children = <ul className={classes.submenuChild}>{childrenItems}</ul>;
59
+ }
60
+
61
+ // setting keyboardProps if category does not have any sub-category
62
+ const keyboardProps = category.children.length ? {} : props.keyboardProps;
63
+
64
+ return (
65
+ <div className={classes.submenuColumn}>
66
+ <Link
67
+ {...keyboardProps}
68
+ className={classes.link}
69
+ data-cy="MegaMenu-SubmenuColumn-link"
70
+ to={categoryUrl}
71
+ onClick={() => {
72
+ handleCloseSubMenu();
73
+ onNavigate();
74
+ }}
75
+ >
76
+ <span className={classes.heading}>{category.name}</span>
77
+ </Link>
78
+ {children}
79
+ </div>
80
+ );
81
+ };
82
+
83
+ export default SubmenuColumn;
84
+
85
+ SubmenuColumn.propTypes = {
86
+ category: PropTypes.shape({
87
+ children: PropTypes.array,
88
+ uid: PropTypes.string.isRequired,
89
+ include_in_menu: PropTypes.number,
90
+ isActive: PropTypes.bool.isRequired,
91
+ name: PropTypes.string.isRequired,
92
+ path: PropTypes.array.isRequired,
93
+ position: PropTypes.number.isRequired,
94
+ url_path: PropTypes.string.isRequired
95
+ }).isRequired,
96
+ categoryUrlSuffix: PropTypes.string,
97
+ onNavigate: PropTypes.func.isRequired,
98
+ handleCloseSubMenu: PropTypes.func.isRequired
99
+ };
@@ -0,0 +1,28 @@
1
+ .submenuColumn {
2
+ composes: max-w-[235px] from global;
3
+ composes: p-5 from global;
4
+ }
5
+
6
+ .heading {
7
+ composes: font-semibold from global;
8
+ }
9
+
10
+ .link {
11
+ composes: whitespace-nowrap from global;
12
+
13
+ composes: focus_underline from global;
14
+
15
+ composes: hover_underline from global;
16
+ }
17
+
18
+ .linkActive {
19
+ composes: underline from global;
20
+ }
21
+
22
+ .submenuChild {
23
+ composes: mt-5 from global;
24
+ }
25
+
26
+ .submenuChildItem {
27
+ composes: mb-3 from global;
28
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { storiesOf } from '@storybook/react';
3
+
4
+ import SearchBar from '../searchBar';
5
+ import defaultClasses from '../searchBar.module.css';
6
+
7
+ const stories = storiesOf('Components/SearchBar', module);
8
+
9
+ stories.add('Search Bar', () => (
10
+ <SearchBar classes={defaultClasses} isOpen={true} />
11
+ ));
@@ -0,0 +1,72 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`renders correctly 1`] = `
4
+ <form
5
+ onKeyDown={[Function]}
6
+ onReset={[Function]}
7
+ onSubmit={[Function]}
8
+ >
9
+ <span
10
+ className="root"
11
+ style={
12
+ Object {
13
+ "--iconsAfter": 0,
14
+ "--iconsBefore": 1,
15
+ }
16
+ }
17
+ >
18
+ <span
19
+ className="input"
20
+ >
21
+ <input
22
+ className="input"
23
+ id="search_query"
24
+ name="search_query"
25
+ onBlur={[Function]}
26
+ onChange={[Function]}
27
+ onFocus={[MockFunction]}
28
+ value=""
29
+ />
30
+ </span>
31
+ <span
32
+ className="before"
33
+ >
34
+ <span
35
+ className="root"
36
+ >
37
+ <svg
38
+ className="icon"
39
+ fill="none"
40
+ height={24}
41
+ stroke="currentColor"
42
+ strokeLinecap="round"
43
+ strokeLinejoin="round"
44
+ strokeWidth="2"
45
+ viewBox="0 0 24 24"
46
+ width={24}
47
+ xmlns="http://www.w3.org/2000/svg"
48
+ >
49
+ <circle
50
+ cx="11"
51
+ cy="11"
52
+ r="8"
53
+ />
54
+ <line
55
+ x1="21"
56
+ x2="16.65"
57
+ y1="21"
58
+ y2="16.65"
59
+ />
60
+ </svg>
61
+ </span>
62
+ </span>
63
+ <span
64
+ aria-hidden="false"
65
+ className="after"
66
+ />
67
+ </span>
68
+ <p
69
+ className="root"
70
+ />
71
+ </form>
72
+ `;
@@ -0,0 +1,30 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`renders correctly 1`] = `
4
+ <ul>
5
+ <li>
6
+ <SuggestedCategory
7
+ label="A"
8
+ value="foo"
9
+ />
10
+ </li>
11
+ <li>
12
+ <SuggestedCategory
13
+ label="B"
14
+ value="foo"
15
+ />
16
+ </li>
17
+ <li>
18
+ <SuggestedCategory
19
+ label="C"
20
+ value="foo"
21
+ />
22
+ </li>
23
+ <li>
24
+ <SuggestedCategory
25
+ label="D"
26
+ value="foo"
27
+ />
28
+ </li>
29
+ </ul>
30
+ `;
@@ -0,0 +1,69 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`renders a suggestedProduct component 1`] = `
4
+ Array [
5
+ <div
6
+ className="root container"
7
+ >
8
+ <img
9
+ alt="Product Name"
10
+ aria-hidden="true"
11
+ className="image placeholder"
12
+ loading="eager"
13
+ src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHdpZHRoPSc0JyBoZWlnaHQ9JzUnPjxyZWN0IHdpZHRoPSc0JyBoZWlnaHQ9JzUnIHN0eWxlPSdmaWxsOiBub25lJyAvPjwvc3ZnPg=="
14
+ style={
15
+ Object {
16
+ "--width": "60px",
17
+ }
18
+ }
19
+ width={60}
20
+ />
21
+ <img
22
+ alt="Product Name"
23
+ className="image notLoaded"
24
+ loading="lazy"
25
+ onError={[Function]}
26
+ onLoad={[Function]}
27
+ sizes="60px"
28
+ src="/media/catalog/category/minimalist.jpg"
29
+ srcSet="/media/catalog/category/minimalist.jpg 40w,
30
+ /media/catalog/category/minimalist.jpg 80w,
31
+ /media/catalog/category/minimalist.jpg 160w,
32
+ /media/catalog/category/minimalist.jpg 320w,
33
+ /media/catalog/category/minimalist.jpg 640w,
34
+ /media/catalog/category/minimalist.jpg 960w,
35
+ /media/catalog/category/minimalist.jpg 1280w,
36
+ /media/catalog/category/minimalist.jpg 1600w,
37
+ /media/catalog/category/minimalist.jpg 2560w"
38
+ style={
39
+ Object {
40
+ "--height": "75px",
41
+ "--width": "60px",
42
+ }
43
+ }
44
+ width={60}
45
+ />
46
+ </div>,
47
+ <span
48
+ className="name"
49
+ >
50
+ Product Name
51
+ </span>,
52
+ <span
53
+ className="price"
54
+ >
55
+ <span>
56
+ $
57
+ </span>
58
+ <span>
59
+ 3
60
+ </span>
61
+ <span>
62
+ .
63
+ </span>
64
+ <span>
65
+ 50
66
+ </span>
67
+ </span>,
68
+ ]
69
+ `;
@@ -0,0 +1,7 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`renders correctly 1`] = `
4
+ <ul>
5
+ <li />
6
+ </ul>
7
+ `;
@@ -0,0 +1,12 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`renders correctly 1`] = `
4
+ <h2>
5
+ <span>
6
+ <mock-FormattedMessage
7
+ defaultMessage="Product Suggestions"
8
+ id="searchBar.heading"
9
+ />
10
+ </span>
11
+ </h2>
12
+ `;
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import { InMemoryCache } from '@apollo/client';
3
+ import { MockedProvider } from '@apollo/client/testing';
4
+ import { Form } from 'informed';
5
+ import { createTestInstance } from '@magento/peregrine';
6
+ import typePolicies from '@magento/peregrine/lib/Apollo/policies';
7
+
8
+ import Autocomplete from '../autocomplete';
9
+ import { IntlProvider } from 'react-intl';
10
+
11
+ jest.mock('../../../classify');
12
+ jest.mock('../suggestions', () => () => null);
13
+
14
+ jest.mock('@magento/peregrine/lib/context/eventing', () => ({
15
+ useEventingContext: jest.fn().mockReturnValue([{}, { dispatch: jest.fn() }])
16
+ }));
17
+
18
+ const cache = new InMemoryCache({
19
+ typePolicies
20
+ });
21
+
22
+ test('renders correctly', () => {
23
+ const { root } = createTestInstance(
24
+ <MockedProvider addTypename={true} cache={cache}>
25
+ <IntlProvider locale="en-US">
26
+ <Form>
27
+ <Autocomplete visible={false} />
28
+ </Form>
29
+ </IntlProvider>
30
+ </MockedProvider>
31
+ );
32
+
33
+ expect(root.findByProps({ className: 'root_hidden' })).toBeTruthy();
34
+ expect(root.findByProps({ className: 'message' })).toBeTruthy();
35
+ expect(root.findByProps({ className: 'suggestions' })).toBeTruthy();
36
+ });
37
+
38
+ test('renders correctly when visible', () => {
39
+ const { root } = createTestInstance(
40
+ <MockedProvider addTypename={true} cache={cache}>
41
+ <IntlProvider locale="en-US">
42
+ <Form>
43
+ <Autocomplete visible={true} />
44
+ </Form>
45
+ </IntlProvider>
46
+ </MockedProvider>
47
+ );
48
+
49
+ expect(root.findByProps({ className: 'root_visible' })).toBeTruthy();
50
+ expect(root.findByProps({ className: 'message' })).toBeTruthy();
51
+ expect(root.findByProps({ className: 'suggestions' })).toBeTruthy();
52
+ });
@@ -0,0 +1,82 @@
1
+ import React from 'react';
2
+ import { useHistory } from 'react-router-dom';
3
+
4
+ import { Form } from 'informed';
5
+ import { act } from 'react-test-renderer';
6
+ import { createTestInstance } from '@magento/peregrine';
7
+
8
+ import Autocomplete from '../autocomplete';
9
+ import SearchBar from '../searchBar';
10
+ import SearchField from '../searchField';
11
+
12
+ jest.mock('../../../classify');
13
+ jest.mock('../autocomplete', () => () => null);
14
+ jest.mock('../searchField', () => () => null);
15
+ jest.mock('react-router-dom', () => ({
16
+ useHistory: jest.fn(() => ({})),
17
+ useLocation: jest.fn(() => ({}))
18
+ }));
19
+
20
+ const push = jest.fn();
21
+ useHistory.mockImplementation(() => ({ push }));
22
+
23
+ test('renders correctly', () => {
24
+ const { root } = createTestInstance(<SearchBar isOpen={false} />);
25
+
26
+ expect(root.findByProps({ className: 'root' })).toBeTruthy();
27
+ expect(root.findByProps({ className: 'container' })).toBeTruthy();
28
+ expect(root.findByProps({ className: 'form' })).toBeTruthy();
29
+ expect(root.findByProps({ className: 'search' })).toBeTruthy();
30
+ expect(root.findByProps({ className: 'autocomplete' })).toBeTruthy();
31
+ });
32
+
33
+ test('sets different classnames when open', () => {
34
+ const { root } = createTestInstance(<SearchBar isOpen={true} />);
35
+
36
+ expect(root.findAllByProps({ className: 'root' })).toHaveLength(0);
37
+ expect(root.findByProps({ className: 'root_open' })).toBeTruthy();
38
+ });
39
+
40
+ test('expands or collapses on change, depending on the value', () => {
41
+ const { root } = createTestInstance(<SearchBar isOpen={false} />);
42
+
43
+ expect(root.findByType(Autocomplete).props.visible).toBe(false);
44
+
45
+ act(() => {
46
+ root.findByType(SearchField).props.onChange('foo');
47
+ });
48
+
49
+ expect(root.findByType(Autocomplete).props.visible).toBe(true);
50
+
51
+ act(() => {
52
+ root.findByType(SearchField).props.onChange('');
53
+ });
54
+
55
+ expect(root.findByType(Autocomplete).props.visible).toBe(false);
56
+ });
57
+
58
+ test('expands on focus', () => {
59
+ const { root } = createTestInstance(<SearchBar isOpen={false} />);
60
+
61
+ expect(root.findByType(Autocomplete).props.visible).toBe(false);
62
+
63
+ act(() => {
64
+ root.findByType(SearchField).props.onFocus();
65
+ });
66
+
67
+ expect(root.findByType(Autocomplete).props.visible).toBe(true);
68
+ });
69
+
70
+ test('navigates on submit', () => {
71
+ const { root } = createTestInstance(<SearchBar isOpen={false} />);
72
+
73
+ const inputString = 'foo';
74
+
75
+ act(() => {
76
+ root.findByType(Form).props.onSubmit({
77
+ search_query: inputString
78
+ });
79
+ });
80
+
81
+ expect(push).toHaveBeenLastCalledWith(`/search.html?query=${inputString}`);
82
+ });
@@ -0,0 +1,87 @@
1
+ import React from 'react';
2
+ import { Form } from 'informed';
3
+ import { act } from 'react-test-renderer';
4
+ import { createTestInstance } from '@magento/peregrine';
5
+ import Trigger from '../../Trigger';
6
+ import SearchField from '../searchField';
7
+
8
+ jest.mock('@magento/peregrine/lib/context/app', () => {
9
+ const state = {};
10
+ const api = {};
11
+ return {
12
+ useAppContext: jest.fn(() => [state, api])
13
+ };
14
+ });
15
+
16
+ jest.mock('../../../classify');
17
+ jest.mock('../../Trigger', () => () => null);
18
+
19
+ const onChange = jest.fn();
20
+ const onFocus = jest.fn();
21
+
22
+ test('renders correctly', () => {
23
+ const instance = createTestInstance(
24
+ <Form initialValues={{ search_query: '' }}>
25
+ <SearchField onChange={onChange} onFocus={onFocus} />
26
+ </Form>
27
+ );
28
+
29
+ expect(instance.toJSON()).toMatchSnapshot();
30
+ });
31
+
32
+ test('renders no reset button if value is empty', () => {
33
+ const { root } = createTestInstance(
34
+ <Form initialValues={{ search_query: '' }}>
35
+ <SearchField onChange={onChange} onFocus={onFocus} />
36
+ </Form>
37
+ );
38
+
39
+ expect(root.findAllByType(Trigger)).toHaveLength(0);
40
+ });
41
+
42
+ test('renders a reset button', () => {
43
+ let formApi;
44
+
45
+ const { root } = createTestInstance(
46
+ <Form
47
+ getApi={api => {
48
+ formApi = api;
49
+ }}
50
+ >
51
+ <SearchField onChange={onChange} onFocus={onFocus} />
52
+ </Form>
53
+ );
54
+
55
+ act(() => {
56
+ formApi.setValue('search_query', 'a');
57
+ });
58
+
59
+ expect(root.findAllByType(Trigger)).toHaveLength(1);
60
+ });
61
+
62
+ test('reset button resets the form', () => {
63
+ let formApi;
64
+
65
+ const { root } = createTestInstance(
66
+ <Form
67
+ getApi={api => {
68
+ formApi = api;
69
+ }}
70
+ >
71
+ <SearchField onChange={onChange} onFocus={onFocus} />
72
+ </Form>
73
+ );
74
+
75
+ act(() => {
76
+ formApi.setValue('search_query', 'a');
77
+ });
78
+
79
+ const trigger = root.findByType(Trigger);
80
+ const { action: resetForm } = trigger.props;
81
+
82
+ act(() => {
83
+ resetForm();
84
+ });
85
+
86
+ expect(formApi.getValue('search_query')).toBeUndefined();
87
+ });
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { useLocation } from 'react-router-dom';
3
+ import { createTestInstance } from '@magento/peregrine';
4
+ import SuggestedCategories from '../suggestedCategories';
5
+ import SuggestedCategory from '../suggestedCategory';
6
+
7
+ jest.mock('react-router-dom', () => ({
8
+ Link: jest.fn(() => null),
9
+ useLocation: jest.fn()
10
+ }));
11
+ jest.mock('../suggestedCategory', () => 'SuggestedCategory');
12
+
13
+ useLocation.mockReturnValue(globalThis.location);
14
+
15
+ const categories = [
16
+ { label: 'A', value_string: 'a' },
17
+ { label: 'B', value_string: 'b' },
18
+ { label: 'C', value_string: 'c' },
19
+ { label: 'D', value_string: 'd' },
20
+ { label: 'E', value_string: 'e' }
21
+ ];
22
+
23
+ test('renders correctly', () => {
24
+ const instance = createTestInstance(
25
+ <SuggestedCategories categories={categories} value="foo" />
26
+ );
27
+
28
+ expect(instance.toJSON()).toMatchSnapshot();
29
+ });
30
+
31
+ test('renders a max of 4 categories by default', () => {
32
+ const { root } = createTestInstance(
33
+ <SuggestedCategories categories={categories} value="foo" />
34
+ );
35
+
36
+ expect(root.findAllByType(SuggestedCategory)).toHaveLength(4);
37
+ });
38
+
39
+ test('allows the render limit to be configured', () => {
40
+ const { root } = createTestInstance(
41
+ <SuggestedCategories categories={categories} limit={2} value="foo" />
42
+ );
43
+
44
+ expect(root.findAllByType(SuggestedCategory)).toHaveLength(2);
45
+ });
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import TestRenderer from 'react-test-renderer';
3
+ import SuggestedProduct from '../suggestedProduct';
4
+
5
+ jest.mock('../../../classify');
6
+ jest.mock('react-router-dom', () => ({
7
+ Link: ({ children }) => children
8
+ }));
9
+ jest.mock('@magento/peregrine/lib/util/makeUrl');
10
+ jest.mock('@magento/peregrine/lib/context/eventing', () => ({
11
+ useEventingContext: jest.fn().mockReturnValue([{}, { dispatch: jest.fn() }])
12
+ }));
13
+
14
+ const defaultProps = {
15
+ handleOnProductOpen: jest.fn(),
16
+ url_key: 'urlKey',
17
+ small_image: '/media/catalog/category/minimalist.jpg',
18
+ name: 'Product Name',
19
+ price: {
20
+ regularPrice: {
21
+ amount: {
22
+ currency: 'USD',
23
+ value: 3.5
24
+ }
25
+ }
26
+ },
27
+ price_range: {
28
+ maximum_price: {
29
+ final_price: {
30
+ currency: 'USD',
31
+ value: 3.5
32
+ }
33
+ }
34
+ }
35
+ };
36
+
37
+ test('renders a suggestedProduct component', () => {
38
+ const component = TestRenderer.create(
39
+ <SuggestedProduct {...defaultProps} />
40
+ );
41
+
42
+ expect(component.toJSON()).toMatchSnapshot();
43
+ });
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { createTestInstance } from '@magento/peregrine';
3
+
4
+ import mapProduct from '../../../util/mapProduct';
5
+ import SuggestedProduct from '../suggestedProduct';
6
+ import SuggestedProducts from '../suggestedProducts';
7
+
8
+ jest.mock('../../../util/mapProduct', () => jest.fn());
9
+ jest.mock('../suggestedProduct', () => () => null);
10
+
11
+ const products = [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }];
12
+
13
+ test('renders correctly', () => {
14
+ const subset = products.slice(0, 1);
15
+
16
+ const instance = createTestInstance(
17
+ <SuggestedProducts products={subset} />
18
+ );
19
+
20
+ expect(instance.toJSON()).toMatchSnapshot();
21
+ });
22
+
23
+ test('renders a max of 3 products by default', () => {
24
+ const { root } = createTestInstance(
25
+ <SuggestedProducts products={products} />
26
+ );
27
+
28
+ expect(root.findAllByType(SuggestedProduct)).toHaveLength(3);
29
+ });
30
+
31
+ test('allows the render limit to be configured', () => {
32
+ const { root } = createTestInstance(
33
+ <SuggestedProducts limit={2} products={products} />
34
+ );
35
+
36
+ expect(root.findAllByType(SuggestedProduct)).toHaveLength(2);
37
+ });
38
+
39
+ test('calls `mapProduct()` for each item', () => {
40
+ createTestInstance(<SuggestedProducts limit={4} products={products} />);
41
+
42
+ products.forEach((product, index) => {
43
+ expect(mapProduct).toHaveBeenNthCalledWith(1 + index, product);
44
+ });
45
+ });