From 8b663ae571d6643aef253169ea4560cb65144df3 Mon Sep 17 00:00:00 2001 From: Ayush Gupta Date: Tue, 28 Jun 2016 09:38:31 -0400 Subject: [PATCH] :bug: fixes options not being overwritten --- lib/content-types/merge.js | 5 +++++ package.json | 1 + tests/fixtures/content-types/baz.yml | 13 +++++++++++++ tests/form.js | 15 +++++++++++++++ tests/validate.js | 1 - 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/content-types/merge.js b/lib/content-types/merge.js index 31e4abb..d777e51 100644 --- a/lib/content-types/merge.js +++ b/lib/content-types/merge.js @@ -114,6 +114,11 @@ const squish = (types) => { merged.validation = plugin.inputs[attr].validation; merged.type = plugin.inputs[attr].type; + // Options of attribute overrides default + if (attribute.inputs[attr].hasOwnProperty('options')) { + merged.options = attribute.inputs[attr].options; + } + // add required if it doesn't exist if (!merged.hasOwnProperty('required')) { merged.required = plugin.required; diff --git a/package.json b/package.json index e6648cb..d291a66 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "eslint-config-punchcard": "^1.0.0", "ghooks": "^1.2.4", "input-plugin-datetime": "^0.0.1", + "input-plugin-select": "^0.1.0", "input-plugin-email": "^0.1.0", "input-plugin-quote": "0.0.1", "input-plugin-text": "^0.0.5", diff --git a/tests/fixtures/content-types/baz.yml b/tests/fixtures/content-types/baz.yml index 830a936..98179ec 100644 --- a/tests/fixtures/content-types/baz.yml +++ b/tests/fixtures/content-types/baz.yml @@ -70,3 +70,16 @@ attributes: required: 'publish' settings: empty: false + - type: select + name: example dropdown + id: example-dropdown + inputs: + select: + label: Example Dropdown + options: + - label: Option 1 + value: option1 + - label: Option 2 + value: option2 + settings: + multiple: false diff --git a/tests/form.js b/tests/form.js index 8162b1d..7fe05a3 100644 --- a/tests/form.js +++ b/tests/form.js @@ -119,3 +119,18 @@ test('Form Generation, with errors', t => { t.true(includes(rendered.html, 'name="email-field--email" aria-invalid="true"', 'error adds aria-invalid')); }); }); + +test('Form Generation, overrides options in select', t => { + return types.only('baz').then(result => { + return form(result); + }).then(rendered => { + t.true(includes(rendered.html, '', 'determines existence of option1')); + t.true(includes(rendered.html, '', 'determines existence of option2')); + t.false(includes(rendered.html, '', 'determines non-existence of default option 1')); + t.false(includes(rendered.html, '', 'determines non-existence of default option 2')); + t.false(includes(rendered.html, '', 'determines non-existence of default option 3')); + t.false(includes(rendered.html, '', 'determines non-existence of default option 4')); + }); +}); + + diff --git a/tests/validate.js b/tests/validate.js index 3aaab06..e6deb52 100644 --- a/tests/validate.js +++ b/tests/validate.js @@ -196,7 +196,6 @@ test('Validate - Pass', t => { }; const result = validation(input, ct); - t.true(result, 'All validation passes'); }); });