1
1
import {
2
- screen ,
3
2
render ,
3
+ screen ,
4
4
} from '@commercetools-frontend/application-shell/test-utils' ;
5
5
import { Suspense } from 'react' ;
6
6
import { MemoryRouter } from 'react-router' ;
7
7
import { IntlProvider } from 'react-intl' ;
8
8
import AvailabilityList from './list' ;
9
9
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
+ } ) ) ;
10
23
11
24
describe ( 'test MethodDetails.tsx' , ( ) => {
12
25
it ( 'test render' , async ( ) => {
13
26
const pricingConstraints = [
14
27
{
15
28
id : 1 ,
16
- currency : 'GBP1' ,
17
- country : 'UK1' ,
29
+ currencyCode : 'GBP1' ,
30
+ countryCode : 'UK1' ,
18
31
minAmount : 100 ,
19
32
maxAmount : 2000 ,
20
- surchargeCost : '2%' ,
33
+ surchargeCost : {
34
+ percentageAmount : 2 ,
35
+ renderedText : '2%' ,
36
+ } ,
21
37
} ,
22
38
{
23
39
id : 2 ,
24
- currency : 'GBP2' ,
25
- country : 'DE2' ,
40
+ currencyCode : 'GBP2' ,
41
+ countryCode : 'DE2' ,
26
42
minAmount : 1000 ,
27
43
maxAmount : 30000 ,
28
- surchargeCost : '4%' ,
44
+ surchargeCost : {
45
+ percentageAmount : 4 ,
46
+ renderedText : '4%' ,
47
+ } ,
29
48
} ,
30
49
{
31
50
id : 3 ,
32
- currency : 'EUR3' ,
33
- country : 'DE3' ,
51
+ currencyCode : 'EUR3' ,
52
+ countryCode : 'DE3' ,
34
53
minAmount : 500 ,
35
54
maxAmount : 10000 ,
36
- surchargeCost : '2 % + € 0,35' ,
55
+ surchargeCost : {
56
+ percentageAmount : 2 ,
57
+ fixedAmount : 100 ,
58
+ renderedText : '2% + 100EUR3' ,
59
+ } ,
37
60
} ,
38
61
] ;
39
62
@@ -62,7 +85,23 @@ describe('test MethodDetails.tsx', () => {
62
85
} as unknown as string ,
63
86
} ;
64
87
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 (
66
105
< MemoryRouter >
67
106
< Suspense fallback = { < div > Loading...</ div > } >
68
107
< IntlProvider
@@ -76,12 +115,12 @@ describe('test MethodDetails.tsx', () => {
76
115
) ;
77
116
78
117
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 ( ) ;
82
121
expect ( screen . getByText ( minAmount ) ) . not . toBeNull ( ) ;
83
122
expect ( screen . getByText ( maxAmount ) ) . not . toBeNull ( ) ;
84
- expect ( screen . getByText ( surchargeCost ) ) . not . toBeNull ( ) ;
123
+ expect ( screen . getByText ( surchargeCost . renderedText ) ) . not . toBeNull ( ) ;
85
124
}
86
125
) ;
87
126
} ) ;
0 commit comments