UNPKG

formio

Version:

The formio server application.

1,676 lines (1,556 loc) • 174 kB
/* eslint-disable strict */ /* eslint-disable max-len */ /* eslint-env mocha */ const request = require('./formio-supertest'); var assert = require('assert'); var Chance = require('chance'); var chance = new Chance(); var _ = require('lodash'); var docker = process.env.DOCKER; const nock = require('nock'); module.exports = function(app, template, hook) { var Helper = require('./helper')(app); var helper = null; function updateFormAndGetSubmissions(form, done) { helper.updateForm(form, (err) => { if (err) { return done(err); } helper.getSubmissions(form.name, (err, formsubs) => { if (err) { return done(err); } done(null, formsubs); }); }); } nock('https://random.com') .get('/') .reply(200, [ {id: 1, name: 'Alice'}, {id: 2, name: 'Bob'} ]); describe('Form Submissions', function() { it('Sets up a default project', function(done) { var owner = (app.hasProjects || docker) ? template.formio.owner : template.users.admin; helper = new Helper(owner); helper.project().user('user', 'user1').execute(done); }); describe('Unnested Submissions', function() { it('Saves values for each single value component type1', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); helper .form('test', test.components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); it('Custom conditional components that rely on fetched data should work correctly', function(done) { const test = require('./fixtures/forms/customConditionalComponents.js'); helper .form('test', test.components) .submission({data:test.submission}) .execute(function(err) { if (err) { return done(err); } const submission = helper.getLastSubmission(); assert.strictEqual(Object.keys(submission.data).length, 2); assert('aaPocCheckboxStage' in submission.data); assert('stageData' in submission.data); done(); }); }); it('Saves values for each single value component type2', function(done) { var test = require('./fixtures/forms/singlecomponents2.js'); helper .form('test', test.components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } signatureSubmission1 = helper.getLastSubmission(); assert.deepEqual(test.submission, signatureSubmission1.data); done(); }); }); var signatureSubmission1 = null; it('Saves submission with a null signature.', function(done) { var test = _.cloneDeep(require('./fixtures/forms/singlecomponents2.js')); test.submission.signature2 = null; helper .form('test', test.components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } signatureSubmission1 = helper.getLastSubmission(); // Should coerse the value to an empty string. test.submission.signature2 = ""; assert.deepEqual(test.submission, signatureSubmission1.data); done(); }); }); it('Updates the submission with a null signature', function(done) { var test = _.cloneDeep(require('./fixtures/forms/singlecomponents2.js')); var updateSub = _.cloneDeep(signatureSubmission1); updateSub.data.signature2 = null; helper.updateSubmission(updateSub, function(err, updated) { // Should coerse the value to an empty string. test.submission.signature2 = ""; assert.deepEqual(test.submission, updated.data); done(); }); }); var signatureSubmission = null; it('Saves values with required signature', function(done) { var test = _.cloneDeep(require('./fixtures/forms/singlecomponents3.js')); helper .form('test', test.components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } signatureSubmission = helper.getLastSubmission(); assert.deepEqual(test.submission, signatureSubmission.data); done(); }); }); it('Updating signatures does not wipe out the signature.', function(done) { var test = _.cloneDeep(require('./fixtures/forms/singlecomponents3.js')); var updateSub = _.cloneDeep(signatureSubmission); helper.updateSubmission(updateSub, function(err, updated) { assert.deepEqual(test.submission, updated.data); done(); }); }); it('Saving signatures with Bad string does not wipe out the signature.', function(done) { var test = _.cloneDeep(require('./fixtures/forms/singlecomponents3.js')); var updateSub = _.cloneDeep(signatureSubmission); updateSub.data.signature2 = 'YES'; helper.updateSubmission(updateSub, function(err, updated) { // Ensure that it does not erase the signature. assert.deepEqual(test.submission, updated.data); done(); }); }); it('Saving signatures with Any other string does not wipe out the signature.', function(done) { var test = _.cloneDeep(require('./fixtures/forms/singlecomponents3.js')); var updateSub = _.cloneDeep(signatureSubmission); updateSub.data.signature2 = 'sdfsfsdfsdf'; helper.updateSubmission(updateSub, function(err, updated) { // Ensure that it does not erase the signature. assert.deepEqual(test.submission, updated.data); done(); }); }); it('Updating signatures with empty string invalidates.', function(done) { var updateSub = _.cloneDeep(signatureSubmission); updateSub.data.signature2 = ''; helper.updateSubmission(updateSub, helper.owner, [/application\/json/, 400], function(err, updated) { // It should fail validation. assert.equal(updated.name, 'ValidationError'); assert.equal(updated.details.length, 1); assert.equal(updated.details[0].message, 'Signature is required'); assert.equal(updated.details[0].path, 'signature2'); assert.equal(updated.details[0].context.validator, 'required'); done(); }); }); it('Gives an error with an empty signature.', function(done) { var test = _.cloneDeep(require('./fixtures/forms/singlecomponents3.js')); test.submission.signature2 = ''; helper .form('test', test.components) .submission(test.submission) .expect(400) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.equal(submission.name, 'ValidationError'); assert.equal(submission.details.length, 1); assert.equal(submission.details[0].message, 'Signature is required'); assert.equal(submission.details[0].path, 'signature2'); assert.equal(submission.details[0].context.validator, 'required'); done(); }); }); it('Gives an error with a signature not present.', function(done) { var test = _.cloneDeep(require('./fixtures/forms/singlecomponents3.js')); delete test.submission.signature2; helper .form('test', test.components) .submission(test.submission) .expect(400) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.equal(submission.name, 'ValidationError'); assert.equal(submission.details.length, 1); assert.equal(submission.details[0].message, 'Signature is required'); assert.equal(submission.details[0].path, 'signature2'); assert.equal(submission.details[0].context.validator, 'required'); done(); }); }); it('Throws away extra values', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var values = Object.assign({}, test.submission, { extra: true, more: 'stuff', objectval: { other: 'things' }, arrayVal: [ 'never', 'gonna', 'give', 'you', 'up' ] }); helper .form('test', test.components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); it('Should validate input mask', function(done) { var components = [ { "label": "Text Field", "inputMask": "aaa", "applyMaskOn": "change", "tableView": true, "validateWhenHidden": false, "key": "textField", "type": "textfield", "input": true } ]; var values = { textField: '123' }; helper .form('test', components) .submission(values) .expect(400) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.equal(submission.name, 'ValidationError'); assert.deepEqual(submission.details, [ { context: { hasLabel: true, index: 0, key: 'textField', validator: 'mask', label: 'Text Field', path: 'textField', value: '123', }, message: 'Text Field does not match the mask.', level: 'error', path: ['textField'] } ]); done(); }); }); it('Saves values for each multiple value component', function(done) { var test = require('./fixtures/forms/multicomponents.js'); helper .form('test', test.components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); }); describe('Server Calculated', function() { it('Recalculate value on server', function(done) { var test = require('./fixtures/forms/servercalculate.js'); helper .form('test', test.components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); it('Fails to recalculate value because of corrupted submission', function(done) { var test = require('./fixtures/forms/servercalculate.js'); helper .form('test', test.components) .submission(test.falseSubmission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.falseSubmission, submission.data); done(); }); }); }); describe('Fieldset nesting', function() { it('Nests single value components in a fieldset', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "key": "fieldset1", "input": false, "tableView": true, "legend": "Fieldset", "components": test.components, "type": "fieldset", "conditional": { "show": null, "when": null, "eq": "" } }]; helper .form('test', components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); it('Nests multiple value components in a fieldset', function(done) { var test = require('./fixtures/forms/multicomponents.js'); var components = [{ "key": "fieldset1", "input": false, "tableView": true, "legend": "Fieldset", "components": test.components, "type": "fieldset", "conditional": { "show": null, "when": null, "eq": "" } }]; helper .form('test', components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }) }); describe('Column nesting', function() { it('Nests single value components in a column', function(done) { var test1 = require('./fixtures/forms/singlecomponents1.js'); var test2 = require('./fixtures/forms/singlecomponents2.js'); var components = [{ "key": "columns1", "input": false, "columns": [ { "components": test1.components }, { "components": test2.components } ], "type": "columns", "conditional": { "show": null, "when": null, "eq": "" } }]; var combined = Object.assign({}, test1.submission, test2.submission); helper .form('test', components) .submission(combined) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(combined, submission.data); done(); }); }); it('Nests multiple value components in a column', function(done) { var test1 = require('./fixtures/forms/singlecomponents1.js'); var test2 = require('./fixtures/forms/multicomponents.js'); var components = [{ "key": "columns1", "input": false, "columns": [ { "components": test1.components }, { "components": test2.components } ], "type": "columns", "conditional": { "show": null, "when": null, "eq": "" } }]; var combined = Object.assign({}, test1.submission, test2.submission); helper .form('test', components) .submission(combined) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(combined, submission.data); done(); }); }); }); describe('Panel nesting', function() { it('Nests single value components in a panel', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "key": "panel1", "input": false, "title": "Panel", "theme": "default", "components": test.components, "type": "panel", "conditional": { "show": null, "when": null, "eq": "" } }]; helper .form('test', components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); it('Nests multiple value components in a panel', function(done) { var test = require('./fixtures/forms/multicomponents.js'); var components = [{ "key": "panel1", "input": false, "title": "Panel", "theme": "default", "components": test.components, "type": "panel", "conditional": { "show": null, "when": null, "eq": "" } }]; helper .form('test', components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }) }); describe('Well nesting', function() { it('Nests single value components in a well', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "key": "well1", "input": false, "components": test.components, "type": "well", "conditional": { "show": null, "when": null, "eq": "" } }]; helper .form('test', components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); it('Nests multiple value components in a well', function(done) { var test = require('./fixtures/forms/multicomponents.js'); var components = [{ "key": "well1", "input": false, "components": test.components, "type": "well", "conditional": { "show": null, "when": null, "eq": "" } }]; helper .form('test', components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }) }); describe('Table nesting', function() { it('Nests components in a table', function(done) { var test1 = require('./fixtures/forms/singlecomponents1.js'); var test2 = require('./fixtures/forms/singlecomponents2.js'); var test3 = require('./fixtures/forms/multicomponents.js'); var components = [{ "key": "table1", "conditional": { "eq": "", "when": null, "show": null }, "type": "table", "condensed": false, "hover": false, "bordered": true, "striped": true, "caption": "", "header": [], "rows": [ [ { "components": test1.components }, { "components": [] }, { "components": [] } ], [ { "components": [] }, { "components": test2.components }, { "components": [] } ], [ { "components": [] }, { "components": [] }, { "components": test3.components } ] ], "numCols": 3, "numRows": 3, "input": false }]; var values = Object.assign({}, test1.submission, test2.submission, test3.submission); helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(values, submission.data); done(); }); }); }); describe('Custom components', function() { it('Saves custom components', function(done) { var test = require('./fixtures/forms/custom.js'); helper .form('test', test.components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); it('Nests single value components in a custom component', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "key": "custom1", "input": false, "tableView": true, "legend": "Custom", "components": test.components, "type": "mycustomtype" }]; helper .form('customform', components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); //it('Nests single value components in a custom tree component', function(done) { // var test = require('./fixtures/forms/singlecomponents1.js'); // var components = [{ // "key": "custom1", // "input": false, // "tableView": true, // "tree": true, // "legend": "Custom", // "components": test.components, // "type": "mycustomtype" // }]; // // var submissionData = { custom1: test.submission }; // // helper // .form('customform', components) // .submission(submissionData) // .execute(function(err) { // if (err) { // return done(err); // } // // var submission = helper.getLastSubmission(); // assert.deepEqual(submissionData, submission.data); // done(); // }); //}); }); describe('Container nesting', function() { it('Nests single value components in a container', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "input": true, "tree": true, "components": test.components, "tableView": true, "label": "Container", "key": "container1", "protected": false, "persistent": true, "type": "container", "conditional": { "show": null, "when": null, "eq": "" } }]; var values = { container1: test.submission }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(values, submission.data); done(); }); }); it('Removes extra values in a container', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "input": true, "tree": true, "components": test.components, "tableView": true, "label": "Container", "key": "container1", "protected": false, "persistent": true, "type": "container", "conditional": { "show": null, "when": null, "eq": "" } }]; var sub = { container1: test.submission } var values = { container1: Object.assign({}, test.submission, { extra: true, stuff: 'bad', never: ['gonna', 'give', 'you', 'up'] }) }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(sub, submission.data); done(); }); }); it('Nests a container in a container', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "input": true, "tree": true, "components": [{ "input": true, "tree": true, "components": test.components, "tableView": true, "label": "Container", "key": "container2", "protected": false, "persistent": true, "type": "container", "conditional": { "show": null, "when": null, "eq": "" } }], "tableView": true, "label": "Container", "key": "container1", "protected": false, "persistent": true, "type": "container", "conditional": { "show": null, "when": null, "eq": "" } }]; var values = { container1: { container2: test.submission } }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(values, submission.data); done(); }); }); it('Nests a container in a datagrid', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "conditional": { "eq": "", "when": null, "show": null }, "type": "datagrid", "persistent": true, "protected": false, "key": "datagrid1", "label": "Datagrid", "tableView": true, "tree": true, "input": true, "components": [{ "input": true, "tree": true, "components": test.components, "tableView": true, "label": "Container", "key": "container2", "protected": false, "persistent": true, "type": "container", "conditional": { "show": null, "when": null, "eq": "" } }] }]; var values = { datagrid1: [{ container2: test.submission }] }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(values, submission.data); done(); }); }); }); describe('Datagrid nesting', function() { it('Nests single value components in a datagrid', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "conditional": { "eq": "", "when": null, "show": null }, "type": "datagrid", "persistent": true, "protected": false, "key": "datagrid1", "label": "Datagrid", "tableView": true, "components": test.components, "tree": true, "input": true }]; var values = { datagrid1: [test.submission, test.submission] } helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(values, submission.data); done(); }); }); //it('Removes extra values in a datagrid', function(done) { // var test = require('./fixtures/forms/singlecomponents1.js'); // var components = [{ // "conditional": { // "eq": "", // "when": null, // "show": null // }, // "type": "datagrid", // "persistent": true, // "protected": false, // "key": "datagrid1", // "label": "Datagrid", // "tableView": true, // "components": test.components, // "tree": true, // "input": true // }]; // // var sub = { // datagrid1: [test.submission, test.submission] // } // var values = { // datagrid1: [Object.assign({}, test.submission, { // extra: true, // stuff: 'bad', // never: ['gonna', 'give', 'you', 'up'] // }), test.submission] // }; // // helper // .form('test', components) // .submission(values) // .execute(function(err) { // if (err) { // return done(err); // } // // var submission = helper.getLastSubmission(); // assert.deepEqual(sub, submission.data); // done(); // }); //}); it('Nests a datagrid in a datagrid', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "conditional": { "eq": "", "when": null, "show": null }, "type": "datagrid", "persistent": true, "protected": false, "key": "datagrid1", "label": "Datagrid", "tableView": true, "components": [ { "conditional": { "eq": "", "when": null, "show": null }, "type": "datagrid", "persistent": true, "protected": false, "key": "datagrid2", "label": "Datagrid", "tableView": true, "components": test.components, "tree": true, "input": true } ], "tree": true, "input": true }]; var values = { datagrid1: [{ datagrid2: [test.submission] }] }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(values, submission.data); done(); }); }); it('Nests a datagrid in a container', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "input": true, "tree": true, "tableView": true, "label": "Container", "key": "container1", "protected": false, "persistent": true, "type": "container", "conditional": { "show": null, "when": null, "eq": "" }, "components": [ { "conditional": { "eq": "", "when": null, "show": null }, "type": "datagrid", "persistent": true, "protected": false, "key": "datagrid2", "label": "Datagrid", "tableView": true, "components": test.components, "tree": true, "input": true } ] }]; var values = { container1: { datagrid2: [test.submission] } }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(values, submission.data); done(); }); }); }); describe('Deep nesting', function() { it('Nests deeply in layout components', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "key": "fieldset1", "input": false, "tableView": true, "type": "fieldset", "legend": "Fieldset", "components": [ { "key": "columns1", "input": false, "type": "columns", "columns": [ { "components": [ { "key": "panel1", "input": false, "title": "Panel", "type": "panel", "theme": "default", "components": [ { "key": "well1", "input": false, "components": [ { "key": "well2", "input": false, "type": "well", "components": test.components, "conditional": { "show": null, "when": null, "eq": "" } } ], "type": "well", "conditional": { "show": null, "when": null, "eq": "" } } ], "conditional": { "show": null, "when": null, "eq": "" } } ] }, { "components": [] } ], "conditional": { "show": null, "when": null, "eq": "" } } ], "conditional": { "show": null, "when": null, "eq": "" } }]; helper .form('test', components) .submission(test.submission) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(test.submission, submission.data); done(); }); }); it('Nests a datagrid deeply in layout components', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "key": "fieldset1", "input": false, "tableView": true, "type": "fieldset", "legend": "Fieldset", "components": [ { "key": "columns1", "input": false, "type": "columns", "columns": [ { "components": [ { "key": "panel1", "input": false, "title": "Panel", "type": "panel", "theme": "default", "components": [ { "key": "well1", "input": false, "type": "well", "components": [ { "key": "well2", "input": false, "type": "well", "components": [ { "conditional": { "eq": "", "when": null, "show": null }, "type": "datagrid", "persistent": true, "protected": false, "key": "datagrid1", "label": "Datagrid", "tableView": true, "components": test.components, "tree": true, "input": true } ], "conditional": { "show": null, "when": null, "eq": "" } } ], "conditional": { "show": null, "when": null, "eq": "" } } ], "conditional": { "show": null, "when": null, "eq": "" } } ] }, { "components": [] } ], "conditional": { "show": null, "when": null, "eq": "" } } ], "conditional": { "show": null, "when": null, "eq": "" } }]; var values = { datagrid1: [test.submission] }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(values, submission.data); done(); }); }); it('Nests a container deeply in layout components', function(done) { var test = require('./fixtures/forms/singlecomponents1.js'); var components = [{ "key": "fieldset1", "input": false, "tableView": true, "type": "fieldset", "legend": "Fieldset", "components": [ { "key": "columns1", "input": false, "type": "columns", "columns": [ { "components": [ { "key": "panel1", "input": false, "title": "Panel", "type": "panel", "theme": "default", "components": [ { "key": "well1", "input": false, "components": [ { "key": "well2", "input": false, "type": "well", "components": [ { "input": true, "tree": true, "components": test.components, "tableView": true, "label": "Container", "key": "container1", "protected": false, "persistent": true, "type": "container", "conditional": { "show": null, "when": null, "eq": "" } } ], "conditional": { "show": null, "when": null, "eq": "" } } ], "type": "well", "conditional": { "show": null, "when": null, "eq": "" } } ], "conditional": { "show": null, "when": null, "eq": "" } } ] }, { "components": [] } ], "conditional": { "show": null, "when": null, "eq": "" } } ], "conditional": { "show": null, "when": null, "eq": "" } }]; var values = { container1: test.submission }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); assert.deepEqual(values, submission.data); done(); }); }); }); describe('Protected fields are protected', function() { it('Does not return a protected password field', function(done) { var components = [ { "input": true, "tableView": true, "inputType": "text", "inputMask": "", "label": "Text Field", "key": "textField", "placeholder": "", "prefix": "", "suffix": "", "multiple": false, "defaultValue": "", "protected": false, "unique": false, "persistent": true, "validate": { "required": false, "minLength": "", "maxLength": "", "pattern": "", "custom": "", "customPrivate": false }, "conditional": { "show": null, "when": null, "eq": "" }, "type": "textfield" }, { "input": true, "tableView": false, "inputType": "password", "label": "Password", "key": "password", "placeholder": "", "prefix": "", "suffix": "", "protected": true, "persistent": true, "type": "password", "conditional": { "show": null, "when": null, "eq": "" } } ]; var values = { textField: 'My Value', password: 'password' }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var result = {textField: 'My Value'}; var submission = helper.getLastSubmission(); assert.deepEqual(result, submission.data); done(); }); }); it('Does not return a protected text field', function(done) { var components = [ { "input": true, "tableView": true, "inputType": "text", "inputMask": "", "label": "Text Field", "key": "textField", "placeholder": "", "prefix": "", "suffix": "", "multiple": false, "defaultValue": "", "protected": true, "unique": false, "persistent": true, "validate": { "required": false, "minLength": "", "maxLength": "", "pattern": "", "custom": "", "customPrivate": false }, "conditional": { "show": null, "when": null, "eq": "" }, "type": "textfield" }, { "input": true, "tableView": false, "inputType": "password", "label": "Password", "key": "password", "placeholder": "", "prefix": "", "suffix": "", "protected": false, "persistent": true, "type": "password", "conditional": { "show": null, "when": null, "eq": "" } } ]; var values = { textField: 'My Value', password: 'password' }; helper .form('test', components) .submission(values) .execute(function(err) { if (err) { return done(err); } var submission = helper.getLastSubmission(); // Password is a hash so can't use old value. assert(submission.data.hasOwnProperty('password'), 'Should return the password hash'); done(); }); }); }); describe('Conditional Fields', function() { it('Requires a conditionally visible field', function(done) { var components = [ { "input": true, "tableView": true, "inputType": "radio", "label": "Selector", "key": "selector", "values": [ { "value": "one", "label": "One" }, { "value": "two", "label": "Two" } ], "defaultValue": "", "protected": false, "persistent": true, "validate": { "required": false, "custom": "", "customPrivate": false }, "type": "radio", "conditional": { "show": "", "when": null, "eq": "" } }, { "input": true, "tableView": true, "inputType": "text", "inputMask": "", "label": "Required Field", "key": "requiredField", "placeholder": "", "prefix": "", "suffix": "", "multiple": false, "defaultValue": "", "protected": false, "unique": false, "persistent": true, "validate": { "required": true, "minLength": "", "maxLength": "", "pattern": "", "custom": "", "customPrivate": false }, "conditional": { "show": "true", "when": "selector", "eq": "two" }, "type": "textfield" } ]; var values = { selector: 'two' }; helper .form('test', components) .submission(values) .expect(400) .execute(function(err) { if (err) {