Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exui-1105-Judicial User complex types not showing with field show conditions #1622

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
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.13",
"version": "6.19.13-exui-1105",
"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.13",
"version": "6.19.13-exui-1105",
"engines": {
"yarn": "^3.5.0",
"npm": "^8.10.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,6 @@ describe('WizardPageFieldToCaseFieldMapper - nested Collection of Collection typ

expect(timelineEventDate.hidden).toEqual(true);
expect(timelineEventDescription.hidden).toEqual(true);
expect(timelineEventDescription.display_context).toEqual('HIDDEN');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ export class WizardPageFieldToCaseFieldMapper {

childrenCaseFields.forEach(e => this.hideParentIfAllChildrenHidden(e));

// filter out judicialuser field to avoid issue with the field to be hide/unhide based on the selection
if (childrenCaseFields.length > 0 && this.allCaseFieldsHidden(childrenCaseFields)) {
caseField.hidden = true;
caseField.display_context = 'HIDDEN';
if (caseField.field_type.id !== 'JudicialUser' && caseField.field_type.collection_field_type?.id !== 'JudicialUser') {
caseField.display_context = 'HIDDEN';
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,24 @@ describe('FormValueService', () => {
});

describe('removeUnnecessaryFields', () => {
function buildCaseField(id: string, properties: object, value?: any): CaseField {
return ({
id,
...properties,
value
}) as CaseField;
}

const TEXT_FIELD1: CaseField = buildCaseField('idamId', {
field_type: { id: 'Text', type: 'Text' },
hidden: false
}, null);

const TEXT_FIELD2: CaseField = buildCaseField('personalCode', {
field_type: { id: 'Text', type: 'Text' },
hidden: false
}, null);

it('should empty the collection field if it contains only id', () => {
const data = {collection1: [{id: '123'}]};
const caseField = new CaseField();
Expand All @@ -744,6 +762,49 @@ describe('FormValueService', () => {
const actual = {collection1: [{id: '123'}]};
expect(JSON.stringify(data)).toEqual(JSON.stringify(actual));
});

it('should keep the data if field is JudicialUser', () => {
const data = { reservedToJudgeInterloc: {
idamId: null,
personalCode: null
}};
const caseField = new CaseField();
const fieldType = new FieldType();
fieldType.id = 'JudicialUser';
fieldType.min = null;
fieldType.type = 'Complex';
fieldType.complex_fields= [TEXT_FIELD1, TEXT_FIELD2];
caseField.field_type = fieldType;
caseField.id = 'reservedToJudgeInterloc';
caseField.display_context = 'OPTIONAL';

formValueService.removeUnnecessaryFields(data, [caseField]);
const actual = { reservedToJudgeInterloc: {
idamId: null,
personalCode: null
}};
expect(JSON.stringify(data)).toEqual(JSON.stringify(actual));
});

it('should keep the data if field is JudicialUser', () => {
const data = { reservedToJudgeInterloc: {
idamId: null,
personalCode: null
}};
const caseField = new CaseField();
const fieldType = new FieldType();
fieldType.id = 'JudicialUser1';
fieldType.min = null;
fieldType.type = 'Complex';
fieldType.complex_fields= [TEXT_FIELD1, TEXT_FIELD2];
caseField.field_type = fieldType;
caseField.id = 'reservedToJudgeInterloc';
caseField.display_context = 'OPTIONAL';

formValueService.removeUnnecessaryFields(data, [caseField]);
const actual = {};
expect(JSON.stringify(data)).toEqual(JSON.stringify(actual));
});
});
describe('removeInvalidCollectionData', () => {
it('should empty the collection field if it contains only id', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export class FormValueService {
this.removeUnnecessaryFields(data[field.id], field.field_type.complex_fields, clearEmpty);
// Also remove any optional complex objects that are completely empty.
// EUI-4244: Ritesh's fix, passing true instead of clearEmpty.
if (FormValueService.clearOptionalEmpty(true, data[field.id], field)) {
if (FormValueService.clearOptionalEmpty(true, data[field.id], field) && field.field_type.id !== 'JudicialUser') {
delete data[field.id];
}
if (data[field.id] && FormValueService.isEmptyData(data[field.id]) && fromPreviousPage
Expand Down