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

FIO-8537: Fixing the filter processor to handle nested component data properly. #117

Merged
merged 4 commits into from
Jul 16, 2024
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
250 changes: 193 additions & 57 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,29 +831,7 @@ describe('Process Tests', () => {
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
pathName: '/',
onLine: true,
headers: {
host: 'localhost:3000',
connection: 'keep-alive',
'content-length': '9020',
pragma: 'no-cache',
'cache-control': 'no-cache',
'sec-ch-ua':
'"Chromium";v="122", "Not(A:Brand";v="24", "Brave";v="122"',
accept: 'application/json',
'content-type': 'application/json',
'sec-ch-ua-mobile': '?0',
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'sec-gpc': '1',
'accept-language': 'en-US,en',
origin: 'http://localhost:3000',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
referer: 'http://localhost:3000/',
'accept-encoding': 'gzip, deflate, br',
},

},
data: {
number: 23,
Expand Down Expand Up @@ -969,40 +947,7 @@ describe('Process Tests', () => {
},
owner: '65ea3601c3792e416cabcb2a',
access: [],
metadata: {
timezone: 'America/Chicago',
offset: -360,
origin: 'http://localhost:3000',
referrer: '',
browserName: 'Netscape',
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
pathName: '/',
onLine: true,
headers: {
'accept-language': 'en-US,en',
'cache-control': 'no-cache',
connection: 'keep-alive',
origin: 'http://localhost:3000',
pragma: 'no-cache',
referer: 'http://localhost:3000/',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'sec-gpc': '1',
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
accept: 'application/json',
'content-type': 'application/json',
'sec-ch-ua':
'"Chromium";v="122", "Not(A:Brand";v="24", "Brave";v="122"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
host: 'localhost:3000',
'accept-encoding': 'gzip, deflate, br',
'content-length': '18055',
},
},

_vnote: '',
state: 'submitted',
form: '65ea368b705068f84a93c87a',
Expand All @@ -1024,6 +969,8 @@ describe('Process Tests', () => {
submission.data = context.data;
context.processors = ProcessTargets.evaluator;
processSync(context);
console.log(context.scope.errors);

assert.equal(context.scope.errors.length, 0);
});
it('should remove submission data not in a nested form definition', async function () {
Expand Down Expand Up @@ -2853,6 +2800,185 @@ describe('Process Tests', () => {
expect((context.scope as ValidationScope).errors).to.have.length(1);
});
});
it('Should not return fields from conditionally hidden containers', async () => {
const form = {
display: 'form',
"components": [
{
"title": "__information_on_the_appointee",
"theme": "primary",
"collapsible": false,
"key": "HeadingNestedFormCandidates",
"type": "panel",
"label": "Appointees",
"input": false,
"tableView": false,
"components": [
{
"label": "Appointees",
"hideLabel": true,
"tableView": false,

"addAnother": "__add_appointee",
"modal": true,
"saveRow": "Close",
"rowDrafts": true,
"key": "candidates",
"type": "editgrid",
"displayAsTable": false,
"input": true,
"components": [
{
"label": "Appointee",
"tableView": false,
"key": "candidate",
"type": "container",
"input": true,
"components": [
{
"label": "Data",
"tableView": false,
"key": "data",
"type": "container",
"input": true,
"components": [
{
"label": "Tabs",
"components": [
{
"label": "__6_time_commitment",
"key": "section6tab",
"components": [
{
"label": "Section 6",
"tableView": false,
"clearOnHide": true,
"validateWhenHidden": false,
"key": "section6",
"properties": {
"clearHiddenOnSave": "true"
},
"customConditional": "show = false;",
"type": "container",
"input": true,
"components": [
{
"title": "__6_dash_time_commitment",
"theme": "primary",
"collapsible": false,
"key": "heading6",
"type": "panel",
"label": "Time Commitment",
"input": false,
"tableView": false,
"components": [
{
"label": "__a_information_to_be_provided_by_the_supervised_entity_the",
"description": "__ul_li_see_the_report_on_declared_time_commitment_of",
"autoExpand": false,
"tableView": true,
"validate": {
"required": true
},
"key": "entityExpectedTimeCommit",
"type": "textarea",
"input": true
},
{
"label": "c",
"tableView": false,
"key": "c",
"type": "container",
"input": true,
"components": []
},
{
"label": "__d_list_of_executive_and_non_executive_directorships_and_other",
"description": "__for_each_directorship_or_other_activity_a_separate_row_needs",
"tableView": false,
"addAnother": "__add_another",
"validate": {
"required": true
},
"rowDrafts": false,
"key": "d",
"type": "editgrid",
"input": true,
"components": []
}
]
}
]
}
]
}
],
"key": "tabs1",
"type": "tabs",
"input": false,
"tableView": false
}
]
}
]
}
]
}
]
},
{
"label": "Submit",
"action": "saveState",
"showValidations": false,
"tableView": false,
"key": "submit",
"type": "button",
"input": true,
"state": "draft"
}
],

};
const submission = {
"data": {
"candidates": [
{
"candidate": {
"data": {
"section6": {
"c": {},
"d": []
}
}
}
}
],
"submit": true
}
};

const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
console.log(JSON.stringify(context.data, null, 2))
expect(context.data).to.deep.equal({
candidates:[{candidate:{data:{}}}],
submit: true

});
})

describe('For EditGrid:', () => {
const components = [
{
Expand Down Expand Up @@ -2893,9 +3019,14 @@ describe('Process Tests', () => {
form: {
data: {
textField: 'test',
invalidField: 'bad',
},

},
},
{
invalidDataGridField: 'wrong',
},
],
},
};
Expand All @@ -2914,7 +3045,12 @@ describe('Process Tests', () => {
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
console.log(JSON.stringify(context.data, null, 2));

expect((context.scope as ValidationScope).errors).to.have.length(0);
expect(context.data).to.deep.equal({
editGrid: [{ form: { data: { textField: 'test' } } }],
});
});
it('Should not validate required component when it is not filled out', async () => {
const submission = {
Expand Down
6 changes: 3 additions & 3 deletions src/process/filter/__tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ it('Should not filter empty array value for dataGrid component', async () => {
};
const context: any = generateProcessorContext(dataGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataGrid': {'compModelType': 'array', 'include': true}});
expect(context.scope.filter).to.deep.equal({'dataGrid': {'compModelType': 'array', 'include': true, value: []}});
});

it('Should not filter empty array value for editGrid component', async () => {
Expand All @@ -46,7 +46,7 @@ it('Should not filter empty array value for editGrid component', async () => {
};
const context: any = generateProcessorContext(editGridComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'editGrid': {'compModelType': 'array', 'include': true}});
expect(context.scope.filter).to.deep.equal({'editGrid': {'compModelType': 'array', 'include': true, value: []}});
});

it('Should not filter empty array value for datTable component', async () => {
Expand All @@ -69,5 +69,5 @@ it('Should not filter empty array value for datTable component', async () => {
};
const context: any = generateProcessorContext(dataTableComp, data);
filterProcessSync(context);
expect(context.scope.filter).to.deep.equal({'dataTable': {'compModelType': 'array', 'include': true}});
expect(context.scope.filter).to.deep.equal({'dataTable': {'compModelType': 'array', 'include': true, value: []}});
});
Loading
Loading