Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha committed Jan 10, 2025
1 parent d57e521 commit 7946a08
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/app/auth/switch-org/switch-org.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const roles = ['OWNER', 'USER', 'FYLER'];
const email = '[email protected]';
const org_id = 'orNVthTo2Zyo';

fdescribe('SwitchOrgPage', () => {
describe('SwitchOrgPage', () => {
let component: SwitchOrgPage;
let fixture: ComponentFixture<SwitchOrgPage>;
let loaderService: jasmine.SpyObj<LoaderService>;
Expand Down
172 changes: 119 additions & 53 deletions src/app/fyle/spender-onboarding/spender-onboarding.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpenderOnboardingPage>;
let loaderService: jasmine.SpyObj<LoaderService>;
Expand All @@ -33,6 +35,7 @@ fdescribe('SpenderOnboardingPage', () => {
'skipSmsOptInStep',
'markSmsOptInStepAsComplete',
'markWelcomeModalStepAsComplete',
'setOnboardingStatusEvent',
]);
const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']);
const corporateCreditCardExpenseServiceSpy = jasmine.createSpyObj('CorporateCreditCardExpenseService', [
Expand Down Expand Up @@ -63,64 +66,127 @@ fdescribe('SpenderOnboardingPage', () => {
CorporateCreditCardExpenseService
) as jasmine.SpyObj<CorporateCreditCardExpenseService>;
router = TestBed.inject(Router) as jasmine.SpyObj<Router>;
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();
}));
});
});
29 changes: 28 additions & 1 deletion src/app/post-verification/invited-user/invited-user.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InvitedUserPage>;
let networkService: jasmine.SpyObj<NetworkService>;
Expand All @@ -38,6 +43,8 @@ fdescribe('InvitedUserPage', () => {
let trackingService: jasmine.SpyObj<TrackingService>;
let matSnackBar: jasmine.SpyObj<MatSnackBar>;
let snackbarProperties: jasmine.SpyObj<SnackbarPropertiesService>;
let orgSettingsService: jasmine.SpyObj<OrgSettingsService>;
let spenderOnboardingService: jasmine.SpyObj<SpenderOnboardingService>;

beforeEach(waitForAsync(() => {
const networkServiceSpy = jasmine.createSpyObj('NetworkService', ['connectivityWatcher', 'isOnline']);
Expand All @@ -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],
Expand All @@ -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();
Expand All @@ -81,6 +92,8 @@ fdescribe('InvitedUserPage', () => {
trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj<TrackingService>;
matSnackBar = TestBed.inject(MatSnackBar) as jasmine.SpyObj<MatSnackBar>;
snackbarProperties = TestBed.inject(SnackbarPropertiesService) as jasmine.SpyObj<SnackbarPropertiesService>;
spenderOnboardingService = TestBed.inject(SpenderOnboardingService) as jasmine.SpyObj<SpenderOnboardingService>;
orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj<OrgSettingsService>;

networkService.connectivityWatcher.and.returnValue(new EventEmitter());
networkService.isOnline.and.returnValue(of(true));
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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']);
}));
});

0 comments on commit 7946a08

Please sign in to comment.