discourse/test/javascripts/widgets/user-menu-test.js.es6

103 lines
2.5 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import { moduleForWidget, widgetTest } from "helpers/widget-test";
2018-06-15 23:03:24 +08:00
moduleForWidget("user-menu");
2018-06-15 23:03:24 +08:00
widgetTest("basics", {
template: '{{mount-widget widget="user-menu"}}',
test(assert) {
2018-06-15 23:03:24 +08:00
assert.ok(this.$(".user-menu").length);
assert.ok(this.$(".user-activity-link").length);
assert.ok(this.$(".user-bookmarks-link").length);
assert.ok(this.$(".user-preferences-link").length);
assert.ok(this.$(".notifications").length);
assert.ok(this.$(".dismiss-link").length);
}
});
2018-06-15 23:03:24 +08:00
widgetTest("log out", {
template: '{{mount-widget widget="user-menu" logout="logout"}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
2018-06-15 23:03:24 +08:00
this.on("logout", () => (this.loggedOut = true));
},
async test(assert) {
2018-06-15 23:03:24 +08:00
assert.ok(this.$(".logout").length);
await click(".logout");
assert.ok(this.loggedOut);
}
});
2018-06-15 23:03:24 +08:00
widgetTest("private messages - disabled", {
template: '{{mount-widget widget="user-menu"}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
this.siteSettings.enable_personal_messages = false;
},
test(assert) {
2018-06-15 23:03:24 +08:00
assert.ok(!this.$(".user-pms-link").length);
}
});
2018-06-15 23:03:24 +08:00
widgetTest("private messages - enabled", {
template: '{{mount-widget widget="user-menu"}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
this.siteSettings.enable_personal_messages = true;
},
test(assert) {
2018-06-15 23:03:24 +08:00
assert.ok(this.$(".user-pms-link").length);
}
});
2018-06-15 23:03:24 +08:00
widgetTest("anonymous", {
template:
'{{mount-widget widget="user-menu" toggleAnonymous="toggleAnonymous"}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
this.currentUser.setProperties({ is_anonymous: false, trust_level: 3 });
this.siteSettings.allow_anonymous_posting = true;
this.siteSettings.anonymous_posting_min_trust_level = 3;
2018-06-15 23:03:24 +08:00
this.on("toggleAnonymous", () => (this.anonymous = true));
},
async test(assert) {
2018-06-15 23:03:24 +08:00
assert.ok(this.$(".enable-anonymous").length);
await click(".enable-anonymous");
assert.ok(this.anonymous);
}
});
2018-06-15 23:03:24 +08:00
widgetTest("anonymous - disabled", {
template: '{{mount-widget widget="user-menu"}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
this.siteSettings.allow_anonymous_posting = false;
},
test(assert) {
2018-06-15 23:03:24 +08:00
assert.ok(!this.$(".enable-anonymous").length);
}
});
2018-06-15 23:03:24 +08:00
widgetTest("anonymous - switch back", {
template:
'{{mount-widget widget="user-menu" toggleAnonymous="toggleAnonymous"}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
this.currentUser.setProperties({ is_anonymous: true });
this.siteSettings.allow_anonymous_posting = true;
2018-06-15 23:03:24 +08:00
this.on("toggleAnonymous", () => (this.anonymous = true));
},
async test(assert) {
2018-06-15 23:03:24 +08:00
assert.ok(this.$(".disable-anonymous").length);
await click(".disable-anonymous");
assert.ok(this.anonymous);
}
});