@riosst100/pwa-marketplace 1.2.4 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/OperatingHours/index.js +1 -0
- package/src/components/OperatingHours/operatingHours.js +32 -0
- package/src/components/Seller/seller.js +2 -119
- package/src/components/Seller/sellerAddressCard.js +48 -0
- package/src/components/SellerDetail/index.js +1 -0
- package/src/components/SellerDetail/sellerDetail.js +158 -0
- package/src/components/SellerInformation/sellerInformation.js +20 -29
- package/src/components/SellerLocation/sellerLocation.js +4 -5
- package/src/components/SellerLocation/sellerLocationItem.js +6 -8
- package/src/components/SellerProducts/sellerProducts.js +212 -40
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenu.spec.js +91 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenuItem.spec.js +123 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/Submenu.spec.js +61 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/SubmenuColumn.spec.js +50 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenu.spec.js.snap +114 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenuItem.spec.js.snap +71 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/Submenu.spec.js.snap +59 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/SubmenuColumn.spec.js.snap +34 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/index.js +1 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.js +90 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.module.css +12 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.js +156 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.module.css +31 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.js +89 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.module.css +43 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.js +99 -0
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.module.css +28 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__stories__/searchBar.js +11 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/searchField.spec.js.snap +72 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedCategories.spec.js.snap +30 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProduct.spec.js.snap +69 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProducts.spec.js.snap +7 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestions.spec.js.snap +12 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/autocomplete.spec.js +52 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchBar.spec.js +82 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchField.spec.js +87 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedCategories.spec.js +45 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProduct.spec.js +43 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProducts.spec.js +45 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestions.spec.js +110 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.js +172 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.module.css +62 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/index.js +1 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.js +74 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.module.css +50 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchField.js +40 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.js +48 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.module.css +13 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategory.js +49 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategory.module.css +0 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.js +97 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.module.css +24 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.js +43 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.module.css +13 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.js +75 -0
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.module.css +6 -0
- package/src/talons/Seller/seller.gql.js +70 -5
- package/src/talons/Seller/useSeller.js +6 -1
- package/src/talons/SellerProducts/useSellerProducts.js +129 -0
- package/src/theme/vars.js +7 -0
|
@@ -1,46 +1,218 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import React, { Fragment, Suspense, useMemo, useRef } from 'react';
|
|
2
|
+
import { FormattedMessage } from 'react-intl';
|
|
3
|
+
import { array, number, shape, string } from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import { useIsInViewport } from '@magento/peregrine/lib/hooks/useIsInViewport';
|
|
6
|
+
|
|
7
|
+
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
8
|
+
import Breadcrumbs from '@magento/venia-ui/lib/components/Breadcrumbs';
|
|
9
|
+
import FilterModalOpenButton, {
|
|
10
|
+
FilterModalOpenButtonShimmer
|
|
11
|
+
} from '@magento/venia-ui/lib/components/FilterModalOpenButton';
|
|
12
|
+
import { FilterSidebarShimmer } from '@magento/venia-ui/lib/components/FilterSidebar';
|
|
13
|
+
import Gallery, { GalleryShimmer } from '@magento/venia-ui/lib/components/Gallery';
|
|
14
|
+
import { StoreTitle } from '@magento/venia-ui/lib/components/Head';
|
|
15
|
+
import Pagination from '@magento/venia-ui/lib/components/Pagination';
|
|
16
|
+
import ProductSort, { ProductSortShimmer } from '@magento/venia-ui/lib/components/ProductSort';
|
|
17
|
+
import RichContent from '@magento/venia-ui/lib/components/RichContent';
|
|
18
|
+
import Shimmer from '@magento/venia-ui/lib/components/Shimmer';
|
|
19
|
+
import SortedByContainer, {
|
|
20
|
+
SortedByContainerShimmer
|
|
21
|
+
} from '@magento/venia-ui/lib/components/SortedByContainer';
|
|
22
|
+
import defaultClasses from '@magento/venia-ui/lib/RootComponents/Category/category.module.css';
|
|
23
|
+
import NoProductsFound from '@magento/venia-ui/lib/RootComponents/Category/NoProductsFound';
|
|
24
|
+
import { useSellerProducts } from '@riosst100/pwa-marketplace/src/talons/SellerProducts/useSellerProducts';
|
|
25
|
+
|
|
26
|
+
const FilterModal = React.lazy(() => import('@magento/venia-ui/lib/components/FilterModal'));
|
|
27
|
+
const FilterSidebar = React.lazy(() =>
|
|
28
|
+
import('@magento/venia-ui/lib/components/FilterSidebar')
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const SellerProducts = props => {
|
|
32
|
+
const {
|
|
33
|
+
categoryId,
|
|
34
|
+
data,
|
|
35
|
+
isLoading,
|
|
36
|
+
pageControl,
|
|
37
|
+
sortProps,
|
|
38
|
+
pageSize
|
|
39
|
+
} = props;
|
|
40
|
+
const [currentSort] = sortProps;
|
|
41
|
+
|
|
42
|
+
const talonProps = useSellerProducts({
|
|
43
|
+
categoryId,
|
|
44
|
+
data,
|
|
45
|
+
pageSize
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
availableSortMethods,
|
|
50
|
+
categoryName,
|
|
51
|
+
categoryDescription,
|
|
52
|
+
filters,
|
|
53
|
+
items,
|
|
54
|
+
totalCount,
|
|
55
|
+
totalPagesFromData
|
|
56
|
+
} = talonProps;
|
|
57
|
+
|
|
58
|
+
const sidebarRef = useRef(null);
|
|
59
|
+
const classes = useStyle(defaultClasses, props.classes);
|
|
60
|
+
const shouldRenderSidebarContent = useIsInViewport({
|
|
61
|
+
elementRef: sidebarRef
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const shouldShowFilterButtons = filters && filters.length;
|
|
65
|
+
const shouldShowFilterShimmer = filters === null;
|
|
66
|
+
|
|
67
|
+
// If there are no products we can hide the sort button.
|
|
68
|
+
const shouldShowSortButtons = totalPagesFromData && availableSortMethods;
|
|
69
|
+
const shouldShowSortShimmer = !totalPagesFromData && isLoading;
|
|
70
|
+
|
|
71
|
+
const maybeFilterButtons = shouldShowFilterButtons ? (
|
|
72
|
+
<FilterModalOpenButton filters={filters} />
|
|
73
|
+
) : shouldShowFilterShimmer ? (
|
|
74
|
+
<FilterModalOpenButtonShimmer />
|
|
75
|
+
) : null;
|
|
76
|
+
|
|
77
|
+
const filtersModal = shouldShowFilterButtons ? (
|
|
78
|
+
<FilterModal filters={filters} />
|
|
79
|
+
) : null;
|
|
80
|
+
|
|
81
|
+
const sidebar = shouldShowFilterButtons ? (
|
|
82
|
+
<FilterSidebar filters={filters} />
|
|
83
|
+
) : shouldShowFilterShimmer ? (
|
|
84
|
+
<FilterSidebarShimmer />
|
|
85
|
+
) : null;
|
|
86
|
+
|
|
87
|
+
const maybeSortButton = shouldShowSortButtons ? (
|
|
88
|
+
<ProductSort
|
|
89
|
+
sortProps={sortProps}
|
|
90
|
+
availableSortMethods={availableSortMethods}
|
|
91
|
+
/>
|
|
92
|
+
) : shouldShowSortShimmer ? (
|
|
93
|
+
<ProductSortShimmer />
|
|
94
|
+
) : null;
|
|
95
|
+
|
|
96
|
+
const maybeSortContainer = shouldShowSortButtons ? (
|
|
97
|
+
<SortedByContainer currentSort={currentSort} />
|
|
98
|
+
) : shouldShowSortShimmer ? (
|
|
99
|
+
<SortedByContainerShimmer />
|
|
100
|
+
) : null;
|
|
101
|
+
|
|
102
|
+
const categoryResultsHeading =
|
|
103
|
+
totalCount > 0 ? (
|
|
104
|
+
<FormattedMessage
|
|
105
|
+
id={'categoryContent.resultCount'}
|
|
106
|
+
values={{
|
|
107
|
+
count: totalCount
|
|
108
|
+
}}
|
|
109
|
+
defaultMessage={'{count} Results'}
|
|
110
|
+
/>
|
|
111
|
+
) : isLoading ? (
|
|
112
|
+
<Shimmer width={5} />
|
|
113
|
+
) : null;
|
|
114
|
+
|
|
115
|
+
const categoryDescriptionElement = categoryDescription ? (
|
|
116
|
+
<RichContent html={categoryDescription} />
|
|
117
|
+
) : null;
|
|
118
|
+
|
|
119
|
+
const content = useMemo(() => {
|
|
120
|
+
if (!totalPagesFromData && !isLoading) {
|
|
121
|
+
return <NoProductsFound categoryId={categoryId} />;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const gallery = totalPagesFromData ? (
|
|
125
|
+
<Gallery items={items} />
|
|
126
|
+
) : (
|
|
127
|
+
<GalleryShimmer items={items} />
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const pagination = totalPagesFromData ? (
|
|
131
|
+
<Pagination pageControl={pageControl} />
|
|
132
|
+
) : null;
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<Fragment>
|
|
136
|
+
<section className={classes.gallery}>{gallery}</section>
|
|
137
|
+
<div className={classes.pagination}>{pagination}</div>
|
|
138
|
+
</Fragment>
|
|
139
|
+
);
|
|
140
|
+
}, [
|
|
141
|
+
categoryId,
|
|
142
|
+
classes.gallery,
|
|
143
|
+
classes.pagination,
|
|
144
|
+
isLoading,
|
|
145
|
+
items,
|
|
146
|
+
pageControl,
|
|
147
|
+
totalPagesFromData
|
|
148
|
+
]);
|
|
149
|
+
|
|
150
|
+
const categoryTitle = categoryName ? categoryName : <Shimmer width={5} />;
|
|
151
|
+
|
|
9
152
|
return (
|
|
10
|
-
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
153
|
+
<Fragment>
|
|
154
|
+
<Breadcrumbs categoryId={categoryId} />
|
|
155
|
+
<StoreTitle>{categoryName}</StoreTitle>
|
|
156
|
+
<article className={classes.root} data-cy="SellerProducts-root">
|
|
157
|
+
<div className={classes.categoryHeader}>
|
|
158
|
+
<h1 aria-live="polite" className={classes.title}>
|
|
159
|
+
<div
|
|
160
|
+
className={classes.categoryTitle}
|
|
161
|
+
data-cy="SellerProducts-categoryTitle"
|
|
162
|
+
>
|
|
163
|
+
{categoryTitle}
|
|
164
|
+
</div>
|
|
165
|
+
</h1>
|
|
166
|
+
{categoryDescriptionElement}
|
|
19
167
|
</div>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<div className='flex flex-col gap-y-[30px]'>
|
|
26
|
-
<div className='flex w-full items-center justify-between'>
|
|
27
|
-
<Search />
|
|
28
|
-
<SortBy />
|
|
29
|
-
</div>
|
|
30
|
-
<div className='product-list w-full grid grid-cols-4 gap-4'>
|
|
31
|
-
<ProductItem />
|
|
32
|
-
<ProductItem />
|
|
33
|
-
<ProductItem />
|
|
34
|
-
<ProductItem />
|
|
35
|
-
<ProductItem />
|
|
168
|
+
<div className={classes.contentWrapper}>
|
|
169
|
+
<div ref={sidebarRef} className={classes.sidebar}>
|
|
170
|
+
<Suspense fallback={<FilterSidebarShimmer />}>
|
|
171
|
+
{shouldRenderSidebarContent ? sidebar : null}
|
|
172
|
+
</Suspense>
|
|
36
173
|
</div>
|
|
37
|
-
<div className=
|
|
38
|
-
<
|
|
174
|
+
<div className={classes.categoryContent}>
|
|
175
|
+
<div className={classes.heading}>
|
|
176
|
+
<div
|
|
177
|
+
data-cy="SellerProducts-categoryInfo"
|
|
178
|
+
className={classes.categoryInfo}
|
|
179
|
+
>
|
|
180
|
+
{categoryResultsHeading}
|
|
181
|
+
</div>
|
|
182
|
+
<div className={classes.headerButtons}>
|
|
183
|
+
{maybeFilterButtons}
|
|
184
|
+
{maybeSortButton}
|
|
185
|
+
</div>
|
|
186
|
+
{maybeSortContainer}
|
|
187
|
+
</div>
|
|
188
|
+
{content}
|
|
189
|
+
<Suspense fallback={null}>{filtersModal}</Suspense>
|
|
39
190
|
</div>
|
|
40
191
|
</div>
|
|
41
|
-
</
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
}
|
|
192
|
+
</article>
|
|
193
|
+
</Fragment>
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export default SellerProducts;
|
|
45
198
|
|
|
46
|
-
|
|
199
|
+
SellerProducts.propTypes = {
|
|
200
|
+
classes: shape({
|
|
201
|
+
gallery: string,
|
|
202
|
+
pagination: string,
|
|
203
|
+
root: string,
|
|
204
|
+
categoryHeader: string,
|
|
205
|
+
title: string,
|
|
206
|
+
categoryTitle: string,
|
|
207
|
+
sidebar: string,
|
|
208
|
+
categoryContent: string,
|
|
209
|
+
heading: string,
|
|
210
|
+
categoryInfo: string,
|
|
211
|
+
headerButtons: string
|
|
212
|
+
}),
|
|
213
|
+
// sortProps contains the following structure:
|
|
214
|
+
// [{sortDirection: string, sortAttribute: string, sortText: string},
|
|
215
|
+
// React.Dispatch<React.SetStateAction<{sortDirection: string, sortAttribute: string, sortText: string}]
|
|
216
|
+
sortProps: array,
|
|
217
|
+
pageSize: number
|
|
218
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
3
|
+
|
|
4
|
+
import { createTestInstance } from '@magento/peregrine';
|
|
5
|
+
import { useIsInViewport } from '@magento/peregrine/lib/hooks/useIsInViewport';
|
|
6
|
+
|
|
7
|
+
import MegaMenu from '../megaMenu';
|
|
8
|
+
|
|
9
|
+
jest.mock('@magento/venia-ui/lib/classify');
|
|
10
|
+
jest.mock('@magento/peregrine/lib/hooks/useIsInViewport');
|
|
11
|
+
jest.mock('@magento/peregrine/lib/talons/MegaMenu/useMegaMenu', () => ({
|
|
12
|
+
useMegaMenu: jest.fn().mockReturnValue({
|
|
13
|
+
megaMenuData: {
|
|
14
|
+
id: 1,
|
|
15
|
+
name: 'Clothing',
|
|
16
|
+
children: [
|
|
17
|
+
{
|
|
18
|
+
id: 2,
|
|
19
|
+
name: 'Women',
|
|
20
|
+
url_path: 'women',
|
|
21
|
+
children: [
|
|
22
|
+
{
|
|
23
|
+
id: 5,
|
|
24
|
+
name: 'Bottoms',
|
|
25
|
+
url_path: 'bottoms',
|
|
26
|
+
isActive: true,
|
|
27
|
+
children: []
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 3,
|
|
33
|
+
name: 'Men',
|
|
34
|
+
url_path: 'men',
|
|
35
|
+
children: []
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 4,
|
|
39
|
+
name: 'Gear',
|
|
40
|
+
url_path: 'gear',
|
|
41
|
+
children: []
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
activeCategoryId: 5,
|
|
46
|
+
categoryUrlSuffix: '.html',
|
|
47
|
+
useOutsideAlerter: () => {}
|
|
48
|
+
})
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
describe('#MegaMenu', () => {
|
|
52
|
+
test('useEffect', () => {
|
|
53
|
+
const useEffect = jest.spyOn(React, 'useEffect');
|
|
54
|
+
|
|
55
|
+
const mockUseEffect = () => {
|
|
56
|
+
useEffect.mockImplementationOnce(mockFunction => mockFunction());
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
mockUseEffect();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('not resetting the menu', () => {
|
|
63
|
+
const handleClickOutside = jest.fn();
|
|
64
|
+
|
|
65
|
+
expect(handleClickOutside).toHaveBeenCalledTimes(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('renders empty div if not in viewport', () => {
|
|
69
|
+
useIsInViewport.mockReturnValue(false);
|
|
70
|
+
|
|
71
|
+
const instance = createTestInstance(
|
|
72
|
+
<MemoryRouter>
|
|
73
|
+
<MegaMenu />
|
|
74
|
+
</MemoryRouter>
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
expect(instance.toJSON()).toMatchSnapshot();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('renders menu if in viewport', () => {
|
|
81
|
+
useIsInViewport.mockReturnValue(true);
|
|
82
|
+
|
|
83
|
+
const instance = createTestInstance(
|
|
84
|
+
<MemoryRouter>
|
|
85
|
+
<MegaMenu />
|
|
86
|
+
</MemoryRouter>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(instance.toJSON()).toMatchSnapshot();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Link } from 'react-router-dom';
|
|
3
|
+
import { act } from 'react-test-renderer';
|
|
4
|
+
|
|
5
|
+
import { createTestInstance } from '@magento/peregrine';
|
|
6
|
+
|
|
7
|
+
import MegaMenuItem from '../megaMenuItem';
|
|
8
|
+
|
|
9
|
+
jest.mock('../../../classify');
|
|
10
|
+
jest.mock('../../Icon', () => props => <mock-Icon {...props} />);
|
|
11
|
+
jest.mock('../submenu', () => props => <mock-Submenu {...props} />);
|
|
12
|
+
jest.mock('react', () => {
|
|
13
|
+
const React = jest.requireActual('react');
|
|
14
|
+
const memoSpy = jest.spyOn(React, 'useMemo');
|
|
15
|
+
|
|
16
|
+
return Object.assign(React, {
|
|
17
|
+
useMemo: memoSpy
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const mockHandleKeyDown = jest.fn();
|
|
22
|
+
|
|
23
|
+
jest.mock('react-router-dom', () => ({
|
|
24
|
+
Link: jest.fn(() => props => <mock-Link {...props} />)
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
jest.mock('@magento/peregrine/lib/talons/MegaMenu/useMegaMenuItem', () => ({
|
|
28
|
+
useMegaMenuItem: jest.fn(() => {
|
|
29
|
+
return {
|
|
30
|
+
isFocused: false,
|
|
31
|
+
isActive: false,
|
|
32
|
+
handleMenuItemFocus: jest.fn(),
|
|
33
|
+
handleCloseSubMenu: jest.fn(),
|
|
34
|
+
isMenuActive: false,
|
|
35
|
+
handleKeyDown: mockHandleKeyDown
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
let inputProps = {};
|
|
41
|
+
|
|
42
|
+
const Component = () => {
|
|
43
|
+
return <MegaMenuItem {...inputProps} />;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const givenDefaultValues = () => {
|
|
47
|
+
inputProps = {
|
|
48
|
+
activeCategoryId: 1,
|
|
49
|
+
category: {
|
|
50
|
+
id: 1,
|
|
51
|
+
name: 'Women',
|
|
52
|
+
url_path: 'women',
|
|
53
|
+
isActive: true,
|
|
54
|
+
children: [
|
|
55
|
+
{
|
|
56
|
+
id: 2,
|
|
57
|
+
name: 'Bottoms',
|
|
58
|
+
url_path: 'bottoms',
|
|
59
|
+
children: []
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 3,
|
|
63
|
+
name: 'Tops',
|
|
64
|
+
url_path: 'tops',
|
|
65
|
+
isActive: false,
|
|
66
|
+
children: []
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
rootCategoryName: 'Clothing',
|
|
71
|
+
categoryUrlSuffix: '.html',
|
|
72
|
+
mainNavWidth: 200,
|
|
73
|
+
subMenuState: 'test',
|
|
74
|
+
disableFocus: false
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
describe('Mega menu item renders correctly', () => {
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
givenDefaultValues();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('it renders correctly', () => {
|
|
84
|
+
const instance = createTestInstance(<Component />);
|
|
85
|
+
|
|
86
|
+
expect(instance.toJSON()).toMatchSnapshot();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('it marks the active category', () => {
|
|
90
|
+
const { root } = createTestInstance(<Component />);
|
|
91
|
+
|
|
92
|
+
expect(root.findByType(Link).props.className).toEqual('megaMenuLink');
|
|
93
|
+
expect(root.findByType(Link).props.to).toEqual('/women.html');
|
|
94
|
+
expect(root.findByType(Link).props.children[0]).toEqual('Women');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should call a11yClick', () => {
|
|
98
|
+
const { root } = createTestInstance(<Component />);
|
|
99
|
+
|
|
100
|
+
act(() => {
|
|
101
|
+
root.findByType(Link).props.onKeyDown();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(mockHandleKeyDown).toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('it does not render submenu when item does not have children', () => {
|
|
108
|
+
const categoryWithoutChildren = {
|
|
109
|
+
id: 3,
|
|
110
|
+
name: 'Tops',
|
|
111
|
+
url_path: 'tops',
|
|
112
|
+
isActive: false,
|
|
113
|
+
children: []
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const instance = createTestInstance(
|
|
117
|
+
<Component category={categoryWithoutChildren} />
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
expect(instance.toJSON().children.length).toEqual(1);
|
|
121
|
+
expect(instance.toJSON()).toMatchSnapshot();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createTestInstance } from '@magento/peregrine';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
|
|
5
|
+
import Submenu from '../submenu';
|
|
6
|
+
|
|
7
|
+
jest.mock('../../../classify');
|
|
8
|
+
jest.mock('../submenuColumn', () => props => <mock-SubmenuColumn {...props} />);
|
|
9
|
+
jest.mock('react', () => {
|
|
10
|
+
const React = jest.requireActual('react');
|
|
11
|
+
const callbackSpy = jest.spyOn(React, 'useCallback');
|
|
12
|
+
|
|
13
|
+
return Object.assign(React, {
|
|
14
|
+
callbackSpy: callbackSpy
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const handleCloseSubMenu = jest.fn().mockName('handleCloseSubMenu');
|
|
19
|
+
|
|
20
|
+
describe('Submenu renders correctly', () => {
|
|
21
|
+
const props = {
|
|
22
|
+
items: [
|
|
23
|
+
{
|
|
24
|
+
id: 1,
|
|
25
|
+
name: 'Bottoms',
|
|
26
|
+
url_path: 'bottoms',
|
|
27
|
+
children: [
|
|
28
|
+
{
|
|
29
|
+
id: 3,
|
|
30
|
+
name: 'Pants',
|
|
31
|
+
url_path: 'pants',
|
|
32
|
+
isActive: false,
|
|
33
|
+
children: []
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 2,
|
|
39
|
+
name: 'Tops',
|
|
40
|
+
url_path: 'tops',
|
|
41
|
+
isActive: false,
|
|
42
|
+
children: []
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
rootCategoryName: 'Clothing',
|
|
46
|
+
firstLevelCategoryName: 'Women',
|
|
47
|
+
categoryUrlSuffix: '.html',
|
|
48
|
+
handleCloseSubMenu,
|
|
49
|
+
isFocused: false,
|
|
50
|
+
subMenuState: false
|
|
51
|
+
};
|
|
52
|
+
test('it renders correctly', () => {
|
|
53
|
+
const instance = createTestInstance(
|
|
54
|
+
<MemoryRouter>
|
|
55
|
+
<Submenu {...props} />
|
|
56
|
+
</MemoryRouter>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(instance.toJSON()).toMatchSnapshot();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createTestInstance } from '@magento/peregrine';
|
|
3
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
4
|
+
|
|
5
|
+
import SubmenuColumn from '../submenuColumn';
|
|
6
|
+
|
|
7
|
+
jest.mock('../../../classify');
|
|
8
|
+
|
|
9
|
+
describe('Submenu column renders correctly', () => {
|
|
10
|
+
const props = {
|
|
11
|
+
category: {
|
|
12
|
+
id: 1,
|
|
13
|
+
name: 'Pants',
|
|
14
|
+
url_path: 'pants',
|
|
15
|
+
children: [
|
|
16
|
+
{
|
|
17
|
+
id: 2,
|
|
18
|
+
name: 'Jeans',
|
|
19
|
+
url_path: 'jeans',
|
|
20
|
+
isActive: true,
|
|
21
|
+
children: []
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
categoryUrlSuffix: '.html'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
test('it renders correctly', () => {
|
|
29
|
+
const instance = createTestInstance(
|
|
30
|
+
<MemoryRouter>
|
|
31
|
+
<SubmenuColumn {...props} />
|
|
32
|
+
</MemoryRouter>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(instance.toJSON()).toMatchSnapshot();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('it renders active state', () => {
|
|
39
|
+
const instance = createTestInstance(
|
|
40
|
+
<MemoryRouter>
|
|
41
|
+
<SubmenuColumn {...props} />
|
|
42
|
+
</MemoryRouter>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const activeLink = instance.root.findByProps({
|
|
46
|
+
className: 'linkActive'
|
|
47
|
+
});
|
|
48
|
+
expect(activeLink.props.children).toEqual('Jeans');
|
|
49
|
+
});
|
|
50
|
+
});
|