@bytebrand/fe-ui-core 4.2.92 → 4.2.94
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/Checkout/RadioGroup.test.tsx +95 -0
- package/__tests__/components/Checkout/ServiceCardWrapper.test.tsx +53 -0
- package/__tests__/components/Checkout/Switcher.test.tsx +43 -0
- package/package.json +1 -1
- package/source/components/Checkout/RadioCards/AdditionalServiceCard/ServiceCardWrapper.tsx +1 -1
- package/source/components/Checkout/Switcher/Switcher.tsx +1 -1
- package/source/components/VehicleDetailedSidebar/partials/PriceContent.styl +2 -1
- package/source/components/VehicleDetailedSidebar/partials/PriceContent.tsx +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent, screen, prettyDOM, waitFor } from '@testing-library/react';
|
|
3
|
+
import RadioGroup from '../../../source/components/_common/Radio/RadioGroup';
|
|
4
|
+
import ServiceCardWrapper from '../../../source/components/Checkout/RadioCards/AdditionalServiceCard/ServiceCardWrapper';
|
|
5
|
+
|
|
6
|
+
const onChangeMock = jest.fn();
|
|
7
|
+
|
|
8
|
+
const children = [
|
|
9
|
+
<ServiceCardWrapper
|
|
10
|
+
key={1}
|
|
11
|
+
label={'additionalServices.warranty.label'}
|
|
12
|
+
infoContent={'warranty'}
|
|
13
|
+
footerText={'completeService'}
|
|
14
|
+
value={3}
|
|
15
|
+
warrantyCard={true}
|
|
16
|
+
price={897456123}
|
|
17
|
+
additionalOptions={['Alles aus Bronze Garantiepaket', 'Klima- & Kühlsysteme', 'Elektrische Anlagen']}
|
|
18
|
+
monthly={'additionalServices.monthly'}
|
|
19
|
+
className={'className'}
|
|
20
|
+
modalTitle={'title'}
|
|
21
|
+
modalContent={[
|
|
22
|
+
'Motor',
|
|
23
|
+
'Schalt- & Automatikgetriebe',
|
|
24
|
+
'Differenzial'
|
|
25
|
+
]}
|
|
26
|
+
onCheckoutModalClick={() => {}}
|
|
27
|
+
isHybridOrElectric={false}
|
|
28
|
+
warrantyName={'name'}
|
|
29
|
+
/>,
|
|
30
|
+
<ServiceCardWrapper
|
|
31
|
+
key={2}
|
|
32
|
+
label={'additionalServices.another.label'}
|
|
33
|
+
infoContent={'another'}
|
|
34
|
+
footerText={'completeService'}
|
|
35
|
+
value={2}
|
|
36
|
+
warrantyCard={true}
|
|
37
|
+
price={987654321}
|
|
38
|
+
additionalOptions={['Option 1', 'Option 2', 'Option 3']}
|
|
39
|
+
monthly={'additionalServices.monthly'}
|
|
40
|
+
className={'className'}
|
|
41
|
+
modalTitle={'title'}
|
|
42
|
+
modalContent={[
|
|
43
|
+
'Option 1',
|
|
44
|
+
'Option 2',
|
|
45
|
+
'Option 3'
|
|
46
|
+
]}
|
|
47
|
+
onCheckoutModalClick={() => {}}
|
|
48
|
+
isHybridOrElectric={false}
|
|
49
|
+
warrantyName={'name'}
|
|
50
|
+
checked={false}
|
|
51
|
+
/>
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
describe('RadioGroup', () => {
|
|
55
|
+
it('renders correctly with children', () => {
|
|
56
|
+
const { getByText } = render(
|
|
57
|
+
<RadioGroup
|
|
58
|
+
name='testRadioGroup'
|
|
59
|
+
value={1}
|
|
60
|
+
onChange={onChangeMock}
|
|
61
|
+
error={false}
|
|
62
|
+
containerClassName='containerClassName'
|
|
63
|
+
childClassName='childClassName'
|
|
64
|
+
wrapperClassname='wrapperClassname'
|
|
65
|
+
radioName='radioName'
|
|
66
|
+
onBlur={() => {}}
|
|
67
|
+
>
|
|
68
|
+
{children}
|
|
69
|
+
</RadioGroup>
|
|
70
|
+
);
|
|
71
|
+
expect(getByText('additionalServices.warranty.label')).toBeInTheDocument();
|
|
72
|
+
expect(getByText('additionalServices.another.label')).toBeInTheDocument();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('calls onChange when a radio button is selected', () => {
|
|
76
|
+
const { getByRole, getByDisplayValue } = render(
|
|
77
|
+
<RadioGroup
|
|
78
|
+
name='testRadioGroup'
|
|
79
|
+
value={1}
|
|
80
|
+
onChange={onChangeMock}
|
|
81
|
+
error={false}
|
|
82
|
+
containerClassName='containerClassName'
|
|
83
|
+
childClassName='childClassName'
|
|
84
|
+
wrapperClassname='wrapperClassname'
|
|
85
|
+
radioName='radioName'
|
|
86
|
+
onBlur={() => {}}
|
|
87
|
+
>
|
|
88
|
+
{children}
|
|
89
|
+
</RadioGroup>
|
|
90
|
+
);
|
|
91
|
+
const radioOption1 = getByRole('radio', { name: 'additionalServices.warranty.label 897.456.123 € /additionalServices.monthly warranty Alles aus Bronze Garantiepaket Klima- & Kühlsysteme Elektrische Anlagen' });
|
|
92
|
+
fireEvent.click(radioOption1);
|
|
93
|
+
expect(onChangeMock).toHaveBeenCalledTimes(1);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent, prettyDOM } from '@testing-library/react';
|
|
3
|
+
import ServiceCardWrapper from '../../../source/components/Checkout/RadioCards/AdditionalServiceCard/ServiceCardWrapper';
|
|
4
|
+
|
|
5
|
+
describe('ServiceCardWrapper', () => {
|
|
6
|
+
const defaultProps = {
|
|
7
|
+
value: '1',
|
|
8
|
+
checked: false,
|
|
9
|
+
onCheckoutModalClick: jest.fn()
|
|
10
|
+
};
|
|
11
|
+
const getWrapper = (props = {}) => {
|
|
12
|
+
return render(<ServiceCardWrapper {...defaultProps} {...props} />);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
it('should render all elements properly', () => {
|
|
16
|
+
const { container } = getWrapper({
|
|
17
|
+
label: 'Test label',
|
|
18
|
+
price: 100,
|
|
19
|
+
checked: true,
|
|
20
|
+
footerText: 'Test footer text'
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(screen.getByText('Test label')).toBeInTheDocument();
|
|
24
|
+
expect(screen.getByText('100')).toBeInTheDocument();
|
|
25
|
+
expect(screen.getByText('€')).toBeInTheDocument();
|
|
26
|
+
expect(container.querySelector('input[type="radio"]')).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should call onChange function with proper arguments on radio button click', () => {
|
|
30
|
+
const onChange = jest.fn();
|
|
31
|
+
const { container } = getWrapper({
|
|
32
|
+
value: '2',
|
|
33
|
+
onChange
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
fireEvent.click(container.querySelector('input[type="radio"]'));
|
|
37
|
+
|
|
38
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(onChange).toHaveBeenCalledWith(expect.any(Object), true, '2');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should not call onChange function on radio button click if disabled', () => {
|
|
43
|
+
const onChange = jest.fn();
|
|
44
|
+
const { container } = getWrapper({
|
|
45
|
+
disabled: true,
|
|
46
|
+
onChange
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
fireEvent.click(container.querySelector('input[type="radio"]'));
|
|
50
|
+
|
|
51
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import Switcher from '../../../source/components/Checkout/Switcher/Switcher';
|
|
4
|
+
|
|
5
|
+
describe('Switcher component', () => {
|
|
6
|
+
it('Should render options in Switcher', () => {
|
|
7
|
+
const options = ['Option 1', 'Option 2', 'Option 3'];
|
|
8
|
+
const { getAllByRole } = render(
|
|
9
|
+
<Switcher options={options} value={1} />
|
|
10
|
+
);
|
|
11
|
+
const toggleButtons = getAllByRole('button');
|
|
12
|
+
expect(toggleButtons.length).toBe(options.length);
|
|
13
|
+
options.forEach((option, index) => {
|
|
14
|
+
expect(toggleButtons[index]).toHaveTextContent(option);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('Should call onChange function when an option is selected', () => {
|
|
19
|
+
const options = ['Option 1', 'Option 2', 'Option 3'];
|
|
20
|
+
const onChangeMock = jest.fn();
|
|
21
|
+
const { getAllByRole } = render(
|
|
22
|
+
<Switcher options={options} value={1} onChange={onChangeMock} />
|
|
23
|
+
);
|
|
24
|
+
const toggleButtons = getAllByRole('button');
|
|
25
|
+
fireEvent.click(toggleButtons[1]);
|
|
26
|
+
expect(onChangeMock).toHaveBeenCalledTimes(1);
|
|
27
|
+
expect(onChangeMock).toHaveBeenCalledWith(expect.anything(), 2, undefined);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('Should pass correct values to ToggleButton', () => {
|
|
31
|
+
const options = ['Option 1', 'Option 2', 'Option 3'];
|
|
32
|
+
const value = 2;
|
|
33
|
+
const { getAllByRole } = render(
|
|
34
|
+
<Switcher options={options} value={value} />
|
|
35
|
+
);
|
|
36
|
+
const toggleButtons = getAllByRole('button');
|
|
37
|
+
options.forEach((option, index) => {
|
|
38
|
+
const toggleButton = toggleButtons[index];
|
|
39
|
+
expect(toggleButton).toHaveTextContent(option);
|
|
40
|
+
expect(toggleButton).toHaveAttribute('value', String(index + 1));
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
package/package.json
CHANGED
|
@@ -194,7 +194,7 @@ const ServiceCardWrapper = ({
|
|
|
194
194
|
{deliveryCard && <VehicleDeliveryContent {...vehicleDeliveryContentProps} />}
|
|
195
195
|
</label>
|
|
196
196
|
{warrantyCard && warrantyName !== 'no-warranty' &&
|
|
197
|
-
<span className={styles.contentFooter}
|
|
197
|
+
<span className={styles.contentFooter} data-testid={'modal-button'}
|
|
198
198
|
onClick={() => onCheckoutModalClick(modalWarrantyProps)}>
|
|
199
199
|
{footerText}
|
|
200
200
|
<IconSVG className={styles.infoTransparent} name='infoIcon' customDimensions/>
|
|
@@ -94,7 +94,7 @@ const PriceContent: React.FunctionComponent<IPriceContentProps> = ({
|
|
|
94
94
|
</div>
|
|
95
95
|
) : null}
|
|
96
96
|
</span>
|
|
97
|
-
<div>
|
|
97
|
+
<div className={styles.wrapper}>
|
|
98
98
|
<PriceRating {...priceRatingProps} />
|
|
99
99
|
<span className={styles.priceInfo}>
|
|
100
100
|
<span className={styles.priceInfoLabel} onClick={onAdjustRateClick}>
|