From c06b00a54e3ad9ebd4acd8707e8150e0916bc305 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Thu, 9 May 2019 14:08:10 +0300 Subject: [PATCH] FIX: Hide Uncategorized in site menu when disabled. (#7509) --- .../discourse/widgets/hamburger-menu.js.es6 | 6 ++++ .../widgets/hamburger-menu-test.js.es6 | 35 ++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6 b/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6 index b7443a5acda..023128bdfd3 100644 --- a/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6 @@ -204,6 +204,12 @@ export default createWidget("hamburger-menu", { ); } + if (!this.siteSettings.allow_uncategorized_topics) { + categories = categories.filter( + c => c.id !== this.site.uncategorized_category_id + ); + } + const moreCount = categories.length - maxCategoriesToDisplay; categories = categories.slice(0, maxCategoriesToDisplay); diff --git a/test/javascripts/widgets/hamburger-menu-test.js.es6 b/test/javascripts/widgets/hamburger-menu-test.js.es6 index fe2db01422c..f1385baf090 100644 --- a/test/javascripts/widgets/hamburger-menu-test.js.es6 +++ b/test/javascripts/widgets/hamburger-menu-test.js.es6 @@ -125,19 +125,38 @@ widgetTest("top categories - anonymous", { beforeEach() { this.siteSettings.header_dropdown_category_count = 8; - maxCategoriesToDisplay = this.siteSettings.header_dropdown_category_count; - categoriesByCount = this.site.get("categoriesByCount"); }, test(assert) { - const count = categoriesByCount.length; - const maximum = - count <= maxCategoriesToDisplay ? count : maxCategoriesToDisplay; - assert.equal(find(".category-link").length, maximum); + assert.equal(find(".category-link").length, 8); assert.equal( find(".category-link .category-name").text(), - categoriesByCount - .slice(0, maxCategoriesToDisplay) + this.site + .get("categoriesByCount") + .slice(0, 8) + .map(c => c.name) + .join("") + ); + } +}); + +widgetTest("top categories - allow_uncategorized_topics", { + template: '{{mount-widget widget="hamburger-menu"}}', + anonymous: true, + + beforeEach() { + this.siteSettings.allow_uncategorized_topics = false; + this.siteSettings.header_dropdown_category_count = 8; + }, + + test(assert) { + assert.equal(find(".category-link").length, 8); + assert.equal( + find(".category-link .category-name").text(), + this.site + .get("categoriesByCount") + .filter(c => c.name !== "uncategorized") + .slice(0, 8) .map(c => c.name) .join("") );