mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 18:18:11 +08:00
FIX: Include sub-sub-categories in new/unread counts (#8710)
The count used to be less than the real one because the topics in sub-sub-categories and deeper were not taken into account.
This commit is contained in:

committed by
David Taylor

parent
2583aedd42
commit
7d8c33a094
@ -1,6 +1,7 @@
|
||||
import TopicTrackingState from "discourse/models/topic-tracking-state";
|
||||
import createStore from "helpers/create-store";
|
||||
import Category from "discourse/models/category";
|
||||
import { NotificationLevels } from "discourse/lib/notification-levels";
|
||||
|
||||
QUnit.module("model:topic-tracking-state");
|
||||
|
||||
@ -91,3 +92,79 @@ QUnit.test("subscribe to category", function(assert) {
|
||||
"expect to properly track incoming for subcategory"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("getSubCategoryIds", assert => {
|
||||
const store = createStore();
|
||||
const foo = store.createRecord("category", { id: 1, slug: "foo" });
|
||||
const bar = store.createRecord("category", {
|
||||
id: 2,
|
||||
slug: "bar",
|
||||
parent_category_id: foo.id
|
||||
});
|
||||
const baz = store.createRecord("category", {
|
||||
id: 3,
|
||||
slug: "baz",
|
||||
parent_category_id: bar.id
|
||||
});
|
||||
sandbox.stub(Category, "list").returns([foo, bar, baz]);
|
||||
|
||||
const state = TopicTrackingState.create();
|
||||
assert.deepEqual(Array.from(state.getSubCategoryIds(1)), [1, 2, 3]);
|
||||
assert.deepEqual(Array.from(state.getSubCategoryIds(2)), [2, 3]);
|
||||
assert.deepEqual(Array.from(state.getSubCategoryIds(3)), [3]);
|
||||
});
|
||||
|
||||
QUnit.test("countNew", assert => {
|
||||
const store = createStore();
|
||||
const foo = store.createRecord("category", { id: 1, slug: "foo" });
|
||||
const bar = store.createRecord("category", {
|
||||
id: 2,
|
||||
slug: "bar",
|
||||
parent_category_id: foo.id
|
||||
});
|
||||
const baz = store.createRecord("category", {
|
||||
id: 3,
|
||||
slug: "baz",
|
||||
parent_category_id: bar.id
|
||||
});
|
||||
sandbox.stub(Category, "list").returns([foo, bar, baz]);
|
||||
|
||||
const state = TopicTrackingState.create();
|
||||
|
||||
assert.equal(state.countNew(1), 0);
|
||||
assert.equal(state.countNew(2), 0);
|
||||
assert.equal(state.countNew(3), 0);
|
||||
|
||||
state.states["t112"] = {
|
||||
last_read_post_number: null,
|
||||
id: 112,
|
||||
notification_level: NotificationLevels.TRACKING,
|
||||
category_id: 2
|
||||
};
|
||||
|
||||
assert.equal(state.countNew(1), 1);
|
||||
assert.equal(state.countNew(2), 1);
|
||||
assert.equal(state.countNew(3), 0);
|
||||
|
||||
state.states["t113"] = {
|
||||
last_read_post_number: null,
|
||||
id: 113,
|
||||
notification_level: NotificationLevels.TRACKING,
|
||||
category_id: 3
|
||||
};
|
||||
|
||||
assert.equal(state.countNew(1), 2);
|
||||
assert.equal(state.countNew(2), 2);
|
||||
assert.equal(state.countNew(3), 1);
|
||||
|
||||
state.states["t111"] = {
|
||||
last_read_post_number: null,
|
||||
id: 111,
|
||||
notification_level: NotificationLevels.TRACKING,
|
||||
category_id: 1
|
||||
};
|
||||
|
||||
assert.equal(state.countNew(1), 3);
|
||||
assert.equal(state.countNew(2), 2);
|
||||
assert.equal(state.countNew(3), 1);
|
||||
});
|
||||
|
Reference in New Issue
Block a user