From 4d041d5b8724b0ff799c55485af8597f5cf96002 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 19 Oct 2017 17:34:56 -0700 Subject: [PATCH] [FIX] Fix wizard spec This commit introduces a mutation on input value given to select-box-kit when value is empty. The refactoring required to avoid this would be too heavy atm, but ultimately we would want to avoid this. --- .../components/select-box-kit.js.es6 | 7 +++++++ .../test/components/invite-list-test.js.es6 | 4 ++-- .../components/combo-box-test.js.es6 | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/select-box-kit/components/select-box-kit.js.es6 b/app/assets/javascripts/select-box-kit/components/select-box-kit.js.es6 index 25ed7e3a79..25d4140844 100644 --- a/app/assets/javascripts/select-box-kit/components/select-box-kit.js.es6 +++ b/app/assets/javascripts/select-box-kit/components/select-box-kit.js.es6 @@ -56,6 +56,13 @@ export default Ember.Component.extend(UtilsMixin, DomHelpersMixin, KeyboardMixin this.setProperties({ filterable: false, autoFilterable: false }); } + if (isNone(this.get("none")) && isEmpty(this.get("value")) && !isEmpty(this.get("content"))) { + Ember.run.scheduleOnce("sync", () => { + const firstValue = this.get(`content.0.${this.get("valueAttribute")}`); + this.set("value", firstValue); + }); + } + this._previousScrollParentOverflow = "auto"; }, diff --git a/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 b/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 index 2232f7c89b..cdfe0fbe15 100644 --- a/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 +++ b/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 @@ -1,7 +1,7 @@ -// import { componentTest } from 'wizard/test/helpers/component-test'; +import { componentTest } from 'wizard/test/helpers/component-test'; moduleForComponent('invite-list', { integration: true }); -QUnit.skip('can add users', { +componentTest('can add users', { template: `{{invite-list field=field}}`, beforeEach() { diff --git a/test/javascripts/components/combo-box-test.js.es6 b/test/javascripts/components/combo-box-test.js.es6 index 0c14ff5c23..dcaccdfc1b 100644 --- a/test/javascripts/components/combo-box-test.js.es6 +++ b/test/javascripts/components/combo-box-test.js.es6 @@ -222,3 +222,20 @@ componentTest('with no value and no none', { // andThen(() => assert.equal(selectBox().rows.length, 1) ); // } // }); + + +componentTest('with empty string as value', { + template: '{{combo-box content=items value=value}}', + beforeEach() { + this.set('items', ['evil', 'trout', 'hat']); + this.set('value', ''); + }, + + test(assert) { + expandSelectBox('.combobox'); + + andThen(() => { + assert.equal(selectBox('.combobox').header.name(), 'evil', 'it sets the first row as value'); + }); + } +});