Skip to content

Commit

Permalink
Fix bugs, add tests (2597, 2599, 2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-HMCTS committed Dec 10, 2024
1 parent c99fa77 commit 29489c0
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { ShowCondition } from '../../../directives';
import createSpyObj = jasmine.createSpyObj;
import { LinkedCasesService } from '../../palette/linked-cases/services/linked-cases.service';
import { CaseFlagStateService } from '../services/case-flag-state.service';
import { CaseTab } from 'ccd-case-ui-toolkit';

describe('CaseEditPageComponent - creation and update event trigger tests', () => {
let component: CaseEditPageComponent;
Expand All @@ -77,11 +78,11 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =

const CASE_TYPES_2 = [
{
id: 'Benefit_Xui',
name: 'Benefit_Xui',
description: '',
states: [],
events: [],
id: 'Benefit_Xui',
name: 'Benefit_Xui',
description: '',
states: [],
events: [],
}];
const MOCK_JURISDICTION: Jurisdiction[] = [{
id: 'JURI_1',
Expand Down Expand Up @@ -113,7 +114,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
linkedCasesService = {},
caseFlagStateService = new CaseFlagStateService()
}) =>
new CaseEditPageComponent(
new CaseEditPageComponent(
caseEdit as CaseEditComponent,
route as ActivatedRoute,
formValueService as FormValueService,
Expand All @@ -129,7 +130,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
addressesService as AddressesService,
linkedCasesService as LinkedCasesService,
caseFlagStateService as CaseFlagStateService
);
);

it('should create', () => {
component = initializeComponent({});
Expand Down Expand Up @@ -175,7 +176,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
});

describe('updateEventTriggerCaseFields', () => {
it(`should NOT update event trigger's case fields as eventTrigger is null`, () => {
it('should NOT update event trigger\'s case fields as eventTrigger is null', () => {
component = initializeComponent({});
const caseFieldIdMock = 'bothDefendants';
const jsonDataMock = {} as unknown as CaseEventData;
Expand All @@ -186,7 +187,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
expect(eventTriggerMock).toBeNull();
});

it(`should NOT update event trigger's case fields as eventTrigger has no case fields`, () => {
it('should NOT update event trigger\'s case fields as eventTrigger has no case fields', () => {
component = initializeComponent({});
const caseFieldIdMock = 'bothDefendants';
const jsonDataMock = {} as unknown as CaseEventData;
Expand All @@ -197,7 +198,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
expect(eventTriggerMock).toEqual(jasmine.objectContaining({ id: 'noCaseFields' }));
});

it(`should update event trigger's case fields value`, () => {
it('should update event trigger\'s case fields value', () => {
component = initializeComponent({});
const caseFieldIdMock = 'bothDefendants';
const jsonDataMock = {
Expand All @@ -219,7 +220,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
expect(eventTriggerMock['case_fields'][0].value).toEqual(true);
});

it(`should update event trigger's case fields value with jsonData's object`, () => {
it('should update event trigger\'s case fields value with jsonData\'s object', () => {
component = initializeComponent({});
const caseFieldIdMock = 'bothDefendants';
const result = {
Expand All @@ -246,7 +247,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
expect(eventTriggerMock['case_fields'][0].value).toEqual(jasmine.objectContaining(result));
});

it(`should NOT update event trigger's case fields value as jsonData's value is null`, () => {
it('should NOT update event trigger\'s case fields value as jsonData\'s value is null', () => {
component = initializeComponent({});
const caseFieldIdMock = 'bothDefendants';
const result = {
Expand Down Expand Up @@ -279,7 +280,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
expect(eventTriggerMock['case_fields'][0].value).toEqual(jasmine.objectContaining(result));
});

it(`should NOT update event trigger's case fields value as jsonData's value is undefined`, () => {
it('should NOT update event trigger\'s case fields value as jsonData\'s value is undefined', () => {
component = initializeComponent({});
const caseFieldIdMock = 'bothDefendants';
const result = {
Expand Down Expand Up @@ -310,7 +311,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
expect(eventTriggerMock['case_fields'][0].value).toEqual(jasmine.objectContaining(result));
});

it(`should update event trigger's case fields value as jsonData's value is present`, () => {
it('should update event trigger\'s case fields value as jsonData\'s value is present', () => {
component = initializeComponent({});
const caseFieldIdMock = 'bothDefendants';
const result = {
Expand Down Expand Up @@ -438,11 +439,11 @@ describe('CaseEditPageComponent - all other tests', () => {

const CASE_TYPES_2 = [
{
id: 'Benefit_Xui',
name: 'Benefit_Xui',
description: '',
states: [],
events: [],
id: 'Benefit_Xui',
name: 'Benefit_Xui',
description: '',
states: [],
events: [],
}];
const MOCK_JURISDICTION: Jurisdiction[] = [{
id: 'JURI_1',
Expand All @@ -457,6 +458,7 @@ describe('CaseEditPageComponent - all other tests', () => {
jurisdictionService.getJurisdictions.and.returnValue(of(MOCK_JURISDICTION));
const linkedCasesService = new LinkedCasesService(jurisdictionService, searchService);
const caseFlagStateService = new CaseFlagStateService();
let linkedCasesServiceSpy: jasmine.SpyObj<LinkedCasesService>;

describe('Save and Resume enabled', () => {
const eventTrigger = {
Expand Down Expand Up @@ -576,7 +578,7 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService },
{ provide: AddressesService, useValue: addressesServiceMock },
{ provide: MultipageComponentStateService, useValue: multipageComponentStateService },
{ provide: LinkedCasesService, useValue: linkedCasesService },
Expand Down Expand Up @@ -868,6 +870,29 @@ describe('CaseEditPageComponent - all other tests', () => {
expect(caseFlagStateService.fieldStateToNavigate).toEqual(3);
expect(caseFlagStateService.lastPageFieldState).toEqual(3);
});

it('should remove any unsibmitted data on cancel', () => {
comp.eventTrigger = eventTrigger as CaseEventTrigger;
comp.currentPage = wizardPage;
comp.caseEdit.caseDetails.tabs = [{
id: '123',
fields: [
{
id: 'caseLinks',
value: [
{ value: { CaseReference: 'REF1' } },
{ value: { CaseReference: 'REF2' } },
{ value: { CaseReference: 'REF3' } }
]
}
]
}] as CaseTab[];
linkedCasesServiceSpy = TestBed.inject(LinkedCasesService) as jasmine.SpyObj<LinkedCasesService>;
spyOn(comp, 'isLinkedCasesJourney').and.returnValues(true);
linkedCasesService.initialCaseLinkRefs = ['REF1'];
comp.cancel();
expect(comp.caseEdit.caseDetails.tabs[0].fields[0].value).toEqual([{ 'value': { 'CaseReference': 'REF1' } }]);
});
});

describe('Save and Resume disabled', () => {
Expand Down Expand Up @@ -984,7 +1009,7 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService },
{ provide: AddressesService, useValue: addressesServiceMock },
{ provide: LinkedCasesService, useValue: linkedCasesService },
{ provide: CaseFlagStateService, useValue: caseFlagStateService }
Expand Down Expand Up @@ -1153,7 +1178,7 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService },
{ provide: AddressesService, useValue: addressesServiceMock },
{ provide: LinkedCasesService, useValue: linkedCasesService },
{ provide: CaseFlagStateService, useValue: caseFlagStateService }
Expand Down Expand Up @@ -1327,7 +1352,7 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService },
{ provide: AddressesService, useValue: addressesServiceMock },
{ provide: LinkedCasesService, useValue: linkedCasesService },
{ provide: CaseFlagStateService, useValue: caseFlagStateService }
Expand Down Expand Up @@ -1676,8 +1701,8 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
{ provide: AddressesService, useValue: addressesServiceMock},
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService },
{ provide: AddressesService, useValue: addressesServiceMock },
{ provide: LinkedCasesService, useValue: linkedCasesService },
{ provide: CaseFlagStateService, useValue: caseFlagStateService }
],
Expand Down Expand Up @@ -1732,7 +1757,7 @@ describe('CaseEditPageComponent - all other tests', () => {
const value = control.value;

if (!value) {
return {mockRequired:true};
return { mockRequired: true };
}
}
}
Expand Down Expand Up @@ -1787,7 +1812,7 @@ describe('CaseEditPageComponent - all other tests', () => {
id: 'AddressLine1',
label: 'AddressLine1',
display_context: 'MANDATORY',
field_type: {id: 'Text', type: 'Text'},
field_type: { id: 'Text', type: 'Text' },
value: '',
} as CaseField;

Expand Down Expand Up @@ -1897,7 +1922,7 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService },
{ provide: AddressesService, useValue: addressesServiceMock },
{ provide: LinkedCasesService, useValue: linkedCasesService },
{ provide: CaseFlagStateService, useValue: caseFlagStateService }
Expand Down Expand Up @@ -1944,7 +1969,7 @@ describe('CaseEditPageComponent - all other tests', () => {
expect(comp.validationErrors.length).toBe(3);
comp.generateErrorMessage(wizardPage.case_fields);
comp.validationErrors.forEach((error) => {
expect(error.message).toEqual(`%FIELDLABEL% is required`);
expect(error.message).toEqual('%FIELDLABEL% is required');
});
});

Expand Down Expand Up @@ -1977,7 +2002,7 @@ describe('CaseEditPageComponent - all other tests', () => {
comp.generateErrorMessage(wizardPage.case_fields);
comp.validationErrors.forEach((error) => {
expect(error.message).toEqual(
`The field that is causing the error cannot be determined but there is an error present. Please fill in more of the form`
'The field that is causing the error cannot be determined but there is an error present. Please fill in more of the form'
);
});
});
Expand All @@ -1997,7 +2022,7 @@ describe('CaseEditPageComponent - all other tests', () => {
comp.generateErrorMessage(wizardPage.case_fields);
comp.validationErrors.forEach((error) => {
expect(error.message).toEqual(
`The field that is causing the error cannot be determined but there is an error present`
'The field that is causing the error cannot be determined but there is an error present'
);
});
});
Expand Down Expand Up @@ -2031,7 +2056,7 @@ describe('CaseEditPageComponent - all other tests', () => {
comp.generateErrorMessage(wizardPage.case_fields);
comp.validationErrors.forEach((error) => {
expect(error.message).toEqual(
`%FIELDLABEL% is below the minimum length`
'%FIELDLABEL% is below the minimum length'
);
});
});
Expand Down Expand Up @@ -2064,7 +2089,7 @@ describe('CaseEditPageComponent - all other tests', () => {

comp.generateErrorMessage(wizardPage.case_fields);
comp.validationErrors.forEach((error) => {
expect(error.message).toEqual(`%FIELDLABEL% exceeds the maximum length`);
expect(error.message).toEqual('%FIELDLABEL% exceeds the maximum length');
});
});

Expand Down Expand Up @@ -2112,7 +2137,7 @@ describe('CaseEditPageComponent - all other tests', () => {
comp.generateErrorMessage(wizardPage.case_fields);

comp.validationErrors.forEach((error) => {
expect(error.message).toEqual(`%FIELDLABEL% is required`);
expect(error.message).toEqual('%FIELDLABEL% is required');
});
});

Expand Down Expand Up @@ -2157,7 +2182,7 @@ describe('CaseEditPageComponent - all other tests', () => {
expect(comp.validationErrors.length).toBe(1);
comp.generateErrorMessage(wizardPage.case_fields);
comp.validationErrors.forEach((error) => {
expect(error.message).toEqual(`There is an internal issue with complexField2 fields. The field that is causing the error cannot be determined but there is an error present`);
expect(error.message).toEqual('There is an internal issue with complexField2 fields. The field that is causing the error cannot be determined but there is an error present');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,17 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro

public cancel(): void {
if (this.isLinkedCasesJourney()){
// if the user cancels the journey we need to clean up the data
const linkedCasesTab = this.caseEdit.caseDetails.tabs.find((tab) =>
tab?.fields?.some((field) => field.id === 'caseLinks')
)?.fields?.[0] ?? null;
const initalLinks = this.linkedCasesService.initialCaseLinkRefs;
if (linkedCasesTab && linkedCasesTab?.value.length !== initalLinks.length){
const initialCaseRefs = this.linkedCasesService.initialCaseLinkRefs;
linkedCasesTab.value = linkedCasesTab.value.filter((item) =>
initialCaseRefs.includes(item.value.CaseReference)
);
}
this.linkedCasesService.resetLinkedCaseData();
}
if (this.eventTrigger.can_save_draft) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, of } from 'rxjs';
import { PlaceholderService } from '../../../directives/substitutor/services';

import { CaseField, Jurisdiction, Profile } from '../../../domain';
import { CaseField, CaseTab, Jurisdiction, Profile } from '../../../domain';
import { createAProfile } from '../../../domain/profile/profile.test.fixture';
import { aCaseField } from '../../../fixture/shared.test.fixture';
import { CaseReferencePipe } from '../../../pipes/case-reference/case-reference.pipe';
Expand Down Expand Up @@ -132,6 +132,7 @@ describe('CaseEditSubmitComponent', () => {
let profileNotifier: ProfileNotifier;
let casesReferencePipe: jasmine.SpyObj<CaseReferencePipe>;
let formValidatorsService: jasmine.SpyObj<FormValidatorsService>;
let linkedCasesServiceSpy: jasmine.SpyObj<LinkedCasesService>;
const caseField1: CaseField = aCaseField('field1', 'field1', 'Text', 'OPTIONAL', 4);
const caseField2: CaseField = aCaseField('field2', 'field2', 'Text', 'OPTIONAL', 3, null, false, true);
const caseField3: CaseField = aCaseField('field3', 'field3', 'Text', 'OPTIONAL', 2);
Expand Down Expand Up @@ -803,6 +804,26 @@ describe('CaseEditSubmitComponent', () => {
const previousButton = de.query(By.css('.button-secondary'));
expect(previousButton.nativeElement.textContent).toContain('Previous');
});

it('should remove any unsibmitted data on cancel', () => {
comp.caseEdit.caseDetails.tabs = [{
id: '123',
fields: [
{
id: 'caseLinks',
value: [
{ value: { CaseReference: 'REF1' } },
{ value: { CaseReference: 'REF2' } },
{ value: { CaseReference: 'REF3' } }
]
}
]
}] as CaseTab[];
caseEditComponent.isLinkedCasesSubmission = true;
linkedCasesService.initialCaseLinkRefs = ['REF1'];
comp.cancel();
expect(comp.caseEdit.caseDetails.tabs[0].fields[0].value).toEqual([{ 'value': { 'CaseReference': 'REF1' } }]);
});
});

describe('CaseEditSubmitComponent without custom end button label and with Save and Resume enabled', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export class CaseEditSubmitComponent implements OnInit, OnDestroy {

public submit(): void {
if (this.summary.valid && this.description.valid) {
if (this.caseEdit.isLinkedCasesSubmission){
// once the user submits the linked cases we need to reset the service so data isnt retained if they open the event again
this.linkedCasesService.resetLinkedCaseData();
}
this.caseEdit.submitForm({
eventTrigger: this.eventTrigger,
form: this.editForm,
Expand Down Expand Up @@ -174,6 +178,17 @@ export class CaseEditSubmitComponent implements OnInit, OnDestroy {

public cancel(): void {
if (this.caseEdit.isLinkedCasesSubmission){
// if they cancel on the last CYA page we should ensure there is no unsubmitted data in the caseDetails
const linkedCasesTab = this.caseEdit.caseDetails.tabs.find((tab) =>
tab?.fields?.some((field) => field.id === 'caseLinks')
)?.fields?.[0] ?? null;
const initalLinks = this.linkedCasesService.initialCaseLinkRefs;
if (linkedCasesTab && linkedCasesTab?.value.length !== initalLinks.length){
const initialCaseRefs = this.linkedCasesService.initialCaseLinkRefs;
linkedCasesTab.value = linkedCasesTab.value.filter((item) =>
initialCaseRefs.includes(item.value.CaseReference)
);
}
this.linkedCasesService.resetLinkedCaseData();
}
if (this.eventTrigger.can_save_draft) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export class ConfirmFlagStatusComponent extends AbstractJourneyComponent impleme
this.formGroup.addControl(this.selectedStatusControlName, new FormControl(this.flagCreationStatuses.find(
key => CaseFlagStatus[key] === this.defaultStatus)));
this.formGroup.addControl(this.statusReasonControlName, new FormControl(''));
if (this.multipageComponentStateService.getJourneyCollectionMainObject().journeyPageNumber === CaseFlagFieldState.FLAG_STATUS) {
this.multipageComponentStateService.getJourneyCollectionMainObject().journeyPageNumber = CaseFlagFieldState.FLAG_COMMENTS;
}
}

public onNext(): void {
Expand Down
Loading

0 comments on commit 29489c0

Please sign in to comment.