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
Daniel Waterworth ec4c2a58ea
FIX: Paths with categories and tags were being generated incorrectly (#11167)
Paths prefixed with /tag/ are exclusively for when the tag name is the
next string in the path. Therefore, when a category is being used as
context, the path should start with /tags/ instead.
2020-11-09 12:34:52 +00:00

53 lines
1.5 KiB
JavaScript

import { test, module } from "qunit";
import { run } from "@ember/runloop";
import createStore from "discourse/tests/helpers/create-store";
import NavItem from "discourse/models/nav-item";
import Category from "discourse/models/category";
import Site from "discourse/models/site";
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.equal(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.equal(navItem.get("count"), 0, "it has no count by default");
const tracker = navItem.get("topicTrackingState");
tracker.states["t1"] = { topic_id: 1, last_read_post_number: null };
tracker.incrementMessageCount();
assert.equal(
navItem.get("count"),
1,
"it updates when a new message arrives"
);
});
});