@bytebrand/fe-ui-core 4.2.183 → 4.2.185
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/__tests__/components/UserDasboardPage/sections/CheckoutSection/CheckoutSection.test.tsx +4 -7
- package/__tests__/components/UserDasboardPage/sections/FavoriteSection/FavoriteSection.test.tsx +9 -47
- package/package.json +1 -1
- package/source/components/UserDashboardPage/sections/CheckoutSection/CheckoutSection.tsx +40 -48
- package/source/components/UserDashboardPage/sections/FavoriteSection/FavoriteSection.tsx +2 -30
- package/source/components/_common/Range/Range.tsx +7 -6
- package/source/framework/utils/CommonUtils.ts +14 -3
package/__tests__/components/UserDasboardPage/sections/CheckoutSection/CheckoutSection.test.tsx
CHANGED
|
@@ -578,6 +578,7 @@ const aggStatsData = observable({
|
|
|
578
578
|
const mockProps = {
|
|
579
579
|
t,
|
|
580
580
|
LinkRouter,
|
|
581
|
+
checkoutCars,
|
|
581
582
|
PLACEHOLDER_IMAGE_SMALL_URL: 'PLACEHOLDER_IMAGE_SMALL_URL',
|
|
582
583
|
appStore: { language:'en' },
|
|
583
584
|
carsStore: { aggStatsData },
|
|
@@ -588,16 +589,12 @@ const mockProps = {
|
|
|
588
589
|
describe('CheckoutSection', () => {
|
|
589
590
|
it('renders correctly', () => {
|
|
590
591
|
const { container } = render(<CheckoutSection {...mockProps as any} />);
|
|
591
|
-
expect(mockProps.checkoutStore.getCheckoutCarList).toHaveBeenCalledTimes(1);
|
|
592
|
+
// expect(mockProps.checkoutStore.getCheckoutCarList).toHaveBeenCalledTimes(1);
|
|
592
593
|
expect(container).toBeInTheDocument();
|
|
593
594
|
});
|
|
594
595
|
it('should display correct car data', () => {
|
|
595
596
|
const { container } = render(<CheckoutSection {...mockProps as any} />);
|
|
596
|
-
|
|
597
|
-
// mockProps.checkoutStore.getCheckoutCarList()
|
|
598
|
-
// .then((savedCheckoutDataList: any) => {
|
|
599
|
-
// checkoutCarList = mockProps.checkoutStore.checkoutCars;
|
|
600
|
-
mockProps.checkoutStore.checkoutCars.forEach((element:any) => {
|
|
597
|
+
mockProps.checkoutCars.forEach((element:any) => {
|
|
601
598
|
expect(container).toHaveTextContent(element.title.make);
|
|
602
599
|
});
|
|
603
600
|
// });
|
|
@@ -608,7 +605,7 @@ describe('CheckoutSection', () => {
|
|
|
608
605
|
// .then((savedCheckoutDataList: any) => {
|
|
609
606
|
const checkoutButton = getAllByRole('link')[0];
|
|
610
607
|
fireEvent.click(checkoutButton);
|
|
611
|
-
const expectedUrl = `/checkout/contact-information?carId=${mockProps.
|
|
608
|
+
const expectedUrl = `/checkout/contact-information?carId=${mockProps.checkoutCars[0].id}&isSavedCheckout=true&mainImageId=${mockProps.checkoutCars[0].mainImageId}&model=${mockProps.checkoutCars[0].title.model}&subModel=${mockProps.checkoutCars[0].title.subModel}&make=${mockProps.checkoutCars[0].title.make}`;
|
|
612
609
|
waitFor(() => expect(window.open).toHaveBeenCalledWith(expectedUrl, '_blank'));
|
|
613
610
|
// });
|
|
614
611
|
});
|
package/__tests__/components/UserDasboardPage/sections/FavoriteSection/FavoriteSection.test.tsx
CHANGED
|
@@ -312,8 +312,8 @@ const aggStatsData = observable({
|
|
|
312
312
|
const mockProps = {
|
|
313
313
|
t,
|
|
314
314
|
LinkRouter,
|
|
315
|
+
favoriteCars,
|
|
315
316
|
PLACEHOLDER_IMAGE_SMALL_URL: 'PLACEHOLDER_IMAGE_SMALL_URL',
|
|
316
|
-
pageNumberKey: 'pageNumber',
|
|
317
317
|
favoriteStore: { favoriteCars, favoritesIDs, showList: true, getFavouriteCars: getFavoriteCarsMock, getFavoritesIDs: jest.fn() },
|
|
318
318
|
appStore: {},
|
|
319
319
|
carsStore: { aggStatsData, getAggStatsData: jest.fn() },
|
|
@@ -322,52 +322,14 @@ const mockProps = {
|
|
|
322
322
|
|
|
323
323
|
describe('FavoriteSection', () => {
|
|
324
324
|
test('calls getFavouriteCars when component is mounted', () => {
|
|
325
|
-
render(<FavoriteSection {...mockProps} />);
|
|
326
|
-
expect(
|
|
325
|
+
const { container } = render(<FavoriteSection {...mockProps as any} />);
|
|
326
|
+
expect(container).toBeInTheDocument();
|
|
327
|
+
// expect(mockProps.favoriteStore.getFavouriteCars).toHaveBeenCalledTimes(1);
|
|
327
328
|
});
|
|
328
|
-
test('
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
PLACEHOLDER_IMAGE_SMALL_URL: 'PLACEHOLDER_IMAGE_SMALL_URL',
|
|
334
|
-
pageNumberKey: 4,
|
|
335
|
-
favoriteStore: { favoriteCars, favoritesIDs, showList: true, getFavouriteCars: getFavoriteCarsMock, getFavoritesIDs: jest.fn() },
|
|
336
|
-
appStore: {},
|
|
337
|
-
carsStore: { aggStatsData, getAggStatsData: jest.fn() },
|
|
338
|
-
imagesStore: { getSupportedImageFormat: jest.fn() }
|
|
339
|
-
};
|
|
340
|
-
props.favoriteStore.getFavoritesIDs.mockResolvedValueOnce(['b359d74f-bb96-4fca-9539-579792fe7c36']);
|
|
341
|
-
|
|
342
|
-
render(<FavoriteSection {...props} />);
|
|
343
|
-
expect(props.favoriteStore.getFavoritesIDs).toHaveBeenCalledTimes(1);
|
|
344
|
-
expect(mockProps.carsStore.getAggStatsData).toHaveBeenCalledTimes(1);
|
|
345
|
-
expect(mockProps.carsStore.getAggStatsData).toHaveBeenCalledWith(['b359d74f-bb96-4fca-9539-579792fe7c36']);
|
|
346
|
-
});
|
|
347
|
-
test('does not call getFavoritesIDs when favoritesIDs is not empty', async () => {
|
|
348
|
-
render(<FavoriteSection {...mockProps} />);
|
|
349
|
-
expect(mockProps.favoriteStore.getFavoritesIDs).not.toHaveBeenCalled();
|
|
350
|
-
});
|
|
351
|
-
test('returns the correct current page', () => {
|
|
352
|
-
const mockProps = {
|
|
353
|
-
t: jest.fn(),
|
|
354
|
-
LinkRouter: jest.fn(),
|
|
355
|
-
PLACEHOLDER_IMAGE_SMALL_URL: 'PLACEHOLDER_IMAGE_SMALL_URL',
|
|
356
|
-
pageNumberKey: 'pageNumber',
|
|
357
|
-
favoriteStore: { favoriteCars, favoritesIDs, showList: true, getFavouriteCars: getFavoriteCarsMock, getFavoritesIDs: jest.fn() },
|
|
358
|
-
appStore: {},
|
|
359
|
-
carsStore: {
|
|
360
|
-
aggStatsData: {},
|
|
361
|
-
getAggStatsData: jest.fn()
|
|
362
|
-
},
|
|
363
|
-
imagesStore: {
|
|
364
|
-
getSupportedImageFormat: jest.fn()
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
jest.spyOn(qs, 'parse').mockReturnValueOnce({ pageNumber: '3' });
|
|
368
|
-
const favoriteSectionInstance = new FavoriteSection(mockProps);
|
|
369
|
-
const currentPage = favoriteSectionInstance.getCurrentPage();
|
|
370
|
-
expect(currentPage).toBe(3);
|
|
329
|
+
test('should display correct car data', () => {
|
|
330
|
+
const { container } = render(<FavoriteSection {...mockProps as any} />);
|
|
331
|
+
mockProps.favoriteCars.forEach((element:any) => {
|
|
332
|
+
expect(container).toHaveTextContent(element.title.make);
|
|
333
|
+
});
|
|
371
334
|
});
|
|
372
|
-
|
|
373
335
|
});
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import { isMobileOnly } from 'react-device-detect';
|
|
|
6
6
|
import Slider from 'react-slick';
|
|
7
7
|
import { VehicleSmallCard } from '../../../../../common';
|
|
8
8
|
import { toJS } from 'mobx';
|
|
9
|
+
// import { toJS } from 'mobx';
|
|
9
10
|
|
|
10
11
|
interface ITFunction {
|
|
11
12
|
<T = string>(key: string, options?: object): T;
|
|
@@ -19,71 +20,62 @@ interface ICheckoutSectionProps {
|
|
|
19
20
|
t?: ITFunction;
|
|
20
21
|
LinkRouter: any;
|
|
21
22
|
PLACEHOLDER_IMAGE_SMALL_URL:string;
|
|
22
|
-
|
|
23
|
-
checkoutStore:any;
|
|
23
|
+
checkoutCars?:any;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
class CheckoutSection extends React.Component<ICheckoutSectionProps, {}> {
|
|
27
|
-
componentDidMount() {
|
|
28
|
-
const { checkoutStore } = this.props;
|
|
29
|
-
checkoutStore.getCheckoutCarList();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
27
|
onCarSelectCheckout = (carId?: string) => {
|
|
33
|
-
|
|
34
|
-
const checkoutCars = toJS(this.props.checkoutStore.checkoutCars);
|
|
28
|
+
const checkoutCars = this.props.checkoutCars;
|
|
35
29
|
const car = checkoutCars.find((item: any) => item.id === carId);
|
|
36
30
|
const { mainImageId, title: { model, subModel, make } } = car;
|
|
37
31
|
window.open(`/checkout/contact-information?carId=${carId}&isSavedCheckout=true&mainImageId=${mainImageId}&model=${model}&subModel=${subModel}&make=${make}`, '_blank');
|
|
38
32
|
};
|
|
39
33
|
|
|
40
|
-
|
|
41
|
-
const { t, appStore: { language }, carsStore, imagesStore , PLACEHOLDER_IMAGE_SMALL_URL,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const { mainImageId, title: { model, subModel, make } } = car;
|
|
47
|
-
const src = !!mainImageId && !!car.imagesCount
|
|
34
|
+
renderCheckouts = () => {
|
|
35
|
+
const { t, appStore: { language }, carsStore, imagesStore , PLACEHOLDER_IMAGE_SMALL_URL, checkoutCars } = this.props;
|
|
36
|
+
return checkoutCars.map((car: any) => {
|
|
37
|
+
const carId = _get(car, 'id');
|
|
38
|
+
const { mainImageId, title: { model, subModel, make } } = car;
|
|
39
|
+
const src = !!mainImageId && !!car.imagesCount
|
|
48
40
|
? imagesStore.getSupportedImageFormat(carId, mainImageId, 'small')
|
|
49
41
|
: PLACEHOLDER_IMAGE_SMALL_URL;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
42
|
+
const vehicleProps = {
|
|
43
|
+
...car,
|
|
44
|
+
t,
|
|
45
|
+
language,
|
|
46
|
+
mainImageId,
|
|
47
|
+
src,
|
|
48
|
+
url: `/checkout/contact-information?carId=${carId}&isSavedCheckout=true&mainImageId=${mainImageId}&model=${model}&subModel=${subModel}&make=${make}`,
|
|
49
|
+
id: carId,
|
|
50
|
+
target: '_blank',
|
|
51
|
+
rel: 'noopener noreferrer',
|
|
52
|
+
showSlider: false,
|
|
53
|
+
showOfferBtn: true,
|
|
54
|
+
showFavoriteStar: false,
|
|
55
|
+
priceSubMtl: !isMobileOnly ? t('vehicleProps:value.priceSub') : null,
|
|
56
|
+
stats: {
|
|
57
|
+
imagesCount: _get(car, 'imagesCount'),
|
|
58
|
+
statsData: carsStore.aggStatsData.get(car.id)
|
|
59
|
+
},
|
|
60
|
+
dashboardButtonText: t('vehicleProps:title.toCheckoutCar'),
|
|
61
|
+
i18nPrefixForPriceRating: 'common:',
|
|
62
|
+
className: styles.wrapFavorites,
|
|
63
|
+
classButton: styles.favoriteBtn,
|
|
64
|
+
onDetailsClick: this.onCarSelectCheckout,
|
|
65
|
+
vehicleComponentName: 'favorite'
|
|
66
|
+
};
|
|
75
67
|
|
|
76
|
-
|
|
68
|
+
return (
|
|
77
69
|
<div key={`checkoutCar${carId}`} className={styles.checkoutWrapItem}>
|
|
78
70
|
<VehicleSmallCard {...vehicleProps} />
|
|
79
71
|
</div>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
72
|
+
);
|
|
73
|
+
});
|
|
83
74
|
};
|
|
84
75
|
|
|
85
76
|
render(): JSX.Element {
|
|
86
|
-
const { t,
|
|
77
|
+
const { t, checkoutCars } = this.props;
|
|
78
|
+
|
|
87
79
|
const sliderProps = {
|
|
88
80
|
slidesToShow: 3,
|
|
89
81
|
slidesToScroll: 1,
|
|
@@ -109,7 +101,7 @@ class CheckoutSection extends React.Component<ICheckoutSectionProps, {}> {
|
|
|
109
101
|
|
|
110
102
|
return (
|
|
111
103
|
<>
|
|
112
|
-
{
|
|
104
|
+
{checkoutCars?.length !== 0 ?
|
|
113
105
|
<DashboardSection className={styles.checkoutSection} title={t('DashboardPage:checkoutTitle')}>
|
|
114
106
|
{!isMobileOnly ?
|
|
115
107
|
this.renderCheckouts()
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { toJS } from 'mobx';
|
|
3
|
-
import qs from 'qs';
|
|
4
2
|
import _get from 'lodash/get';
|
|
5
3
|
import DashboardSection from '../../../containers/DasboardSection/DashboardSection';
|
|
6
4
|
import styles from './FavoriteSection.styl';
|
|
@@ -19,42 +17,16 @@ interface IFavoriteSectionProps {
|
|
|
19
17
|
imagesStore: any;
|
|
20
18
|
t?: ITFunction;
|
|
21
19
|
PLACEHOLDER_IMAGE_SMALL_URL: string;
|
|
22
|
-
pageNumberKey: any;
|
|
23
20
|
LinkRouter: any;
|
|
21
|
+
favoriteCars:any;
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
class FavoriteSection extends React.Component<IFavoriteSectionProps, {}> {
|
|
27
|
-
componentDidMount() {
|
|
28
|
-
const currentPage = this.getCurrentPage();
|
|
29
|
-
this.getCarsForPage(currentPage);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getCarsForPage = (page: number): void => {
|
|
33
|
-
const { favoriteStore, carsStore } = this.props;
|
|
34
|
-
if (page) {
|
|
35
|
-
favoriteStore.getFavouriteCars(page);
|
|
36
|
-
|
|
37
|
-
if (!favoriteStore.favoritesIDs.length) {
|
|
38
|
-
favoriteStore.getFavoritesIDs().then((favoritesIDs: any) => {
|
|
39
|
-
carsStore.getAggStatsData(favoritesIDs);
|
|
40
|
-
});
|
|
41
|
-
} else carsStore.getAggStatsData(favoriteStore.favoritesIDs);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
getCurrentPage = () => {
|
|
46
|
-
const { pageNumberKey } = this.props;
|
|
47
|
-
const pageFromQuery = qs.parse(location.search, { ignoreQueryPrefix: true })[pageNumberKey];
|
|
48
|
-
if (!pageFromQuery) return 1;
|
|
49
|
-
const page = Number(pageFromQuery);
|
|
50
|
-
return page > 0 ? page : 1;
|
|
51
|
-
};
|
|
52
25
|
|
|
53
26
|
onCarSelectFavorite = (url: string) => window.open(`/search/vehicle/${url}`, '_blank');
|
|
54
27
|
|
|
55
28
|
private renderFavorites = () => {
|
|
56
|
-
const { t, appStore: { language }, carsStore, imagesStore,
|
|
57
|
-
const favoriteCars = toJS(favoriteStore.favoriteCars);
|
|
29
|
+
const { t, appStore: { language }, carsStore, imagesStore, PLACEHOLDER_IMAGE_SMALL_URL, LinkRouter,favoriteCars } = this.props;
|
|
58
30
|
return favoriteCars.map((car: any, key: any) => {
|
|
59
31
|
const carId = _get(car, 'id');
|
|
60
32
|
const mainImageId = _get(car, 'mainImageId');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { useState, useEffect
|
|
2
|
-
import debounce from 'lodash/debounce';
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
3
2
|
import FormattedNumber from '../../FormattedNumber/FormattedNumber';
|
|
4
3
|
import { Slider } from '@mui/material';
|
|
5
4
|
import { isMobileOnly } from 'react-device-detect';
|
|
5
|
+
import { iOS } from '../../../framework/utils/CommonUtils';
|
|
6
6
|
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
|
7
7
|
|
|
8
8
|
interface IRangeProps {
|
|
@@ -41,6 +41,7 @@ const Range: React.FC<IRangeProps> = ({
|
|
|
41
41
|
maxFinancingFirstInstallment
|
|
42
42
|
}: IRangeProps) => {
|
|
43
43
|
const [rangeValue, setRangeValue] = useState<number | number[]>(0);
|
|
44
|
+
const isIOS = iOS();
|
|
44
45
|
|
|
45
46
|
useEffect(
|
|
46
47
|
() => {
|
|
@@ -50,13 +51,13 @@ const Range: React.FC<IRangeProps> = ({
|
|
|
50
51
|
)
|
|
51
52
|
|
|
52
53
|
const onChangeRange = (event: Event, value: number | number[]) => {
|
|
54
|
+
if (isIOS && event.type === 'mousedown') {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
53
57
|
setRangeValue(value);
|
|
54
58
|
onChange(event, value)
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
// Debounced onChange event handler
|
|
58
|
-
const debouncedOnChange = useMemo(() => debounce(onChangeRange, 0), [onChangeRange]);
|
|
59
|
-
|
|
60
61
|
const formttedValue = (value: number) => {
|
|
61
62
|
return (
|
|
62
63
|
<>
|
|
@@ -75,7 +76,7 @@ const Range: React.FC<IRangeProps> = ({
|
|
|
75
76
|
valueLabelDisplay='auto'
|
|
76
77
|
valueLabelFormat={formttedValue}
|
|
77
78
|
value={rangeValue}
|
|
78
|
-
onChange={
|
|
79
|
+
onChange={onChangeRange}
|
|
79
80
|
sx={{
|
|
80
81
|
color: '#005CCB'
|
|
81
82
|
}}
|
|
@@ -463,9 +463,7 @@ export function getChipFilterValue(
|
|
|
463
463
|
case 'SEATS':
|
|
464
464
|
case 'CUBIC_CAPACITY':
|
|
465
465
|
title = t(`SearchPage:filters.${chipFilterKey.toLocaleLowerCase()}`);
|
|
466
|
-
const
|
|
467
|
-
const to = !!chipFilterValue.to ? `${t('SearchPage:filters.to')} ${chipFilterValue.to}` : '';
|
|
468
|
-
const fromTo = (from && to) ? `${chipFilterValue.from} - ${chipFilterValue.to}` : `${from || to}`;
|
|
466
|
+
const fromTo = `${chipFilterValue.from} - ${chipFilterValue.to}`;
|
|
469
467
|
filterValue = `${title} ${fromTo}`;
|
|
470
468
|
break;
|
|
471
469
|
|
|
@@ -620,3 +618,16 @@ export const convertUnixTimestampToDays = (unixTimestamp: number) => {
|
|
|
620
618
|
export const priceParse = (value: any) => {
|
|
621
619
|
return !!value ? Number.parseFloat(value) : null;
|
|
622
620
|
};
|
|
621
|
+
|
|
622
|
+
// iPad on iOS 13 detection
|
|
623
|
+
export const iOS = () => {
|
|
624
|
+
return [
|
|
625
|
+
'iPad Simulator',
|
|
626
|
+
'iPhone Simulator',
|
|
627
|
+
'iPod Simulator',
|
|
628
|
+
'iPad',
|
|
629
|
+
'iPhone',
|
|
630
|
+
'iPod'
|
|
631
|
+
].includes(navigator.platform)
|
|
632
|
+
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)
|
|
633
|
+
}
|