discourse/test/javascripts/widgets/poster-name-test.js.es6

70 lines
2.0 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("poster-name");
2018-06-15 23:03:24 +08:00
widgetTest("basic rendering", {
template: '{{mount-widget widget="poster-name" args=args}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
2018-06-15 23:03:24 +08:00
this.set("args", {
username: "eviltrout",
usernameUrl: "/u/eviltrout",
name: "Robin Ward",
user_title: "Trout Master"
});
},
test(assert) {
assert.ok(find(".names").length);
assert.ok(find("span.username").length);
assert.ok(find("a[data-user-card=eviltrout]").length);
assert.equal(find(".username a").text(), "eviltrout");
assert.equal(find(".full-name a").text(), "Robin Ward");
assert.equal(find(".user-title").text(), "Trout Master");
}
});
2018-06-15 23:03:24 +08:00
widgetTest("extra classes and glyphs", {
template: '{{mount-widget widget="poster-name" args=args}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
2018-06-15 23:03:24 +08:00
this.set("args", {
username: "eviltrout",
usernameUrl: "/u/eviltrout",
staff: true,
admin: true,
moderator: true,
new_user: true,
2018-06-15 23:03:24 +08:00
primary_group_name: "fish"
});
},
test(assert) {
assert.ok(find("span.staff").length);
assert.ok(find("span.admin").length);
assert.ok(find("span.moderator").length);
assert.ok(find(".d-icon-shield-alt").length);
assert.ok(find("span.new-user").length);
assert.ok(find("span.fish").length);
}
});
2018-06-15 23:03:24 +08:00
widgetTest("disable display name on posts", {
template: '{{mount-widget widget="poster-name" args=args}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
this.siteSettings.display_name_on_posts = false;
2018-06-15 23:03:24 +08:00
this.set("args", { username: "eviltrout", name: "Robin Ward" });
},
test(assert) {
assert.equal(find(".full-name").length, 0);
}
});
widgetTest("doesn't render a name if it's similar to the username", {
template: '{{mount-widget widget="poster-name" args=args}}',
2017-06-15 01:57:58 +08:00
beforeEach() {
2016-06-08 12:57:13 +08:00
this.siteSettings.prioritize_username_in_ux = true;
this.siteSettings.display_name_on_posts = true;
2018-06-15 23:03:24 +08:00
this.set("args", { username: "eviltrout", name: "evil-trout" });
},
test(assert) {
assert.equal(find(".second").length, 0);
}
});