discourse/test/javascripts/models/nav-item-test.js.es6

45 lines
1.2 KiB
Plaintext
Raw Normal View History

import { run } from "@ember/runloop";
2018-06-15 23:03:24 +08:00
import createStore from "helpers/create-store";
import NavItem from "discourse/models/nav-item";
import Category from "discourse/models/category";
import Site from "discourse/models/site";
QUnit.module("NavItem", {
2017-06-15 01:57:58 +08:00
beforeEach() {
run(function() {
const asianCategory = Category.create({
2018-06-15 23:03:24 +08:00
name: "确实是这样",
id: 343434
});
Site.currentProp("categories").addObject(asianCategory);
2014-01-10 02:48:47 +08:00
});
}
});
2018-06-15 23:03:24 +08:00
QUnit.test("href", assert => {
assert.expect(2);
function href(text, expected, label) {
assert.equal(NavItem.fromText(text, {}).get("href"), expected, label);
}
2018-06-15 23:03:24 +08:00
href("latest", "/latest", "latest");
href("categories", "/categories", "categories");
});
QUnit.test("count", 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();
2018-06-15 23:03:24 +08:00
assert.equal(
navItem.get("count"),
1,
"it updates when a new message arrives"
);
});