Skip to content

Commit 1ac9a52

Browse files
test: intacct c1 import settings watchers (#1020)
1 parent fc7be3d commit 1ac9a52

File tree

2 files changed

+115
-5
lines changed

2 files changed

+115
-5
lines changed

src/app/integrations/intacct/intacct-shared/intacct-c1-import-settings/intacct-c1-import-settings.component.spec.ts

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
/* eslint-disable dot-notation */
12
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
import { FormArray, FormBuilder, ReactiveFormsModule } from '@angular/forms';
3+
import { FormArray, FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
34
import { provideRouter, Router, RouterModule } from '@angular/router';
45
import { of, throwError } from 'rxjs';
56
import { IntacctC1ImportSettingsComponent } from './intacct-c1-import-settings.component';
@@ -21,8 +22,7 @@ import {
2122
sageIntacctFieldsSortedByPriorityForC1,
2223
importSettingsWithProjectMapping,
2324
expenseFieldsExpectedForC1,
24-
costCodeFieldValue,
25-
costTypeFieldValue
25+
blankMapping
2626
} from '../../intacct.fixture';
2727
import { IntacctConfiguration } from 'src/app/core/models/db/configuration.model';
2828
import { ImportSettingGet, ImportSettingPost, ImportSettings } from 'src/app/core/models/intacct/intacct-configuration/import-settings.model';
@@ -224,4 +224,106 @@ describe('IntacctC1ImportSettingsComponent', () => {
224224
expect(component.saveInProgress).toBeFalse();
225225
});
226226
});
227+
228+
describe('Watchers', () => {
229+
let isDependentImportEnabledValueChangeSpy: jasmine.Spy;
230+
let blankExpenseField: FormGroup;
231+
let costCodesValueChangeSubscription: jasmine.Spy;
232+
let costTypesValueChangeSubscription: jasmine.Spy;
233+
234+
beforeEach(() => {
235+
component.ngOnInit();
236+
237+
isDependentImportEnabledValueChangeSpy = spyOn(component.importSettingsForm.controls.isDependentImportEnabled.valueChanges, 'subscribe').and.callThrough();
238+
blankExpenseField = component['createFormGroup'](blankMapping);
239+
costCodesValueChangeSubscription = spyOn(component.importSettingsForm.controls.costCodes.valueChanges, 'subscribe');
240+
costTypesValueChangeSubscription = spyOn(component.importSettingsForm.controls.costTypes.valueChanges, 'subscribe');
241+
242+
spyOn(blankExpenseField.valueChanges, 'subscribe').and.callThrough();
243+
});
244+
245+
describe('dependentFieldWatchers', () => {
246+
beforeEach(() => {
247+
component['dependentFieldWatchers']();
248+
});
249+
250+
it('should setup watchers for dependent fields', () => {
251+
expect(component.importSettingsForm.controls.isDependentImportEnabled.valueChanges.subscribe).toHaveBeenCalled();
252+
expect(component.importSettingsForm.controls.costCodes.valueChanges.subscribe).toHaveBeenCalled();
253+
expect(component.importSettingsForm.controls.costTypes.valueChanges.subscribe).toHaveBeenCalled();
254+
});
255+
256+
it('should handle isDependentImportEnabled being set', () => {
257+
component.importSettingsForm.get('isDependentImportEnabled')?.setValue(true);
258+
259+
expect(helperService.enableFormField).toHaveBeenCalledWith(component.importSettingsForm, 'costCodes');
260+
expect(helperService.enableFormField).toHaveBeenCalledWith(component.importSettingsForm, 'costTypes');
261+
expect(helperService.markControllerAsRequired).toHaveBeenCalledWith(component.importSettingsForm, 'costCodes');
262+
expect(helperService.markControllerAsRequired).toHaveBeenCalledWith(component.importSettingsForm, 'costTypes');
263+
expect(component.dependentImportFields[0].isDisabled).toBeFalse();
264+
expect(component.dependentImportFields[1].isDisabled).toBeFalse();
265+
});
266+
267+
it('should handle isDependentImportEnabled being unset', () => {
268+
component.importSettingsForm.get('isDependentImportEnabled')?.setValue(false);
269+
270+
expect(helperService.disableFormField).toHaveBeenCalledWith(component.importSettingsForm, 'costCodes');
271+
expect(helperService.disableFormField).toHaveBeenCalledWith(component.importSettingsForm, 'costTypes');
272+
expect(helperService.clearValidatorAndResetValue).toHaveBeenCalledWith(component.importSettingsForm, 'costCodes');
273+
expect(helperService.clearValidatorAndResetValue).toHaveBeenCalledWith(component.importSettingsForm, 'costTypes');
274+
expect(component.dependentImportFields[0].isDisabled).toBeTrue();
275+
expect(component.dependentImportFields[1].isDisabled).toBeTrue();
276+
});
277+
});
278+
279+
describe('dependentCostFieldsWatchers', () => {
280+
beforeEach(() => {
281+
component['dependentCostFieldsWatchers']('costCodes');
282+
component['dependentCostFieldsWatchers']('costTypes');
283+
});
284+
285+
it('should setup watchers for cost fields', () => {
286+
expect(component.importSettingsForm.controls.costCodes.valueChanges.subscribe).toHaveBeenCalled();
287+
expect(component.importSettingsForm.controls.costTypes.valueChanges.subscribe).toHaveBeenCalled();
288+
});
289+
290+
it('should handle custom field selection for costCodes', () => {
291+
component.importSettingsForm.controls.costCodes.setValue({ attribute_type: 'custom_field' });
292+
293+
expect(component.customFieldType).toBe('costCodes');
294+
expect(component.customFieldControl).toBe(component.importSettingsForm.controls.costCodes);
295+
});
296+
297+
it('should handle custom field selection for costTypes', () => {
298+
component.importSettingsForm.controls.costTypes.setValue({ attribute_type: 'custom_field' });
299+
300+
expect(component.customFieldType).toBe('costTypes');
301+
expect(component.customFieldControl).toBe(component.importSettingsForm.controls.costTypes);
302+
});
303+
304+
it('should handle non-custom field selection', () => {
305+
component.importSettingsForm.controls.costCodes.setValue({ attribute_type: 'some_field' });
306+
expect(component.dependentImportFields[0].isDisabled).toBeTrue();
307+
});
308+
});
309+
310+
describe('importSettingWatcher', () => {
311+
beforeEach(() => {
312+
(component.importSettingsForm.get('expenseFields') as FormArray).controls = [blankExpenseField];
313+
component['importSettingWatcher']();
314+
});
315+
316+
it('should setup watchers for expense fields', () => {
317+
expect(blankExpenseField.valueChanges.subscribe).toHaveBeenCalled();
318+
});
319+
320+
it('should handle custom field selection in expense fields', () => {
321+
spyOn(blankExpenseField, 'patchValue').and.callThrough();
322+
blankExpenseField.patchValue({ source_field: 'custom_field' });
323+
324+
expect(component.customFieldControl).toBe(blankExpenseField);
325+
expect(blankExpenseField.patchValue).toHaveBeenCalledWith(blankMapping);
326+
});
327+
});
328+
});
227329
});

src/app/integrations/intacct/intacct.fixture.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ExpenseGroup, ExpenseGroupDescription, ExpenseGroupResponse } from 'src
99
import { Paginator } from 'src/app/core/models/misc/paginator.model';
1010
import { SkipExportLogResponse } from "src/app/core/models/intacct/db/expense-group.model";
1111
import { ExpenseField } from 'src/app/core/models/intacct/db/expense-field.model';
12-
import { DependentFieldSetting, ImportSettingGet } from 'src/app/core/models/intacct/intacct-configuration/import-settings.model';
12+
import { DependentFieldSetting, ImportSettingGet, MappingSetting } from 'src/app/core/models/intacct/intacct-configuration/import-settings.model';
1313
import { LocationEntityMapping } from 'src/app/core/models/intacct/db/location-entity-mapping.model';
1414
import { GroupedDestinationAttribute } from "src/app/core/models/intacct/db/destination-attribute.model";
1515
import { IntacctConfiguration } from "src/app/core/models/db/configuration.model";
@@ -929,4 +929,12 @@ export const expenseFieldsExpectedForC1 = [
929929
is_custom: false,
930930
source_placeholder: null
931931
}
932-
];
932+
];
933+
934+
export const blankMapping: MappingSetting = {
935+
source_field: '',
936+
destination_field: '',
937+
import_to_fyle: true,
938+
is_custom: false,
939+
source_placeholder: null
940+
};

0 commit comments

Comments
 (0)