2016-04-14 15:23:05 -04:00
|
|
|
import { moduleForWidget, widgetTest } from "helpers/widget-test";
|
2018-07-30 10:50:10 -04:00
|
|
|
import { NotificationLevels } from "discourse/lib/notification-levels";
|
2016-04-14 15:23:05 -04:00
|
|
|
|
|
|
|
moduleForWidget("hamburger-menu");
|
|
|
|
|
2018-07-27 02:41:07 -04:00
|
|
|
const topCategoryIds = [2, 3, 1];
|
2018-07-30 06:07:41 -04:00
|
|
|
let mutedCategoryIds = [];
|
2018-07-30 10:50:10 -04:00
|
|
|
let unreadCategoryIds = [];
|
2018-07-30 06:07:41 -04:00
|
|
|
let categoriesByCount = [];
|
2018-07-27 02:41:07 -04:00
|
|
|
|
2016-04-14 15:23:05 -04:00
|
|
|
widgetTest("prioritize faq", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-04-14 15:23:05 -04:00
|
|
|
this.siteSettings.faq_url = "http://example.com/faq";
|
|
|
|
this.currentUser.set("read_faq", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".faq-priority").length);
|
|
|
|
assert.ok(!find(".faq-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("prioritize faq - user has read", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-04-14 15:23:05 -04:00
|
|
|
this.siteSettings.faq_url = "http://example.com/faq";
|
|
|
|
this.currentUser.set("read_faq", true);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(!find(".faq-priority").length);
|
|
|
|
assert.ok(find(".faq-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("staff menu - not staff", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-04-14 15:23:05 -04:00
|
|
|
this.currentUser.set("staff", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(!find(".admin-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("staff menu", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-04-14 15:23:05 -04:00
|
|
|
this.currentUser.setProperties({
|
2019-07-24 16:01:08 -04:00
|
|
|
moderator: true,
|
2019-03-28 14:15:52 -04:00
|
|
|
reviewable_count: 3
|
2016-04-14 15:23:05 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".admin-link").length);
|
2019-03-28 14:15:52 -04:00
|
|
|
assert.ok(find(".review").length);
|
|
|
|
assert.equal(find(".reviewables").text(), "3");
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(!find(".settings-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("staff menu - admin", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2019-07-24 16:01:08 -04:00
|
|
|
this.currentUser.setProperties({ admin: true });
|
2016-04-14 15:23:05 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".settings-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
widgetTest("reviewable content", {
|
2016-04-14 15:23:05 -04:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-04-14 15:23:05 -04:00
|
|
|
this.currentUser.setProperties({
|
2019-07-24 16:01:08 -04:00
|
|
|
moderator: true,
|
2019-01-03 12:03:01 -05:00
|
|
|
reviewable_count: 5
|
2016-04-14 15:23:05 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2020-07-16 12:00:29 -04:00
|
|
|
assert.equal(find(".reviewables").text(), "5");
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("logged in links", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".new-topics-link").length);
|
|
|
|
assert.ok(find(".unread-topics-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("general links", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
anonymous: true,
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find("li[class='']").length === 0);
|
|
|
|
assert.ok(find(".latest-topics-link").length);
|
|
|
|
assert.ok(!find(".new-topics-link").length);
|
|
|
|
assert.ok(!find(".unread-topics-link").length);
|
|
|
|
assert.ok(find(".top-topics-link").length);
|
|
|
|
assert.ok(find(".badge-link").length);
|
|
|
|
assert.ok(find(".category-link").length > 0);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-30 04:43:00 -04:00
|
|
|
let maxCategoriesToDisplay;
|
|
|
|
|
2018-07-27 02:41:07 -04:00
|
|
|
widgetTest("top categories - anonymous", {
|
2018-07-09 02:52:55 -04:00
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
anonymous: true,
|
|
|
|
|
2018-07-30 04:43:00 -04:00
|
|
|
beforeEach() {
|
2018-07-30 23:42:30 -04:00
|
|
|
this.siteSettings.header_dropdown_category_count = 8;
|
2018-07-30 04:43:00 -04:00
|
|
|
},
|
|
|
|
|
2018-07-27 02:41:07 -04:00
|
|
|
test(assert) {
|
2019-05-09 07:08:10 -04:00
|
|
|
assert.equal(find(".category-link").length, 8);
|
|
|
|
assert.equal(
|
|
|
|
find(".category-link .category-name").text(),
|
|
|
|
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);
|
2018-07-30 16:06:37 -04:00
|
|
|
assert.equal(
|
|
|
|
find(".category-link .category-name").text(),
|
2019-05-09 07:08:10 -04:00
|
|
|
this.site
|
|
|
|
.get("categoriesByCount")
|
|
|
|
.filter(c => c.name !== "uncategorized")
|
|
|
|
.slice(0, 8)
|
2018-07-30 16:06:37 -04:00
|
|
|
.map(c => c.name)
|
|
|
|
.join("")
|
|
|
|
);
|
2018-07-27 02:41:07 -04:00
|
|
|
}
|
|
|
|
});
|
2018-07-09 02:52:55 -04:00
|
|
|
|
2018-07-27 02:41:07 -04:00
|
|
|
widgetTest("top categories", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
2018-07-09 02:52:55 -04:00
|
|
|
|
2018-07-27 02:41:07 -04:00
|
|
|
beforeEach() {
|
2018-07-30 23:42:30 -04:00
|
|
|
this.siteSettings.header_dropdown_category_count = 8;
|
|
|
|
maxCategoriesToDisplay = this.siteSettings.header_dropdown_category_count;
|
2018-07-30 10:50:10 -04:00
|
|
|
categoriesByCount = this.site.get("categoriesByCount").slice();
|
2018-07-30 06:07:41 -04:00
|
|
|
categoriesByCount.every(c => {
|
|
|
|
if (!topCategoryIds.includes(c.id)) {
|
2018-07-30 10:50:10 -04:00
|
|
|
if (mutedCategoryIds.length === 0) {
|
|
|
|
mutedCategoryIds.push(c.id);
|
|
|
|
c.set("notification_level", NotificationLevels.MUTED);
|
|
|
|
} else if (unreadCategoryIds.length === 0) {
|
|
|
|
unreadCategoryIds.push(c.id);
|
2020-07-16 12:17:15 -04:00
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
c.topicTrackingState.states["t123" + i] = {
|
|
|
|
category_id: c.id,
|
|
|
|
last_read_post_number: 1,
|
|
|
|
highest_post_number: 2,
|
|
|
|
notification_level: NotificationLevels.TRACKING
|
|
|
|
};
|
|
|
|
}
|
2018-07-30 10:50:10 -04:00
|
|
|
} else {
|
|
|
|
unreadCategoryIds.splice(0, 0, c.id);
|
2020-07-16 12:17:15 -04:00
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
c.topicTrackingState.states["t321" + i] = {
|
|
|
|
category_id: c.id,
|
|
|
|
last_read_post_number: null
|
|
|
|
};
|
|
|
|
}
|
2018-07-30 10:50:10 -04:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-30 06:07:41 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2018-07-27 02:41:07 -04:00
|
|
|
this.currentUser.set("top_category_ids", topCategoryIds);
|
2018-07-09 02:52:55 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2018-07-27 02:41:07 -04:00
|
|
|
assert.equal(find(".category-link").length, maxCategoriesToDisplay);
|
|
|
|
|
2018-07-30 06:07:41 -04:00
|
|
|
categoriesByCount = categoriesByCount.filter(
|
|
|
|
c => !mutedCategoryIds.includes(c.id)
|
|
|
|
);
|
2018-07-30 10:50:10 -04:00
|
|
|
let ids = [
|
|
|
|
...unreadCategoryIds,
|
|
|
|
...topCategoryIds,
|
|
|
|
...categoriesByCount.map(c => c.id)
|
|
|
|
]
|
2018-07-27 02:41:07 -04:00
|
|
|
.uniq()
|
|
|
|
.slice(0, maxCategoriesToDisplay);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find(".category-link .category-name").text(),
|
2018-07-30 06:07:41 -04:00
|
|
|
ids.map(i => categoriesByCount.find(c => c.id === i).name).join("")
|
2018-07-27 02:41:07 -04:00
|
|
|
);
|
2018-07-09 02:52:55 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-14 15:23:05 -04:00
|
|
|
widgetTest("badges link - disabled", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-04-14 15:23:05 -04:00
|
|
|
this.siteSettings.enable_badges = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(!find(".badge-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("badges link", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".badge-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("user directory link", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".user-directory-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("user directory link - disabled", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-04-14 15:23:05 -04:00
|
|
|
this.siteSettings.enable_user_directory = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(!find(".user-directory-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetTest("general links", {
|
|
|
|
template: '{{mount-widget widget="hamburger-menu"}}',
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.ok(find(".about-link").length);
|
|
|
|
assert.ok(find(".keyboard-shortcuts-link").length);
|
2016-04-14 15:23:05 -04:00
|
|
|
}
|
|
|
|
});
|