From d9a9682f7219f1cf3b8cc5555f8a3157803ab7b0 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 9 Jul 2018 16:52:55 +1000 Subject: [PATCH] FIX: also count sub categories in hamburger when needed previously there were cases where we suppress subcategories yet don't count them this leads to confusion --- .../widgets/hamburger-categories.js.es6 | 13 ++++++- .../widgets/hamburger-menu-test.js.es6 | 39 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/widgets/hamburger-categories.js.es6 b/app/assets/javascripts/discourse/widgets/hamburger-categories.js.es6 index 6675e9db16e..8036f1a4e2e 100644 --- a/app/assets/javascripts/discourse/widgets/hamburger-categories.js.es6 +++ b/app/assets/javascripts/discourse/widgets/hamburger-categories.js.es6 @@ -31,7 +31,18 @@ createWidget("hamburger-category", { } if (!this.currentUser) { - results.push(h("b.topics-count", number(c.get("topic_count")))); + let count = c.get("topic_count"); + + if (c.get("show_subcategory_list")) { + const subcats = c.get("subcategories"); + if (subcats) { + subcats.forEach(s => { + count += s.get("topic_count"); + }); + } + } + + results.push(h("b.topics-count", number(count))); } return results; diff --git a/test/javascripts/widgets/hamburger-menu-test.js.es6 b/test/javascripts/widgets/hamburger-menu-test.js.es6 index 63759812bcb..1dbdfcca6c1 100644 --- a/test/javascripts/widgets/hamburger-menu-test.js.es6 +++ b/test/javascripts/widgets/hamburger-menu-test.js.es6 @@ -125,6 +125,45 @@ widgetTest("general links", { } }); +widgetTest("category links", { + template: '{{mount-widget widget="hamburger-menu"}}', + anonymous: true, + + beforeEach() { + const cat = this.site.get("categoriesList")[0]; + + const parent = Discourse.Category.create({ + id: 1, + topic_count: 5, + name: "parent", + url: "https://test.com/parent", + show_subcategory_list: true, + topicTrackingState: cat.get("topicTrackingState") + }); + const child = Discourse.Category.create({ + id: 2, + parent_category_id: 1, + parentCategory: parent, + topic_count: 4, + name: "child", + url: "https://test.com/child", + topicTrackingState: cat.get("topicTrackingState") + }); + + parent.subcategories = [child]; + + const list = [parent, child]; + this.site.set("categoriesList", list); + }, + + test(assert) { + // if show_subcategory_list is enabled we suppress the categories from hamburger + // this means that people can be confused about counts + assert.equal(this.$(".category-link").length, 1); + assert.equal(this.$(".category-link .topics-count").text(), "9"); + } +}); + widgetTest("badges link - disabled", { template: '{{mount-widget widget="hamburger-menu"}}',