mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 10:58:38 +08:00
[WIP] select-box-kit refactoring
This commit is contained in:
parent
a9f718fe57
commit
ae1743c61f
157 changed files with 3262 additions and 2404 deletions
|
@ -1,74 +1,173 @@
|
|||
import componentTest from 'helpers/component-test';
|
||||
moduleForComponent('combo-box', {integration: true});
|
||||
|
||||
componentTest('with objects', {
|
||||
template: '{{combo-box content=items value=value}}',
|
||||
componentTest('default', {
|
||||
template: '{{combo-box content=items}}',
|
||||
beforeEach() {
|
||||
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');
|
||||
expandSelectBox('.combobox');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(selectBox('.combobox').header.name(), "hello");
|
||||
assert.equal(selectBox('.combobox').rowByValue(1).name(), "hello");
|
||||
assert.equal(selectBox('.combobox').rowByValue(2).name(), "world");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with objects and valueAttribute', {
|
||||
componentTest('with valueAttribute', {
|
||||
template: '{{combo-box content=items valueAttribute="value"}}',
|
||||
beforeEach() {
|
||||
this.set('items', [{value: 0, name: 'hello'}, {value: 1, name: 'world'}]);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.ok(this.$('.combobox').length);
|
||||
assert.equal(this.$("select option[value='0']").text(), 'hello');
|
||||
assert.equal(this.$("select option[value='1']").text(), 'world');
|
||||
expandSelectBox('.combobox');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(selectBox('.combobox').rowByValue(0).name(), "hello");
|
||||
assert.equal(selectBox('.combobox').rowByValue(1).name(), "world");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with an array', {
|
||||
componentTest('with nameProperty', {
|
||||
template: '{{combo-box content=items nameProperty="text"}}',
|
||||
beforeEach() {
|
||||
this.set('items', [{id: 0, text: 'hello'}, {id: 1, text: 'world'}]);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
expandSelectBox('.combobox');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(selectBox('.combobox').rowByValue(0).name(), "hello");
|
||||
assert.equal(selectBox('.combobox').rowByValue(1).name(), "world");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with an array as content', {
|
||||
template: '{{combo-box content=items value=value}}',
|
||||
beforeEach() {
|
||||
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');
|
||||
expandSelectBox('.combobox');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(selectBox('.combobox').rowByValue('evil').name(), "evil");
|
||||
assert.equal(selectBox('.combobox').rowByValue('trout').name(), "trout");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with none', {
|
||||
componentTest('with value and none as a string', {
|
||||
template: '{{combo-box content=items none="test.none" value=value}}',
|
||||
beforeEach() {
|
||||
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
this.set('value', 'trout');
|
||||
},
|
||||
|
||||
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');
|
||||
expandSelectBox('.combobox');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(selectBox('.combobox').noneRow.name(), 'none');
|
||||
assert.equal(selectBox('.combobox').rowByValue("evil").name(), "evil");
|
||||
assert.equal(selectBox('.combobox').rowByValue("trout").name(), "trout");
|
||||
assert.equal(selectBox('.combobox').header.name(), 'trout');
|
||||
assert.equal(this.get('value'), 'trout');
|
||||
});
|
||||
|
||||
selectBoxSelectRow('', {selector: '.combobox' });
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(this.get('value'), null);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with Object none', {
|
||||
template: '{{combo-box content=items none=none value=value selected="something"}}',
|
||||
componentTest('with value and none as an object', {
|
||||
template: '{{combo-box content=items none=none value=value}}',
|
||||
beforeEach() {
|
||||
this.set('none', { id: 'something', name: 'none' });
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
this.set('value', 'evil');
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(this.get('value'), 'something');
|
||||
assert.equal(this.$("select option:eq(0)").text(), 'none');
|
||||
assert.equal(this.$("select option:eq(0)").val(), 'something');
|
||||
assert.equal(this.$("select option:eq(1)").text(), 'evil');
|
||||
assert.equal(this.$("select option:eq(2)").text(), 'trout');
|
||||
expandSelectBox('.combobox');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(selectBox('.combobox').noneRow.name(), 'none');
|
||||
assert.equal(selectBox('.combobox').rowByValue("evil").name(), "evil");
|
||||
assert.equal(selectBox('.combobox').rowByValue("trout").name(), "trout");
|
||||
assert.equal(selectBox('.combobox').header.name(), 'evil');
|
||||
assert.equal(this.get('value'), 'evil');
|
||||
});
|
||||
|
||||
selectBoxSelectNoneRow({ selector: '.combobox' });
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(this.get('value'), null);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with no value and none as an object', {
|
||||
template: '{{combo-box content=items none=none value=value}}',
|
||||
beforeEach() {
|
||||
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
||||
this.set('none', { id: 'something', name: 'none' });
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
this.set('value', null);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
expandSelectBox('.combobox');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(selectBox('.combobox').header.name(), 'none');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with no value and none string', {
|
||||
template: '{{combo-box content=items none=none value=value}}',
|
||||
beforeEach() {
|
||||
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
||||
this.set('none', 'test.none');
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
this.set('value', null);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
expandSelectBox('.combobox');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(selectBox('.combobox').header.name(), 'none');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with no value and no none', {
|
||||
template: '{{combo-box content=items value=value}}',
|
||||
beforeEach() {
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
this.set('value', null);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
expandSelectBox('.combobox');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(selectBox('.combobox').header.name(), 'evil', 'it sets the first row as value');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue