2018-06-15 23:03:24 +08:00
|
|
|
import componentTest from "helpers/component-test";
|
|
|
|
moduleForComponent("combo-box", {
|
2017-12-22 20:08:12 +08:00
|
|
|
integration: true,
|
|
|
|
beforeEach: function() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("subject", selectKit());
|
2017-12-22 20:08:12 +08:00
|
|
|
}
|
|
|
|
});
|
2015-07-29 00:29:40 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("default", {
|
|
|
|
template: "{{combo-box content=items}}",
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("items", [{ id: 1, name: "hello" }, { id: 2, name: "world" }]);
|
2015-07-29 00:29:40 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.subject.header().name(), "hello");
|
|
|
|
assert.equal(this.subject.rowByValue(1).name(), "hello");
|
|
|
|
assert.equal(this.subject.rowByValue(2).name(), "world");
|
2015-07-29 00:29:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with valueAttribute", {
|
2015-08-06 04:19:21 +08:00
|
|
|
template: '{{combo-box content=items valueAttribute="value"}}',
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("items", [
|
|
|
|
{ value: 0, name: "hello" },
|
|
|
|
{ value: 1, name: "world" }
|
|
|
|
]);
|
2015-08-06 04:19:21 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.subject.rowByValue(0).name(), "hello");
|
|
|
|
assert.equal(this.subject.rowByValue(1).name(), "world");
|
2015-08-06 04:19:21 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with nameProperty", {
|
2017-10-20 03:51:08 +08:00
|
|
|
template: '{{combo-box content=items nameProperty="text"}}',
|
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("items", [{ id: 0, text: "hello" }, { id: 1, text: "world" }]);
|
2017-10-20 03:51:08 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.subject.rowByValue(0).name(), "hello");
|
|
|
|
assert.equal(this.subject.rowByValue(1).name(), "world");
|
2017-10-20 03:51:08 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with an array as content", {
|
|
|
|
template: "{{combo-box content=items value=value}}",
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("items", ["evil", "trout", "hat"]);
|
2015-07-29 00:29:40 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.subject.rowByValue("evil").name(), "evil");
|
|
|
|
assert.equal(this.subject.rowByValue("trout").name(), "trout");
|
2015-07-29 00:29:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with value and none as a string", {
|
2015-07-29 00:29:40 +08:00
|
|
|
template: '{{combo-box content=items none="test.none" value=value}}',
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
I18n.translations[I18n.locale].js.test = { none: "none" };
|
|
|
|
this.set("items", ["evil", "trout", "hat"]);
|
|
|
|
this.set("value", "trout");
|
2015-07-29 00:29:40 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.subject.noneRow().name(), "none");
|
|
|
|
assert.equal(this.subject.rowByValue("evil").name(), "evil");
|
|
|
|
assert.equal(this.subject.rowByValue("trout").name(), "trout");
|
|
|
|
assert.equal(this.subject.header().name(), "trout");
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "trout");
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.selectNoneRow();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, null);
|
2015-07-29 00:29:40 +08:00
|
|
|
}
|
|
|
|
});
|
2017-04-20 11:48:59 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with value and none as an object", {
|
|
|
|
template: "{{combo-box content=items none=none value=value}}",
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("none", { id: "something", name: "none" });
|
|
|
|
this.set("items", ["evil", "trout", "hat"]);
|
|
|
|
this.set("value", "evil");
|
2017-04-20 11:48:59 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.subject.noneRow().name(), "none");
|
|
|
|
assert.equal(this.subject.rowByValue("evil").name(), "evil");
|
|
|
|
assert.equal(this.subject.rowByValue("trout").name(), "trout");
|
|
|
|
assert.equal(this.subject.header().name(), "evil");
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "evil");
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.selectNoneRow();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, null);
|
2017-10-20 03:51:08 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with no value and none as an object", {
|
|
|
|
template: "{{combo-box content=items none=none value=value}}",
|
2017-10-20 03:51:08 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
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);
|
2017-10-20 03:51:08 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.subject.header().name(), "none");
|
2017-10-20 03:51:08 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with no value and none string", {
|
|
|
|
template: "{{combo-box content=items none=none value=value}}",
|
2017-10-20 03:51:08 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
I18n.translations[I18n.locale].js.test = { none: "none" };
|
|
|
|
this.set("none", "test.none");
|
|
|
|
this.set("items", ["evil", "trout", "hat"]);
|
|
|
|
this.set("value", null);
|
2017-10-20 03:51:08 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.subject.header().name(), "none");
|
2017-10-20 03:51:08 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with no value and no none", {
|
|
|
|
template: "{{combo-box content=items value=value}}",
|
2017-10-20 03:51:08 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("items", ["evil", "trout", "hat"]);
|
|
|
|
this.set("value", null);
|
2017-10-20 03:51:08 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 16:42:53 +08:00
|
|
|
this.subject.header().name(),
|
2018-07-25 02:12:09 +08:00
|
|
|
"evil",
|
|
|
|
"it sets the first row as value"
|
|
|
|
);
|
2017-04-20 11:48:59 +08:00
|
|
|
}
|
|
|
|
});
|
2017-10-20 05:32:37 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with empty string as value", {
|
|
|
|
template: "{{combo-box content=items value=value}}",
|
2017-10-20 08:34:56 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("items", ["evil", "trout", "hat"]);
|
|
|
|
this.set("value", "");
|
2017-10-20 08:34:56 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 16:42:53 +08:00
|
|
|
this.subject.header().name(),
|
2018-07-25 02:12:09 +08:00
|
|
|
"evil",
|
|
|
|
"it sets the first row as value"
|
|
|
|
);
|
2017-10-20 08:34:56 +08:00
|
|
|
}
|
|
|
|
});
|
2018-03-29 19:42:00 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with noneLabel", {
|
|
|
|
template:
|
|
|
|
"{{combo-box content=items allowAutoSelectFirst=false noneLabel=noneLabel}}",
|
2018-03-29 19:42:00 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
I18n.translations[I18n.locale].js.test = { none: "none" };
|
|
|
|
this.set("items", ["evil", "trout", "hat"]);
|
|
|
|
this.set("noneLabel", "test.none");
|
2018-03-29 19:42:00 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2019-05-27 16:15:39 +08:00
|
|
|
await this.subject.expand();
|
2018-07-25 02:12:09 +08:00
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 16:42:53 +08:00
|
|
|
this.subject.header().name(),
|
2018-07-25 02:12:09 +08:00
|
|
|
"none",
|
|
|
|
"it displays noneLabel as the header name"
|
|
|
|
);
|
2018-03-29 19:42:00 +08:00
|
|
|
}
|
|
|
|
});
|