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/nav-item-test.js
2021-11-08 10:26:28 +01:00

61 lines
1.7 KiB
JavaScript

import { module, test } from "qunit";
import Category from "discourse/models/category";
import NavItem from "discourse/models/nav-item";
import Site from "discourse/models/site";
import createStore from "discourse/tests/helpers/create-store";
import { run } from "@ember/runloop";
module("Unit | Model | nav-item", function (hooks) {
hooks.beforeEach(function () {
run(function () {
const fooCategory = Category.create({
slug: "foo",
id: 123,
});
Site.currentProp("categories").addObject(fooCategory);
});
});
test("href", function (assert) {
assert.expect(4);
function href(text, opts, expected, label) {
assert.strictEqual(
NavItem.fromText(text, opts).get("href"),
expected,
label
);
}
href("latest", {}, "/latest", "latest");
href("categories", {}, "/categories", "categories");
href("latest", { tagId: "bar" }, "/tag/bar/l/latest", "latest with tag");
href(
"latest",
{ tagId: "bar", category: Category.findBySlugPath(["foo"]) },
"/tags/c/foo/123/bar/l/latest",
"latest with tag and category"
);
});
test("count", function (assert) {
const navItem = createStore().createRecord("nav-item", { name: "new" });
assert.strictEqual(navItem.get("count"), 0, "it has no count by default");
const tracker = navItem.get("topicTrackingState");
tracker.modifyState("t1", {
topic_id: 1,
last_read_post_number: null,
created_in_new_period: true,
});
tracker.incrementMessageCount();
assert.strictEqual(
navItem.get("count"),
1,
"it updates when a new message arrives"
);
});
});