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 173e75219b..b7f98c721b 100644 --- a/src/app/auth/switch-org/switch-org.page.spec.ts +++ b/src/app/auth/switch-org/switch-org.page.spec.ts @@ -54,7 +54,7 @@ const roles = ['OWNER', 'USER', 'FYLER']; const email = 'ajain@fyle.in'; const org_id = 'orNVthTo2Zyo'; -fdescribe('SwitchOrgPage', () => { +describe('SwitchOrgPage', () => { let component: SwitchOrgPage; let fixture: ComponentFixture; let loaderService: jasmine.SpyObj; diff --git a/src/app/fyle/spender-onboarding/spender-onboarding.page.spec.ts b/src/app/fyle/spender-onboarding/spender-onboarding.page.spec.ts index 8728d62b73..9fca790692 100644 --- a/src/app/fyle/spender-onboarding/spender-onboarding.page.spec.ts +++ b/src/app/fyle/spender-onboarding/spender-onboarding.page.spec.ts @@ -12,8 +12,10 @@ import { orgSettingsData } from 'src/app/core/test-data/accounts.service.spec.da import { onboardingStatusData } from 'src/app/core/mock-data/onboarding-status.data'; import { extendedOrgUserResponse } from 'src/app/core/test-data/tasks.service.spec.data'; import { OnboardingStepStatus } from 'src/app/core/models/onboarding-step-status.model'; +import { orgSettingsWoTaxAndRtf } from 'src/app/core/mock-data/org-settings.data'; +import { statementUploadedCard } from 'src/app/core/mock-data/platform-corporate-card.data'; -fdescribe('SpenderOnboardingPage', () => { +describe('SpenderOnboardingPage', () => { let component: SpenderOnboardingPage; let fixture: ComponentFixture; let loaderService: jasmine.SpyObj; @@ -33,6 +35,7 @@ fdescribe('SpenderOnboardingPage', () => { 'skipSmsOptInStep', 'markSmsOptInStepAsComplete', 'markWelcomeModalStepAsComplete', + 'setOnboardingStatusEvent', ]); const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']); const corporateCreditCardExpenseServiceSpy = jasmine.createSpyObj('CorporateCreditCardExpenseService', [ @@ -63,64 +66,127 @@ fdescribe('SpenderOnboardingPage', () => { CorporateCreditCardExpenseService ) as jasmine.SpyObj; router = TestBed.inject(Router) as jasmine.SpyObj; + spenderOnboardingService.markWelcomeModalStepAsComplete.and.returnValue(of({ is_complete: true })); }); - it('ionViewWillEnter(): should show loader and fetch onboarding data on ionViewWillEnter', (done) => { - loaderService.showLoader.and.resolveTo(); - orgUserService.getCurrent.and.returnValue(of(extendedOrgUserResponse)); - orgSettingsService.get.and.returnValue(of(orgSettingsData)); - spenderOnboardingService.getOnboardingStatus.and.returnValue(of(onboardingStatusData)); - corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([])); + describe('ionViewWillEnter(): ', () => { + it('should show loader and fetch onboarding data on ionViewWillEnter', (done) => { + loaderService.showLoader.and.resolveTo(); + orgUserService.getCurrent.and.returnValue(of(extendedOrgUserResponse)); + orgSettingsService.get.and.returnValue(of(orgSettingsData)); + spenderOnboardingService.getOnboardingStatus.and.returnValue(of(onboardingStatusData)); + corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([])); - component.ionViewWillEnter(); + component.ionViewWillEnter(); - fixture.whenStable().then(() => { - fixture.detectChanges(); + fixture.whenStable().then(() => { + fixture.detectChanges(); + + expect(loaderService.showLoader).toHaveBeenCalledTimes(1); + expect(component.userFullName).toBe('Aiyush'); + expect(component.currentStep).toBe(OnboardingStep.CONNECT_CARD); + expect(component.isLoading).toBeFalse(); + expect(loaderService.hideLoader).toHaveBeenCalled(); + done(); + }); + }); + + it('should go to Opt in step when RTF is disabled', (done) => { + loaderService.showLoader.and.resolveTo(); + orgUserService.getCurrent.and.returnValue(of(extendedOrgUserResponse)); + orgSettingsService.get.and.returnValue(of(orgSettingsWoTaxAndRtf)); + spenderOnboardingService.getOnboardingStatus.and.returnValue(of(onboardingStatusData)); + corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([statementUploadedCard])); - expect(loaderService.showLoader).toHaveBeenCalledTimes(1); - expect(component.userFullName).toBe('Aiyush'); - expect(component.currentStep).toBe(OnboardingStep.CONNECT_CARD); - expect(component.isLoading).toBeFalse(); - expect(loaderService.hideLoader).toHaveBeenCalled(); - done(); + component.ionViewWillEnter(); + + fixture.whenStable().then(() => { + fixture.detectChanges(); + + expect(loaderService.showLoader).toHaveBeenCalledTimes(1); + expect(component.userFullName).toBe('Aiyush'); + expect(component.currentStep).toBe(OnboardingStep.OPT_IN); + expect(component.isLoading).toBeFalse(); + done(); + }); + }); + + it('should go to Opt in step when connect card is skipped', (done) => { + loaderService.showLoader.and.resolveTo(); + orgUserService.getCurrent.and.returnValue(of(extendedOrgUserResponse)); + orgSettingsService.get.and.returnValue(of(orgSettingsData)); + spenderOnboardingService.getOnboardingStatus.and.returnValue( + of({ ...onboardingStatusData, step_connect_cards_is_skipped: true }) + ); + corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([statementUploadedCard])); + + component.ionViewWillEnter(); + + fixture.whenStable().then(() => { + fixture.detectChanges(); + + expect(loaderService.showLoader).toHaveBeenCalledTimes(1); + expect(component.userFullName).toBe('Aiyush'); + expect(component.currentStep).toBe(OnboardingStep.OPT_IN); + expect(component.isLoading).toBeFalse(); + done(); + }); }); }); - it('skipOnboardingStep(): should skip the current onboarding step', fakeAsync(() => { - const onboardingRequestResponse: OnboardingStepStatus = { - is_configured: false, - is_skipped: true, - }; - component.currentStep = OnboardingStep.CONNECT_CARD; - spenderOnboardingService.skipConnectCardsStep.and.returnValue(of(onboardingRequestResponse)); - component.skipOnboardingStep(); - tick(); - expect(spenderOnboardingService.skipConnectCardsStep).toHaveBeenCalled(); - - component.currentStep = OnboardingStep.OPT_IN; - spenderOnboardingService.skipSmsOptInStep.and.returnValue(of(onboardingRequestResponse)); - component.skipOnboardingStep(); - tick(); - expect(spenderOnboardingService.skipSmsOptInStep).toHaveBeenCalled(); - })); - - it('markStepAsComplete(): should mark the current step as complete', fakeAsync(() => { - const onboardingRequestResponse: OnboardingStepStatus = { - is_configured: true, - is_skipped: false, - }; - component.currentStep = OnboardingStep.CONNECT_CARD; - spenderOnboardingService.markConnectCardsStepAsComplete.and.returnValue(of(onboardingRequestResponse)); - component.markStepAsComplete(); - tick(); - expect(spenderOnboardingService.markConnectCardsStepAsComplete).toHaveBeenCalled(); - - component.currentStep = OnboardingStep.OPT_IN; - fixture.detectChanges(); - spenderOnboardingService.markSmsOptInStepAsComplete.and.returnValue(of(onboardingRequestResponse)); - spenderOnboardingService.markWelcomeModalStepAsComplete.and.returnValue(of({ is_complete: true })); - component.markStepAsComplete(); - tick(); - expect(spenderOnboardingService.markSmsOptInStepAsComplete).toHaveBeenCalled(); - })); + describe('skipOnboardingStep(): ', () => { + it('should skip the current onboarding step - connect card', fakeAsync(() => { + const onboardingRequestResponse: OnboardingStepStatus = { + is_configured: false, + is_skipped: true, + }; + component.currentStep = OnboardingStep.CONNECT_CARD; + spenderOnboardingService.skipConnectCardsStep.and.returnValue(of(onboardingRequestResponse)); + component.skipOnboardingStep(); + tick(); + expect(spenderOnboardingService.skipConnectCardsStep).toHaveBeenCalled(); + })); + + it('should skip the current onboarding step - opt in', fakeAsync(() => { + const onboardingRequestResponse: OnboardingStepStatus = { + is_configured: false, + is_skipped: true, + }; + component.currentStep = OnboardingStep.OPT_IN; + spenderOnboardingService.skipSmsOptInStep.and.returnValue(of(onboardingRequestResponse)); + spenderOnboardingService.markWelcomeModalStepAsComplete.and.returnValue(of({ is_complete: true })); + component.skipOnboardingStep(); + tick(); + expect(spenderOnboardingService.skipSmsOptInStep).toHaveBeenCalled(); + expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_dashboard']); + })); + }); + + describe('markStepAsComplete(): ', () => { + it('should mark the current step as complete - Connect Card', fakeAsync(() => { + const onboardingRequestResponse: OnboardingStepStatus = { + is_configured: true, + is_skipped: false, + }; + component.currentStep = OnboardingStep.CONNECT_CARD; + spenderOnboardingService.markConnectCardsStepAsComplete.and.returnValue(of(onboardingRequestResponse)); + component.markStepAsComplete(); + tick(); + expect(spenderOnboardingService.markConnectCardsStepAsComplete).toHaveBeenCalled(); + })); + + it('should mark the current step as complete', fakeAsync(() => { + const onboardingRequestResponse: OnboardingStepStatus = { + is_configured: true, + is_skipped: false, + }; + component.currentStep = OnboardingStep.OPT_IN; + fixture.detectChanges(); + spenderOnboardingService.markWelcomeModalStepAsComplete.and.returnValue(of({ is_complete: true })); + spenderOnboardingService.markSmsOptInStepAsComplete.and.returnValue(of(onboardingRequestResponse)); + component.markStepAsComplete(); + tick(); + expect(spenderOnboardingService.markSmsOptInStepAsComplete).toHaveBeenCalled(); + })); + }); }); diff --git a/src/app/post-verification/invited-user/invited-user.page.spec.ts b/src/app/post-verification/invited-user/invited-user.page.spec.ts index 71a6d4ca3e..0d2199dcca 100644 --- a/src/app/post-verification/invited-user/invited-user.page.spec.ts +++ b/src/app/post-verification/invited-user/invited-user.page.spec.ts @@ -24,8 +24,13 @@ import { eouRes3 } from 'src/app/core/mock-data/extended-org-user.data'; import { OrgService } from 'src/app/core/services/org.service'; import { ToastMessageComponent } from 'src/app/shared/components/toast-message/toast-message.component'; import { RouterTestingModule } from '@angular/router/testing'; +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'; +import { onboardingStatusData } from 'src/app/core/mock-data/onboarding-status.data'; +import { orgSettingsData } from 'src/app/core/test-data/org-settings.service.spec.data'; -fdescribe('InvitedUserPage', () => { +describe('InvitedUserPage', () => { let component: InvitedUserPage; let fixture: ComponentFixture; let networkService: jasmine.SpyObj; @@ -38,6 +43,8 @@ fdescribe('InvitedUserPage', () => { let trackingService: jasmine.SpyObj; let matSnackBar: jasmine.SpyObj; let snackbarProperties: jasmine.SpyObj; + let orgSettingsService: jasmine.SpyObj; + let spenderOnboardingService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const networkServiceSpy = jasmine.createSpyObj('NetworkService', ['connectivityWatcher', 'isOnline']); @@ -52,6 +59,8 @@ fdescribe('InvitedUserPage', () => { ]); const matSnackBarSpy = jasmine.createSpyObj('MatSnackBar', ['openFromComponent']); const snackbarPropertiesSpy = jasmine.createSpyObj('SnackbarPropertiesService', ['setSnackbarProperties']); + const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']); + const spenderOnboardingServiceSpy = jasmine.createSpyObj('SpenderOnboardingService', ['getOnboardingStatus']); TestBed.configureTestingModule({ declarations: [InvitedUserPage], imports: [IonicModule.forRoot(), MatIconTestingModule, RouterTestingModule], @@ -67,6 +76,8 @@ fdescribe('InvitedUserPage', () => { { provide: TrackingService, useValue: trackingServiceSpy }, { provide: MatSnackBar, useValue: matSnackBarSpy }, { provide: SnackbarPropertiesService, useValue: snackbarPropertiesSpy }, + { provide: OrgSettingsService, useValue: orgSettingsServiceSpy }, + { provide: SpenderOnboardingService, useValue: spenderOnboardingServiceSpy }, ], schemas: [NO_ERRORS_SCHEMA], }).compileComponents(); @@ -81,6 +92,8 @@ fdescribe('InvitedUserPage', () => { trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj; matSnackBar = TestBed.inject(MatSnackBar) as jasmine.SpyObj; snackbarProperties = TestBed.inject(SnackbarPropertiesService) as jasmine.SpyObj; + spenderOnboardingService = TestBed.inject(SpenderOnboardingService) as jasmine.SpyObj; + orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj; networkService.connectivityWatcher.and.returnValue(new EventEmitter()); networkService.isOnline.and.returnValue(of(true)); @@ -89,6 +102,10 @@ fdescribe('InvitedUserPage', () => { component = fixture.componentInstance; component.isConnected$ = of(true); fixture.detectChanges(); + spenderOnboardingService.getOnboardingStatus.and.returnValue( + of({ ...onboardingStatusData, state: OnboardingState.COMPLETED }) + ); + orgSettingsService.get.and.returnValue(of(orgSettingsData)); })); it('should create', () => { @@ -265,4 +282,14 @@ fdescribe('InvitedUserPage', () => { // @ts-ignore expect(component.router.navigate).toHaveBeenCalledOnceWith(['/', 'auth', 'sign_in']); // Should navigate to the correct route }); + + it('navigateToDashboard(): should navigate to spender onboarding when onboarding status is not complete', fakeAsync(() => { + spenderOnboardingService.getOnboardingStatus.and.returnValue( + of({ ...onboardingStatusData, state: OnboardingState.YET_TO_START }) + ); + orgSettingsService.get.and.returnValue(of(orgSettingsData)); + component.navigateToDashboard(); + tick(); + expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'spender_onboarding']); + })); });