From a781e56c3f56dd8e307e9c463e2734c05e378f09 Mon Sep 17 00:00:00 2001 From: brendanjbond Date: Mon, 11 Nov 2024 10:41:12 +0100 Subject: [PATCH] more tests --- src/process/__tests__/process.test.ts | 46 ++++++++++++++++++- .../clearHidden/__tests__/clearHidden.test.ts | 26 ++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/process/__tests__/process.test.ts b/src/process/__tests__/process.test.ts index 7ce9b638..4e81b5cc 100644 --- a/src/process/__tests__/process.test.ts +++ b/src/process/__tests__/process.test.ts @@ -1603,7 +1603,6 @@ describe('Process Tests', function () { }); }); - // TODO: test case naming it('Should not unset submission data of nested forms with identical keys', function () { const parentForm = { display: 'form', @@ -3323,6 +3322,51 @@ describe('Process Tests', function () { }); }); + it('Should include submission data for intentionally hidden fields', async function () { + const form = { + display: 'form', + components: [ + { + type: 'textfield', + key: 'textField', + label: 'Text Field', + input: true, + }, + { + type: 'textarea', + key: 'textArea', + label: 'Text Area', + input: true, + hidden: true, + }, + ], + }; + + const submission = { + data: { + textField: 'not empty', + textArea: 'also not empty', + }, + }; + + const context = { + form, + submission, + data: submission.data, + components: form.components, + processors: ProcessTargets.evaluator, + scope: {}, + config: { + server: true, + }, + }; + processSync(context); + expect(context.data).to.deep.equal({ + textField: 'not empty', + textArea: 'also not empty', + }); + }); + it('Should not filter a simple datamap compoennt', async function () { const form = { display: 'form', diff --git a/src/process/clearHidden/__tests__/clearHidden.test.ts b/src/process/clearHidden/__tests__/clearHidden.test.ts index ddb42e1a..1209f76b 100644 --- a/src/process/clearHidden/__tests__/clearHidden.test.ts +++ b/src/process/clearHidden/__tests__/clearHidden.test.ts @@ -32,7 +32,7 @@ describe('clearHidden', function () { expect(context.data).to.deep.equal({ foo: 'bar' }); }); - it('Should clear conditiionally hidden component data when clearOnHide is true', function () { + it('Should clear conditionally hidden component data when clearOnHide is true', function () { // Test case data const context = { component: { @@ -60,4 +60,28 @@ describe('clearHidden', function () { clearHiddenProcess(context); expect(context.data).to.deep.equal({}); }); + + it('Should not clear component data when the component is intentionally hidden', function () { + // Test case data + const context = { + component: { + type: 'textfield', + key: 'foo', + clearOnHide: true, + input: true, + hidden: true, + }, + data: { + foo: 'bar', + }, + value: 'foo', + row: {}, + scope: { + clearHidden: {}, + }, + path: 'foo', + }; + clearHiddenProcess(context); + expect(context.data).to.deep.equal({ foo: 'bar' }); + }); });