2018-06-15 23:03:24 +08:00
|
|
|
import { moduleForWidget, widgetTest } from "helpers/widget-test";
|
2016-04-15 03:23:05 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
moduleForWidget("hamburger-menu");
|
2016-04-15 03:23:05 +08:00
|
|
|
|
2018-07-27 14:41:07 +08:00
|
|
|
const topCategoryIds = [2, 3, 1];
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("prioritize faq", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.siteSettings.faq_url = "http://example.com/faq";
|
|
|
|
this.currentUser.set("read_faq", false);
|
2016-04-15 03:23:05 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(this.$(".faq-priority").length);
|
|
|
|
assert.ok(!this.$(".faq-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("prioritize faq - user has read", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.siteSettings.faq_url = "http://example.com/faq";
|
|
|
|
this.currentUser.set("read_faq", true);
|
2016-04-15 03:23:05 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(!this.$(".faq-priority").length);
|
|
|
|
assert.ok(this.$(".faq-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("staff menu - not staff", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.currentUser.set("staff", false);
|
2016-04-15 03:23:05 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(!this.$(".admin-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("staff menu", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.currentUser.setProperties({
|
|
|
|
staff: true,
|
|
|
|
site_flagged_posts_count: 3
|
|
|
|
});
|
2016-04-15 03:23:05 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(this.$(".admin-link").length);
|
|
|
|
assert.ok(this.$(".flagged-posts-link").length);
|
|
|
|
assert.equal(this.$(".flagged-posts").text(), "3");
|
|
|
|
assert.ok(!this.$(".settings-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("staff menu - admin", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2016-04-15 03:23:05 +08:00
|
|
|
this.currentUser.setProperties({ staff: true, admin: true });
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(this.$(".settings-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("queued posts", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2016-04-15 03:23:05 +08:00
|
|
|
this.currentUser.setProperties({
|
|
|
|
staff: true,
|
|
|
|
show_queued_posts: true,
|
|
|
|
post_queue_new_count: 5
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(this.$(".queued-posts-link").length);
|
|
|
|
assert.equal(this.$(".queued-posts").text(), "5");
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("queued posts - disabled", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2016-04-15 03:23:05 +08:00
|
|
|
this.currentUser.setProperties({ staff: true, show_queued_posts: false });
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(!this.$(".queued-posts-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("logged in links", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(this.$(".new-topics-link").length);
|
|
|
|
assert.ok(this.$(".unread-topics-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("general links", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
anonymous: true,
|
|
|
|
|
|
|
|
test(assert) {
|
2017-02-14 00:27:30 +08:00
|
|
|
assert.ok(this.$("li[class='']").length === 0);
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(this.$(".latest-topics-link").length);
|
|
|
|
assert.ok(!this.$(".new-topics-link").length);
|
|
|
|
assert.ok(!this.$(".unread-topics-link").length);
|
|
|
|
assert.ok(this.$(".top-topics-link").length);
|
|
|
|
assert.ok(this.$(".badge-link").length);
|
|
|
|
assert.ok(this.$(".category-link").length > 0);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-30 16:43:00 +08:00
|
|
|
let maxCategoriesToDisplay;
|
|
|
|
|
2018-07-27 14:41:07 +08:00
|
|
|
widgetTest("top categories - anonymous", {
|
2018-07-09 14:52:55 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
anonymous: true,
|
|
|
|
|
2018-07-30 16:43:00 +08:00
|
|
|
beforeEach() {
|
|
|
|
this.siteSettings.hamburger_menu_categories_count = 8;
|
|
|
|
maxCategoriesToDisplay = this.siteSettings.hamburger_menu_categories_count;
|
|
|
|
},
|
|
|
|
|
2018-07-27 14:41:07 +08:00
|
|
|
test(assert) {
|
|
|
|
const count = this.site.get("categoriesByCount").length;
|
|
|
|
const maximum =
|
|
|
|
count <= maxCategoriesToDisplay ? count : maxCategoriesToDisplay;
|
|
|
|
assert.equal(find(".category-link").length, maximum);
|
|
|
|
}
|
|
|
|
});
|
2018-07-09 14:52:55 +08:00
|
|
|
|
2018-07-27 14:41:07 +08:00
|
|
|
widgetTest("top categories", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
2018-07-09 14:52:55 +08:00
|
|
|
|
2018-07-27 14:41:07 +08:00
|
|
|
beforeEach() {
|
2018-07-30 16:43:00 +08:00
|
|
|
this.siteSettings.hamburger_menu_categories_count = 8;
|
|
|
|
maxCategoriesToDisplay = this.siteSettings.hamburger_menu_categories_count;
|
2018-07-27 14:41:07 +08:00
|
|
|
this.currentUser.set("top_category_ids", topCategoryIds);
|
2018-07-09 14:52:55 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-07-27 14:41:07 +08:00
|
|
|
assert.equal(find(".category-link").length, maxCategoriesToDisplay);
|
|
|
|
|
2018-07-30 16:43:00 +08:00
|
|
|
const categoriesList = this.site.get("categoriesByCount");
|
2018-07-27 14:41:07 +08:00
|
|
|
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("")
|
|
|
|
);
|
2018-07-09 14:52:55 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("badges link - disabled", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2016-04-15 03:23:05 +08:00
|
|
|
this.siteSettings.enable_badges = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(!this.$(".badge-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("badges link", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(this.$(".badge-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("user directory link", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(this.$(".user-directory-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("user directory link - disabled", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2016-04-15 03:23:05 +08:00
|
|
|
this.siteSettings.enable_user_directory = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(!this.$(".user-directory-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
widgetTest("general links", {
|
2016-04-15 03:23:05 +08:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
|
|
|
test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.ok(this.$(".about-link").length);
|
|
|
|
assert.ok(this.$(".keyboard-shortcuts-link").length);
|
2016-04-15 03:23:05 +08:00
|
|
|
}
|
|
|
|
});
|