mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 04:01:18 +08:00
FIX: category-drop initial state was incorrect (#6743)
This commit is contained in:
92
test/javascripts/components/category-drop-test.js.es6
Normal file
92
test/javascripts/components/category-drop-test.js.es6
Normal file
@ -0,0 +1,92 @@
|
||||
import componentTest from "helpers/component-test";
|
||||
import Category from "discourse/models/category";
|
||||
|
||||
moduleForComponent("category-drop", {
|
||||
integration: true,
|
||||
beforeEach: function() {
|
||||
this.set("subject", selectKit());
|
||||
}
|
||||
});
|
||||
|
||||
componentTest("subcatgories - no selection", {
|
||||
template:
|
||||
"{{category-drop onSelect=onSelect category=category parentCategory=parentCategory categories=childCategories subCategory=true noSubcategories=false}}",
|
||||
|
||||
beforeEach() {
|
||||
const parentCategory = Category.findById(2);
|
||||
|
||||
const childCategories = this.site.get("categoriesList").filter(c => {
|
||||
return c.get("parentCategory") === parentCategory;
|
||||
});
|
||||
|
||||
this.set("childCategories", childCategories);
|
||||
this.set("parentCategory", parentCategory);
|
||||
},
|
||||
|
||||
async test(assert) {
|
||||
assert.equal(
|
||||
this.get("subject")
|
||||
.header()
|
||||
.title(),
|
||||
I18n.t("categories.all_subcategories")
|
||||
);
|
||||
|
||||
await this.get("subject").expand();
|
||||
|
||||
assert.equal(
|
||||
this.get("subject")
|
||||
.rowByIndex(0)
|
||||
.name(),
|
||||
I18n.t("categories.no_subcategory")
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
this.get("subject")
|
||||
.rowByIndex(1)
|
||||
.name(),
|
||||
this.get("childCategories.firstObject.name")
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
componentTest("subcatgories - selection", {
|
||||
template:
|
||||
"{{category-drop onSelect=onSelect category=category parentCategory=parentCategory categories=childCategories subCategory=true noSubcategories=false}}",
|
||||
|
||||
beforeEach() {
|
||||
const parentCategory = Category.findById(2);
|
||||
|
||||
const childCategories = this.site.get("categoriesList").filter(c => {
|
||||
return c.get("parentCategory") === parentCategory;
|
||||
});
|
||||
|
||||
this.set("childCategories", childCategories);
|
||||
this.set("category", childCategories.get("firstObject"));
|
||||
this.set("parentCategory", parentCategory);
|
||||
},
|
||||
|
||||
async test(assert) {
|
||||
assert.equal(
|
||||
this.get("subject")
|
||||
.header()
|
||||
.title(),
|
||||
this.get("childCategories.firstObject.name")
|
||||
);
|
||||
|
||||
await this.get("subject").expand();
|
||||
|
||||
assert.equal(
|
||||
this.get("subject")
|
||||
.rowByIndex(0)
|
||||
.name(),
|
||||
I18n.t("categories.all_subcategories")
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
this.get("subject")
|
||||
.rowByIndex(1)
|
||||
.name(),
|
||||
I18n.t("categories.no_subcategory")
|
||||
);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user