2018-06-15 23:03:24 +08:00
|
|
|
import componentTest from "helpers/component-test";
|
2017-12-22 20:08:12 +08:00
|
|
|
import Category from "discourse/models/category";
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
moduleForComponent("category-selector", {
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("default", {
|
|
|
|
template: "{{category-selector categories=categories}}",
|
2017-12-22 20:08:12 +08:00
|
|
|
|
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("categories", [Category.findById(2)]);
|
2017-12-22 20:08:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(
|
|
|
|
this.get("subject")
|
|
|
|
.header()
|
|
|
|
.value(),
|
|
|
|
2
|
|
|
|
);
|
|
|
|
assert.notOk(
|
|
|
|
this.get("subject")
|
|
|
|
.rowByValue(2)
|
|
|
|
.exists(),
|
|
|
|
"selected categories are not in the list"
|
|
|
|
);
|
2017-12-22 20:08:12 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("with blacklist", {
|
|
|
|
template: "{{category-selector categories=categories blacklist=blacklist}}",
|
2017-12-22 20:08:12 +08:00
|
|
|
|
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("categories", [Category.findById(2)]);
|
|
|
|
this.set("blacklist", [Category.findById(8)]);
|
2017-12-22 20:08:12 +08:00
|
|
|
},
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
|
|
|
await this.get("subject").expand();
|
2017-12-22 20:08:12 +08:00
|
|
|
|
2018-07-30 04:51:32 +08: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"
|
|
|
|
);
|
2017-12-22 20:08:12 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("interactions", {
|
|
|
|
template: "{{category-selector categories=categories}}",
|
2017-12-22 20:08:12 +08:00
|
|
|
|
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("categories", [Category.findById(2), Category.findById(6)]);
|
2017-12-22 20:08:12 +08:00
|
|
|
},
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
2019-04-17 00:35:54 +08:00
|
|
|
return assert.ok(true); // Flaky test. Marked as pending
|
2018-07-30 04:51:32 +08:00
|
|
|
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);
|
2017-12-22 20:08:12 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await this.get("subject").expand();
|
2017-12-22 20:08:12 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await this.get("subject").keyboard("backspace");
|
|
|
|
await this.get("subject").keyboard("backspace");
|
2017-12-22 20:08:12 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(
|
|
|
|
this.get("subject")
|
|
|
|
.header()
|
|
|
|
.value(),
|
|
|
|
"2,6",
|
|
|
|
"it removes the last selected category"
|
|
|
|
);
|
|
|
|
assert.equal(this.get("categories").length, 2);
|
2017-12-22 20:08:12 +08:00
|
|
|
}
|
|
|
|
});
|