2018-06-15 23:03:24 +08:00
|
|
|
import TopicTrackingState from "discourse/models/topic-tracking-state";
|
|
|
|
import createStore from "helpers/create-store";
|
2019-11-09 02:30:41 +08:00
|
|
|
import Category from "discourse/models/category";
|
2014-02-11 12:28:05 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.module("model:topic-tracking-state");
|
2014-02-11 12:28:05 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
QUnit.test("sync", function(assert) {
|
2015-09-04 04:55:55 +08:00
|
|
|
const state = TopicTrackingState.create();
|
2018-06-15 23:03:24 +08:00
|
|
|
state.states["t111"] = { last_read_post_number: null };
|
2014-02-11 12:28:05 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2014-02-11 12:28:05 +08:00
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
2014-02-11 12:28:05 +08:00
|
|
|
});
|
2015-09-21 08:36:20 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
QUnit.test("subscribe to category", function(assert) {
|
2015-09-21 08:36:20 +08:00
|
|
|
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
|
|
|
|
}),
|
2015-09-21 08:36:20 +08:00
|
|
|
categoryList = [darth, luke];
|
|
|
|
|
2019-11-09 02:30:41 +08:00
|
|
|
sandbox.stub(Category, "list").returns(categoryList);
|
2015-09-21 08:36:20 +08:00
|
|
|
|
|
|
|
const state = TopicTrackingState.create();
|
|
|
|
|
2019-12-17 05:33:38 +08:00
|
|
|
state.trackIncoming("c/darth/1/l/latest");
|
2015-09-21 08:36:20 +08:00
|
|
|
|
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 }
|
|
|
|
});
|
2015-09-21 08:36:20 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.equal(
|
|
|
|
state.get("incomingCount"),
|
|
|
|
2,
|
|
|
|
"expect to properly track incoming for category"
|
|
|
|
);
|
2015-09-21 08:36:20 +08:00
|
|
|
|
|
|
|
state.resetTracking();
|
2019-12-17 05:33:38 +08:00
|
|
|
state.trackIncoming("c/darth/luke/2/l/latest");
|
2015-09-21 08:36:20 +08:00
|
|
|
|
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 }
|
|
|
|
});
|
2015-09-21 08:36:20 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.equal(
|
|
|
|
state.get("incomingCount"),
|
|
|
|
1,
|
|
|
|
"expect to properly track incoming for subcategory"
|
|
|
|
);
|
|
|
|
});
|