diff --git a/addon/components/md-select.js b/addon/components/md-select.js index 5a81cce6..6894c06c 100644 --- a/addon/components/md-select.js +++ b/addon/components/md-select.js @@ -5,6 +5,9 @@ import layout from '../templates/components/md-select'; export default MaterializeInputField.extend({ layout: layout, + optionLabelPath: 'content', + optionValuePath: 'content', + didInsertElement() { this._super(...arguments); this._setupSelect(); diff --git a/tests/unit/components/materialize-checkboxes-test.js b/tests/unit/components/materialize-checkboxes-test.js index 3281be29..8c49ab85 100644 --- a/tests/unit/components/materialize-checkboxes-test.js +++ b/tests/unit/components/materialize-checkboxes-test.js @@ -29,6 +29,17 @@ test('it renders', function(assert) { assert.equal(component._state, 'inDOM'); }); +test('simple array test', function (assert) { + var component = this.subject({ + content: Ember.A(['Dexter Morgan', 'Deborah Morgan', 'Harry Morgan']), + selection: Ember.A(['Harry Morgan']) + }); + this.render(); + assert.deepEqual(this.$('label').toArray().map(x => Ember.$(x).text()), ['Dexter Morgan', 'Deborah Morgan', 'Harry Morgan'], 'Choices are valid'); + assert.equal(this.$('input[type="checkbox"]')[2].checked, true, 'Third checkbox is checked'); +}); + + disabledGroupTest(); groupItemsRenderTest(); initialSelectionTest(Ember.A(['bbb', 'ccc'])); diff --git a/tests/unit/components/materialize-radios-test.js b/tests/unit/components/materialize-radios-test.js index a8cde0b6..58b2d9b1 100644 --- a/tests/unit/components/materialize-radios-test.js +++ b/tests/unit/components/materialize-radios-test.js @@ -1,3 +1,5 @@ +import Ember from 'ember'; + import { moduleForComponent, test @@ -28,6 +30,18 @@ test('it renders', function(assert) { assert.equal(component._state, 'inDOM'); }); +test('simple array test', function (assert) { + var component = this.subject({ + content: Ember.A(['Dexter Morgan', 'Deborah Morgan', 'Harry Morgan']), + selection: 'Harry Morgan' + }); + this.render(); + + assert.deepEqual(this.$('label').toArray().map(x => Ember.$(x).text().trim()), ['Dexter Morgan', 'Deborah Morgan', 'Harry Morgan'], 'Choices are valid'); + assert.equal(this.$('input[type="radio"]')[2].checked, true, 'Third radio is checked'); +}); + + disabledGroupTest(); groupItemsRenderTest(); initialSelectionTest('bbb'); diff --git a/tests/unit/components/materialize-select-test.js b/tests/unit/components/materialize-select-test.js index 1c447291..fd934059 100644 --- a/tests/unit/components/materialize-select-test.js +++ b/tests/unit/components/materialize-select-test.js @@ -44,3 +44,20 @@ test('select label is active with value', function(assert) { this.render(); assert.ok(component.$('>label').hasClass('active')); }); + +test('select creates the correct choices from a simple content array', function(assert) { + + var component = this.subject({ + content: new Ember.A(['Walter White', 'Jesee Pinkman', 'Gus Freng']), + value: 'Jesee Pinkman' + }); + this.render(); + assert.equal(component.$('input').val(), 'Jesee Pinkman', 'Initially selected value is correct'); + + assert.deepEqual( + this.$('.dropdown-content li span').toArray().map(x => x.innerText), + ['Walter White', 'Jesee Pinkman', 'Gus Freng'], + 'Choices are valid' + ); + +}); diff --git a/tests/unit/components/materialize-switches-test.js b/tests/unit/components/materialize-switches-test.js index eb49440f..7162c332 100644 --- a/tests/unit/components/materialize-switches-test.js +++ b/tests/unit/components/materialize-switches-test.js @@ -29,6 +29,16 @@ test('it renders', function(assert) { assert.equal(component._state, 'inDOM'); }); +test('simple array test', function (assert) { + var component = this.subject({ + content: Ember.A(['Dexter Morgan', 'Deborah Morgan', 'Harry Morgan']), + selection: Ember.A(['Deborah Morgan']) + }); + this.render(); + assert.deepEqual(this.$('.switch-label').toArray().map(x => Ember.$(x).text()), ['Dexter Morgan', 'Deborah Morgan', 'Harry Morgan'], 'Choices are valid'); + assert.equal(this.$('input[type="checkbox"]')[1].checked, true, 'Second checkbox is checked'); +}); + disabledGroupTest(); groupItemsRenderTest(); initialSelectionTest(Ember.A(['bbb', 'ccc']));