@@ -202,6 +202,7 @@ describe('IntacctImportSettingsComponent', () => {
202202 } ) ;
203203 } ) ;
204204
205+
205206 describe ( 'Save' , ( ) => {
206207 it ( 'should successfully save import settings during onboarding' , fakeAsync ( ( ) => {
207208 siWorkspaceService . getIntacctOnboardingState . and . returnValue ( IntacctOnboardingState . IMPORT_SETTINGS ) ;
@@ -287,4 +288,104 @@ describe('IntacctImportSettingsComponent', () => {
287288 ) ;
288289 } ) ) ;
289290 } ) ;
291+
292+ describe ( 'Watchers' , ( ) => {
293+ describe ( 'Import Settings Watcher' , ( ) => {
294+ beforeEach ( ( ) => {
295+ component . ngOnInit ( ) ;
296+ fixture . detectChanges ( ) ;
297+ } ) ;
298+
299+ it ( 'should trigger custom field dialog when a source field is set to custom_field' , ( ) => {
300+ const expenseFieldArray = component . importSettingsForm . get ( 'expenseFields' ) as FormArray ;
301+ spyOn ( component as any , 'addCustomField' ) . and . callThrough ( ) ;
302+
303+ const firstControl = expenseFieldArray . at ( 0 ) ;
304+ firstControl . patchValue ( {
305+ source_field : 'custom_field' ,
306+ destination_field : 'TEST_FIELD' ,
307+ import_to_fyle : true
308+ } ) ;
309+
310+ expect ( component [ 'addCustomField' ] ) . toHaveBeenCalled ( ) ;
311+ expect ( component . showDialog ) . toBeTrue ( ) ;
312+ expect ( component . customFieldControl ) . toEqual ( firstControl ) ;
313+ } ) ;
314+
315+ it ( 'should update validators when importTaxCodes value changes' , ( ) => {
316+ const taxCodesControl = component . importSettingsForm . get ( 'sageIntacctTaxCodes' ) ;
317+
318+ component . importSettingsForm . patchValue ( {
319+ importTaxCodes : true
320+ } ) ;
321+ expect ( taxCodesControl ?. hasValidator ( Validators . required ) ) . toBeTrue ( ) ;
322+
323+ component . importSettingsForm . patchValue ( {
324+ importTaxCodes : false
325+ } ) ;
326+ expect ( taxCodesControl ?. hasValidator ( Validators . required ) ) . toBeFalse ( ) ;
327+ } ) ;
328+ } ) ;
329+
330+ describe ( 'Cost Codes and Cost Types Watcher' , ( ) => {
331+ beforeEach ( ( ) => {
332+ fixture . detectChanges ( ) ;
333+ } ) ;
334+
335+ it ( 'should handle isDependentImportEnabled changes' , ( ) => {
336+ const costCodesControl = component . importSettingsForm . get ( 'costCodes' ) ;
337+ const costTypesControl = component . importSettingsForm . get ( 'costTypes' ) ;
338+
339+ component . importSettingsForm . patchValue ( {
340+ isDependentImportEnabled : true
341+ } ) ;
342+
343+ expect ( costCodesControl ?. enabled ) . toBeTrue ( ) ;
344+ expect ( costTypesControl ?. enabled ) . toBeTrue ( ) ;
345+ expect ( costCodesControl ?. hasValidator ( Validators . required ) ) . toBeTrue ( ) ;
346+ expect ( costTypesControl ?. hasValidator ( Validators . required ) ) . toBeTrue ( ) ;
347+
348+ component . importSettingsForm . patchValue ( {
349+ isDependentImportEnabled : false
350+ } ) ;
351+
352+ expect ( costCodesControl ?. enabled ) . toBeFalse ( ) ;
353+ expect ( costTypesControl ?. enabled ) . toBeFalse ( ) ;
354+ expect ( costCodesControl ?. hasValidator ( Validators . required ) ) . toBeFalse ( ) ;
355+ expect ( costTypesControl ?. hasValidator ( Validators . required ) ) . toBeFalse ( ) ;
356+ } ) ;
357+
358+ it ( 'should handle custom field selection for cost codes' , ( ) => {
359+ spyOn ( component as any , 'addCustomField' ) . and . callThrough ( ) ;
360+
361+ component . importSettingsForm . patchValue ( {
362+ costCodes : {
363+ attribute_type : 'custom_field' ,
364+ source_field : 'custom_field'
365+ }
366+ } ) ;
367+
368+ expect ( component [ 'addCustomField' ] ) . toHaveBeenCalled ( ) ;
369+ expect ( component . customFieldForDependentField ) . toBeTrue ( ) ;
370+ expect ( component . customFieldControl ) . toBe ( component . importSettingsForm . get ( 'costCodes' ) ! ) ;
371+ expect ( component . importSettingsForm . get ( 'costCodes' ) ?. value . source_field ) . toBeNull ( ) ;
372+ } ) ;
373+
374+ it ( 'should handle custom field selection for cost types' , ( ) => {
375+ spyOn ( component as any , 'addCustomField' ) . and . callThrough ( ) ;
376+
377+ component . importSettingsForm . patchValue ( {
378+ costTypes : {
379+ attribute_type : 'custom_field' ,
380+ source_field : 'custom_field'
381+ }
382+ } ) ;
383+
384+ expect ( component [ 'addCustomField' ] ) . toHaveBeenCalled ( ) ;
385+ expect ( component . customFieldForDependentField ) . toBeTrue ( ) ;
386+ expect ( component . customFieldControl ) . toBe ( component . importSettingsForm . get ( 'costTypes' ) ! ) ;
387+ expect ( component . importSettingsForm . get ( 'costTypes' ) ?. value . source_field ) . toBeNull ( ) ;
388+ } ) ;
389+ } ) ;
390+ } ) ;
290391} ) ;
0 commit comments