@blaze-cms/react-page-builder 0.124.0-alpha.9 → 0.124.0
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/CHANGELOG.md +303 -0
- package/README.md +8 -0
- package/lib/application/query/index.js +8 -2
- package/lib/application/query/index.js.map +1 -1
- package/lib/components/Button.js +18 -5
- package/lib/components/Button.js.map +1 -1
- package/lib/components/Card/CardContainer.js +3 -7
- package/lib/components/Card/CardContainer.js.map +1 -1
- package/lib/components/Card/CardFactory.js +6 -3
- package/lib/components/Card/CardFactory.js.map +1 -1
- package/lib/components/CarouselWrapper.js +2 -2
- package/lib/components/CarouselWrapper.js.map +1 -1
- package/lib/components/Image/ImageRender.js +5 -1
- package/lib/components/Image/ImageRender.js.map +1 -1
- package/lib/components/ItemList/ItemListButton/ItemListButton.js +161 -0
- package/lib/components/ItemList/ItemListButton/ItemListButton.js.map +1 -0
- package/lib/components/ItemList/ItemListButton/index.js +16 -0
- package/lib/components/ItemList/ItemListButton/index.js.map +1 -0
- package/lib/components/ItemList/ItemListCounter/ItemListCounter.js +83 -0
- package/lib/components/ItemList/ItemListCounter/ItemListCounter.js.map +1 -0
- package/lib/components/ItemList/ItemListCounter/index.js +16 -0
- package/lib/components/ItemList/ItemListCounter/index.js.map +1 -0
- package/lib/components/ItemList/ItemListNew/ItemListNew.js +87 -0
- package/lib/components/ItemList/ItemListNew/ItemListNew.js.map +1 -0
- package/lib/components/ItemList/ItemListNew/index.js +16 -0
- package/lib/components/ItemList/ItemListNew/index.js.map +1 -0
- package/lib/components/ItemList/constants.js +19 -0
- package/lib/components/ItemList/constants.js.map +1 -0
- package/lib/components/ItemList/helpers/get-item-list-data.js +17 -0
- package/lib/components/ItemList/helpers/get-item-list-data.js.map +1 -0
- package/lib/components/ItemList/helpers/get-item-list-id.js +23 -0
- package/lib/components/ItemList/helpers/get-item-list-id.js.map +1 -0
- package/lib/components/ItemList/helpers/get-item-list-ids.js +28 -0
- package/lib/components/ItemList/helpers/get-item-list-ids.js.map +1 -0
- package/lib/components/ItemList/helpers/index.js +50 -0
- package/lib/components/ItemList/helpers/index.js.map +1 -0
- package/lib/components/ItemList/helpers/set-item-list-id.js +22 -0
- package/lib/components/ItemList/helpers/set-item-list-id.js.map +1 -0
- package/lib/components/ItemList/helpers/set-param-and-redirect.js +51 -0
- package/lib/components/ItemList/helpers/set-param-and-redirect.js.map +1 -0
- package/lib/components/ItemList/hooks/index.js +18 -0
- package/lib/components/ItemList/hooks/index.js.map +1 -0
- package/lib/components/ItemList/hooks/use-item-list-id.js +45 -0
- package/lib/components/ItemList/hooks/use-item-list-id.js.map +1 -0
- package/lib/components/LazyImage/LazyImage.js +5 -1
- package/lib/components/LazyImage/LazyImage.js.map +1 -1
- package/lib/components/List/ListBuilder.js +12 -6
- package/lib/components/List/ListBuilder.js.map +1 -1
- package/lib/components/List/ListFactory.js +34 -7
- package/lib/components/List/ListFactory.js.map +1 -1
- package/lib/components/List/helpers/has-required-item-list-details.js +29 -0
- package/lib/components/List/helpers/has-required-item-list-details.js.map +1 -0
- package/lib/components/List/helpers/index.js +8 -0
- package/lib/components/List/helpers/index.js.map +1 -1
- package/lib/components/Menu/Menu.js +41 -28
- package/lib/components/Menu/Menu.js.map +1 -1
- package/lib/components/Menu/MenuContext.js +20 -0
- package/lib/components/Menu/MenuContext.js.map +1 -0
- package/lib/components/MenuItem/MenuItem.js +26 -7
- package/lib/components/MenuItem/MenuItem.js.map +1 -1
- package/lib/components/SearchContent/SearchContent.js +183 -0
- package/lib/components/SearchContent/SearchContent.js.map +1 -0
- package/lib/components/SearchContent/SearchContentItems.js +51 -0
- package/lib/components/SearchContent/SearchContentItems.js.map +1 -0
- package/lib/components/SearchContent/SearchContentResults.js +45 -0
- package/lib/components/SearchContent/SearchContentResults.js.map +1 -0
- package/lib/components/SearchContent/SearchContentToggleIcon.js +42 -0
- package/lib/components/SearchContent/SearchContentToggleIcon.js.map +1 -0
- package/lib/components/SearchContent/index.js +2 -301
- package/lib/components/SearchContent/index.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/FiltersList.js +2 -4
- package/lib/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +16 -66
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js +87 -23
- package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib/components/SearchFilter/components/Checkbox.js +19 -9
- package/lib/components/SearchFilter/components/Checkbox.js.map +1 -1
- package/lib/components/SearchFilter/components/Select.js +27 -11
- package/lib/components/SearchFilter/components/Select.js.map +1 -1
- package/lib/components/SearchFilter/components/TextSearch.js +1 -5
- package/lib/components/SearchFilter/components/TextSearch.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-filters-query.js +87 -0
- package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -0
- package/lib/components/SearchFilter/helpers/build-query.js +1 -1
- package/lib/components/SearchFilter/helpers/build-query.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
- package/lib/components/SearchFilter/helpers/build-raw-query-stringified.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js +18 -3
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -1
- package/lib/components/SearchFilter/helpers/index.js +8 -0
- package/lib/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib/components/SearchFilter/helpers/parse-filter-value.js +3 -7
- package/lib/components/SearchFilter/helpers/parse-filter-value.js.map +1 -1
- package/lib/components/index.js +16 -1
- package/lib/components/index.js.map +1 -1
- package/lib/constants/index.js +3 -1
- package/lib/constants/index.js.map +1 -1
- package/lib/helpers/build-raw-query.js.map +1 -1
- package/lib/hooks/helpers/append-gtm-classname.js +1 -0
- package/lib/hooks/helpers/append-gtm-classname.js.map +1 -1
- package/lib-es/application/query/index.js +45 -1
- package/lib-es/application/query/index.js.map +1 -1
- package/lib-es/components/Button.js +18 -6
- package/lib-es/components/Button.js.map +1 -1
- package/lib-es/components/Card/CardContainer.js +3 -7
- package/lib-es/components/Card/CardContainer.js.map +1 -1
- package/lib-es/components/Card/CardFactory.js +7 -4
- package/lib-es/components/Card/CardFactory.js.map +1 -1
- package/lib-es/components/CarouselWrapper.js +2 -2
- package/lib-es/components/CarouselWrapper.js.map +1 -1
- package/lib-es/components/Image/ImageRender.js +4 -1
- package/lib-es/components/Image/ImageRender.js.map +1 -1
- package/lib-es/components/ItemList/ItemListButton/ItemListButton.js +111 -0
- package/lib-es/components/ItemList/ItemListButton/ItemListButton.js.map +1 -0
- package/lib-es/components/ItemList/ItemListButton/index.js +3 -0
- package/lib-es/components/ItemList/ItemListButton/index.js.map +1 -0
- package/lib-es/components/ItemList/ItemListCounter/ItemListCounter.js +60 -0
- package/lib-es/components/ItemList/ItemListCounter/ItemListCounter.js.map +1 -0
- package/lib-es/components/ItemList/ItemListCounter/index.js +3 -0
- package/lib-es/components/ItemList/ItemListCounter/index.js.map +1 -0
- package/lib-es/components/ItemList/ItemListNew/ItemListNew.js +64 -0
- package/lib-es/components/ItemList/ItemListNew/ItemListNew.js.map +1 -0
- package/lib-es/components/ItemList/ItemListNew/index.js +3 -0
- package/lib-es/components/ItemList/ItemListNew/index.js.map +1 -0
- package/lib-es/components/ItemList/constants.js +6 -0
- package/lib-es/components/ItemList/constants.js.map +1 -0
- package/lib-es/components/ItemList/helpers/get-item-list-data.js +7 -0
- package/lib-es/components/ItemList/helpers/get-item-list-data.js.map +1 -0
- package/lib-es/components/ItemList/helpers/get-item-list-id.js +11 -0
- package/lib-es/components/ItemList/helpers/get-item-list-id.js.map +1 -0
- package/lib-es/components/ItemList/helpers/get-item-list-ids.js +13 -0
- package/lib-es/components/ItemList/helpers/get-item-list-ids.js.map +1 -0
- package/lib-es/components/ItemList/helpers/index.js +6 -0
- package/lib-es/components/ItemList/helpers/index.js.map +1 -0
- package/lib-es/components/ItemList/helpers/set-item-list-id.js +10 -0
- package/lib-es/components/ItemList/helpers/set-item-list-id.js.map +1 -0
- package/lib-es/components/ItemList/helpers/set-param-and-redirect.js +20 -0
- package/lib-es/components/ItemList/helpers/set-param-and-redirect.js.map +1 -0
- package/lib-es/components/ItemList/hooks/index.js +2 -0
- package/lib-es/components/ItemList/hooks/index.js.map +1 -0
- package/lib-es/components/ItemList/hooks/use-item-list-id.js +26 -0
- package/lib-es/components/ItemList/hooks/use-item-list-id.js.map +1 -0
- package/lib-es/components/LazyImage/LazyImage.js +4 -1
- package/lib-es/components/LazyImage/LazyImage.js.map +1 -1
- package/lib-es/components/List/ListBuilder.js +12 -6
- package/lib-es/components/List/ListBuilder.js.map +1 -1
- package/lib-es/components/List/ListFactory.js +33 -9
- package/lib-es/components/List/ListFactory.js.map +1 -1
- package/lib-es/components/List/helpers/has-required-item-list-details.js +20 -0
- package/lib-es/components/List/helpers/has-required-item-list-details.js.map +1 -0
- package/lib-es/components/List/helpers/index.js +1 -0
- package/lib-es/components/List/helpers/index.js.map +1 -1
- package/lib-es/components/Menu/Menu.js +54 -46
- package/lib-es/components/Menu/Menu.js.map +1 -1
- package/lib-es/components/Menu/MenuContext.js +6 -0
- package/lib-es/components/Menu/MenuContext.js.map +1 -0
- package/lib-es/components/MenuItem/MenuItem.js +24 -9
- package/lib-es/components/MenuItem/MenuItem.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContent.js +129 -0
- package/lib-es/components/SearchContent/SearchContent.js.map +1 -0
- package/lib-es/components/SearchContent/SearchContentItems.js +33 -0
- package/lib-es/components/SearchContent/SearchContentItems.js.map +1 -0
- package/lib-es/components/SearchContent/SearchContentResults.js +31 -0
- package/lib-es/components/SearchContent/SearchContentResults.js.map +1 -0
- package/lib-es/components/SearchContent/SearchContentToggleIcon.js +30 -0
- package/lib-es/components/SearchContent/SearchContentToggleIcon.js.map +1 -0
- package/lib-es/components/SearchContent/index.js +1 -205
- package/lib-es/components/SearchContent/index.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js +2 -4
- package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +10 -43
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js +70 -15
- package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib-es/components/SearchFilter/components/Checkbox.js +18 -9
- package/lib-es/components/SearchFilter/components/Checkbox.js.map +1 -1
- package/lib-es/components/SearchFilter/components/Select.js +23 -8
- package/lib-es/components/SearchFilter/components/Select.js.map +1 -1
- package/lib-es/components/SearchFilter/components/TextSearch.js +1 -5
- package/lib-es/components/SearchFilter/components/TextSearch.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js +54 -0
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/build-query.js +1 -1
- package/lib-es/components/SearchFilter/helpers/build-query.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
- package/lib-es/components/SearchFilter/helpers/build-raw-query-stringified.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js +13 -1
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/index.js +2 -1
- package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/parse-filter-value.js +3 -3
- package/lib-es/components/SearchFilter/helpers/parse-filter-value.js.map +1 -1
- package/lib-es/components/index.js +10 -1
- package/lib-es/components/index.js.map +1 -1
- package/lib-es/constants/index.js +2 -1
- package/lib-es/constants/index.js.map +1 -1
- package/lib-es/helpers/build-raw-query.js.map +1 -1
- package/lib-es/hooks/helpers/append-gtm-classname.js +1 -0
- package/lib-es/hooks/helpers/append-gtm-classname.js.map +1 -1
- package/package.json +5 -4
- package/src/application/query/index.js +51 -1
- package/src/components/Button.js +27 -5
- package/src/components/Card/CardContainer.js +2 -6
- package/src/components/Card/CardFactory.js +5 -3
- package/src/components/CarouselWrapper.js +2 -2
- package/src/components/Image/ImageRender.js +3 -0
- package/src/components/ItemList/ItemListButton/ItemListButton.js +94 -0
- package/src/components/ItemList/ItemListButton/index.js +3 -0
- package/src/components/ItemList/ItemListCounter/ItemListCounter.js +52 -0
- package/src/components/ItemList/ItemListCounter/index.js +3 -0
- package/src/components/ItemList/ItemListNew/ItemListNew.js +51 -0
- package/src/components/ItemList/ItemListNew/index.js +3 -0
- package/src/components/ItemList/constants.js +5 -0
- package/src/components/ItemList/helpers/get-item-list-data.js +6 -0
- package/src/components/ItemList/helpers/get-item-list-id.js +11 -0
- package/src/components/ItemList/helpers/get-item-list-ids.js +10 -0
- package/src/components/ItemList/helpers/index.js +5 -0
- package/src/components/ItemList/helpers/set-item-list-id.js +9 -0
- package/src/components/ItemList/helpers/set-param-and-redirect.js +20 -0
- package/src/components/ItemList/hooks/index.js +1 -0
- package/src/components/ItemList/hooks/use-item-list-id.js +27 -0
- package/src/components/LazyImage/LazyImage.js +11 -1
- package/src/components/List/ListBuilder.js +10 -5
- package/src/components/List/ListFactory.js +48 -12
- package/src/components/List/helpers/has-required-item-list-details.js +14 -0
- package/src/components/List/helpers/index.js +1 -0
- package/src/components/Menu/Menu.js +61 -54
- package/src/components/Menu/MenuContext.js +5 -0
- package/src/components/MenuItem/MenuItem.js +39 -14
- package/src/components/SearchContent/SearchContent.js +136 -0
- package/src/components/SearchContent/SearchContentItems.js +28 -0
- package/src/components/SearchContent/SearchContentResults.js +27 -0
- package/src/components/SearchContent/SearchContentToggleIcon.js +27 -0
- package/src/components/SearchContent/index.js +1 -217
- package/src/components/SearchFilter/SearchFilter/FiltersList.js +30 -37
- package/src/components/SearchFilter/SearchFilter/SearchFilter.js +10 -25
- package/src/components/SearchFilter/SearchFilterContainer.js +61 -16
- package/src/components/SearchFilter/components/Checkbox.js +23 -8
- package/src/components/SearchFilter/components/Select.js +18 -11
- package/src/components/SearchFilter/components/TextSearch.js +1 -3
- package/src/components/SearchFilter/helpers/build-filters-query.js +40 -0
- package/src/components/SearchFilter/helpers/build-query.js +3 -1
- package/src/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
- package/src/components/SearchFilter/helpers/get-initial-filter-values.js +12 -1
- package/src/components/SearchFilter/helpers/index.js +3 -1
- package/src/components/SearchFilter/helpers/parse-filter-value.js +3 -3
- package/src/components/index.js +10 -1
- package/src/constants/index.js +2 -0
- package/src/helpers/build-raw-query.js +1 -0
- package/src/hooks/helpers/append-gtm-classname.js +3 -0
- package/tests/unit/src/components/Button.test.js +55 -1
- package/tests/unit/src/components/ItemList/ItemListButton.test.js +175 -0
- package/tests/unit/src/components/ItemList/ItemListCounter.test.js +65 -0
- package/tests/unit/src/components/ItemList/ItemListNew.test.js +164 -0
- package/tests/unit/src/components/ItemList/__snapshots__/ItemListButton.test.js.snap +107 -0
- package/tests/unit/src/components/ItemList/__snapshots__/ItemListCounter.test.js.snap +31 -0
- package/tests/unit/src/components/ItemList/__snapshots__/ItemListNew.test.js.snap +27 -0
- package/tests/unit/src/components/ItemList/helpers/get-item-list-data.test.js +28 -0
- package/tests/unit/src/components/ItemList/helpers/get-item-list-id.test.js +20 -0
- package/tests/unit/src/components/ItemList/helpers/get-item-list-ids.test.js +19 -0
- package/tests/unit/src/components/ItemList/helpers/set-item-list-id.test.js +13 -0
- package/tests/unit/src/components/ItemList/helpers/set-param-and-redirect.test.js +30 -0
- package/tests/unit/src/components/ItemList/hooks/use-item-list-id.test.js +32 -0
- package/tests/unit/src/components/List/helpers/has-required-item-list-details.test.js +30 -0
- package/tests/unit/src/components/Menu/Menu.test.js +9 -3
- package/tests/unit/src/components/Menu/__snapshots__/Menu.test.js.snap +12 -11
- package/tests/unit/src/components/MenuItem/MenuItem.test.js +1 -1
- package/tests/unit/src/components/MenuItem/SubMenu.test.js +5 -1
- package/tests/unit/src/components/MenuItem/__snapshots__/MenuItem.test.js.snap +54 -10
- package/tests/unit/src/components/SearchContent/SearchContent.test.js +29 -0
- package/tests/unit/src/components/SearchContent/__snapshots__/SearchContent.test.js.snap +9 -0
- package/tests/unit/src/components/SearchFilter/SearchFilter/SearchFilter.test.js +3 -6
- package/tests/unit/src/components/SearchFilter/components/__snapshots__/Checkbox.test.js.snap +2 -0
- package/tests/unit/src/components/SearchFilter/components/__snapshots__/Select.test.js.snap +4 -0
- package/tests/unit/src/components/SearchFilter/helpers/build-query.test.js +2 -2
- package/tests/unit/src/components/SearchFilter/helpers/get-initial-filter-values.test.js +25 -11
- package/tests/unit/src/components/SearchFilter/helpers/parse-filter-value.test.js +1 -1
- package/tests/unit/src/components/__snapshots__/index.test.js.snap +12 -0
|
@@ -5,7 +5,7 @@ import { MdSearch } from 'react-icons/md';
|
|
|
5
5
|
import { withTitle } from '../../../HOC';
|
|
6
6
|
import { SEARCH_TERM } from '../constants';
|
|
7
7
|
|
|
8
|
-
const TextSearch = ({ label, searchValue, updateFilterValues
|
|
8
|
+
const TextSearch = ({ label, searchValue, updateFilterValues }) => (
|
|
9
9
|
<div className="search">
|
|
10
10
|
<div className="search__wrapper">
|
|
11
11
|
<div className="form-field form-field--input form-field--search">
|
|
@@ -34,10 +34,8 @@ const TextSearch = ({ label, searchValue, updateFilterValues, handleSubmit, filt
|
|
|
34
34
|
);
|
|
35
35
|
|
|
36
36
|
TextSearch.propTypes = {
|
|
37
|
-
filterValues: PropTypes.object.isRequired,
|
|
38
37
|
searchValue: PropTypes.string.isRequired,
|
|
39
38
|
updateFilterValues: PropTypes.func.isRequired,
|
|
40
|
-
handleSubmit: PropTypes.func.isRequired,
|
|
41
39
|
label: PropTypes.string
|
|
42
40
|
};
|
|
43
41
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const builFilterObject = (key, value, filters) => {
|
|
2
|
+
const isArray = Array.isArray(value);
|
|
3
|
+
if (!isArray) {
|
|
4
|
+
const singleFilterObj = { match: { [key]: value } };
|
|
5
|
+
filters.push(singleFilterObj);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
value.forEach(filterValue => {
|
|
10
|
+
filters.push({ match: { [key]: filterValue } });
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
const buildFiltersQuery = (query, filterBy, filterByProperty) => {
|
|
14
|
+
const mustFilters = [];
|
|
15
|
+
Object.keys(query).forEach(queryKey => {
|
|
16
|
+
if (queryKey === 'search_term' || queryKey === 'shouldSearch') return;
|
|
17
|
+
if (!queryKey || !query[queryKey]) return;
|
|
18
|
+
const queryValue = query[queryKey];
|
|
19
|
+
const queryKeyword = `${queryKey}.keyword`;
|
|
20
|
+
builFilterObject(queryKeyword, queryValue, mustFilters);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (filterByProperty && filterByProperty.length) {
|
|
24
|
+
filterByProperty &&
|
|
25
|
+
filterByProperty.forEach(filterByPropOption => {
|
|
26
|
+
const [filterByPropKey] = filterByPropOption.split('/');
|
|
27
|
+
filterBy.forEach(filterByOption => {
|
|
28
|
+
if (filterByOption.indexOf(filterByPropKey) === -1) return;
|
|
29
|
+
const [, filteryByValue] = filterByOption.split('/');
|
|
30
|
+
const filterByKeyword = `${filterByPropKey}.keyword`;
|
|
31
|
+
if (!filteryByValue) return;
|
|
32
|
+
mustFilters.push({ match: { [filterByKeyword]: filteryByValue } });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return mustFilters;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default buildFiltersQuery;
|
|
@@ -3,7 +3,9 @@ import parseFilterValue from './parse-filter-value';
|
|
|
3
3
|
|
|
4
4
|
const buildQuery = (filterValues, filters) => {
|
|
5
5
|
const newQuery = [];
|
|
6
|
-
const searchValue = filterValues[SEARCH_TERM]
|
|
6
|
+
const searchValue = filterValues[SEARCH_TERM]
|
|
7
|
+
? encodeURIComponent(filterValues[SEARCH_TERM])
|
|
8
|
+
: '';
|
|
7
9
|
if (searchValue) newQuery.push(`${SEARCH_TERM}=${searchValue}`);
|
|
8
10
|
|
|
9
11
|
filters.forEach(({ propsToDisplay, type }) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KEYWORD, SIZE } from '../constants';
|
|
2
2
|
|
|
3
|
-
const buildRawQueryStringified = (checkboxSelectValues, rangeValues, entity) => {
|
|
3
|
+
const buildRawQueryStringified = (checkboxSelectValues, rangeValues, entity, mustFilters) => {
|
|
4
4
|
if (!checkboxSelectValues.length && !rangeValues.length) return '';
|
|
5
5
|
|
|
6
6
|
const aggs = {};
|
|
@@ -36,6 +36,7 @@ const buildRawQueryStringified = (checkboxSelectValues, rangeValues, entity) =>
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
],
|
|
39
|
+
must: mustFilters,
|
|
39
40
|
minimum_should_match: 1
|
|
40
41
|
}
|
|
41
42
|
}
|
|
@@ -3,12 +3,23 @@ import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
|
3
3
|
|
|
4
4
|
const getInitialFilterValues = (filterData, filters, query) => {
|
|
5
5
|
const filterValues = {};
|
|
6
|
+
filterValues[SEARCH_TERM] = query[SEARCH_TERM] || '';
|
|
7
|
+
|
|
8
|
+
if (!filterData) {
|
|
9
|
+
filters.forEach(({ propsToDisplay: [key] }) => {
|
|
10
|
+
filterValues[key] = null;
|
|
11
|
+
});
|
|
12
|
+
filterValues.dataNotSet = true;
|
|
13
|
+
return filterValues;
|
|
14
|
+
}
|
|
15
|
+
|
|
6
16
|
Object.keys(filterData).forEach(key => {
|
|
7
17
|
const filterProps =
|
|
8
18
|
filters.find(({ propsToDisplay }) => propsToDisplay.find(prop => key === prop)) || {};
|
|
9
19
|
filterValues[key] = getFilterValueFromQuery(key, filterProps, filterData[key], query);
|
|
10
20
|
});
|
|
11
|
-
|
|
21
|
+
|
|
22
|
+
filterValues.dataNotSet = false;
|
|
12
23
|
|
|
13
24
|
return filterValues;
|
|
14
25
|
};
|
|
@@ -13,6 +13,7 @@ import isDeviceDesktop from './is-device-desktop';
|
|
|
13
13
|
import getInitialFilterValues from './get-initial-filter-values';
|
|
14
14
|
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
15
15
|
import buildQuery from './build-query';
|
|
16
|
+
import buildFiltersQuery from './build-filters-query';
|
|
16
17
|
|
|
17
18
|
export {
|
|
18
19
|
buildQuery,
|
|
@@ -30,5 +31,6 @@ export {
|
|
|
30
31
|
getSelectOptions,
|
|
31
32
|
isDeviceDesktop,
|
|
32
33
|
getInitialFilterValues,
|
|
33
|
-
getFilterValueFromQuery
|
|
34
|
+
getFilterValueFromQuery,
|
|
35
|
+
buildFiltersQuery
|
|
34
36
|
};
|
|
@@ -8,10 +8,10 @@ const parseFilterValue = (key, type, value) => {
|
|
|
8
8
|
if (value.minValue === value.min && value.maxValue === value.max) return null;
|
|
9
9
|
return `${key}=${value.minValue}-${value.maxValue}`;
|
|
10
10
|
case CHECKBOX:
|
|
11
|
-
if (typeof value === 'string') return `${key}=${value}`;
|
|
12
|
-
return value.map(val => `${key}=${val}`).join('&');
|
|
11
|
+
if (typeof value === 'string') return `${key}=${encodeURIComponent(value)}`;
|
|
12
|
+
return value.map(val => `${key}=${encodeURIComponent(val)}`).join('&');
|
|
13
13
|
case SELECT: {
|
|
14
|
-
const parsedValue = value
|
|
14
|
+
const parsedValue = encodeURIComponent(value);
|
|
15
15
|
return `${key}=${parsedValue}`;
|
|
16
16
|
}
|
|
17
17
|
|
package/src/components/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export default {
|
|
|
18
18
|
video: dynamic(() => import(/* webpackChunkName: "blazePbVideo" */ './Video')),
|
|
19
19
|
wrapper: dynamic(() => import(/* webpackChunkName: "blazePbWrapper" */ './Wrapper')),
|
|
20
20
|
searchcontent: dynamic(() =>
|
|
21
|
-
import(/* webpackChunkName: "blazePbSearchFilter" */ './SearchContent')
|
|
21
|
+
import(/* webpackChunkName: "blazePbSearchFilter" */ './SearchContent/SearchContent')
|
|
22
22
|
),
|
|
23
23
|
searchfilter: dynamic(() =>
|
|
24
24
|
import(/* webpackChunkName: "blazePbSearchFilter" */ './SearchFilter')
|
|
@@ -42,5 +42,14 @@ export default {
|
|
|
42
42
|
import(/* webpackChunkName: "blazePbPasswordResetRequest" */ './PasswordResetRequest')
|
|
43
43
|
),
|
|
44
44
|
breadcrumb: dynamic(() => import(/* webpackChunkName: "blazePbBreadcrumb" */ './Breadcrumb')),
|
|
45
|
+
itemlistbutton: dynamic(() =>
|
|
46
|
+
import(/* webpackChunkName: "blazePbItemListButton" */ './ItemList/ItemListButton')
|
|
47
|
+
),
|
|
48
|
+
itemlistcounter: dynamic(() =>
|
|
49
|
+
import(/* webpackChunkName: "blazePbItemListCounter" */ './ItemList/ItemListCounter')
|
|
50
|
+
),
|
|
51
|
+
itemlistnew: dynamic(() =>
|
|
52
|
+
import(/* webpackChunkName: "blazePbItemListNew" */ './ItemList/ItemListNew')
|
|
53
|
+
),
|
|
45
54
|
backtotop: dynamic(() => import(/* webpackChunkName: "blazePbBackToTop" */ './BackToTop'))
|
|
46
55
|
};
|
package/src/constants/index.js
CHANGED
|
@@ -17,6 +17,7 @@ const RANGE = 'range';
|
|
|
17
17
|
const CHECKBOX = 'checkbox';
|
|
18
18
|
const ELEMENT = 'element';
|
|
19
19
|
const MENU_ITEM = 'menuitem';
|
|
20
|
+
const SUB_MENU = 'submenu';
|
|
20
21
|
const SELECT = 'select';
|
|
21
22
|
const ON_CLICK = 'onClick';
|
|
22
23
|
const KEYWORD = 'keyword';
|
|
@@ -303,6 +304,7 @@ export {
|
|
|
303
304
|
MOBILE_WIDTH,
|
|
304
305
|
HIDDEN,
|
|
305
306
|
MENU_ITEM,
|
|
307
|
+
SUB_MENU,
|
|
306
308
|
LOGIN_FORM,
|
|
307
309
|
PASSWORD_REGEX,
|
|
308
310
|
PASSWORD_VALIDATION_MESSAGE,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { act, render } from '@testing-library/react';
|
|
2
|
+
import { act, render, fireEvent, waitFor } from '@testing-library/react';
|
|
3
3
|
import '@testing-library/jest-dom/extend-expect';
|
|
4
4
|
import Button from '../../../../src/components/Button';
|
|
5
5
|
|
|
@@ -20,6 +20,16 @@ const componentProps = {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
const contentToShow = 'Content to show';
|
|
24
|
+
|
|
25
|
+
const seoVisivilityProps = {
|
|
26
|
+
text: 'show more',
|
|
27
|
+
afterClickText: 'show less',
|
|
28
|
+
url: '',
|
|
29
|
+
icon: '',
|
|
30
|
+
children: [<p>Content to show</p>]
|
|
31
|
+
};
|
|
32
|
+
|
|
23
33
|
const renderComponent = async props => {
|
|
24
34
|
let renderResults;
|
|
25
35
|
|
|
@@ -68,4 +78,48 @@ describe('Button component', () => {
|
|
|
68
78
|
const { container } = await renderComponent(logoutButton);
|
|
69
79
|
expect(container.innerHTML).toBe('');
|
|
70
80
|
});
|
|
81
|
+
|
|
82
|
+
it('should toggle button text and render child components for SEO visibility ', async () => {
|
|
83
|
+
const props = {
|
|
84
|
+
...componentProps,
|
|
85
|
+
...seoVisivilityProps,
|
|
86
|
+
childSeoVisibility: true
|
|
87
|
+
};
|
|
88
|
+
const { container, getByText } = await renderComponent(props);
|
|
89
|
+
|
|
90
|
+
const element = await waitFor(() => getByText('show more'));
|
|
91
|
+
expect(container.innerHTML).toContain(contentToShow);
|
|
92
|
+
|
|
93
|
+
fireEvent(
|
|
94
|
+
element,
|
|
95
|
+
new MouseEvent('click', {
|
|
96
|
+
bubbles: true,
|
|
97
|
+
cancelable: true
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
expect(container.innerHTML).toContain('show less');
|
|
101
|
+
expect(container.innerHTML).toContain(contentToShow);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should toggle button text hide child components when SEO visibility is disabled', async () => {
|
|
105
|
+
const props = {
|
|
106
|
+
...componentProps,
|
|
107
|
+
...seoVisivilityProps,
|
|
108
|
+
childSeoVisibility: false
|
|
109
|
+
};
|
|
110
|
+
const { container, getByText } = await renderComponent(props);
|
|
111
|
+
|
|
112
|
+
const element = await waitFor(() => getByText('show more'));
|
|
113
|
+
expect(container.innerHTML).not.toContain(contentToShow);
|
|
114
|
+
|
|
115
|
+
fireEvent(
|
|
116
|
+
element,
|
|
117
|
+
new MouseEvent('click', {
|
|
118
|
+
bubbles: true,
|
|
119
|
+
cancelable: true
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
expect(container.innerHTML).toContain('show less');
|
|
123
|
+
expect(container.innerHTML).toContain(contentToShow);
|
|
124
|
+
});
|
|
71
125
|
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
+
import { render, waitFor, fireEvent } from '@testing-library/react';
|
|
4
|
+
import { MockedProvider } from '@apollo/client/testing';
|
|
5
|
+
|
|
6
|
+
import ItemListButton from '../../../../../src/components/ItemList/ItemListButton';
|
|
7
|
+
import {
|
|
8
|
+
getItemList,
|
|
9
|
+
addItemsToList,
|
|
10
|
+
removeItemsFromList
|
|
11
|
+
} from '../../../../../src/application/query';
|
|
12
|
+
import userItemListId from '../../../../../src/components/ItemList/hooks/use-item-list-id';
|
|
13
|
+
import setItemListId from '../../../../../src/components/ItemList/helpers/set-item-list-id';
|
|
14
|
+
|
|
15
|
+
jest.mock('../../../../../src/components/ItemList/hooks/use-item-list-id', () =>
|
|
16
|
+
jest.fn(() => ({ listId: 'LIST ID' }))
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
jest.mock('../../../../../src/components/ItemList/helpers/set-item-list-id', () => {
|
|
20
|
+
const originalModule = jest.requireActual(
|
|
21
|
+
'../../../../../src/components/ItemList/helpers/set-item-list-id'
|
|
22
|
+
);
|
|
23
|
+
return jest.fn((...args) => originalModule.default(...args));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const listId = 'LIST ID';
|
|
27
|
+
const missingListId = 'MISSING';
|
|
28
|
+
const emptyListId = 'EMPTY';
|
|
29
|
+
const listItem = { itemId: 'ID', itemEntity: 'ENTITY' };
|
|
30
|
+
const listName = 'list_name';
|
|
31
|
+
const props = {
|
|
32
|
+
listName,
|
|
33
|
+
modifier: 'modifier',
|
|
34
|
+
parent: {
|
|
35
|
+
itemId: 'ID',
|
|
36
|
+
itemEntity: 'ENTITY'
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const mocks = [
|
|
41
|
+
{
|
|
42
|
+
request: {
|
|
43
|
+
query: getItemList,
|
|
44
|
+
variables: { id: listId }
|
|
45
|
+
},
|
|
46
|
+
result: {
|
|
47
|
+
data: {
|
|
48
|
+
getItemList: { id: listId, listItems: [listItem] }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
request: {
|
|
54
|
+
query: getItemList,
|
|
55
|
+
variables: { id: missingListId }
|
|
56
|
+
},
|
|
57
|
+
result: {
|
|
58
|
+
data: {
|
|
59
|
+
getItemList: null
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
request: {
|
|
65
|
+
query: getItemList,
|
|
66
|
+
variables: { id: emptyListId }
|
|
67
|
+
},
|
|
68
|
+
result: {
|
|
69
|
+
data: {
|
|
70
|
+
getItemList: { id: emptyListId, listItems: [] }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
request: {
|
|
76
|
+
query: addItemsToList,
|
|
77
|
+
variables: { name: listName, id: '', listItems: [props.parent] }
|
|
78
|
+
},
|
|
79
|
+
result: {
|
|
80
|
+
data: {
|
|
81
|
+
addItemsToList: {
|
|
82
|
+
result: { id: listId, listItems: [listItem] }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
request: {
|
|
89
|
+
query: removeItemsFromList,
|
|
90
|
+
variables: { listId, listItems: [props.parent] }
|
|
91
|
+
},
|
|
92
|
+
result: {
|
|
93
|
+
data: {
|
|
94
|
+
removeItemsFromList: {
|
|
95
|
+
result: { id: listId, listItems: [listItem] }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
const selectedClasses = 'item-list-button item-list-button--selected modifier';
|
|
103
|
+
const unselectedClasses = 'item-list-button modifier';
|
|
104
|
+
const buttonRole = 'button';
|
|
105
|
+
|
|
106
|
+
describe('ItemListButton component', () => {
|
|
107
|
+
beforeEach(() => {
|
|
108
|
+
jest.clearAllMocks();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should render button marked selected when current parent is in the list', async () => {
|
|
112
|
+
const { asFragment, getByRole } = render(
|
|
113
|
+
<MockedProvider mocks={mocks}>
|
|
114
|
+
<ItemListButton {...props} />
|
|
115
|
+
</MockedProvider>
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
await waitFor(() => getByRole(buttonRole));
|
|
119
|
+
const button = getByRole(buttonRole);
|
|
120
|
+
expect(button).toHaveClass(selectedClasses);
|
|
121
|
+
expect(asFragment()).toMatchSnapshot();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should add and remove item to the list on click', async () => {
|
|
125
|
+
userItemListId.mockReturnValueOnce({ listId: '' }).mockReturnValueOnce({ listId });
|
|
126
|
+
const { asFragment, getByRole } = render(
|
|
127
|
+
<MockedProvider mocks={mocks}>
|
|
128
|
+
<ItemListButton {...props} />
|
|
129
|
+
</MockedProvider>
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
await waitFor(() => getByRole(buttonRole));
|
|
133
|
+
const button = getByRole(buttonRole);
|
|
134
|
+
fireEvent.click(button);
|
|
135
|
+
await waitFor(() => getByRole(buttonRole));
|
|
136
|
+
const selectedButton = getByRole(buttonRole);
|
|
137
|
+
expect(selectedButton).toHaveClass(selectedClasses);
|
|
138
|
+
expect(asFragment()).toMatchSnapshot();
|
|
139
|
+
|
|
140
|
+
fireEvent.click(selectedButton);
|
|
141
|
+
await waitFor(() => getByRole(buttonRole));
|
|
142
|
+
const removedButton = getByRole(buttonRole);
|
|
143
|
+
expect(removedButton).toHaveClass(unselectedClasses);
|
|
144
|
+
expect(asFragment()).toMatchSnapshot();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should set list id from mutation', async () => {
|
|
148
|
+
userItemListId.mockReturnValue({ listId: '' });
|
|
149
|
+
const { getByRole } = render(
|
|
150
|
+
<MockedProvider mocks={mocks}>
|
|
151
|
+
<ItemListButton {...props} />
|
|
152
|
+
</MockedProvider>
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
await waitFor(() => getByRole(buttonRole));
|
|
156
|
+
const button = getByRole(buttonRole);
|
|
157
|
+
fireEvent.click(button);
|
|
158
|
+
await waitFor(() => getByRole(buttonRole));
|
|
159
|
+
expect(setItemListId).toHaveBeenCalledWith(listName, listId);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should render button not marked selected when current parent is not in the list', async () => {
|
|
163
|
+
userItemListId.mockReturnValue({ listId: emptyListId });
|
|
164
|
+
const { asFragment, getByRole } = render(
|
|
165
|
+
<MockedProvider mocks={mocks}>
|
|
166
|
+
<ItemListButton {...props} />
|
|
167
|
+
</MockedProvider>
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
await waitFor(() => getByRole(buttonRole));
|
|
171
|
+
const button = getByRole(buttonRole);
|
|
172
|
+
expect(button).toHaveClass(unselectedClasses);
|
|
173
|
+
expect(asFragment()).toMatchSnapshot();
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
+
import { render, waitFor, fireEvent } from '@testing-library/react';
|
|
4
|
+
import { MockedProvider } from '@apollo/client/testing';
|
|
5
|
+
import { useRouter } from 'next/router';
|
|
6
|
+
import ItemListCounter from '../../../../../src/components/ItemList/ItemListCounter';
|
|
7
|
+
import { getItemList } from '../../../../../src/application/query';
|
|
8
|
+
|
|
9
|
+
jest.mock('../../../../../src/components/ItemList/hooks/use-item-list-id', () =>
|
|
10
|
+
jest.fn(() => ({ listId: 'LIST ID' }))
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
jest.mock('next/router', () => {
|
|
14
|
+
const push = jest.fn();
|
|
15
|
+
return {
|
|
16
|
+
useRouter: jest.fn(() => ({ push }))
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const listId = 'LIST ID';
|
|
21
|
+
const listItem = { itemId: 'ID', itemEntity: 'ENTITY' };
|
|
22
|
+
const listName = 'list_name';
|
|
23
|
+
const props = {
|
|
24
|
+
listName,
|
|
25
|
+
modifier: 'modifier',
|
|
26
|
+
url: '/list-url'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const mocks = [
|
|
30
|
+
{
|
|
31
|
+
request: {
|
|
32
|
+
query: getItemList,
|
|
33
|
+
variables: { id: listId }
|
|
34
|
+
},
|
|
35
|
+
result: {
|
|
36
|
+
data: {
|
|
37
|
+
getItemList: { id: listId, listItems: [listItem] }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const buttonRole = 'button';
|
|
44
|
+
const router = useRouter();
|
|
45
|
+
|
|
46
|
+
describe('ItemListCounter component', () => {
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
jest.clearAllMocks();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should display listItem count and route to url', async () => {
|
|
52
|
+
const { asFragment, getByRole, getByText } = render(
|
|
53
|
+
<MockedProvider mocks={mocks}>
|
|
54
|
+
<ItemListCounter {...props} />
|
|
55
|
+
</MockedProvider>
|
|
56
|
+
);
|
|
57
|
+
await waitFor(() => getByText('1'));
|
|
58
|
+
|
|
59
|
+
const button = getByRole(buttonRole);
|
|
60
|
+
expect(asFragment()).toMatchSnapshot();
|
|
61
|
+
|
|
62
|
+
fireEvent.click(button);
|
|
63
|
+
expect(router.push).toHaveBeenCalledWith('/Resolver', `${props.url}?itemListId=${listId}`);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
+
import { render, waitFor, fireEvent } from '@testing-library/react';
|
|
4
|
+
import { MockedProvider } from '@apollo/client/testing';
|
|
5
|
+
import { useRouter } from 'next/router';
|
|
6
|
+
import ItemListNew from '../../../../../src/components/ItemList/ItemListNew';
|
|
7
|
+
import { getItemList } from '../../../../../src/application/query';
|
|
8
|
+
import userItemListId from '../../../../../src/components/ItemList/hooks/use-item-list-id';
|
|
9
|
+
import getItemListData from '../../../../../src/components/ItemList/helpers/get-item-list-data';
|
|
10
|
+
import setItemListId from '../../../../../src/components/ItemList/helpers/set-item-list-id';
|
|
11
|
+
import setParamAndRedirect from '../../../../../src/components/ItemList/helpers/set-param-and-redirect';
|
|
12
|
+
import { LIST_ITEM_QUERY_PARAM } from '../../../../../src/components/ItemList/constants';
|
|
13
|
+
|
|
14
|
+
jest.mock('next/router', () => {
|
|
15
|
+
const useRouterMock = jest.fn(() => ({ asPath: '/test' }));
|
|
16
|
+
return { useRouter: useRouterMock };
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
jest.mock('../../../../../src/components/ItemList/hooks/use-item-list-id', () =>
|
|
20
|
+
jest.fn(() => ({ listId: 'LIST ID' }))
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
jest.mock('../../../../../src/components/ItemList/helpers/set-item-list-id', () => {
|
|
24
|
+
const originalModule = jest.requireActual(
|
|
25
|
+
'../../../../../src/components/ItemList/helpers/set-item-list-id'
|
|
26
|
+
);
|
|
27
|
+
return jest.fn((...args) => originalModule.default(...args));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
jest.mock('../../../../../src/components/ItemList/helpers/set-param-and-redirect', () => jest.fn());
|
|
31
|
+
|
|
32
|
+
jest.mock('../../../../../src/components/ItemList/helpers/get-item-list-data', () => {
|
|
33
|
+
const originalModule = jest.requireActual(
|
|
34
|
+
'../../../../../src/components/ItemList/helpers/get-item-list-data'
|
|
35
|
+
);
|
|
36
|
+
return jest.fn((...args) => originalModule.default(...args));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const listId = 'LIST ID';
|
|
40
|
+
const missingListId = 'MISSING';
|
|
41
|
+
const emptyListId = 'EMPTY';
|
|
42
|
+
const queryListId = 'QUERY-LIST-ID';
|
|
43
|
+
const queryListItem = { itemId: 'ID FROM QUERY', itemEntity: 'ENTITY' };
|
|
44
|
+
const mocks = [
|
|
45
|
+
{
|
|
46
|
+
request: {
|
|
47
|
+
query: getItemList,
|
|
48
|
+
variables: { id: listId }
|
|
49
|
+
},
|
|
50
|
+
result: {
|
|
51
|
+
data: {
|
|
52
|
+
getItemList: { id: listId, listItems: [{ itemId: 'ID', itemEntity: 'ENTITY' }] }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
request: {
|
|
58
|
+
query: getItemList,
|
|
59
|
+
variables: { id: missingListId }
|
|
60
|
+
},
|
|
61
|
+
result: {
|
|
62
|
+
data: {
|
|
63
|
+
getItemList: null
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
request: {
|
|
69
|
+
query: getItemList,
|
|
70
|
+
variables: { id: emptyListId }
|
|
71
|
+
},
|
|
72
|
+
result: {
|
|
73
|
+
data: {
|
|
74
|
+
getItemList: { id: emptyListId, listItems: [] }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
request: {
|
|
80
|
+
query: getItemList,
|
|
81
|
+
variables: { id: queryListId }
|
|
82
|
+
},
|
|
83
|
+
result: {
|
|
84
|
+
data: {
|
|
85
|
+
getItemList: { id: queryListId, listItems: [queryListItem] }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
describe('ItemListNew component', () => {
|
|
92
|
+
const props = {
|
|
93
|
+
listName: 'list_name',
|
|
94
|
+
modifier: 'button',
|
|
95
|
+
text: 'Clear list'
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
jest.clearAllMocks();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should match snapshot and render without throwing an error', async () => {
|
|
103
|
+
const { asFragment, getByText } = render(
|
|
104
|
+
<MockedProvider mocks={mocks}>
|
|
105
|
+
<ItemListNew {...props} />
|
|
106
|
+
</MockedProvider>
|
|
107
|
+
);
|
|
108
|
+
await waitFor(() => expect(getByText(props.text)).toBeInTheDocument());
|
|
109
|
+
expect(asFragment()).toMatchSnapshot();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should not render if list not found', async () => {
|
|
113
|
+
userItemListId.mockReturnValue({ listId: missingListId });
|
|
114
|
+
const { asFragment } = render(
|
|
115
|
+
<MockedProvider mocks={mocks}>
|
|
116
|
+
<ItemListNew {...props} listName={missingListId} />
|
|
117
|
+
</MockedProvider>
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
await waitFor(() => expect(getItemListData).toHaveBeenCalled());
|
|
121
|
+
expect(asFragment()).toMatchSnapshot();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should render using listId from query', async () => {
|
|
125
|
+
userItemListId.mockReturnValue({ listId });
|
|
126
|
+
const queryStringPath = { asPath: `/test?${LIST_ITEM_QUERY_PARAM}=${queryListId}` };
|
|
127
|
+
useRouter.mockReturnValueOnce(queryStringPath).mockReturnValueOnce(queryStringPath);
|
|
128
|
+
const { asFragment } = render(
|
|
129
|
+
<MockedProvider mocks={mocks}>
|
|
130
|
+
<ItemListNew {...props} listName={queryListId} />
|
|
131
|
+
</MockedProvider>
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
await waitFor(() => expect(getItemListData).toHaveBeenCalled());
|
|
135
|
+
expect(getItemListData).toHaveBeenCalledWith({
|
|
136
|
+
getItemList: { id: queryListId, listItems: [queryListItem] }
|
|
137
|
+
});
|
|
138
|
+
expect(asFragment()).toMatchSnapshot();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should not render if list has not items', async () => {
|
|
142
|
+
userItemListId.mockReturnValue({ listId: emptyListId });
|
|
143
|
+
const { asFragment } = render(
|
|
144
|
+
<MockedProvider mocks={mocks}>
|
|
145
|
+
<ItemListNew {...props} listName={emptyListId} />
|
|
146
|
+
</MockedProvider>
|
|
147
|
+
);
|
|
148
|
+
await waitFor(() => expect(getItemListData).toHaveBeenCalled());
|
|
149
|
+
expect(asFragment()).toMatchSnapshot();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should clear id and redirect onclick', async () => {
|
|
153
|
+
userItemListId.mockReturnValue({ listId });
|
|
154
|
+
const { getByText } = render(
|
|
155
|
+
<MockedProvider mocks={mocks}>
|
|
156
|
+
<ItemListNew {...props} />
|
|
157
|
+
</MockedProvider>
|
|
158
|
+
);
|
|
159
|
+
await waitFor(() => expect(getByText(props.text)).toBeInTheDocument());
|
|
160
|
+
fireEvent.click(getByText(props.text));
|
|
161
|
+
expect(setItemListId).toHaveBeenCalledWith(props.listName, '');
|
|
162
|
+
expect(setParamAndRedirect).toHaveBeenCalled();
|
|
163
|
+
});
|
|
164
|
+
});
|