From 0c79118b9e7262950a83dd980f5affb3c7026607 Mon Sep 17 00:00:00 2001 From: aastha Date: Wed, 8 Jan 2025 13:35:34 +0530 Subject: [PATCH] Minor --- .../auth/switch-org/switch-org.page.spec.ts | 42 ++++++++++++++++++- src/app/auth/switch-org/switch-org.page.ts | 8 +++- ...r-onboarding-opt-in-step.component.spec.ts | 11 ++++- .../spender-onboarding.page.ts | 3 ++ .../sidemenu/sidemenu.component.spec.ts | 28 ++++++++++--- 5 files changed, 81 insertions(+), 11 deletions(-) diff --git a/src/app/auth/switch-org/switch-org.page.spec.ts b/src/app/auth/switch-org/switch-org.page.spec.ts index 48a1a9361f..88bd205f07 100644 --- a/src/app/auth/switch-org/switch-org.page.spec.ts +++ b/src/app/auth/switch-org/switch-org.page.spec.ts @@ -44,6 +44,11 @@ import { DeepLinkService } from 'src/app/core/services/deep-link.service'; import { platformExpenseData } from 'src/app/core/mock-data/platform/v1/expense.data'; import { transformedExpenseData } from 'src/app/core/mock-data/transformed-expense.data'; import { LaunchDarklyService } from 'src/app/core/services/launch-darkly.service'; +import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; +import { orgSettingsData } from 'src/app/core/test-data/org-settings.service.spec.data'; +import { SpenderOnboardingService } from 'src/app/core/services/spender-onboarding.service'; +import { onboardingStatusData } from 'src/app/core/mock-data/onboarding-status.data'; +import { OnboardingState } from 'src/app/core/models/onboarding-state.enum'; const roles = ['OWNER', 'USER', 'FYLER']; const email = 'ajain@fyle.in'; @@ -73,6 +78,8 @@ describe('SwitchOrgPage', () => { let transactionService: jasmine.SpyObj; let expensesService: jasmine.SpyObj; let deepLinkService: jasmine.SpyObj; + let orgSettingsService: jasmine.SpyObj; + let spenderOnboardingService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const platformSpy = jasmine.createSpyObj('Platform', ['is']); @@ -110,6 +117,8 @@ describe('SwitchOrgPage', () => { const expensesServiceSpy = jasmine.createSpyObj('ExpensesService', ['getExpenseById']); const deepLinkServiceSpy = jasmine.createSpyObj('DeepLinkService', ['getExpenseRoute']); const ldSpy = jasmine.createSpyObj('LaunchDarklyService', ['initializeUser']); + const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']); + const spenderOnboardingServiceSpy = jasmine.createSpyObj('SpenderOnboardingSettings', ['getOnboardingSettings']); TestBed.configureTestingModule({ declarations: [SwitchOrgPage, ActiveOrgCardComponent, OrgCardComponent, FyZeroStateComponent], @@ -150,6 +159,14 @@ describe('SwitchOrgPage', () => { provide: LoaderService, useValue: loaderServiceSpy, }, + { + provide: OrgSettingsService, + useValue: orgSettingsServiceSpy, + }, + { + provide: SpenderOnboardingService, + useValue: spenderOnboardingServiceSpy, + }, { provide: UserService, useValue: userServiceSpy, @@ -256,11 +273,14 @@ describe('SwitchOrgPage', () => { deepLinkService = TestBed.inject(DeepLinkService) as jasmine.SpyObj; transactionService = TestBed.inject(TransactionService) as jasmine.SpyObj; expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj; + spenderOnboardingService = TestBed.inject(SpenderOnboardingService) as jasmine.SpyObj; + orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj; component.searchRef = fixture.debugElement.query(By.css('#search')); component.searchOrgsInput = fixture.debugElement.query(By.css('.smartlook-show')); component.contentRef = fixture.debugElement.query(By.css('.switch-org__content-container__content-block')); fixture.detectChanges(); + spyOn(component, 'navigateToDashboard').and.callThrough(); })); it('should create', () => { @@ -642,16 +662,34 @@ describe('SwitchOrgPage', () => { }); describe('navigateBasedOnUserStatus(): ', () => { - it('should navigate to dashboard if status is active', (done) => { + it('should navigate to dashboard if status is active', fakeAsync(() => { const config = { isPendingDetails: false, roles, eou: apiEouRes, }; - + orgSettingsService.get.and.returnValue(of(orgSettingsData)); + spenderOnboardingService.getOnboardingStatus.and.returnValue( + of({ ...onboardingStatusData, state: OnboardingState.COMPLETED }) + ); + tick(); component.navigateBasedOnUserStatus(config).subscribe((res) => { expect(res).toBeNull(); expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_dashboard']); + }); + })); + + it('should navigate to spender onboarding if status not COMPLETE', (done) => { + const config = { + isPendingDetails: false, + roles, + eou: apiEouRes, + }; + orgSettingsService.get.and.returnValue(of(orgSettingsData)); + spenderOnboardingService.getOnboardingStatus.and.returnValue(of(onboardingStatusData)); + component.navigateBasedOnUserStatus(config).subscribe((res) => { + expect(res).toBeNull(); + expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'spender_onboarding']); done(); }); }); diff --git a/src/app/auth/switch-org/switch-org.page.ts b/src/app/auth/switch-org/switch-org.page.ts index b3e7b8f189..226de20f0f 100644 --- a/src/app/auth/switch-org/switch-org.page.ts +++ b/src/app/auth/switch-org/switch-org.page.ts @@ -31,7 +31,6 @@ import { TransactionService } from 'src/app/core/services/transaction.service'; import { DeepLinkService } from 'src/app/core/services/deep-link.service'; import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { LaunchDarklyService } from 'src/app/core/services/launch-darkly.service'; -import { OrgSettings } from 'src/app/core/models/org-settings.model'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { SpenderOnboardingService } from 'src/app/core/services/spender-onboarding.service'; import { OnboardingState } from 'src/app/core/models/onboarding-state.enum'; @@ -321,7 +320,12 @@ export class SwitchOrgPage implements OnInit, AfterViewChecked { navigateToDashboard(openOptInDialog?: boolean): void { forkJoin([this.orgSettingsService.get(), this.spenderOnboardingService.getOnboardingStatus()]).subscribe( ([orgSettings, onboardingStatus]) => { - if (onboardingStatus.state !== OnboardingState.COMPLETED) { + if ( + (orgSettings.visa_enrollment_settings.enabled || + orgSettings.mastercard_enrollment_settings.enabled || + orgSettings.amex_feed_enrollment_settings.enabled) && + onboardingStatus.state !== OnboardingState.COMPLETED + ) { this.router.navigate(['/', 'enterprise', 'spender_onboarding']); } else { this.router.navigate([ diff --git a/src/app/fyle/spender-onboarding/spender-onboarding-opt-in-step/spender-onboarding-opt-in-step.component.spec.ts b/src/app/fyle/spender-onboarding/spender-onboarding-opt-in-step/spender-onboarding-opt-in-step.component.spec.ts index b31b1913e1..48e405f93f 100644 --- a/src/app/fyle/spender-onboarding/spender-onboarding-opt-in-step/spender-onboarding-opt-in-step.component.spec.ts +++ b/src/app/fyle/spender-onboarding/spender-onboarding-opt-in-step/spender-onboarding-opt-in-step.component.spec.ts @@ -23,6 +23,8 @@ import { snackbarPropertiesRes2 } from 'src/app/core/mock-data/snackbar-properti import { ToastMessageComponent } from 'src/app/shared/components/toast-message/toast-message.component'; import { UserEventService } from 'src/app/core/services/user-event.service'; import { FormBuilder } from '@angular/forms'; +import { SpenderOnboardingService } from 'src/app/core/services/spender-onboarding.service'; +import { onboardingStatusData } from 'src/app/core/mock-data/onboarding-status.data'; describe('SpenderOnboardingOptInStepComponent', () => { let component: SpenderOnboardingOptInStepComponent; @@ -35,8 +37,8 @@ describe('SpenderOnboardingOptInStepComponent', () => { let trackingService: jasmine.SpyObj; let matSnackbar: jasmine.SpyObj; let loaderService: jasmine.SpyObj; - let platformHandlerService: jasmine.SpyObj; let userEventService: jasmine.SpyObj; + let spenderOnboardingService: jasmine.SpyObj; let fb: FormBuilder; beforeEach(waitForAsync(() => { @@ -63,6 +65,7 @@ describe('SpenderOnboardingOptInStepComponent', () => { const browserHandlerServiceSpy = jasmine.createSpyObj('BrowserHandlerService', ['openLinkWithToolbarColor']); const platformHandlerServiceSpy = jasmine.createSpyObj('PlatformHandlerService', ['registerBackButtonAction']); const userEventServiceSpy = jasmine.createSpyObj('UserEventService', ['clearTaskCache']); + const spenderOnboardingServiceSpy = jasmine.createSpyObj('SpenderOnboardingService', ['getOnboardingStatus']); TestBed.configureTestingModule({ declarations: [SpenderOnboardingOptInStepComponent], @@ -80,6 +83,7 @@ describe('SpenderOnboardingOptInStepComponent', () => { { provide: BrowserHandlerService, useValue: browserHandlerServiceSpy }, { provide: PlatformHandlerService, useValue: platformHandlerServiceSpy }, { provide: UserEventService, useValue: userEventServiceSpy }, + { provide: SpenderOnboardingService, useValue: spenderOnboardingServiceSpy }, ], schemas: [NO_ERRORS_SCHEMA], }).compileComponents(); @@ -96,7 +100,7 @@ describe('SpenderOnboardingOptInStepComponent', () => { trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj; matSnackbar = TestBed.inject(MatSnackBar) as jasmine.SpyObj; loaderService = TestBed.inject(LoaderService) as jasmine.SpyObj; - platformHandlerService = TestBed.inject(PlatformHandlerService) as jasmine.SpyObj; + spenderOnboardingService = TestBed.inject(SpenderOnboardingService) as jasmine.SpyObj; userEventService = TestBed.inject(UserEventService) as jasmine.SpyObj; fb = TestBed.inject(FormBuilder); })); @@ -108,6 +112,9 @@ describe('SpenderOnboardingOptInStepComponent', () => { describe('ngOnInit():', () => { beforeEach(() => { component.eou = cloneDeep(eouRes2); + spenderOnboardingService.getOnboardingStatus.and.returnValue( + of({ ...onboardingStatusData, step_connect_cards_is_skipped: true }) + ); }); it('should not set mobileNumberInputValue if mobile number is not present in DB', () => { diff --git a/src/app/fyle/spender-onboarding/spender-onboarding.page.ts b/src/app/fyle/spender-onboarding/spender-onboarding.page.ts index 23eddd5a24..ee7676e58d 100644 --- a/src/app/fyle/spender-onboarding/spender-onboarding.page.ts +++ b/src/app/fyle/spender-onboarding/spender-onboarding.page.ts @@ -46,6 +46,8 @@ export class SpenderOnboardingPage { ) {} ionViewWillEnter(): void { + this.router.navigateByUrl('/enterprise/my_dashboard', { skipLocationChange: true }); + this.router.navigate(['/', 'enterprise', 'my_dashboard']); this.isLoading = true; from(this.loaderService.showLoader()) .pipe( @@ -144,6 +146,7 @@ export class SpenderOnboardingPage { if (this.redirectionCount > 0) { this.redirectionCount--; } else { + this.router.navigateByUrl('/enterprise/my_dashboard', { skipLocationChange: true }); this.router.navigate(['/', 'enterprise', 'my_dashboard']); } }, 1000); diff --git a/src/app/shared/components/sidemenu/sidemenu.component.spec.ts b/src/app/shared/components/sidemenu/sidemenu.component.spec.ts index d057d5553c..39643e262b 100644 --- a/src/app/shared/components/sidemenu/sidemenu.component.spec.ts +++ b/src/app/shared/components/sidemenu/sidemenu.component.spec.ts @@ -34,6 +34,9 @@ import { setSideMenuRes, } from 'src/app/core/mock-data/sidemenu.data'; import { delegatorData } from 'src/app/core/mock-data/platform/v1/delegator.data'; +import { SpenderOnboardingService } from 'src/app/core/services/spender-onboarding.service'; +import { onboardingStatusData } from 'src/app/core/mock-data/onboarding-status.data'; +import { OnboardingState } from 'src/app/core/models/onboarding-state.enum'; describe('SidemenuComponent', () => { let component: SidemenuComponent; @@ -50,6 +53,7 @@ describe('SidemenuComponent', () => { let orgService: jasmine.SpyObj; let authService: jasmine.SpyObj; let orgUserSettingsService: jasmine.SpyObj; + let spenderOnboardingService: jasmine.SpyObj; @Component({ selector: 'app-sidemenu', @@ -83,6 +87,7 @@ describe('SidemenuComponent', () => { const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']); authServiceSpy.getEou.and.resolveTo(apiEouRes); const orgUserSettingsServiceSpy = jasmine.createSpyObj('OrgUserSettingsService', ['get']); + const spenderOnboardingServiceSpy = jasmine.createSpyObj('SpenderOnboardingService', ['getOnboardingStatus']); TestBed.configureTestingModule({ declarations: [SidemenuComponent], @@ -100,6 +105,7 @@ describe('SidemenuComponent', () => { { provide: OrgService, useValue: orgServiceSpy }, { provide: AuthService, useValue: authServiceSpy }, { provide: OrgUserSettingsService, useValue: orgUserSettingsServiceSpy }, + { provide: SpenderOnboardingService, useValue: spenderOnboardingServiceSpy }, ], schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], }).compileComponents(); @@ -116,6 +122,7 @@ describe('SidemenuComponent', () => { orgService = TestBed.inject(OrgService) as jasmine.SpyObj; authService = TestBed.inject(AuthService) as jasmine.SpyObj; orgUserSettingsService = TestBed.inject(OrgUserSettingsService) as jasmine.SpyObj; + spenderOnboardingService = TestBed.inject(SpenderOnboardingService) as jasmine.SpyObj; networkService.connectivityWatcher.and.returnValue(new EventEmitter()); @@ -448,8 +455,14 @@ describe('SidemenuComponent', () => { }); }); - describe('setupSideMenu()', () => { - it('should setup the side menu', () => { + describe('setupSideMenu(): ', () => { + beforeEach(() => { + spenderOnboardingService.getOnboardingStatus.and.returnValue( + of({ ...onboardingStatusData, state: OnboardingState.COMPLETED }) + ); + }); + + it('should setup the side menu', fakeAsync(() => { const getPrimarySidemenuOptionsSpy = spyOn(component, 'getPrimarySidemenuOptions').and.returnValue( getPrimarySidemenuOptionsRes1 ); @@ -458,22 +471,24 @@ describe('SidemenuComponent', () => { ); const resData = setSideMenuRes; component.setupSideMenu(true, orgData1, true); + tick(); fixture.detectChanges(); expect(component.filteredSidemenuList).toEqual(resData); expect(getPrimarySidemenuOptionsSpy).toHaveBeenCalledOnceWith(true, false); expect(getSecondarySidemenuOptionsSpy).toHaveBeenCalledOnceWith(orgData1, true, true, false); - }); + })); - it('should only get the primary options when there is no internet connection', () => { + it('should only get the primary options when there is no internet connection', fakeAsync(() => { const getPrimarySidemenuOptionsOfflineSpy = spyOn(component, 'getPrimarySidemenuOptionsOffline').and.returnValue( sidemenuData1 ); const resData = sidemenuData1; component.setupSideMenu(false, orgData1, false); fixture.detectChanges(); + tick(); expect(component.filteredSidemenuList).toEqual(resData); expect(getPrimarySidemenuOptionsOfflineSpy).toHaveBeenCalledTimes(1); - }); + })); }); describe('goToProfile():', () => { @@ -516,6 +531,9 @@ describe('SidemenuComponent', () => { orgUserService.getCurrent.and.returnValue(of(currentEouRes)); sidemenuService.getAllowedActions.and.returnValue(of(sidemenuAllowedActions)); + spenderOnboardingService.getOnboardingStatus.and.returnValue( + of({ ...onboardingStatusData, state: OnboardingState.COMPLETED }) + ); component.showSideMenuOnline(); tick(500);