UX: Display only top categories in hamburger menu (#6146)

This commit is contained in:
Vinoth Kannan
2018-07-27 12:11:07 +05:30
committed by GitHub
parent e4208113a8
commit dac29b5ebc
7 changed files with 122 additions and 46 deletions

View File

@ -2,6 +2,9 @@ import { moduleForWidget, widgetTest } from "helpers/widget-test";
moduleForWidget("hamburger-menu");
const maxCategoriesToDisplay = 6;
const topCategoryIds = [2, 3, 1];
widgetTest("prioritize faq", {
template: '{{mount-widget widget="hamburger-menu"}}',
@ -125,42 +128,40 @@ widgetTest("general links", {
}
});
widgetTest("category links", {
widgetTest("top categories - anonymous", {
template: '{{mount-widget widget="hamburger-menu"}}',
anonymous: true,
test(assert) {
const count = this.site.get("categoriesByCount").length;
const maximum =
count <= maxCategoriesToDisplay ? count : maxCategoriesToDisplay;
assert.equal(find(".category-link").length, maximum);
}
});
widgetTest("top categories", {
template: '{{mount-widget widget="hamburger-menu"}}',
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);
this.currentUser.set("top_category_ids", topCategoryIds);
},
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");
assert.equal(find(".category-link").length, maxCategoriesToDisplay);
const categoriesList = this.site
.get("categoriesByCount")
.reject(c => c.parent_category_id);
let ids = topCategoryIds
.concat(categoriesList.map(c => c.id))
.uniq()
.slice(0, maxCategoriesToDisplay);
assert.equal(
find(".category-link .category-name").text(),
ids.map(i => categoriesList.find(c => c.id === i).name).join("")
);
}
});