1- import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2-
1+ import { ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
2+ import { FormBuilder , ReactiveFormsModule , Validators } from '@angular/forms' ;
3+ import { provideRouter , Router } from '@angular/router' ;
4+ import { of } from 'rxjs' ;
35import { IntacctAdvancedSettingsComponent } from './intacct-advanced-settings.component' ;
6+ import { SiAdvancedSettingService } from 'src/app/core/services/si/si-configuration/si-advanced-setting.service' ;
7+ import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service' ;
8+ import { TrackingService } from 'src/app/core/services/integration/tracking.service' ;
9+ import { SiWorkspaceService } from 'src/app/core/services/si/si-core/si-workspace.service' ;
10+ import { SiMappingsService } from 'src/app/core/services/si/si-core/si-mappings.service' ;
11+ import { 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' ;
14+ import { SharedModule } from 'src/app/shared/shared.module' ;
415
5- xdescribe ( 'IntacctAdvancedSettingsComponent' , ( ) => {
16+ describe ( 'IntacctAdvancedSettingsComponent' , ( ) => {
617 let component : IntacctAdvancedSettingsComponent ;
718 let fixture : ComponentFixture < IntacctAdvancedSettingsComponent > ;
19+ let advancedSettingsService : jasmine . SpyObj < SiAdvancedSettingService > ;
20+ let router : Router ;
21+ let toastService : jasmine . SpyObj < IntegrationsToastService > ;
22+ let trackingService : jasmine . SpyObj < TrackingService > ;
23+ let workspaceService : jasmine . SpyObj < SiWorkspaceService > ;
24+ let mappingService : jasmine . SpyObj < SiMappingsService > ;
25+
826
927 beforeEach ( async ( ) => {
28+ const advancedSettingsServiceSpy = jasmine . createSpyObj ( 'SiAdvancedSettingService' , [ 'getAdvancedSettings' , 'getExpenseFilter' , 'getAdditionalEmails' ] ) ;
29+ const toastServiceSpy = jasmine . createSpyObj ( 'IntegrationsToastService' , [ 'displayToastMessage' ] ) ;
30+ const trackingServiceSpy = jasmine . createSpyObj ( 'TrackingService' , [ 'trackTimeSpent' , 'integrationsOnboardingCompletion' , 'intacctUpdateEvent' ] ) ;
31+ const workspaceServiceSpy = jasmine . createSpyObj ( 'SiWorkspaceService' , [ 'getIntacctOnboardingState' , 'setIntacctOnboardingState' ] ) ;
32+ const mappingServiceSpy = jasmine . createSpyObj ( 'SiMappingsService' , [ 'getGroupedDestinationAttributes' , 'getConfiguration' , 'refreshSageIntacctDimensions' , 'refreshFyleDimensions' ] ) ;
1033 await TestBed . configureTestingModule ( {
11- declarations : [ IntacctAdvancedSettingsComponent ]
12- } )
13- . compileComponents ( ) ;
34+ declarations : [ IntacctAdvancedSettingsComponent , SkipExportComponent ] ,
35+ imports : [ SharedModule , ReactiveFormsModule ] ,
36+ providers : [
37+ FormBuilder ,
38+ { provide : SiAdvancedSettingService , useValue : advancedSettingsServiceSpy } ,
39+ { provide : IntegrationsToastService , useValue : toastServiceSpy } ,
40+ { provide : TrackingService , useValue : trackingServiceSpy } ,
41+ { provide : SiWorkspaceService , useValue : workspaceServiceSpy } ,
42+ { provide : SiMappingsService , useValue : mappingServiceSpy } ,
43+ provideRouter ( [ ] )
44+ ]
45+ } ) . compileComponents ( ) ;
46+
47+ advancedSettingsService = TestBed . inject ( SiAdvancedSettingService ) as jasmine . SpyObj < SiAdvancedSettingService > ;
48+ toastService = TestBed . inject ( IntegrationsToastService ) as jasmine . SpyObj < IntegrationsToastService > ;
49+ trackingService = TestBed . inject ( TrackingService ) as jasmine . SpyObj < TrackingService > ;
50+ workspaceService = TestBed . inject ( SiWorkspaceService ) as jasmine . SpyObj < SiWorkspaceService > ;
51+ mappingService = TestBed . inject ( SiMappingsService ) as jasmine . SpyObj < SiMappingsService > ;
52+ router = TestBed . inject ( Router ) ;
53+
54+ advancedSettingsService . getAdditionalEmails . and . returnValue ( of ( adminEmails ) ) ;
55+ advancedSettingsService . getAdvancedSettings . and . returnValue ( of ( advancedSettings ) ) ;
56+ advancedSettingsService . getExpenseFilter . and . returnValue ( of ( expenseFilter as ExpenseFilterResponse ) ) ;
57+ mappingService . getGroupedDestinationAttributes . and . returnValue ( of ( groupedAttributes ) ) ;
58+ mappingService . getConfiguration . and . returnValue ( of ( configurationForAddvancedSettings ) ) ;
1459
1560 fixture = TestBed . createComponent ( IntacctAdvancedSettingsComponent ) ;
1661 component = fixture . componentInstance ;
17- fixture . detectChanges ( ) ;
1862 } ) ;
1963
2064 it ( 'should create' , ( ) => {
2165 expect ( component ) . toBeTruthy ( ) ;
2266 } ) ;
23- } ) ;
67+
68+ it ( 'should initialize with correct data' , fakeAsync ( ( ) => {
69+ fixture . detectChanges ( ) ;
70+ tick ( ) ;
71+
72+ expect ( component . isLoading ) . toBeFalse ( ) ;
73+ expect ( component . adminEmails ) . toEqual ( adminEmails . concat ( advancedSettings . workspace_schedules . additional_email_options ) ) ;
74+ expect ( component . advancedSettings ) . toEqual ( advancedSettings ) ;
75+ expect ( component . sageIntacctLocations ) . toEqual ( groupedAttributes . LOCATION ) ;
76+ expect ( component . sageIntacctDefaultItem ) . toEqual ( groupedAttributes . ITEM ) ;
77+ expect ( component . sageIntacctDepartments ) . toEqual ( groupedAttributes . DEPARTMENT ) ;
78+ expect ( component . sageIntacctProjects ) . toEqual ( groupedAttributes . PROJECT ) ;
79+ expect ( component . sageIntacctClasses ) . toEqual ( groupedAttributes . CLASS ) ;
80+ expect ( component . sageIntacctPaymentAccount ) . toEqual ( groupedAttributes . PAYMENT_ACCOUNT ) ;
81+ expect ( component . reimbursableExpense ) . toEqual ( configurationForAddvancedSettings . reimbursable_expenses_object ) ;
82+ expect ( component . corporateCreditCardExpense ) . toEqual ( configurationForAddvancedSettings . corporate_credit_card_expenses_object ) ;
83+ expect ( component . importVendorsAsMerchants ) . toEqual ( configurationForAddvancedSettings . import_vendors_as_merchants ) ;
84+ expect ( component . useMerchantInJournalLine ) . toEqual ( configurationForAddvancedSettings . use_merchant_in_journal_line ) ;
85+ expect ( component . employeeFieldMapping ) . toEqual ( configurationForAddvancedSettings . employee_field_mapping ) ;
86+ } ) ) ;
87+
88+ it ( 'should initialize forms correctly' , ( ) => {
89+ fixture . detectChanges ( ) ;
90+
91+ expect ( component . advancedSettingsForm ) . toBeDefined ( ) ;
92+ expect ( component . skipExportForm ) . toBeDefined ( ) ;
93+
94+ expect ( component . advancedSettingsForm . get ( 'exportSchedule' ) ?. value ) . toBeTrue ( ) ;
95+ expect ( component . advancedSettingsForm . get ( 'exportScheduleFrequency' ) ?. value ) . toBe ( 12 ) ;
96+ expect ( component . advancedSettingsForm . get ( 'setDescriptionField' ) ?. value ) . toEqual ( [ 'employee_email' , 'merchant' , 'purpose' ] ) ;
97+ } ) ;
98+
99+ it ( 'should handle onboarding state correctly' , ( ) => {
100+ spyOnProperty ( router , 'url' ) . and . returnValue ( '/integrations/intacct/onboarding/advanced_settings' ) ;
101+ fixture . detectChanges ( ) ;
102+
103+ expect ( component . isOnboarding ) . toBeTrue ( ) ;
104+ } ) ;
105+
106+ it ( 'should handle non-onboarding state correctly' , ( ) => {
107+ spyOnProperty ( router , 'url' ) . and . returnValue ( '/integrations/intacct/advanced_settings' ) ;
108+ fixture . detectChanges ( ) ;
109+
110+ expect ( component . isOnboarding ) . toBeFalse ( ) ;
111+ } ) ;
112+
113+ it ( 'should create memo preview correctly' , ( ) => {
114+ fixture . detectChanges ( ) ;
115+
116+ const expectedPreview = '[email protected] - Pizza Hut - Client Meeting' ; 117+ expect ( component . memoPreviewText ) . toBe ( expectedPreview ) ;
118+ } ) ;
119+ } ) ;
0 commit comments