This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/models/site-test.js
Robin Ward 71d37953d5 REFACTOR: Import QUnit and related helpers rather than globals
We used many global functions to handle tests when they should be
imported like other libraries in our application. This also gets us
closer to the way Ember CLI prefers our tests to be laid out.
2020-10-07 11:50:49 -04:00

74 lines
2.0 KiB
JavaScript

import { test, module } from "qunit";
import createStore from "discourse/tests/helpers/create-store";
import Site from "discourse/models/site";
module("model:site");
test("create", (assert) => {
assert.ok(Site.create(), "it can create with no parameters");
});
test("instance", (assert) => {
const site = Site.current();
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"
);
});
test("create categories", (assert) => {
const store = createStore();
const site = store.createRecord("site", {
categories: [
{ id: 1234, name: "Test" },
{ id: 3456, name: "Test Subcategory", parent_category_id: 1234 },
{ id: 3458, name: "Invalid Subcategory", parent_category_id: 6666 },
],
});
const categories = site.get("categories");
site.get("sortedCategories");
assert.present(categories, "The categories are present");
assert.equal(categories.length, 3, "it loaded all three categories");
const parent = categories.findBy("id", 1234);
assert.present(parent, "it loaded the parent category");
assert.blank(parent.get("parentCategory"), "it has no parent category");
assert.equal(parent.get("subcategories").length, 1);
const subcategory = categories.findBy("id", 3456);
assert.present(subcategory, "it loaded the subcategory");
assert.equal(
subcategory.get("parentCategory"),
parent,
"it has associated the child with the parent"
);
// remove invalid category and child
categories.removeObject(categories[2]);
categories.removeObject(categories[1]);
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"
);
});