Skip to content

Commit

Permalink
test: Add tests for Connnect Card - 1 (#3410)
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha authored Jan 10, 2025
1 parent 8f4abaf commit e44959e
Show file tree
Hide file tree
Showing 16 changed files with 599 additions and 98 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
Loading

0 comments on commit e44959e

Please sign in to comment.