From 0b833aedcfb869970e4190e4ae590db781c8c45c Mon Sep 17 00:00:00 2001 From: Devansh Vashisht Date: Mon, 9 Nov 2026 18:06:45 +0530 Subject: [PATCH] WEB-1430: Fix the two Jest specs failing on dev - create-gsim-account.charges.spec.ts: provide GroupsService, which the component injects since WEB-1388. - prepay-loan.component.spec.ts: stub the :loanId/actions/:action route with pathFromRoot, which the base component navigates from since WEB-657, and assert the loan general tab it lands on. --- .../prepay-loan/prepay-loan.component.spec.ts | 31 ++++++++++++++++--- .../create-gsim-account.charges.spec.ts | 3 ++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/app/loans/loans-view/loan-account-actions/prepay-loan/prepay-loan.component.spec.ts b/src/app/loans/loans-view/loan-account-actions/prepay-loan/prepay-loan.component.spec.ts index 7101174649..5005055fcd 100644 --- a/src/app/loans/loans-view/loan-account-actions/prepay-loan/prepay-loan.component.spec.ts +++ b/src/app/loans/loans-view/loan-account-actions/prepay-loan/prepay-loan.component.spec.ts @@ -42,6 +42,24 @@ describe('PrepayLoanComponent - contract termination', () => { let loansServiceStub: any; let routerStub: any; + /** + * The action route as the router activates it: `:loanId/actions/:action`, the + * route the base component walks up to when it navigates to a loan tab. + */ + function actionRouteStub(): any { + const loansContainerRoute: any = {}; + const route: any = { + routeConfig: { path: ':loanId/actions/:action' }, + parent: loansContainerRoute, + snapshot: { params: { loanId: '1' } } + }; + route.pathFromRoot = [ + loansContainerRoute, + route + ]; + return route; + } + /** * Builds the component against stubbed collaborators and runs ngOnInit, so the tests exercise the real form, * date bounds and payload logic without rendering the template. @@ -54,10 +72,7 @@ describe('PrepayLoanComponent - contract termination', () => { providers: [ FormBuilder, { provide: ChangeDetectorRef, useValue: { markForCheck: jest.fn() } }, - { - provide: ActivatedRoute, - useValue: { snapshot: { params: { loanId: '1' } } } - }, + { provide: ActivatedRoute, useValue: actionRouteStub() }, { provide: Router, useValue: routerStub }, { provide: LoansService, useValue: loansServiceStub }, { @@ -220,7 +235,15 @@ describe('PrepayLoanComponent - contract termination', () => { locale: 'en', dateFormat: 'dd MMMM yyyy' }); + // Back to the loan's general tab, built from the route that holds `:loanId` rather than `../` counting. expect(routerStub.navigate).toHaveBeenCalledTimes(1); + expect(routerStub.navigate).toHaveBeenCalledWith( + [ + '1', + 'general' + ], + { queryParams: { productType: 'loan' }, relativeTo: TestBed.inject(ActivatedRoute).parent } + ); }); it('leaves the prepay flow on the business date bound and asks for no loan details', () => { diff --git a/src/app/savings/gsim-account/create-gsim-account/create-gsim-account.charges.spec.ts b/src/app/savings/gsim-account/create-gsim-account/create-gsim-account.charges.spec.ts index 10317bc867..9a8eb1f37b 100644 --- a/src/app/savings/gsim-account/create-gsim-account/create-gsim-account.charges.spec.ts +++ b/src/app/savings/gsim-account/create-gsim-account/create-gsim-account.charges.spec.ts @@ -10,6 +10,7 @@ import { TestBed } from '@angular/core/testing'; import { ActivatedRoute, Router } from '@angular/router'; import { of } from 'rxjs'; import { Dates } from 'app/core/utils/dates'; +import { GroupsService } from 'app/groups/groups.service'; import { SettingsService } from 'app/settings/settings.service'; import { SavingsService } from '../../savings.service'; import { CreateGsimAccountComponent } from './create-gsim-account.component'; @@ -32,6 +33,8 @@ describe('CreateGsimAccountComponent charges', () => { }, { provide: Router, useValue: { navigate: jest.fn() } }, { provide: SavingsService, useValue: {} }, + // only submit() looks the new GSIM account up; building the request bodies never calls it + { provide: GroupsService, useValue: {} }, { provide: SettingsService, useValue: { language: { code: 'en' }, dateFormat: 'dd MMMM yyyy' } }, // the dates already hold their display text, so formatting keeps it { provide: Dates, useValue: { formatDate: (value: any): string => value } }