1+ /* eslint-disable dot-notation */
12import { ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
2- import { FormBuilder , ReactiveFormsModule , Validators } from '@angular/forms' ;
3+ import { FormBuilder , FormGroup , ReactiveFormsModule , Validators } from '@angular/forms' ;
34import { provideRouter , Router } from '@angular/router' ;
45import { of , throwError } from 'rxjs' ;
56import { IntacctAdvancedSettingsComponent } from './intacct-advanced-settings.component' ;
@@ -9,12 +10,12 @@ import { TrackingService } from 'src/app/core/services/integration/tracking.serv
910import { SiWorkspaceService } from 'src/app/core/services/si/si-core/si-workspace.service' ;
1011import { SiMappingsService } from 'src/app/core/services/si/si-core/si-mappings.service' ;
1112import { SkipExportComponent } from 'src/app/shared/components/si/helper/skip-export/skip-export.component' ;
12- import { adminEmails , advancedSettings , configurationForAddvancedSettings , expenseFilter , groupedAttributes } from '../../intacct.fixture' ;
13- import { ExpenseFilterResponse } from 'src/app/core/models/intacct/intacct-configuration/advanced-settings.model' ;
13+ import { adminEmails , advancedSettings , configurationForAdvancedSettings , configurationWithFyleToIntacct , configurationWithIntacctToFyle , configurationWithOutSync , expenseFilter , groupedAttributes } from '../../intacct.fixture' ;
14+ import { Configuration , ExpenseFilterResponse } from 'src/app/core/models/intacct/intacct-configuration/advanced-settings.model' ;
1415import { SharedModule } from 'src/app/shared/shared.module' ;
15- import { PaymentSyncDirection } from 'src/app/core/models/enum/enum.model' ;
1616import { IntacctOnboardingState , PaymentSyncDirection , ToastSeverity } from 'src/app/core/models/enum/enum.model' ;
1717import { SkipExport } from 'src/app/core/models/intacct/misc/skip-export.model' ;
18+ import { DestinationAttribute } from 'src/app/core/models/db/destination-attribute.model' ;
1819
1920describe ( 'IntacctAdvancedSettingsComponent' , ( ) => {
2021 let component : IntacctAdvancedSettingsComponent ;
@@ -65,7 +66,7 @@ describe('IntacctAdvancedSettingsComponent', () => {
6566 advancedSettingsService . getAdvancedSettings . and . returnValue ( of ( advancedSettings ) ) ;
6667 advancedSettingsService . getExpenseFilter . and . returnValue ( of ( expenseFilter as ExpenseFilterResponse ) ) ;
6768 mappingService . getGroupedDestinationAttributes . and . returnValue ( of ( groupedAttributes ) ) ;
68- mappingService . getConfiguration . and . returnValue ( of ( configurationForAddvancedSettings ) ) ;
69+ mappingService . getConfiguration . and . returnValue ( of ( configurationForAdvancedSettings ) ) ;
6970
7071 fixture = TestBed . createComponent ( IntacctAdvancedSettingsComponent ) ;
7172 component = fixture . componentInstance ;
@@ -89,11 +90,11 @@ describe('IntacctAdvancedSettingsComponent', () => {
8990 expect ( component . sageIntacctProjects ) . toEqual ( groupedAttributes . PROJECT ) ;
9091 expect ( component . sageIntacctClasses ) . toEqual ( groupedAttributes . CLASS ) ;
9192 expect ( component . sageIntacctPaymentAccount ) . toEqual ( groupedAttributes . PAYMENT_ACCOUNT ) ;
92- expect ( component . reimbursableExpense ) . toEqual ( configurationForAddvancedSettings . reimbursable_expenses_object ) ;
93- expect ( component . corporateCreditCardExpense ) . toEqual ( configurationForAddvancedSettings . corporate_credit_card_expenses_object ) ;
94- expect ( component . importVendorsAsMerchants ) . toEqual ( configurationForAddvancedSettings . import_vendors_as_merchants ) ;
95- expect ( component . useMerchantInJournalLine ) . toEqual ( configurationForAddvancedSettings . use_merchant_in_journal_line ) ;
96- expect ( component . employeeFieldMapping ) . toEqual ( configurationForAddvancedSettings . employee_field_mapping ) ;
93+ expect ( component . reimbursableExpense ) . toEqual ( configurationForAdvancedSettings . reimbursable_expenses_object ) ;
94+ expect ( component . corporateCreditCardExpense ) . toEqual ( configurationForAdvancedSettings . corporate_credit_card_expenses_object ) ;
95+ expect ( component . importVendorsAsMerchants ) . toEqual ( configurationForAdvancedSettings . import_vendors_as_merchants ) ;
96+ expect ( component . useMerchantInJournalLine ) . toEqual ( configurationForAdvancedSettings . use_merchant_in_journal_line ) ;
97+ expect ( component . employeeFieldMapping ) . toEqual ( configurationForAdvancedSettings . employee_field_mapping ) ;
9798 } ) ) ;
9899
99100 it ( 'should initialize forms correctly' , ( ) => {
@@ -227,4 +228,103 @@ describe('IntacctAdvancedSettingsComponent', () => {
227228 expect ( component . saveInProgress ) . toBeFalse ( ) ;
228229 } ) ) ;
229230 } ) ;
231+
232+ describe ( 'Utility Functions' , ( ) => {
233+ describe ( 'navigateToPreviousStep' , ( ) => {
234+ it ( 'should navigate to the import settings page' , ( ) => {
235+ component . navigateToPreviousStep ( ) ;
236+ expect ( router . navigate ) . toHaveBeenCalledWith ( [ '/integrations/intacct/onboarding/import_settings' ] ) ;
237+ } ) ;
238+ } ) ;
239+
240+ describe ( 'isOverflowing' , ( ) => {
241+ it ( 'should return the mapping value if element is overflowing' , ( ) => {
242+ const element = { offsetWidth : 100 , scrollWidth : 150 } ;
243+ const mapping = { value : 'test value' } as DestinationAttribute ;
244+ expect ( component . isOverflowing ( element , mapping ) ) . toBe ( 'test value' ) ;
245+ } ) ;
246+
247+ it ( 'should return an empty string if element is not overflowing' , ( ) => {
248+ const element = { offsetWidth : 150 , scrollWidth : 100 } ;
249+ const mapping = { value : 'test value' } as DestinationAttribute ;
250+ expect ( component . isOverflowing ( element , mapping ) ) . toBe ( '' ) ;
251+ } ) ;
252+ } ) ;
253+
254+ describe ( 'refreshDimensions' , ( ) => {
255+ it ( 'should call refreshSageIntacctDimensions and refreshFyleDimensions' , ( ) => {
256+ mappingService . refreshSageIntacctDimensions . and . returnValue ( of ( { } ) ) ;
257+ mappingService . refreshFyleDimensions . and . returnValue ( of ( { } ) ) ;
258+
259+ component . refreshDimensions ( true ) ;
260+
261+ expect ( mappingService . refreshSageIntacctDimensions ) . toHaveBeenCalled ( ) ;
262+ expect ( mappingService . refreshFyleDimensions ) . toHaveBeenCalled ( ) ;
263+ expect ( toastService . displayToastMessage ) . toHaveBeenCalledWith ( ToastSeverity . SUCCESS , 'Syncing data dimensions from Sage Intacct' ) ;
264+ } ) ;
265+ } ) ;
266+
267+ describe ( 'removeFilter' , ( ) => {
268+ it ( 'should reset the form control' , ( ) => {
269+ const formGroup = new FormGroup ( { } ) ;
270+ const resetSpy = spyOn ( formGroup , 'reset' ) ;
271+
272+ component . removeFilter ( formGroup ) ;
273+
274+ expect ( resetSpy ) . toHaveBeenCalled ( ) ;
275+ } ) ;
276+ } ) ;
277+
278+ describe ( 'getPaymentSyncConfiguration' , ( ) => {
279+ it ( 'should return FYLE_TO_INTACCT when sync_fyle_to_sage_intacct_payments is true' , ( ) => {
280+ expect ( component [ 'getPaymentSyncConfiguration' ] ( configurationWithFyleToIntacct ) ) . toBe ( PaymentSyncDirection . FYLE_TO_INTACCT ) ;
281+ } ) ;
282+
283+ it ( 'should return INTACCT_TO_FYLE when sync_sage_intacct_to_fyle_payments is true' , ( ) => {
284+ expect ( component [ 'getPaymentSyncConfiguration' ] ( configurationWithIntacctToFyle ) ) . toBe ( PaymentSyncDirection . INTACCT_TO_FYLE ) ;
285+ } ) ;
286+
287+ it ( 'should return an empty string when both sync options are false' , ( ) => {
288+ expect ( component [ 'getPaymentSyncConfiguration' ] ( configurationWithOutSync ) ) . toBe ( '' ) ;
289+ } ) ;
290+ } ) ;
291+
292+ describe ( 'compareObjects' , ( ) => {
293+ it ( 'should return true for identical objects' , ( ) => {
294+ const obj1 = { id : 1 , name : 'Test' } ;
295+ const obj2 = { id : 1 , name : 'Test' } ;
296+ expect ( component . compareObjects ( obj1 , obj2 ) ) . toBe ( true ) ;
297+ } ) ;
298+
299+ it ( 'should return false for different objects' , ( ) => {
300+ const obj1 = { id : 1 , name : 'Test' } ;
301+ const obj2 = { id : 2 , name : 'Different' } ;
302+ expect ( component . compareObjects ( obj1 , obj2 ) ) . toBe ( false ) ;
303+ } ) ;
304+ } ) ;
305+
306+ describe ( 'isCCT' , ( ) => {
307+ beforeEach ( ( ) => {
308+ fixture . detectChanges ( ) ;
309+ } ) ;
310+
311+ it ( 'should return true when autoSyncPayments is FYLE_TO_INTACCT' , ( ) => {
312+ component . advancedSettingsForm . patchValue ( { autoSyncPayments : PaymentSyncDirection . FYLE_TO_INTACCT } ) ;
313+ expect ( component . isCCT ( ) ) . toBe ( true ) ;
314+ } ) ;
315+
316+ it ( 'should return false when autoSyncPayments is not FYLE_TO_INTACCT' , ( ) => {
317+ component . advancedSettingsForm . patchValue ( { autoSyncPayments : PaymentSyncDirection . INTACCT_TO_FYLE } ) ;
318+ expect ( component . isCCT ( ) ) . toBe ( false ) ;
319+ } ) ;
320+ } ) ;
321+
322+ describe ( 'updateForm' , ( ) => {
323+ it ( 'should update skipExportForm with the provided form' , ( ) => {
324+ const newForm = new FormGroup ( { } ) ;
325+ component . updateForm ( newForm ) ;
326+ expect ( component . skipExportForm ) . toBe ( newForm ) ;
327+ } ) ;
328+ } ) ;
329+ } ) ;
230330} ) ;
0 commit comments