Skip to content

Commit

Permalink
test: Fix tests related to newer imports (#3412)
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha authored Jan 9, 2025
1 parent 73f752e commit 9250085
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 77 deletions.
42 changes: 40 additions & 2 deletions src/app/auth/switch-org/switch-org.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';
Expand Down Expand Up @@ -73,6 +78,8 @@ describe('SwitchOrgPage', () => {
let transactionService: jasmine.SpyObj<TransactionService>;
let expensesService: jasmine.SpyObj<ExpensesService>;
let deepLinkService: jasmine.SpyObj<DeepLinkService>;
let orgSettingsService: jasmine.SpyObj<OrgSettingsService>;
let spenderOnboardingService: jasmine.SpyObj<SpenderOnboardingService>;

beforeEach(waitForAsync(() => {
const platformSpy = jasmine.createSpyObj('Platform', ['is']);
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -150,6 +159,14 @@ describe('SwitchOrgPage', () => {
provide: LoaderService,
useValue: loaderServiceSpy,
},
{
provide: OrgSettingsService,
useValue: orgSettingsServiceSpy,
},
{
provide: SpenderOnboardingService,
useValue: spenderOnboardingServiceSpy,
},
{
provide: UserService,
useValue: userServiceSpy,
Expand Down Expand Up @@ -256,11 +273,14 @@ describe('SwitchOrgPage', () => {
deepLinkService = TestBed.inject(DeepLinkService) as jasmine.SpyObj<DeepLinkService>;
transactionService = TestBed.inject(TransactionService) as jasmine.SpyObj<TransactionService>;
expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj<ExpensesService>;
spenderOnboardingService = TestBed.inject(SpenderOnboardingService) as jasmine.SpyObj<SpenderOnboardingService>;
orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj<OrgSettingsService>;

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', () => {
Expand Down Expand Up @@ -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();
});
});
Expand Down
8 changes: 6 additions & 2 deletions src/app/auth/switch-org/switch-org.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
role="button"
(click)="enrollCards()"
appFormButtonValidation
[disabled]="!fg.valid"
[loading]="cardsEnrolling"
[loadingText]="'Continue'"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { HttpErrorResponse } from '@angular/common/http';
import {
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
} from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { AbstractControl, FormBuilder, FormControl, FormGroup, ValidationErrors, Validators } from '@angular/forms';
import { PopoverController } from '@ionic/angular';
import { error } from 'console';
import { catchError, concatMap, from, map, noop, of, switchMap, tap } from 'rxjs';
import { catchError, concatMap, from, map, of } from 'rxjs';
import { CardNetworkType } from 'src/app/core/enums/card-network-type';
import { OrgSettings } from 'src/app/core/models/org-settings.model';
import { OverlayResponse } from 'src/app/core/models/overlay-response.modal';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ng-container *ngIf="optInFlowState === OptInFlowState.MOBILE_INPUT">
<div class="opt-in-step__mobile-input-container">
<div class="opt-in-step__mobile-input-container__label">
<span> Mobile number </span>
<span> Mobile Number </span>
</div>
<input
#mobileInput
Expand Down Expand Up @@ -91,8 +91,21 @@
</div>
</div>

<div class="opt-in-step__primary-cta-container" *ngIf="optInFlowState === OptInFlowState.MOBILE_INPUT">
<ion-button class="btn-primary opt-in-step__primary-cta" fill="clear" role="button" (click)="saveMobileNumber()">
<div
class="opt-in-step__cta-container"
[ngClass]="{ 'opt-in-step__without-go-back': !showGoBackCta, 'opt-in-step__with-go-back': showGoBackCta }"
>
<div fill="clear" class="opt-in-step__cta-secondary" (click)="goBackToConnectCard()" *ngIf="showGoBackCta">
<ion-icon class="opt-in-step__arrow-icon" [src]="'/assets/svg/arrow-left.svg'" slot="icon-only"></ion-icon>
<span class="opt-in-step__cta-text">Go back</span>
</div>
<ion-button
*ngIf="optInFlowState === OptInFlowState.MOBILE_INPUT"
class="btn-primary opt-in-step__primary-cta"
fill="clear"
role="button"
(click)="saveMobileNumber()"
>
Continue
</ion-button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
height: 100%;
}

&__primary-cta-container {
&__cta-container {
display: flex;
flex-direction: row;
justify-content: flex-end;
}

&__card-number-input {
width: fit-content !important;
margin-right: 24px;
&::placeholder {
word-spacing: 24px;
}
&__with-go-back {
justify-content: space-between;
}

&__without-go-back {
justify-content: flex-end;
}

&__heading {
Expand All @@ -46,6 +45,7 @@
&__primary-cta {
width: 108px;
align-self: flex-end;
margin-bottom: 20px;
}

&__toolbar-title {
Expand Down Expand Up @@ -73,7 +73,7 @@
}

&__input-container {
padding: 16px 16px 8px;
padding: 16px 16px 8px 16px;
border-radius: 8px;
border: 1px solid $grey;

Expand Down Expand Up @@ -269,22 +269,11 @@
}
}

&__primary-cta {
margin: 16px auto;
width: 90%;

.mat-button-base {
width: 100%;
font-weight: 700;
min-height: 47px;
}
}

&__otp-container {
display: flex;
justify-content: center;
justify-content: flex-start;
align-items: center;
margin-bottom: 32px;
margin-bottom: 16px;

&__label {
margin: 0 8px 0 0;
Expand Down Expand Up @@ -400,15 +389,29 @@
font-size: 14px;
}
}

&__help-article-icon {
margin: 4px 0px 0px 6px;
width: 14px;
height: 14px;
}
}

&__footer {
margin-bottom: calc(env(safe-area-inset-bottom));
}

&__cta-text {
font-size: 14px;
font-weight: 500;
}

&__arrow-icon {
margin-right: 6px;
height: 18px;
width: 18px;
}

&__cta-secondary {
display: flex;
align-items: center;
justify-content: center;
color: $blue-black;
flex-direction: row;
padding: 16px 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,8 +37,8 @@ describe('SpenderOnboardingOptInStepComponent', () => {
let trackingService: jasmine.SpyObj<TrackingService>;
let matSnackbar: jasmine.SpyObj<MatSnackBar>;
let loaderService: jasmine.SpyObj<LoaderService>;
let platformHandlerService: jasmine.SpyObj<PlatformHandlerService>;
let userEventService: jasmine.SpyObj<UserEventService>;
let spenderOnboardingService: jasmine.SpyObj<SpenderOnboardingService>;
let fb: FormBuilder;

beforeEach(waitForAsync(() => {
Expand All @@ -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],
Expand All @@ -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();
Expand All @@ -96,7 +100,7 @@ describe('SpenderOnboardingOptInStepComponent', () => {
trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj<TrackingService>;
matSnackbar = TestBed.inject(MatSnackBar) as jasmine.SpyObj<MatSnackBar>;
loaderService = TestBed.inject(LoaderService) as jasmine.SpyObj<LoaderService>;
platformHandlerService = TestBed.inject(PlatformHandlerService) as jasmine.SpyObj<PlatformHandlerService>;
spenderOnboardingService = TestBed.inject(SpenderOnboardingService) as jasmine.SpyObj<SpenderOnboardingService>;
userEventService = TestBed.inject(UserEventService) as jasmine.SpyObj<UserEventService>;
fb = TestBed.inject(FormBuilder);
}));
Expand All @@ -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', () => {
Expand Down
Loading

0 comments on commit 9250085

Please sign in to comment.