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

107 lines
2.2 KiB
Plaintext
Raw Normal View History

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