DEV: add countTags to topic tracking state

This introduces a new core API to get counts per tag from topic
tracking state

This API will only be useful if a plugin enable tags in topic
tracking state using

`TopicTrackingState.include_tags_in_report = true`
This commit is contained in:
Sam Saffron
2020-06-01 17:05:04 +10:00
parent 32735be5bd
commit 82de9c5308
2 changed files with 90 additions and 12 deletions

View File

@ -14,6 +14,56 @@ QUnit.module("model:topic-tracking-state", {
}
});
QUnit.test("tag counts", function(assert) {
const state = TopicTrackingState.create();
state.loadStates([
{
topic_id: 1,
last_read_post_number: null,
tags: ["foo", "new"]
},
{
topic_id: 2,
last_read_post_number: null,
tags: ["new"]
},
{
topic_id: 3,
last_read_post_number: null,
tags: ["random"]
},
{
topic_id: 4,
last_read_post_number: 1,
highest_post_number: 7,
tags: ["unread"],
notification_level: NotificationLevels.TRACKING
},
{
topic_id: 5,
last_read_post_number: 1,
highest_post_number: 7,
tags: ["bar", "unread"],
notification_level: NotificationLevels.TRACKING
},
{
topic_id: 6,
last_read_post_number: 1,
highest_post_number: 7,
tags: null,
notification_level: NotificationLevels.TRACKING
}
]);
const states = state.countTags(["new", "unread"]);
assert.equal(states["new"].newCount, 2, "new counts");
assert.equal(states["new"].unreadCount, 0, "new counts");
assert.equal(states["unread"].unreadCount, 2, "unread counts");
assert.equal(states["unread"].newCount, 0, "unread counts");
});
QUnit.test("sync", function(assert) {
const state = TopicTrackingState.create();
state.states["t111"] = { last_read_post_number: null };