discourse/test/javascripts/components/value-list-test.js.es6
Joffrey JAFFEUX 0431942f3d
DEV: select-kit 2 (#7998)
This new iteration of select-kit focuses on following best principales and disallowing mutations inside select-kit components. A best effort has been made to avoid breaking changes, however if you content was a flat array, eg: ["foo", "bar"] You will need to set valueProperty=null and nameProperty=null on the component.

Also almost every component should have an `onChange` handler now to decide what to do with the updated data. **select-kit will not mutate your data by itself anymore**
2020-02-03 14:22:14 +01:00

131 lines
2.9 KiB
JavaScript

import selectKit from "helpers/select-kit-helper";
import componentTest from "helpers/component-test";
moduleForComponent("value-list", { integration: true });
componentTest("adding a value", {
template: "{{value-list values=values}}",
skip: true,
beforeEach() {
this.set("values", "vinkas\nosama");
},
async test(assert) {
await selectKit().expand();
await selectKit().fillInFilter("eviltrout");
await selectKit().keyboard("enter");
assert.ok(
find(".values .value").length === 3,
"it adds the value to the list of values"
);
assert.deepEqual(
this.values,
"vinkas\nosama\neviltrout",
"it adds the value to the list of values"
);
}
});
componentTest("removing a value", {
template: "{{value-list values=values}}",
beforeEach() {
this.set("values", "vinkas\nosama");
},
async test(assert) {
await click(".values .value[data-index='0'] .remove-value-btn");
assert.ok(
find(".values .value").length === 1,
"it removes the value from the list of values"
);
assert.equal(this.values, "osama", "it removes the expected value");
}
});
componentTest("selecting a value", {
template: "{{value-list values=values choices=choices}}",
beforeEach() {
this.setProperties({
values: "vinkas\nosama",
choices: ["maja", "michael"]
});
},
async test(assert) {
await selectKit().expand();
await selectKit().selectRowByValue("maja");
assert.ok(
find(".values .value").length === 3,
"it adds the value to the list of values"
);
assert.deepEqual(
this.values,
"vinkas\nosama\nmaja",
"it adds the value to the list of values"
);
}
});
componentTest("array support", {
template: "{{value-list values=values inputType='array'}}",
beforeEach() {
this.set("values", ["vinkas", "osama"]);
},
async test(assert) {
this.set("values", ["vinkas", "osama"]);
await selectKit().expand();
await selectKit().fillInFilter("eviltrout");
await selectKit().keyboard("enter");
assert.ok(
find(".values .value").length === 3,
"it adds the value to the list of values"
);
assert.deepEqual(
this.values,
["vinkas", "osama", "eviltrout"],
"it adds the value to the list of values"
);
}
});
componentTest("delimiter support", {
template: "{{value-list values=values inputDelimiter='|'}}",
beforeEach() {
this.set("values", "vinkas|osama");
},
skip: true,
async test(assert) {
await selectKit().expand();
await selectKit().fillInFilter("eviltrout");
await selectKit().keyboard("enter");
assert.ok(
find(".values .value").length === 3,
"it adds the value to the list of values"
);
assert.deepEqual(
this.values,
"vinkas|osama|eviltrout",
"it adds the value to the list of values"
);
}
});