discourse/test/javascripts/components/category-selector-test.js.es6

95 lines
2.1 KiB
Plaintext
Raw Normal View History

2018-06-15 11:03:24 -04:00
import componentTest from "helpers/component-test";
import Category from "discourse/models/category";
2018-06-15 11:03:24 -04:00
moduleForComponent("category-selector", {
integration: true,
beforeEach: function() {
2018-06-15 11:03:24 -04:00
this.set("subject", selectKit());
}
});
2018-06-15 11:03:24 -04:00
componentTest("default", {
template: "{{category-selector categories=categories}}",
beforeEach() {
2018-06-15 11:03:24 -04:00
this.set("categories", [Category.findById(2)]);
},
test(assert) {
2018-07-29 16:51:32 -04:00
assert.equal(
this.get("subject")
.header()
.value(),
2
);
assert.notOk(
this.get("subject")
.rowByValue(2)
.exists(),
"selected categories are not in the list"
);
}
});
2018-06-15 11:03:24 -04:00
componentTest("with blacklist", {
template: "{{category-selector categories=categories blacklist=blacklist}}",
beforeEach() {
2018-06-15 11:03:24 -04:00
this.set("categories", [Category.findById(2)]);
this.set("blacklist", [Category.findById(8)]);
},
2018-07-29 16:51:32 -04:00
async test(assert) {
await this.get("subject").expand();
2018-07-29 16:51:32 -04:00
assert.ok(
this.get("subject")
.rowByValue(6)
.exists(),
"not blacklisted categories are in the list"
);
assert.notOk(
this.get("subject")
.rowByValue(8)
.exists(),
"blacklisted categories are not in the list"
);
}
});
2018-06-15 11:03:24 -04:00
componentTest("interactions", {
template: "{{category-selector categories=categories}}",
beforeEach() {
2018-06-15 11:03:24 -04:00
this.set("categories", [Category.findById(2), Category.findById(6)]);
},
2018-07-29 16:51:32 -04:00
async test(assert) {
await this.get("subject").expand();
await this.get("subject").selectRowByValue(8);
assert.equal(
this.get("subject")
.header()
.value(),
"2,6,8",
"it adds the selected category"
);
assert.equal(this.get("categories").length, 3);
2018-07-29 16:51:32 -04:00
await this.get("subject").expand();
2018-07-29 16:51:32 -04:00
await this.get("subject").keyboard("backspace");
await this.get("subject").keyboard("backspace");
2018-07-29 16:51:32 -04:00
assert.equal(
this.get("subject")
.header()
.value(),
"2,6",
"it removes the last selected category"
);
assert.equal(this.get("categories").length, 2);
}
});