Skip to content

Commit

Permalink
Exui 837 cya fix (#1581)
Browse files Browse the repository at this point in the history
* Revert "Revert "fix for exui-837 (#1559)" (#1576)"

This reverts commit bb05e82.

* Candidate fix for issues with 837 fix

* updated fix and unit tests for exui-837

* lint

---------

Co-authored-by: RiteshHMCTS <[email protected]>
Co-authored-by: Ritesh Dsouza <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2023
1 parent bb05e82 commit dbb0d17
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "6.19.5",
"version": "6.19.8",
"engines": {
"yarn": "^3.5.0",
"npm": "^8.10.0"
Expand Down
2 changes: 1 addition & 1 deletion projects/ccd-case-ui-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "6.19.5",
"version": "6.19.8",
"engines": {
"yarn": "^3.5.0",
"npm": "^8.10.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
FormValueService,
LoadingService,
} from '../../../services';
import { ValidPageListCaseFieldsService } from '../services/valid-page-list-caseFields.service';
import { FieldsUtils } from '../../../services/fields/fields.utils';
import { text } from '../../../test/helpers';
import { MockRpxTranslatePipe } from '../../../test/mock-rpx-translate.pipe';
Expand All @@ -52,7 +53,7 @@ import { Wizard, WizardPage } from '../domain';
import { PageValidationService } from '../services';
import { CaseEditPageText } from './case-edit-page-text.enum';
import { CaseEditPageComponent } from './case-edit-page.component';

import { ShowCondition } from '../../../directives';
import createSpyObj = jasmine.createSpyObj;

describe('CaseEditPageComponent - creation and update event trigger tests', () => {
Expand All @@ -76,6 +77,7 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
caseFieldService = {},
caseEditDataService = {},
loadingService = {},
validPageListCaseFieldsService = {}
}) =>
new CaseEditPageComponent(
caseEdit as CaseEditComponent,
Expand All @@ -87,7 +89,8 @@ describe('CaseEditPageComponent - creation and update event trigger tests', () =
dialog as MatDialog,
caseFieldService as CaseFieldService,
caseEditDataService as CaseEditDataService,
loadingService as LoadingService
loadingService as LoadingService,
validPageListCaseFieldsService as ValidPageListCaseFieldsService
);

it('should create', () => {
Expand Down Expand Up @@ -294,15 +297,33 @@ describe('CaseEditPageComponent - all other tests', () => {
let wizardPage = createWizardPage(
[createCaseField('field1', 'field1Value')],
false,
0
0,
1
);
const wizardPage1 = createWizardPage(
[createCaseField('field1', 'field1Value')],
false,
0,
2
);
const wizardPage2 = createWizardPage(
[createCaseField('field3', 'field3Value')],
false,
0,
3
);
wizardPage1.parsedShowCondition = ShowCondition.getInstance(null);
wizardPage2.parsedShowCondition = ShowCondition.getInstance(null);
const pageList = [wizardPage1, wizardPage2];
const readOnly = new CaseField();
const fieldTypeSanitiser = new FieldTypeSanitiser();
const formValueService = new FormValueService(fieldTypeSanitiser);
const formErrorService = new FormErrorService();
const firstPage = new WizardPage();
const caseFieldService = new CaseFieldService();
const pageValidationService = new PageValidationService(caseFieldService);
const fieldsUtils = new FieldsUtils();
const validPageListCaseFieldsService = new ValidPageListCaseFieldsService(fieldsUtils);
let route: any;
let snapshot: any;
const FORM_GROUP_NO_JUDICIAL_USERS = new FormGroup({
Expand Down Expand Up @@ -352,6 +373,7 @@ describe('CaseEditPageComponent - all other tests', () => {
firstPage.case_fields = [
createCaseField('field1', 'SOME_VALUE')
];
firstPage.parsedShowCondition = ShowCondition.getInstance(null);
cancelled = createSpyObj('cancelled', ['emit']);
caseEditComponentStub = {
form: FORM_GROUP,
Expand All @@ -373,7 +395,8 @@ describe('CaseEditPageComponent - all other tests', () => {
metadataFields: [caseField2],
},
getNextPage: () => null,
callbackErrorsSubject: new Subject<any>()
callbackErrorsSubject: new Subject<any>(),
validPageList: pageList
};
snapshot = {
queryParamMap: createSpyObj('queryParamMap', ['get']),
Expand Down Expand Up @@ -448,9 +471,10 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: MatDialog, useValue: dialog },
{ provide: CaseFieldService, useValue: caseFieldService },
{ provide: CaseEditDataService, useValue: caseEditDataService },
FieldsUtils,
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock }
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
],
}).compileComponents();
fixture = TestBed.createComponent(CaseEditPageComponent);
Expand Down Expand Up @@ -766,7 +790,8 @@ describe('CaseEditPageComponent - all other tests', () => {
metadataFields: [],
},
getNextPage: () => null,
callbackErrorsSubject: new Subject<any>()
callbackErrorsSubject: new Subject<any>(),
validPageList: pageList
};
snapshot = {
queryParamMap: createSpyObj('queryParamMap', ['get']),
Expand Down Expand Up @@ -841,9 +866,10 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: MatDialog, useValue: dialog },
{ provide: CaseFieldService, useValue: caseFieldService },
{ provide: CaseEditDataService, useValue: caseEditDataService },
FieldsUtils,
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
],
}).compileComponents();
})
Expand Down Expand Up @@ -941,7 +967,8 @@ describe('CaseEditPageComponent - all other tests', () => {
title_display: '# 1234567812345678: test',
},
},
getNextPage: () => null
getNextPage: () => null,
validPageList: pageList
};

route = {
Expand Down Expand Up @@ -1000,9 +1027,10 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: MatDialog, useValue: dialog },
{ provide: CaseFieldService, useValue: caseFieldService },
{ provide: CaseEditDataService, useValue: caseEditDataService },
FieldsUtils,
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
],
}).compileComponents();
})
Expand Down Expand Up @@ -1097,7 +1125,8 @@ describe('CaseEditPageComponent - all other tests', () => {
},
getNextPage: () => null,
callbackErrorsSubject: new Subject<any>(),
ignoreWarning: true
ignoreWarning: true,
validPageList: pageList
};
snapshot = {
queryParamMap: createSpyObj('queryParamMap', ['get']),
Expand Down Expand Up @@ -1125,6 +1154,7 @@ describe('CaseEditPageComponent - all other tests', () => {
eventData
);
spyOn(formValueService, 'removeUnnecessaryFields');
spyOn(validPageListCaseFieldsService, 'deleteNonValidatedFields');

caseEditDataService = createSpyObj('caseEditDataService',
[
Expand Down Expand Up @@ -1166,9 +1196,10 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: MatDialog, useValue: dialog },
{ provide: CaseFieldService, useValue: caseFieldService },
{ provide: CaseEditDataService, useValue: caseEditDataService },
FieldsUtils,
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
],
}).compileComponents();
})
Expand All @@ -1185,7 +1216,8 @@ describe('CaseEditPageComponent - all other tests', () => {
aCaseField('judicialUserField2', 'judicialUser2', 'JudicialUser', 'OPTIONAL', null),
],
false,
0
0,
2
);
comp.wizard = new Wizard([wizardPage]);
// Rebuild the FORM_GROUP object before use because it gets modified by the "should call validate" test
Expand Down Expand Up @@ -1219,6 +1251,7 @@ describe('CaseEditPageComponent - all other tests', () => {
expect(formValueService.sanitise).toHaveBeenCalled();
expect(formValueService.removeUnnecessaryFields).toHaveBeenCalled();
expect(loadingServiceMock.register).toHaveBeenCalled();
expect(validPageListCaseFieldsService.deleteNonValidatedFields).toHaveBeenCalled();

fixture.whenStable().then(() => {
expect(comp.caseEdit.eventTrigger.case_id).toEqual(DRAFT_PREFIX + draft.id);
Expand Down Expand Up @@ -1422,7 +1455,8 @@ describe('CaseEditPageComponent - all other tests', () => {
metadataFields: [caseField2],
},
getNextPage: () => null,
callbackErrorsSubject: new Subject<any>()
callbackErrorsSubject: new Subject<any>(),
validPageList: pageList
};
snapshot = {
queryParamMap: createSpyObj('queryParamMap', ['get']),
Expand Down Expand Up @@ -1496,9 +1530,10 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: MatDialog, useValue: dialog },
{ provide: CaseFieldService, useValue: caseFieldService },
{ provide: CaseEditDataService, useValue: caseEditDataService },
FieldsUtils,
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock }
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
],
}).compileComponents();
})
Expand Down Expand Up @@ -1621,7 +1656,8 @@ describe('CaseEditPageComponent - all other tests', () => {
tabs: [],
metadataFields: [],
},
getNextPage: () => null
getNextPage: () => null,
validPageList: pageList
};
snapshot = {
queryParamMap: createSpyObj('queryParamMap', ['get']),
Expand Down Expand Up @@ -1690,9 +1726,10 @@ describe('CaseEditPageComponent - all other tests', () => {
{ provide: MatDialog, useValue: dialog },
{ provide: CaseFieldService, useValue: caseFieldService },
{ provide: CaseEditDataService, useValue: caseEditDataService },
FieldsUtils,
{ provide: FieldsUtils, useValue: fieldsUtils },
PlaceholderService,
{ provide: LoadingService, useValue: loadingServiceMock }
{ provide: LoadingService, useValue: loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
],
}).compileComponents();
})
Expand Down Expand Up @@ -1939,7 +1976,8 @@ describe('CaseEditPageComponent - all other tests', () => {
function createWizardPage(
fields: CaseField[] = [],
isMultiColumn = false,
order = 0
order = 0,
id = 1
): WizardPage {
const wp: WizardPage = new WizardPage();
wp.case_fields = fields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CaseEditComponent } from '../case-edit/case-edit.component';
import { WizardPage } from '../domain/wizard-page.model';
import { Wizard } from '../domain/wizard.model';
import { PageValidationService } from '../services/page-validation.service';
import { ValidPageListCaseFieldsService } from '../services/valid-page-list-caseFields.service';

@Component({
selector: 'ccd-case-edit-page',
Expand Down Expand Up @@ -72,7 +73,7 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro
}

constructor(
public readonly caseEdit: CaseEditComponent,
public caseEdit: CaseEditComponent,
private readonly route: ActivatedRoute,
private readonly formValueService: FormValueService,
private readonly formErrorService: FormErrorService,
Expand All @@ -81,7 +82,8 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro
private readonly dialog: MatDialog,
private readonly caseFieldService: CaseFieldService,
private readonly caseEditDataService: CaseEditDataService,
private readonly loadingService: LoadingService
private readonly loadingService: LoadingService,
private readonly validPageListCaseFieldsService: ValidPageListCaseFieldsService
) {
}

Expand Down Expand Up @@ -276,6 +278,9 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro
}

if (!this.caseEdit.isSubmitting && !this.currentPageIsNotValid()) {
if (this.caseEdit.validPageList.findIndex(page=> page.id === this.currentPage.id) === -1) {
this.caseEdit.validPageList.push(this.currentPage);
}
this.caseEdit.isSubmitting = true;
this.caseEdit.error = null;
const caseEventData: CaseEventData = this.buildCaseEventData();
Expand Down Expand Up @@ -566,6 +571,9 @@ export class CaseEditPageComponent implements OnInit, AfterViewChecked, OnDestro
// Get hold of the CaseEventData.
const caseEventData: CaseEventData = this.formValueService.sanitise(formFields) as CaseEventData;

// delete fields which are not part of the case event journey wizard pages case fields
this.validPageListCaseFieldsService.deleteNonValidatedFields(this.caseEdit.validPageList, caseEventData.data, this.eventTrigger.case_fields, fromPreviousPage);

// Tidy it up before we return it.
this.formValueService.removeUnnecessaryFields(caseEventData.data, caseFields, clearEmpty, clearNonCase,
fromPreviousPage, this.currentPage.case_fields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { PaletteUtilsModule } from '../../palette';
import { Confirmation, Wizard, WizardPage, WizardPageField } from '../domain';
import { CaseNotifier } from '../services';
import { WizardFactoryService } from '../services/wizard-factory.service';
import { ValidPageListCaseFieldsService } from '../services/valid-page-list-caseFields.service';
import { CaseEditComponent } from './case-edit.component';
import createSpyObj = jasmine.createSpyObj;

Expand Down Expand Up @@ -211,6 +212,7 @@ describe('CaseEditComponent', () => {
const registrarService = new ConditionalShowRegistrarService();
let route: any;
let mockSessionStorageService: jasmine.SpyObj<SessionStorageService>;
const validPageListCaseFieldsService = new ValidPageListCaseFieldsService(fieldsUtils);

describe('profile available in route', () => {
routerStub = {
Expand Down Expand Up @@ -268,6 +270,7 @@ describe('CaseEditComponent', () => {
'populateLinkedCasesDetailsFromCaseFields'
]);
mockSessionStorageService = createSpyObj<SessionStorageService>('SessionStorageService', ['getItem', 'removeItem', 'setItem']);
spyOn(validPageListCaseFieldsService, 'deleteNonValidatedFields');

route = {
queryParams: of({Origin: 'viewDraft'}),
Expand Down Expand Up @@ -317,7 +320,8 @@ describe('CaseEditComponent', () => {
{provide: ActivatedRoute, useValue: route},
SessionStorageService,
WindowService,
{ provide: LoadingService, loadingServiceMock }
{ provide: LoadingService, loadingServiceMock },
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
]
})
.compileComponents();
Expand Down Expand Up @@ -1219,6 +1223,7 @@ describe('CaseEditComponent', () => {
expect(formValueService.removeCaseFieldsOfType)
.toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Array), ['FlagLauncher', 'ComponentLauncher']);
expect(formValueService.repopulateFormDataFromCaseFieldValues).toHaveBeenCalled();
expect(validPageListCaseFieldsService.deleteNonValidatedFields).toHaveBeenCalled();
});

it('should NOT submit the case due to error', () => {
Expand Down Expand Up @@ -1395,7 +1400,8 @@ describe('CaseEditComponent', () => {
{provide: Router, useValue: routerStub},
{provide: ActivatedRoute, useValue: mockRouteNoProfile},
SessionStorageService,
WindowService
WindowService,
{ provide: ValidPageListCaseFieldsService, useValue: validPageListCaseFieldsService},
]
})
.compileComponents();
Expand Down
Loading

0 comments on commit dbb0d17

Please sign in to comment.