mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: New "Dropdown" user field type
This commit is contained in:
45
test/javascripts/components/combo-box-test.js.es6
Normal file
45
test/javascripts/components/combo-box-test.js.es6
Normal file
@@ -0,0 +1,45 @@
|
||||
import componentTest from 'helpers/component-test';
|
||||
moduleForComponent('combo-box', {integration: true});
|
||||
|
||||
componentTest('with objects', {
|
||||
template: '{{combo-box content=items value=value}}',
|
||||
setup() {
|
||||
this.set('items', [{id: 1, name: 'hello'}, {id: 2, name: 'world'}]);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(this.get('value'), 1);
|
||||
assert.ok(this.$('.combobox').length);
|
||||
assert.equal(this.$("select option[value='1']").text(), 'hello');
|
||||
assert.equal(this.$("select option[value='2']").text(), 'world');
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with an array', {
|
||||
template: '{{combo-box content=items value=value}}',
|
||||
setup() {
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(this.get('value'), 'evil');
|
||||
assert.ok(this.$('.combobox').length);
|
||||
assert.equal(this.$("select option[value='evil']").text(), 'evil');
|
||||
assert.equal(this.$("select option[value='trout']").text(), 'trout');
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with none', {
|
||||
template: '{{combo-box content=items none="test.none" value=value}}',
|
||||
setup() {
|
||||
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(this.$("select option:eq(0)").text(), 'none');
|
||||
assert.equal(this.$("select option:eq(0)").val(), '');
|
||||
assert.equal(this.$("select option:eq(1)").text(), 'evil');
|
||||
assert.equal(this.$("select option:eq(2)").text(), 'trout');
|
||||
}
|
||||
});
|
||||
@@ -2,13 +2,11 @@ import componentTest from 'helpers/component-test';
|
||||
moduleForComponent('value-list', {integration: true});
|
||||
|
||||
componentTest('functionality', {
|
||||
template: '{{value-list value=values}}',
|
||||
test: function(assert) {
|
||||
andThen(() => {
|
||||
assert.ok(this.$('.values .value').length === 0, 'it has no values');
|
||||
assert.ok(this.$('input').length, 'it renders the input');
|
||||
assert.ok(this.$('.btn-primary[disabled]').length, 'it is disabled with no value');
|
||||
});
|
||||
template: '{{value-list values=values inputType="array"}}',
|
||||
test(assert) {
|
||||
assert.ok(this.$('.values .value').length === 0, 'it has no values');
|
||||
assert.ok(this.$('input').length, 'it renders the input');
|
||||
assert.ok(this.$('.btn-primary[disabled]').length, 'it is disabled with no value');
|
||||
|
||||
fillIn('input', 'eviltrout');
|
||||
andThen(() => {
|
||||
@@ -17,9 +15,10 @@ componentTest('functionality', {
|
||||
|
||||
click('.btn-primary');
|
||||
andThen(() => {
|
||||
assert.ok(this.$('.values .value').length === 1, 'it adds the value');
|
||||
assert.ok(this.$('input').val() === '', 'it clears the input');
|
||||
assert.equal(this.$('.values .value').length, 1, 'it adds the value');
|
||||
assert.equal(this.$('input').val(), '', 'it clears the input');
|
||||
assert.ok(this.$('.btn-primary[disabled]').length, "it is disabled again");
|
||||
assert.equal(this.get('values'), 'eviltrout', 'it appends the value');
|
||||
});
|
||||
|
||||
click('.value .btn-small');
|
||||
@@ -28,3 +27,41 @@ componentTest('functionality', {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with string delimited values', {
|
||||
template: '{{value-list values=valueString}}',
|
||||
setup() {
|
||||
this.set('valueString', "hello\nworld");
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(this.$('.values .value').length, 2);
|
||||
|
||||
fillIn('input', 'eviltrout');
|
||||
click('.btn-primary');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(this.$('.values .value').length, 3);
|
||||
assert.equal(this.get('valueString'), "hello\nworld\neviltrout");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with array values', {
|
||||
template: '{{value-list values=valueArray inputType="array"}}',
|
||||
setup() {
|
||||
this.set('valueArray', ['abc', 'def']);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(this.$('.values .value').length, 2);
|
||||
|
||||
fillIn('input', 'eviltrout');
|
||||
click('.btn-primary');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(this.$('.values .value').length, 3);
|
||||
assert.deepEqual(this.get('valueArray'), ['abc', 'def', 'eviltrout']);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user