Skip to content

Commit

Permalink
Merge pull request #78 from truenorth/simple-array
Browse files Browse the repository at this point in the history
[Bugfix] Select - simple array case
  • Loading branch information
mike-north committed Apr 24, 2015
2 parents d6f264a + 0b19aca commit 81d8e68
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addon/components/md-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/components/materialize-checkboxes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
14 changes: 14 additions & 0 deletions tests/unit/components/materialize-radios-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Ember from 'ember';

import {
moduleForComponent,
test
Expand Down Expand Up @@ -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');
17 changes: 17 additions & 0 deletions tests/unit/components/materialize-select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

});
10 changes: 10 additions & 0 deletions tests/unit/components/materialize-switches-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']));

0 comments on commit 81d8e68

Please sign in to comment.