@bytebrand/fe-ui-core 4.2.61 → 4.2.63

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.
@@ -0,0 +1,128 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react'
3
+ import AdditionalOrderInfo from '../../../../../source/components/UserDashboardPage/sections/OrderStatusSection/AdditionalOrderInfo';
4
+ import { getFormattedPrice } from '../../../../../source/framework/utils/CommonUtils';
5
+
6
+ const t = (phrase: string | string[], options: object) => {
7
+ if (options) {
8
+ const value = Object.values(options).map((option) => option)
9
+ return `${phrase} ${value}`;
10
+ }
11
+ return phrase;
12
+ }
13
+
14
+ const commonProps = {
15
+ t,
16
+ redirectToUrl: () => {},
17
+ }
18
+
19
+ const additionalOrderData = (buyingType: 'buy' | 'leasing' | 'financing', objectData: any) => {
20
+ const {
21
+ customerFirstname,
22
+ customerLastname,
23
+ currentSalesPrice,
24
+ preparationCost,
25
+ registrationCost,
26
+ licensePlateCost,
27
+ transportationCost,
28
+ monthlyInstallment,
29
+ paybackPeriod,
30
+ deposit
31
+ } = objectData;
32
+ return {
33
+ addressData: [
34
+ { label: 'Billing address:', value: `${customerFirstname} ${customerLastname}` },
35
+ { label: 'Vehicle delivery:', value: 'Hannes Käther, Wittenberger Str. 81, 04129 Leipzig' }
36
+ ],
37
+ carPriceData: [
38
+ { label: 'Car price', value: getFormattedPrice(currentSalesPrice, '$,.2f', ' €') },
39
+ { label: 'Preparation cost', value: getFormattedPrice(preparationCost, '$,.2f', ' €')},
40
+ { label: 'vehicle registration', value: getFormattedPrice(registrationCost, '$,.2f', ' €') },
41
+ { label: 'license plates', value: getFormattedPrice(licensePlateCost, '$,.2f', ' €') },
42
+ { label: 'Delivery', value: getFormattedPrice(transportationCost, '$,.2f', ' €') },
43
+ buyingType !== 'buy' &&
44
+ { label: `${buyingType} rate`, value: `${getFormattedPrice(monthlyInstallment, '$,.2f', '', '€')} per month` },
45
+ buyingType !== 'buy' &&
46
+ { label: 'Running time (months)', value: `${paybackPeriod} months` },
47
+ buyingType !== 'buy' &&
48
+ { label: 'Deposit', value: getFormattedPrice(deposit, '$,.2f', ' €') }
49
+ ],
50
+ overallRate: {
51
+ label: 'Your overall rate',
52
+ value: buyingType === 'buy' ? currentSalesPrice : monthlyInstallment
53
+ }
54
+ };
55
+ }
56
+
57
+ describe('AdditionalOrderInfo', () => {
58
+ it('renders AdditionalOrderInfo component without error', () => {
59
+ const objectData = {
60
+ customerFirstname: 'firstName',
61
+ customerLastname: 'lastName',
62
+ currentSalesPrice: 12000,
63
+ preparationCost: 1200,
64
+ registrationCost: 1000,
65
+ licensePlateCost: 1200,
66
+ transportationCost: 3000,
67
+ monthlyInstallment: 1000,
68
+ paybackPeriod: 48,
69
+ deposit: 5000
70
+ }
71
+
72
+ const additionalOrderInfoProps = {
73
+ ...commonProps,
74
+ buyingType: 'leasing',
75
+ additionalOrderData: additionalOrderData('leasing', objectData)
76
+ }
77
+ const { container } = render(<AdditionalOrderInfo {...additionalOrderInfoProps} />);
78
+ expect(container).toBeInTheDocument();
79
+ });
80
+
81
+ it('renders AdditionalOrderInfo component without some data', () => {
82
+ const objectData = {
83
+ customerFirstname: 'firstName',
84
+ customerLastname: 'lastName',
85
+ currentSalesPrice: 12000,
86
+ preparationCost: 1200,
87
+ registrationCost: 1000
88
+ }
89
+
90
+ const additionalOrderInfoProps = {
91
+ ...commonProps,
92
+ buyingType: 'leasing',
93
+ additionalOrderData: additionalOrderData('leasing', objectData)
94
+ }
95
+ const { container } = render(<AdditionalOrderInfo {...additionalOrderInfoProps} />);
96
+ expect(container).toBeInTheDocument();
97
+ });
98
+
99
+ it('renders AdditionalOrderInfo component with "buy" buying type', () => {
100
+ const objectData = {
101
+ customerFirstname: 'firstName',
102
+ customerLastname: 'lastName',
103
+ currentSalesPrice: 12000,
104
+ preparationCost: 1200,
105
+ registrationCost: 1000
106
+ }
107
+
108
+ const additionalOrderInfoProps = {
109
+ ...commonProps,
110
+ buyingType: 'buy',
111
+ additionalOrderData: additionalOrderData('buy', objectData)
112
+ }
113
+ const { container } = render(<AdditionalOrderInfo {...additionalOrderInfoProps} />);
114
+ expect(container).toBeInTheDocument();
115
+ });
116
+
117
+ it('renders AdditionalOrderInfo component without any data', () => {
118
+ const objectData = {};
119
+
120
+ const additionalOrderInfoProps = {
121
+ ...commonProps,
122
+ buyingType: 'leasing',
123
+ additionalOrderData: additionalOrderData('leasing', objectData)
124
+ }
125
+ const { container } = render(<AdditionalOrderInfo {...additionalOrderInfoProps} />);
126
+ expect(container).toBeInTheDocument();
127
+ });
128
+ });
@@ -0,0 +1,62 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react'
3
+ import OrderStatusSection from '../../../../../source/components/UserDashboardPage/sections/OrderStatusSection/OrderStatusSection';
4
+ import { car } from './mockedPendingRequestedCar';
5
+
6
+ const t = (phrase: string | string[], options: object) => {
7
+ if (options) {
8
+ const value = Object.values(options).map((option) => option)
9
+ return `${phrase} ${value}`;
10
+ }
11
+ return phrase;
12
+ }
13
+ const leasingCar = car;
14
+ const financingCar = { ...car, buyingType: 'financing' };
15
+ const buyCar = { ...car, buyingType: 'buy' };
16
+
17
+ const commonProps = {
18
+ t,
19
+ isFetching: false,
20
+ getSupportedImageFormat: () => {
21
+ return 'https://images.autode-dev.de/carimage/28121b1a-398c-4e9c-9097-51be545817c5/RQ_mHNek5hIk/small-cached.webp'
22
+ },
23
+ redirectToUrl: () => {},
24
+ }
25
+
26
+ describe('OrderStatusSection', () => {
27
+ it('renders OrderStatusSection component without error', () => {
28
+ const orderStatusSectionProps = {
29
+ ...commonProps,
30
+ orderedCars: [
31
+ leasingCar,
32
+ financingCar,
33
+ buyCar
34
+ ]
35
+ }
36
+ const { container } = render(<OrderStatusSection {...orderStatusSectionProps} />);
37
+ expect(container).toBeInTheDocument();
38
+ });
39
+
40
+ it('renders OrderStatusSection component without cars', () => {
41
+ const orderStatusSectionProps = {
42
+ ...commonProps,
43
+ orderedCars: [] as any[]
44
+ }
45
+ const { container } = render(<OrderStatusSection {...orderStatusSectionProps} />);
46
+ expect(container).toBeInTheDocument();
47
+ });
48
+
49
+ it('renders OrderStatusSection component with additional data', () => {
50
+ const orderStatusSectionProps = {
51
+ ...commonProps,
52
+ withAdditionalData: true,
53
+ orderedCars: [
54
+ leasingCar,
55
+ financingCar,
56
+ buyCar
57
+ ]
58
+ }
59
+ const { container } = render(<OrderStatusSection {...orderStatusSectionProps} />);
60
+ expect(container).toBeInTheDocument();
61
+ });
62
+ });
@@ -0,0 +1,69 @@
1
+ export const car = {
2
+ _id: '63e12296aeb426dad4af5e5c',
3
+ odooLead: 213907,
4
+ buyingType: 'leasing',
5
+ car: {
6
+ _id: '30b7bdeb-c193-4dc3-9f92-86680c9fcf59',
7
+ metaData: {
8
+ creationDate: 1675668285,
9
+ modificationDate: 1676979836,
10
+ ownerId: 'ZdHm8pCH0nWnIDdky6rm37JouFv1',
11
+ tsn: null,
12
+ codeKBA: null,
13
+ codeDAT: null,
14
+ codeSchwacke: null,
15
+ codeJato: null,
16
+ mainImageId: 'HekeLJ2ehJ9R',
17
+ secImageId: 'CdhVrQF7kXgP',
18
+ thirdImageId: 'oYLuytuZTBSb',
19
+ vehicleId: 'F6DF54',
20
+ imagesCount: 0,
21
+ allImagesCount: 13,
22
+ postProcessingConfigurationId: null,
23
+ imagePackageID: null,
24
+ imagesByApp: false,
25
+ ownerName: 'Guardian of Auto.de',
26
+ imagesRemovedBg: true
27
+ },
28
+ mainData: {
29
+ make: 'Fiat',
30
+ model: '500',
31
+ subModel: '1,0 GSE HYBRID PIU DOLCEVITA MJ22',
32
+ series: '500',
33
+ trimLine: null,
34
+ vehicleClass: 'selector_vehicleClass_car',
35
+ category: 'selector_category_convertible',
36
+ modelDescription: '',
37
+ condition: 'selector_condition_new',
38
+ usageType: 'selector_unknown',
39
+ firstRegistration: null,
40
+ mileage: 15,
41
+ doors: 3,
42
+ seats: 4,
43
+ constructionYear: null,
44
+ constructionDate: null,
45
+ firstModelsProductionDate: null,
46
+ countryVersion: null,
47
+ numberOfPreviousOwners: 0,
48
+ nonSmokerVehicle: null,
49
+ damageUnrepaired: null,
50
+ accidentDamaged: false,
51
+ roadworthy: true,
52
+ damageByHail: null,
53
+ taxi: null,
54
+ damaged: false
55
+ },
56
+ createdAt: '2023-02-06T15:53:58.836Z',
57
+ currentSalesPrice: 30666,
58
+ delivery: true,
59
+ monthlyInstallment: 401.28,
60
+ paybackPeriod: 36,
61
+ registration: true,
62
+ request: 'REQ228794',
63
+ selfPickup: false,
64
+ status: 'selector_status_handing_over',
65
+ updatedAt: '2023-02-10T09:31:31.859Z',
66
+ user: 'eGWQxSdo97UPkTlYmJrNZVNQCdy1',
67
+ wonStatus: 'pending'
68
+ }
69
+ }
package/commonUtils.ts ADDED
@@ -0,0 +1,11 @@
1
+ import {
2
+ addPrefixToKeys,
3
+ arrToObj,
4
+ checkRangeValuesOnEqual
5
+ } from "./source/framework/utils/CommonUtils";
6
+
7
+ export {
8
+ addPrefixToKeys,
9
+ arrToObj,
10
+ checkRangeValuesOnEqual
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/fe-ui-core",
3
- "version": "4.2.61",
3
+ "version": "4.2.63",
4
4
  "description": "UI components for the auto.de project",
5
5
  "main": "index.ts",
6
6
  "module": "dist/common.js",
@@ -16,13 +16,19 @@ interface IAdditionalOrderData {
16
16
  };
17
17
  }
18
18
 
19
+ interface TFunction {
20
+ <T = string>(key: string, options?: object): T;
21
+ <T = string>(keys: string[], options?: object): T;
22
+ }
23
+
19
24
  interface IAdditionalOrderInfo {
20
- t: i18n.TFunction;
25
+ t: TFunction;
21
26
  additionalOrderData: IAdditionalOrderData;
22
27
  redirectToUrl: (url: string) => void;
28
+ buyingType: string;
23
29
  }
24
30
 
25
- const AdditionalOrderInfo = ({ t, additionalOrderData, redirectToUrl }: IAdditionalOrderInfo) => {
31
+ const AdditionalOrderInfo = ({ t, additionalOrderData, redirectToUrl, buyingType }: IAdditionalOrderInfo) => {
26
32
  const { addressData, carPriceData, overallRate } = additionalOrderData;
27
33
 
28
34
  const redirectToContactPage = () => {
@@ -47,7 +53,7 @@ const AdditionalOrderInfo = ({ t, additionalOrderData, redirectToUrl }: IAdditio
47
53
  {carPriceData.map((data) => {
48
54
  const { value, label } = data;
49
55
  return (
50
- <div className={styles.flexContainer} key={label}>
56
+ <div key={label} className={styles.flexContainer}>
51
57
  <div className={styles.labelText}>{label}</div>
52
58
  <div className={styles.labelText}>{value}</div>
53
59
  </div>
@@ -62,7 +68,7 @@ const AdditionalOrderInfo = ({ t, additionalOrderData, redirectToUrl }: IAdditio
62
68
  price={overallRate.value}
63
69
  numbersAfterDot={2}
64
70
  isNew
65
- monthly='mtl'
71
+ monthly={buyingType !== 'buy' ? 'mtl' : ''}
66
72
  className={styles.totalPrice}
67
73
  afterCommaClassName={styles.decimals}
68
74
  unitClassName={styles.unit}
@@ -8,12 +8,15 @@ import { Skeleton } from '@mui/material';
8
8
 
9
9
  import { getFormattedPrice } from '../../../../framework/utils/CommonUtils';
10
10
 
11
- import i18n from 'i18next';
11
+ interface TFunction {
12
+ <T = string>(key: string, options?: object): T;
13
+ <T = string>(keys: string[], options?: object): T;
14
+ }
12
15
 
13
16
  interface IOrderStatusSection {
14
17
  getSupportedImageFormat: (id: string, mainImageId: string, size: 'small' | 'medium' | 'large') => string;
15
18
  redirectToUrl: (url: string) => void;
16
- t: i18n.TFunction;
19
+ t: TFunction;
17
20
  isFetching: boolean;
18
21
  withAdditionalInfo?: boolean; // for using on /account/my-order.
19
22
  orderedCars: any[]; // TODO: create interface for orderedCars, when the object is formatted by the backend
@@ -35,7 +38,7 @@ const OrderStatusSection = ({
35
38
  const renderRequestedCars = () => {
36
39
  return (
37
40
  <>
38
- {!!orderedCars && orderedCars.map((orderedCar, index) => {
41
+ {!!orderedCars && orderedCars.map((orderedCar: any, index: number) => {
39
42
  const { car: { _id } } = orderedCar;
40
43
  const { car: { mainData: { make, model, subModel } } } = orderedCar;
41
44
  const { car: { metaData: { mainImageId } }} = orderedCar;
@@ -54,9 +57,9 @@ const OrderStatusSection = ({
54
57
  registrationCost,
55
58
  transportationCost,
56
59
  customerAddress: {
57
- customerFirstname,
58
- customerLastname
59
- }
60
+ customerFirstname = '',
61
+ customerLastname = ''
62
+ } = {}
60
63
  } = orderedCar;
61
64
 
62
65
  const additionalOrderData = {
@@ -70,20 +73,23 @@ const OrderStatusSection = ({
70
73
  { label: 'vehicle registration', value: getFormattedPrice(registrationCost, '$,.2f', ' €') },
71
74
  { label: 'license plates', value: getFormattedPrice(licensePlateCost, '$,.2f', ' €') },
72
75
  { label: 'Delivery', value: getFormattedPrice(transportationCost, '$,.2f', ' €') },
73
- { label: `${buyingType} rate`, value: buyingType !== 'buy' ? `${getFormattedPrice(monthlyInstallment, '$,.2f', '', '€')} per month` : getFormattedPrice(monthlyInstallment, '$,.2f', ' €') },
74
- { label: 'Running time (months)', value: `${paybackPeriod} months` },
75
- { label: 'Deposit', value: getFormattedPrice(deposit, '$,.2f', ' €') }
76
+ ...buyingType !== 'buy' ? [
77
+ { label: `${buyingType} rate`, value: `${getFormattedPrice(monthlyInstallment, '$,.2f', '', '€')} per month` },
78
+ { label: 'Running time (months)', value: `${paybackPeriod} months` },
79
+ { label: 'Deposit', value: getFormattedPrice(deposit, '$,.2f', ' €') }
80
+ ] : []
76
81
  ],
77
82
  overallRate: {
78
83
  label: 'Your overall rate',
79
- value: monthlyInstallment
84
+ value: buyingType === 'buy' ? currentSalesPrice : monthlyInstallment
80
85
  }
81
86
  };
82
87
 
83
88
  const additionalOrderInfoProps = {
84
89
  t,
85
90
  additionalOrderData,
86
- redirectToUrl
91
+ redirectToUrl,
92
+ buyingType
87
93
  };
88
94
 
89
95
  const imageUrl = getSupportedImageFormat(_id, mainImageId, 'small');