Skip to content

Commit fd30217

Browse files
Merge branch 'fix/application-unit-test'
2 parents cef542d + bb3136e commit fd30217

File tree

4 files changed

+58
-16
lines changed

4 files changed

+58
-16
lines changed

application/src/components/method-details/availability/details-form.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const AvailabilityDetailsForm = (props: TAvailabilityDetailsFormProps) => {
6767
const [selectedCurrency, setSelectedCurrency] = useState<TCurrencyCode>(
6868
projectCurrencies[0] as TCurrencyCode
6969
);
70+
7071
const [countryOptions, setCountryOptions] = useState<
7172
{ value: string; label: string }[]
7273
>(

application/src/components/method-details/availability/details.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const AvailabilityDetails = (props: TAvailabilityDetailFormProps) => {
8686
maxAmount: maxAmount?.toString(),
8787
surchargeCost: {
8888
percentageAmount: surchargeCost?.percentageAmount ?? 0,
89-
fixedAmount: surchargeCost?.fixedAmount.toString() ?? '0',
89+
fixedAmount: surchargeCost?.fixedAmount?.toString() ?? '0',
9090
},
9191
};
9292

application/src/components/method-details/availability/list.spec.tsx

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,62 @@
11
import {
2-
screen,
32
render,
3+
screen,
44
} from '@commercetools-frontend/application-shell/test-utils';
55
import { Suspense } from 'react';
66
import { MemoryRouter } from 'react-router';
77
import { IntlProvider } from 'react-intl';
88
import AvailabilityList from './list';
99
import { TFetchCustomObjectDetailsQuery } from '../../../types/generated/ctp';
10+
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';
11+
import { useMcMutation } from '@commercetools-frontend/application-shell';
12+
import { useShowNotification } from '@commercetools-frontend/actions-global';
13+
14+
jest.mock('@commercetools-frontend/application-shell-connectors', () => ({
15+
useApplicationContext: jest.fn(),
16+
}));
17+
jest.mock('@commercetools-frontend/application-shell', () => ({
18+
useMcMutation: jest.fn(),
19+
}));
20+
jest.mock('@commercetools-frontend/actions-global', () => ({
21+
useShowNotification: jest.fn(),
22+
}));
1023

1124
describe('test MethodDetails.tsx', () => {
1225
it('test render', async () => {
1326
const pricingConstraints = [
1427
{
1528
id: 1,
16-
currency: 'GBP1',
17-
country: 'UK1',
29+
currencyCode: 'GBP1',
30+
countryCode: 'UK1',
1831
minAmount: 100,
1932
maxAmount: 2000,
20-
surchargeCost: '2%',
33+
surchargeCost: {
34+
percentageAmount: 2,
35+
renderedText: '2%',
36+
},
2137
},
2238
{
2339
id: 2,
24-
currency: 'GBP2',
25-
country: 'DE2',
40+
currencyCode: 'GBP2',
41+
countryCode: 'DE2',
2642
minAmount: 1000,
2743
maxAmount: 30000,
28-
surchargeCost: '4%',
44+
surchargeCost: {
45+
percentageAmount: 4,
46+
renderedText: '4%',
47+
},
2948
},
3049
{
3150
id: 3,
32-
currency: 'EUR3',
33-
country: 'DE3',
51+
currencyCode: 'EUR3',
52+
countryCode: 'DE3',
3453
minAmount: 500,
3554
maxAmount: 10000,
36-
surchargeCost: '2 % + € 0,35',
55+
surchargeCost: {
56+
percentageAmount: 2,
57+
fixedAmount: 100,
58+
renderedText: '2% + 100EUR3',
59+
},
3760
},
3861
];
3962

@@ -62,7 +85,23 @@ describe('test MethodDetails.tsx', () => {
6285
} as unknown as string,
6386
};
6487

65-
render(
88+
(useApplicationContext as jest.Mock).mockReturnValue({
89+
dataLocale: 'de',
90+
projectLanguages: ['de'],
91+
projectCurrencies: ['GBP1', 'GBP2', 'EUR3'],
92+
projectCountries: ['UK1', 'DE2', 'DE3'],
93+
});
94+
95+
(useMcMutation as jest.Mock).mockReturnValue([
96+
jest.fn().mockResolvedValue({}),
97+
{
98+
loading: false,
99+
},
100+
]);
101+
102+
(useShowNotification as jest.Mock).mockReturnValue(jest.fn());
103+
104+
const result = render(
66105
<MemoryRouter>
67106
<Suspense fallback={<div>Loading...</div>}>
68107
<IntlProvider
@@ -76,12 +115,12 @@ describe('test MethodDetails.tsx', () => {
76115
);
77116

78117
pricingConstraints.forEach(
79-
({ currency, country, minAmount, maxAmount, surchargeCost }) => {
80-
expect(screen.getByText(currency)).not.toBeNull();
81-
expect(screen.getByText(country)).not.toBeNull();
118+
({ currencyCode, countryCode, minAmount, maxAmount, surchargeCost }) => {
119+
expect(screen.getByText(currencyCode)).not.toBeNull();
120+
expect(screen.getByText(countryCode)).not.toBeNull();
82121
expect(screen.getByText(minAmount)).not.toBeNull();
83122
expect(screen.getByText(maxAmount)).not.toBeNull();
84-
expect(screen.getByText(surchargeCost)).not.toBeNull();
123+
expect(screen.getByText(surchargeCost.renderedText)).not.toBeNull();
85124
}
86125
);
87126
});

application/src/components/method-details/method-details.spec.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ describe('Test method-details.tsx', () => {
8181
(useApplicationContext as jest.Mock).mockReturnValue({
8282
dataLocale: 'de',
8383
projectLanguages: ['de'],
84+
projectCurrencies: ['DE'],
85+
projectCountries: ['EUR'],
8486
});
8587

8688
(useShowNotification as jest.Mock).mockReturnValue(jest.fn());

0 commit comments

Comments
 (0)