Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha committed Jan 8, 2025
1 parent e389470 commit 0c79118
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 11 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 @@ -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
3 changes: 3 additions & 0 deletions src/app/fyle/spender-onboarding/spender-onboarding.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 23 additions & 5 deletions src/app/shared/components/sidemenu/sidemenu.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,6 +53,7 @@ describe('SidemenuComponent', () => {
let orgService: jasmine.SpyObj<OrgService>;
let authService: jasmine.SpyObj<AuthService>;
let orgUserSettingsService: jasmine.SpyObj<OrgUserSettingsService>;
let spenderOnboardingService: jasmine.SpyObj<SpenderOnboardingService>;

@Component({
selector: 'app-sidemenu',
Expand Down Expand Up @@ -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],
Expand All @@ -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();
Expand All @@ -116,6 +122,7 @@ describe('SidemenuComponent', () => {
orgService = TestBed.inject(OrgService) as jasmine.SpyObj<OrgService>;
authService = TestBed.inject(AuthService) as jasmine.SpyObj<AuthService>;
orgUserSettingsService = TestBed.inject(OrgUserSettingsService) as jasmine.SpyObj<OrgUserSettingsService>;
spenderOnboardingService = TestBed.inject(SpenderOnboardingService) as jasmine.SpyObj<SpenderOnboardingService>;

networkService.connectivityWatcher.and.returnValue(new EventEmitter());

Expand Down Expand Up @@ -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
);
Expand All @@ -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():', () => {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0c79118

Please sign in to comment.