@@ -8,6 +8,16 @@ import { AddressComponent } from 'src/layout/Address/AddressComponent';
88import { renderGenericComponentTest } from 'src/test/renderWithProviders' ;
99import type { RenderGenericComponentTestProps } from 'src/test/renderWithProviders' ;
1010
11+ jest . mock ( 'norway-postal-codes' , ( ) => ( {
12+ __esModule : true ,
13+ default : {
14+ '0001' : 'OSLO' ,
15+ '0002' : 'BERGEN' ,
16+ '1613' : 'FREDRIKSTAD' ,
17+ '4609' : 'KARDEMOMME BY' ,
18+ } ,
19+ } ) ) ;
20+
1121const render = async ( { component, ...rest } : Partial < RenderGenericComponentTestProps < 'Address' > > = { } ) =>
1222 await renderGenericComponentTest ( {
1323 type : 'Address' ,
@@ -27,18 +37,6 @@ const render = async ({ component, ...rest }: Partial<RenderGenericComponentTest
2737 ...component ,
2838 } ,
2939 ...rest ,
30- queries : {
31- fetchPostPlace : async ( input ) => {
32- if ( input === '0001' ) {
33- return { valid : true , result : 'OSLO' } ;
34- }
35- if ( input === '0002' ) {
36- return { valid : true , result : 'BERGEN' } ;
37- }
38- return { valid : false , result : '' } ;
39- } ,
40- ...rest . queries ,
41- } ,
4240 } ) ;
4341
4442describe ( 'AddressComponent' , ( ) => {
@@ -113,10 +111,6 @@ describe('AddressComponent', () => {
113111 } ,
114112 queries : {
115113 fetchFormData : async ( ) => ( { address : 'initial address' , zipCode : '0001' } ) ,
116- fetchPostPlace : ( zipCode : string ) =>
117- zipCode === '0001'
118- ? Promise . resolve ( { valid : true , result : 'OSLO' } )
119- : Promise . resolve ( { valid : false , result : '' } ) ,
120114 } ,
121115 } ) ;
122116
@@ -167,7 +161,7 @@ describe('AddressComponent', () => {
167161 } ) ;
168162
169163 it ( 'should call dispatch for post place when zip code is cleared' , async ( ) => {
170- const { formDataMethods, queries } = await render ( {
164+ const { formDataMethods } = await render ( {
171165 queries : {
172166 fetchFormData : async ( ) => ( { address : 'a' , zipCode : '0001' , postPlace : 'Oslo' } ) ,
173167 } ,
@@ -187,12 +181,10 @@ describe('AddressComponent', () => {
187181 reference : { field : 'postPlace' , dataType : defaultDataTypeMock } ,
188182 newValue : '' ,
189183 } ) ;
190-
191- expect ( queries . fetchPostPlace ) . toHaveBeenCalledTimes ( 1 ) ;
192184 } ) ;
193185
194- it ( 'should only call fetchPostPlace once at the end, when debouncing' , async ( ) => {
195- const { queries } = await render ( {
186+ it ( 'should update post place after typing zip code with debouncing' , async ( ) => {
187+ await render ( {
196188 queries : {
197189 fetchFormData : async ( ) => ( { address : 'a' , zipCode : '' , postPlace : '' } ) ,
198190 } ,
@@ -202,9 +194,6 @@ describe('AddressComponent', () => {
202194 await waitFor ( ( ) => expect ( screen . getByRole ( 'textbox' , { name : 'Poststed' } ) ) . toHaveDisplayValue ( 'BERGEN' ) , {
203195 timeout : 15000 ,
204196 } ) ;
205-
206- expect ( queries . fetchPostPlace ) . toHaveBeenCalledTimes ( 1 ) ;
207- expect ( queries . fetchPostPlace ) . toHaveBeenCalledWith ( '0002' ) ;
208197 } ) ;
209198
210199 it ( 'should display no extra markings when required is false, and labelSettings.optionalIndicator is not true' , async ( ) => {
0 commit comments