Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 },
{
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 } }
Expand Down