discourse/test/javascripts/models/topic-tracking-state-test.js.es6

93 lines
2.0 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import TopicTrackingState from "discourse/models/topic-tracking-state";
import createStore from "helpers/create-store";
2017-06-15 01:57:58 +08:00
QUnit.module("model:topic-tracking-state");
2018-06-15 23:03:24 +08:00
QUnit.test("sync", function(assert) {
const state = TopicTrackingState.create();
2018-06-15 23:03:24 +08:00
state.states["t111"] = { last_read_post_number: null };
state.updateSeen(111, 7);
2018-06-15 23:03:24 +08:00
const list = {
topics: [
{
highest_post_number: null,
id: 111,
unread: 10,
new_posts: 10
}
]
};
state.sync(list, "new");
2018-06-15 23:03:24 +08:00
assert.equal(
list.topics.length,
0,
"expect new topic to be removed as it was seen"
);
});
2018-06-15 23:03:24 +08:00
QUnit.test("subscribe to category", function(assert) {
const store = createStore();
2018-06-15 23:03:24 +08:00
const darth = store.createRecord("category", { id: 1, slug: "darth" }),
luke = store.createRecord("category", {
id: 2,
slug: "luke",
parentCategory: darth
}),
categoryList = [darth, luke];
2018-06-15 23:03:24 +08:00
sandbox.stub(Discourse.Category, "list").returns(categoryList);
const state = TopicTrackingState.create();
2018-06-15 23:03:24 +08:00
state.trackIncoming("c/darth/l/latest");
2018-06-15 23:03:24 +08:00
state.notify({
message_type: "new_topic",
topic_id: 1,
payload: { category_id: 2, topic_id: 1 }
});
state.notify({
message_type: "new_topic",
topic_id: 2,
payload: { category_id: 3, topic_id: 2 }
});
state.notify({
message_type: "new_topic",
topic_id: 3,
payload: { category_id: 1, topic_id: 3 }
});
2018-06-15 23:03:24 +08:00
assert.equal(
state.get("incomingCount"),
2,
"expect to properly track incoming for category"
);
state.resetTracking();
2018-06-15 23:03:24 +08:00
state.trackIncoming("c/darth/luke/l/latest");
2018-06-15 23:03:24 +08:00
state.notify({
message_type: "new_topic",
topic_id: 1,
payload: { category_id: 2, topic_id: 1 }
});
state.notify({
message_type: "new_topic",
topic_id: 2,
payload: { category_id: 3, topic_id: 2 }
});
state.notify({
message_type: "new_topic",
topic_id: 3,
payload: { category_id: 1, topic_id: 3 }
});
2018-06-15 23:03:24 +08:00
assert.equal(
state.get("incomingCount"),
1,
"expect to properly track incoming for subcategory"
);
});