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