2018-06-15 23:03:24 +08:00
|
|
|
import componentTest from "helpers/component-test";
|
|
|
|
moduleForComponent("value-list", { integration: true });
|
2015-06-10 00:19:41 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("functionality", {
|
2015-07-29 00:29:40 +08:00
|
|
|
template: '{{value-list values=values inputType="array"}}',
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
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"
|
|
|
|
);
|
2015-06-10 00:19:41 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
await fillIn("input", "eviltrout");
|
|
|
|
assert.ok(
|
|
|
|
!this.$(".btn-primary[disabled]").length,
|
|
|
|
"it isn't disabled anymore"
|
|
|
|
);
|
2015-06-10 00:19:41 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
await click(".btn-primary");
|
|
|
|
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");
|
2015-06-10 00:19:41 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
await click(".value .btn-small");
|
|
|
|
assert.ok(this.$(".values .value").length === 0, "it removes the value");
|
2015-07-15 01:56:59 +08:00
|
|
|
}
|
2015-06-10 00:19:41 +08:00
|
|
|
});
|
2015-07-29 00:29:40 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with string delimited values", {
|
|
|
|
template: "{{value-list values=valueString}}",
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("valueString", "hello\nworld");
|
2015-07-29 00:29:40 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.equal(this.$(".values .value").length, 2);
|
2015-07-29 00:29:40 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
await fillIn("input", "eviltrout");
|
|
|
|
await click(".btn-primary");
|
2015-07-29 00:29:40 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
assert.equal(this.$(".values .value").length, 3);
|
|
|
|
assert.equal(this.get("valueString"), "hello\nworld\neviltrout");
|
2015-07-29 00:29:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with array values", {
|
2015-07-29 00:29:40 +08:00
|
|
|
template: '{{value-list values=valueArray inputType="array"}}',
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("valueArray", ["abc", "def"]);
|
2015-07-29 00:29:40 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
async test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.equal(this.$(".values .value").length, 2);
|
2015-07-29 00:29:40 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
await fillIn("input", "eviltrout");
|
|
|
|
await click(".btn-primary");
|
2015-07-29 00:29:40 +08:00
|
|
|
|
2018-07-25 02:12:09 +08:00
|
|
|
assert.equal(this.$(".values .value").length, 3);
|
|
|
|
assert.deepEqual(this.get("valueArray"), ["abc", "def", "eviltrout"]);
|
2015-07-29 00:29:40 +08:00
|
|
|
}
|
|
|
|
});
|