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

81 lines
1.9 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) {
assert.equal(this.subject.header().value(), 2);
2018-07-30 04:51:32 +08:00
assert.notOk(
this.subject.rowByValue(2).exists(),
2018-07-30 04:51:32 +08:00
"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)]);
},
2018-07-30 04:51:32 +08:00
async test(assert) {
await this.subject.expand();
2018-07-30 04:51:32 +08:00
assert.ok(
this.subject.rowByValue(6).exists(),
2018-07-30 04:51:32 +08:00
"not blacklisted categories are in the list"
);
assert.notOk(
this.subject.rowByValue(8).exists(),
2018-07-30 04:51:32 +08:00
"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)]);
},
2019-05-01 02:01:21 +08:00
skip: true,
2018-07-30 04:51:32 +08:00
async test(assert) {
await this.subject.expand();
await this.subject.selectRowByValue(8);
2018-07-30 04:51:32 +08:00
assert.equal(
this.subject.header().value(),
2018-07-30 04:51:32 +08:00
"2,6,8",
"it adds the selected category"
);
assert.equal(this.categories.length, 3);
await this.subject.expand();
await this.subject.keyboard("backspace");
await this.subject.keyboard("backspace");
2018-07-30 04:51:32 +08:00
assert.equal(
this.subject.header().value(),
2018-07-30 04:51:32 +08:00
"2,6",
"it removes the last selected category"
);
assert.equal(this.categories.length, 2);
}
});