11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2-
2+ import { FormArray , FormBuilder , ReactiveFormsModule } from '@angular/forms' ;
3+ import { provideRouter , Router , RouterModule } from '@angular/router' ;
4+ import { of } from 'rxjs' ;
35import { IntacctC1ImportSettingsComponent } from './intacct-c1-import-settings.component' ;
6+ import { SiImportSettingService } from 'src/app/core/services/si/si-configuration/si-import-setting.service' ;
7+ import { SiMappingsService } from 'src/app/core/services/si/si-core/si-mappings.service' ;
8+ import { IntacctConnectorService } from 'src/app/core/services/si/si-core/intacct-connector.service' ;
9+ import { StorageService } from 'src/app/core/services/common/storage.service' ;
10+ import { HelperService } from 'src/app/core/services/common/helper.service' ;
11+ import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service' ;
12+ import { TrackingService } from 'src/app/core/services/integration/tracking.service' ;
13+ import { SiWorkspaceService } from 'src/app/core/services/si/si-core/si-workspace.service' ;
14+ import {
15+ importSettings ,
16+ sageIntacctFields ,
17+ fyleFields ,
18+ configuration ,
19+ locationEntityMapping ,
20+ settingsWithDependentFields ,
21+ sageIntacctFieldsSortedByPriorityForC1 ,
22+ importSettingsWithProjectMapping ,
23+ expenseFieldsExpectedForC1
24+ } from '../../intacct.fixture' ;
25+ import { IntacctConfiguration } from 'src/app/core/models/db/configuration.model' ;
26+ import { ImportSettingGet } from 'src/app/core/models/intacct/intacct-configuration/import-settings.model' ;
27+ import { SharedModule } from 'src/app/shared/shared.module' ;
28+ import { HttpClientTestingModule } from '@angular/common/http/testing' ;
429
5- xdescribe ( 'IntacctC1ImportSettingsComponent' , ( ) => {
30+ describe ( 'IntacctC1ImportSettingsComponent' , ( ) => {
631 let component : IntacctC1ImportSettingsComponent ;
732 let fixture : ComponentFixture < IntacctC1ImportSettingsComponent > ;
33+ let router : Router ;
34+ let mappingService : jasmine . SpyObj < SiMappingsService > ;
35+ let importSettingService : jasmine . SpyObj < SiImportSettingService > ;
36+ let connectorService : jasmine . SpyObj < IntacctConnectorService > ;
37+ let storageService : jasmine . SpyObj < StorageService > ;
38+ let toastService : jasmine . SpyObj < IntegrationsToastService > ;
39+ let trackingService : jasmine . SpyObj < TrackingService > ;
40+ let workspaceService : jasmine . SpyObj < SiWorkspaceService > ;
41+ let helperService : jasmine . SpyObj < HelperService > ;
842
943 beforeEach ( async ( ) => {
44+ const mappingServiceSpy = jasmine . createSpyObj ( 'SiMappingsService' , [
45+ 'getSageIntacctFields' ,
46+ 'getFyleFields' ,
47+ 'getConfiguration' ,
48+ 'refreshSageIntacctDimensions' ,
49+ 'refreshFyleDimensions'
50+ ] ) ;
51+ const importSettingServiceSpy = jasmine . createSpyObj ( 'SiImportSettingService' , [ 'getImportSettings' ] ) ;
52+ const connectorServiceSpy = jasmine . createSpyObj ( 'IntacctConnectorService' , [ 'getLocationEntityMapping' ] ) ;
53+ const storageServiceSpy = jasmine . createSpyObj ( 'StorageService' , [ 'get' ] ) ;
54+ const toastServiceSpy = jasmine . createSpyObj ( 'IntegrationsToastService' , [ 'displayToastMessage' ] ) ;
55+ const trackingServiceSpy = jasmine . createSpyObj ( 'TrackingService' , [ 'trackTimeSpent' ] ) ;
56+ const workspaceServiceSpy = jasmine . createSpyObj ( 'SiWorkspaceService' , [ 'getIntacctOnboardingState' ] ) ;
57+ const helperServiceSpy = jasmine . createSpyObj ( 'HelperService' , [
58+ 'disableFormField' ,
59+ 'enableFormField' ,
60+ 'markControllerAsRequired' ,
61+ 'clearValidatorAndResetValue'
62+ ] ) ;
63+
1064 await TestBed . configureTestingModule ( {
11- declarations : [ IntacctC1ImportSettingsComponent ]
12- } )
13- . compileComponents ( ) ;
65+ declarations : [ IntacctC1ImportSettingsComponent ] ,
66+ imports : [ SharedModule , RouterModule . forRoot ( [ ] ) , HttpClientTestingModule , ReactiveFormsModule ] ,
67+ providers : [
68+ FormBuilder ,
69+ { provide : SiMappingsService , useValue : mappingServiceSpy } ,
70+ { provide : SiImportSettingService , useValue : importSettingServiceSpy } ,
71+ { provide : IntacctConnectorService , useValue : connectorServiceSpy } ,
72+ { provide : StorageService , useValue : storageServiceSpy } ,
73+ { provide : IntegrationsToastService , useValue : toastServiceSpy } ,
74+ { provide : TrackingService , useValue : trackingServiceSpy } ,
75+ { provide : SiWorkspaceService , useValue : workspaceServiceSpy } ,
76+ { provide : HelperService , useValue : helperServiceSpy } ,
77+ provideRouter ( [ ] )
78+ ]
79+ } ) . compileComponents ( ) ;
1480
1581 fixture = TestBed . createComponent ( IntacctC1ImportSettingsComponent ) ;
1682 component = fixture . componentInstance ;
17- fixture . detectChanges ( ) ;
83+
84+ router = TestBed . inject ( Router ) ;
85+ mappingService = TestBed . inject ( SiMappingsService ) as jasmine . SpyObj < SiMappingsService > ;
86+ importSettingService = TestBed . inject ( SiImportSettingService ) as jasmine . SpyObj < SiImportSettingService > ;
87+ connectorService = TestBed . inject ( IntacctConnectorService ) as jasmine . SpyObj < IntacctConnectorService > ;
88+ storageService = TestBed . inject ( StorageService ) as jasmine . SpyObj < StorageService > ;
89+ toastService = TestBed . inject ( IntegrationsToastService ) as jasmine . SpyObj < IntegrationsToastService > ;
90+ trackingService = TestBed . inject ( TrackingService ) as jasmine . SpyObj < TrackingService > ;
91+ workspaceService = TestBed . inject ( SiWorkspaceService ) as jasmine . SpyObj < SiWorkspaceService > ;
92+ helperService = TestBed . inject ( HelperService ) as jasmine . SpyObj < HelperService > ;
93+
94+ spyOn ( router , 'navigate' ) ;
95+ spyOnProperty ( router , 'url' ) . and . returnValue ( '/onboarding' ) ;
96+ mappingService . getSageIntacctFields . and . returnValue ( of ( sageIntacctFields ) ) ;
97+ mappingService . getFyleFields . and . returnValue ( of ( fyleFields ) ) ;
98+ mappingService . getConfiguration . and . returnValue ( of ( configuration ) ) ;
99+ importSettingService . getImportSettings . and . returnValue ( of ( importSettings ) ) ;
100+ connectorService . getLocationEntityMapping . and . returnValue ( of ( locationEntityMapping ) ) ;
101+ storageService . get . and . returnValue ( '123' ) ;
18102 } ) ;
19103
20104 it ( 'should create' , ( ) => {
21105 expect ( component ) . toBeTruthy ( ) ;
22106 } ) ;
23- } ) ;
107+
108+ describe ( 'Initialization' , ( ) => {
109+
110+ it ( 'should initialize component with correct data' , ( ) => {
111+ component . ngOnInit ( ) ;
112+ expect ( component . isLoading ) . toBeFalse ( ) ;
113+ expect ( component . sageIntacctFields ) . toEqual ( sageIntacctFieldsSortedByPriorityForC1 ) ;
114+ expect ( component . fyleFields ) . toEqual ( fyleFields ) ;
115+ expect ( component . importSettings ) . toEqual ( importSettings ) ;
116+ } ) ;
117+
118+ it ( 'should handle employee field mapping for EMPLOYEE' , ( ) => {
119+ const employeeConfig = { ...configuration , employee_field_mapping : 'EMPLOYEE' } ;
120+ mappingService . getConfiguration . and . returnValue ( of ( employeeConfig as IntacctConfiguration ) ) ;
121+
122+ component . ngOnInit ( ) ;
123+ expect ( component . intacctCategoryDestination ) . toBe ( 'EXPENSE_TYPE' ) ;
124+ } ) ;
125+
126+ it ( 'should handle employee field mapping for non-EMPLOYEE' , ( ) => {
127+ component . ngOnInit ( ) ;
128+ expect ( component . intacctCategoryDestination ) . toBe ( 'GL_ACCOUNT' ) ;
129+ } ) ;
130+
131+ it ( 'should initialize all form controls' , ( ) => {
132+ component . ngOnInit ( ) ;
133+ expect ( component . importSettingsForm . get ( 'importVendorAsMerchant' ) ) . toBeDefined ( ) ;
134+ expect ( component . importSettingsForm . get ( 'importCategories' ) ) . toBeDefined ( ) ;
135+ expect ( component . importSettingsForm . get ( 'importTaxCodes' ) ) . toBeDefined ( ) ;
136+ expect ( component . importSettingsForm . get ( 'costCodes' ) ) . toBeDefined ( ) ;
137+ expect ( component . importSettingsForm . get ( 'dependentFieldImportToggle' ) ) . toBeDefined ( ) ;
138+ expect ( component . importSettingsForm . get ( 'workspaceId' ) ) . toBeDefined ( ) ;
139+ expect ( component . importSettingsForm . get ( 'costTypes' ) ) . toBeDefined ( ) ;
140+ expect ( component . importSettingsForm . get ( 'isDependentImportEnabled' ) ) . toBeDefined ( ) ;
141+ expect ( component . importSettingsForm . get ( 'sageIntacctTaxCodes' ) ) . toBeDefined ( ) ;
142+ expect ( component . importSettingsForm . get ( 'expenseFields' ) ) . toBeDefined ( ) ;
143+ expect ( component . importSettingsForm . get ( 'importCodeField' ) ) . toBeDefined ( ) ;
144+ expect ( component . importSettingsForm . get ( 'importCodeFields' ) ) . toBeDefined ( ) ;
145+ } ) ;
146+ } ) ;
147+
148+ describe ( 'Form Initialization' , ( ) => {
149+
150+ it ( 'should generate the correct expense fields' , ( ) => {
151+ importSettingService . getImportSettings . and . returnValue ( of (
152+ importSettingsWithProjectMapping as ImportSettingGet
153+ ) ) ;
154+ spyOn < any > ( component , 'createFormGroup' ) . and . callThrough ( ) ;
155+ component . ngOnInit ( ) ;
156+
157+ expect ( component . importSettingsForm . get ( 'expenseFields' ) ?. value ) . toEqual ( expenseFieldsExpectedForC1 ) ;
158+ } ) ;
159+
160+ it ( 'should handle dependent fields correctly' , ( ) => {
161+ importSettingService . getImportSettings . and . returnValue ( of ( settingsWithDependentFields as ImportSettingGet ) ) ;
162+
163+ component . ngOnInit ( ) ;
164+ expect ( component . importSettingsForm . get ( 'isDependentImportEnabled' ) ! . value ) . toBeTrue ( ) ;
165+ expect ( component . importSettingsForm . get ( 'costCodes' ) ) . toBeDefined ( ) ;
166+ expect ( component . importSettingsForm . get ( 'costTypes' ) ) . toBeDefined ( ) ;
167+ } ) ;
168+ } ) ;
169+ } ) ;
0 commit comments