2015-09-04 04:55:55 +08:00
|
|
|
import createStore from "helpers/create-store";
|
2019-11-14 05:00:58 +08:00
|
|
|
import Site from "discourse/models/site";
|
2015-08-12 00:27:07 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.module("model:site");
|
2013-06-17 23:38:30 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("create", (assert) => {
|
2019-11-14 05:00:58 +08:00
|
|
|
assert.ok(Site.create(), "it can create with no parameters");
|
2013-10-30 01:01:42 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("instance", (assert) => {
|
2019-11-14 05:00:58 +08:00
|
|
|
const site = Site.current();
|
2013-06-17 23:38:30 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.present(site, "We have a current site singleton");
|
|
|
|
assert.present(
|
|
|
|
site.get("categories"),
|
|
|
|
"The instance has a list of categories"
|
|
|
|
);
|
|
|
|
assert.present(
|
|
|
|
site.get("flagTypes"),
|
|
|
|
"The instance has a list of flag types"
|
|
|
|
);
|
|
|
|
assert.present(
|
|
|
|
site.get("trustLevels"),
|
|
|
|
"The instance has a list of trust levels"
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2013-10-24 01:29:20 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("create categories", (assert) => {
|
2015-09-04 04:55:55 +08:00
|
|
|
const store = createStore();
|
|
|
|
const site = store.createRecord("site", {
|
2013-10-24 01:29:20 +08:00
|
|
|
categories: [
|
|
|
|
{ id: 1234, name: "Test" },
|
|
|
|
{ id: 3456, name: "Test Subcategory", parent_category_id: 1234 },
|
2015-09-04 04:55:55 +08:00
|
|
|
{ id: 3458, name: "Invalid Subcategory", parent_category_id: 6666 },
|
|
|
|
],
|
2013-10-24 01:29:20 +08:00
|
|
|
});
|
|
|
|
|
2015-09-04 04:55:55 +08:00
|
|
|
const categories = site.get("categories");
|
2015-07-10 10:09:43 +08:00
|
|
|
site.get("sortedCategories");
|
2013-10-24 01:29:20 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.present(categories, "The categories are present");
|
|
|
|
assert.equal(categories.length, 3, "it loaded all three categories");
|
2013-10-24 01:29:20 +08:00
|
|
|
|
2015-09-04 04:55:55 +08:00
|
|
|
const parent = categories.findBy("id", 1234);
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.present(parent, "it loaded the parent category");
|
|
|
|
assert.blank(parent.get("parentCategory"), "it has no parent category");
|
2013-10-24 01:29:20 +08:00
|
|
|
|
2018-07-12 15:59:38 +08:00
|
|
|
assert.equal(parent.get("subcategories").length, 1);
|
|
|
|
|
2015-09-04 04:55:55 +08:00
|
|
|
const subcategory = categories.findBy("id", 3456);
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.present(subcategory, "it loaded the subcategory");
|
|
|
|
assert.equal(
|
|
|
|
subcategory.get("parentCategory"),
|
|
|
|
parent,
|
|
|
|
"it has associated the child with the parent"
|
|
|
|
);
|
2013-10-24 01:29:20 +08:00
|
|
|
|
2015-07-10 10:09:43 +08:00
|
|
|
// remove invalid category and child
|
|
|
|
categories.removeObject(categories[2]);
|
|
|
|
categories.removeObject(categories[1]);
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(
|
|
|
|
categories.length,
|
|
|
|
site.get("categoriesByCount").length,
|
|
|
|
"categories by count should change on removal"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
categories.length,
|
|
|
|
site.get("sortedCategories").length,
|
|
|
|
"sorted categories should change on removal"
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2017-06-15 01:57:58 +08:00
|
|
|
});
|