2019-06-06 04:47:10 -04:00
|
|
|
import selectKit from "helpers/select-kit-helper";
|
2018-12-10 08:05:00 -05:00
|
|
|
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(
|
2019-05-27 04:42:53 -04:00
|
|
|
this.subject.header().title(),
|
2018-12-10 08:05:00 -05:00
|
|
|
I18n.t("categories.all_subcategories")
|
|
|
|
);
|
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
await this.subject.expand();
|
2018-12-10 08:05:00 -05:00
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 04:42:53 -04:00
|
|
|
this.subject.rowByIndex(0).name(),
|
2018-12-10 08:05:00 -05:00
|
|
|
I18n.t("categories.no_subcategory")
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 04:42:53 -04:00
|
|
|
this.subject.rowByIndex(1).name(),
|
2018-12-10 08:05:00 -05:00
|
|
|
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(
|
2019-05-27 04:42:53 -04:00
|
|
|
this.subject.header().title(),
|
2018-12-10 08:05:00 -05:00
|
|
|
this.get("childCategories.firstObject.name")
|
|
|
|
);
|
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
await this.subject.expand();
|
2018-12-10 08:05:00 -05:00
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 04:42:53 -04:00
|
|
|
this.subject.rowByIndex(0).name(),
|
2018-12-10 08:05:00 -05:00
|
|
|
I18n.t("categories.all_subcategories")
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 04:42:53 -04:00
|
|
|
this.subject.rowByIndex(1).name(),
|
2018-12-10 08:05:00 -05:00
|
|
|
I18n.t("categories.no_subcategory")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|