Skip to content

A platform for community discussion. Free, open, simple.

DEV: Remove the legacy widget post menu code (#31211)

Sérgio Saquetim083082f32822
diff --git a/app/assets/javascripts/discourse/app/components/post/menu.gjs b/app/assets/javascripts/discourse/app/components/post/menu.gjs
index d23d481aba2..2c1b04de7dd 100644
--- a/app/assets/javascripts/discourse/app/components/post/menu.gjs
+++ b/app/assets/javascripts/discourse/app/components/post/menu.gjs
@@ -615,7 +615,6 @@ export default class PostMenu extends Component {
{{! this.collapsed is included in the check below because "Show More" button can be overriden to be always visible }}
class={{concatClass
"post-controls"
- "glimmer-post-menu"
(if
(and
(this.showMoreButton.shouldRender
diff --git a/app/assets/javascripts/discourse/app/components/post/menu/buttons/replies.gjs b/app/assets/javascripts/discourse/app/components/post/menu/buttons/replies.gjs
index 7f62bcdeb51..516e5c0a488 100644
--- a/app/assets/javascripts/discourse/app/components/post/menu/buttons/replies.gjs
+++ b/app/assets/javascripts/discourse/app/components/post/menu/buttons/replies.gjs
@@ -43,7 +43,7 @@ export default class PostMenuRepliesButton extends Component {
<template>
<DButton
- class="show-replies btn-icon-text"
+ class="post-action-menu__show-replies show-replies btn-icon-text"
...attributes
disabled={{this.disabled}}
@action={{@buttonActions.toggleReplies}}
diff --git a/app/assets/javascripts/discourse/app/instance-initializers/bookmark-menu.js b/app/assets/javascripts/discourse/app/instance-initializers/bookmark-menu.js
deleted file mode 100644
index e3431248cf3..00000000000
--- a/app/assets/javascripts/discourse/app/instance-initializers/bookmark-menu.js
+++ /dev/null
@@ -1,31 +0,0 @@
-import { withSilencedDeprecations } from "discourse/lib/deprecated";
-import { withPluginApi } from "discourse/lib/plugin-api";
-import PostBookmarkManager from "discourse/lib/post-bookmark-manager";
-
-export default {
- name: "discourse-bookmark-menu",
-
- initialize(container) {
- const currentUser = container.lookup("service:current-user");
-
- withPluginApi("0.10.1", (api) => {
- if (currentUser) {
- withSilencedDeprecations("discourse.post-menu-widget-overrides", () => {
- api.replacePostMenuButton("bookmark", {
- name: "bookmark-menu-shim",
- shouldRender: () => true,
- buildAttrs: (widget) => {
- return {
- post: widget.findAncestorModel(),
- bookmarkManager: new PostBookmarkManager(
- container,
- widget.findAncestorModel()
- ),
- };
- },
- });
- });
- }
- });
- },
-};
diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs
index 82d1b92585c..cf2f851d532 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs
@@ -139,12 +139,6 @@ import { setNotificationsLimit } from "discourse/routes/user-notifications";
import { addComposerSaveErrorCallback } from "discourse/services/composer";
import { addPostClassesCallback } from "discourse/widgets/post";
import { addDecorator } from "discourse/widgets/post-cooked";
-import {
- addButton,
- apiExtraButtons,
- removeButton,
- replaceButton,
-} from "discourse/widgets/post-menu";
import {
addPostSmallActionClassesCallback,
addPostSmallActionIcon,
@@ -199,24 +193,12 @@ const DEPRECATED_POST_STREAM_WIDGETS = [
"topic-post-visited-line",
];
-const DEPRECATED_POST_MENU_WIDGETS = [
- "post-menu",
- "post-user-tip-shim",
- "small-user-list",
-];
-
const POST_STREAM_DEPRECATION_OPTIONS = {
since: "v3.5.0.beta1-dev",
id: "discourse.post-stream-widget-overrides",
// url: "", // TODO (glimmer-post-stream) uncomment when the topic is created on meta
};
-const POST_MENU_DEPRECATION_OPTIONS = {
- since: "v3.4.0.beta3-dev",
- id: "discourse.post-menu-widget-overrides",
- url: "https://meta.discourse.org/t/341014",
-};
-
export const RAW_TOPIC_LIST_DEPRECATION_OPTIONS = {
since: "v3.4.0.beta4-dev",
id: "discourse.hbr-topic-list-overrides",
@@ -942,59 +924,13 @@ class PluginApi {
}
/**
- * Add a new button below a post with your plugin.
- *
- * The `callback` function will be called whenever the post menu is rendered,
- * and if you return an object with the button details it will be rendered.
- *
- * Example:
- *
- * ```
- * api.addPostMenuButton('coffee', () => {
- * return {
- * action: 'drinkCoffee',
- * icon: 'mug-saucer',
- * className: 'hot-coffee',
- * title: 'coffee.title',
- * position: 'first' // can be `first`, `last` or `second-last-hidden`
- * };
- * });
- *
- * ```
- *
- * action: may be a string or a function. If it is a string, a widget action
- * will be triggered. If it is function, the function will be called.
- *
- * function will receive a single argument:
- * {
- * post:
- * showFeedback:
- * }
- *
- * showFeedback can be called to issue a visual feedback on button press.
- * It gets a single argument with a localization key.
- *
- * Example:
- *
- * api.addPostMenuButton('coffee', () => {
- * return {
- * action: ({ post, showFeedback }) => {
- * drinkCoffee(post);
- * showFeedback('discourse_plugin.coffee.drink');
- * },
- * icon: 'mug-saucer',
- * className: 'hot-coffee',
- * }
- * }
+ * Decommissioned API
**/
- addPostMenuButton(name, callback) {
- deprecated(
- "`api.addPostMenuButton` has been deprecated. Use the value transformer `post-menu-buttons` instead.",
- POST_MENU_DEPRECATION_OPTIONS
+ addPostMenuButton() {
+ // eslint-disable-next-line no-console
+ console.error(
+ "`api.addPostMenuButton`: This API was decommissioned. Use the value transformer `post-menu-buttons` instead."
);
-
- apiExtraButtons[name] = callback;
- addButton(name, callback);
}
/**
@@ -1046,54 +982,23 @@ class PluginApi {
}
/**
- * Remove existing button below a post with your plugin.
- *
- * Example:
- *
- * ```
- * api.removePostMenuButton('like');
- * ```
- *
- * ```
- * api.removePostMenuButton('like', (attrs, state, siteSettings, settings, currentUser) => {
- * if (attrs.post_number === 1) {
- * return true;
- * }
- * });
- * ```
+ * Decommissioned API
**/
- removePostMenuButton(name, callback) {
- deprecated(
- "`api.removePostMenuButton` has been deprecated. Use the value transformer `post-menu-buttons` instead.",
- POST_MENU_DEPRECATION_OPTIONS
+ removePostMenuButton() {
+ // eslint-disable-next-line no-console
+ console.error(
+ "`api.removePostMenuButton`: This API was decommissioned. Use the value transformer `post-menu-buttons` instead."
);
-
- removeButton(name, callback);
}
/**
- * Replace an existing button with a widget
- *
- * Example:
- * ```
- * api.replacePostMenuButton("like", {
- * name: "widget-name",
- * buildAttrs: (widget) => {
- * return { post: widget.findAncestorModel() };
- * },
- * shouldRender: (widget) => {
- * const post = widget.findAncestorModel();
- * return post.id === 1
- * }
- * });
+ * Decommissioned API
**/
- replacePostMenuButton(name, widget) {
- deprecated(
- "`api.replacePostMenuButton` has been deprecated. Use the value transformer `post-menu-buttons` instead.",
- POST_MENU_DEPRECATION_OPTIONS
+ replacePostMenuButton() {
+ // eslint-disable-next-line no-console
+ console.error(
+ "`api.replacePostMenuButton`: This API was decommissioned. Use the value transformer `post-menu-buttons` instead."
);
-
- replaceButton(name, widget);
}
/**
@@ -3538,14 +3443,6 @@ class PluginApi {
`The \`${widgetName}\` widget has been deprecated and \`api.${override}\` is no longer a supported override.`,
POST_STREAM_DEPRECATION_OPTIONS
);
- return;
- }
-
- if (DEPRECATED_POST_MENU_WIDGETS.includes(widgetName)) {
- deprecated(
- `The ${widgetName} widget has been deprecated and ${override} is no longer a supported override.`,
- POST_MENU_DEPRECATION_OPTIONS
- );
}
}
}
diff --git a/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js b/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js
index 935f7936a57..f6e81171f7d 100644
--- a/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js
+++ b/app/assets/javascripts/discourse/app/services/deprecation-warning-handler.js
@@ -18,7 +18,6 @@ export const CRITICAL_DEPRECATIONS = [
"discourse.add-header-panel",
"discourse.header-widget-overrides",
"discourse.plugin-outlet-tag-name",
- "discourse.post-menu-widget-overrides",
"discourse.add-flag-property",
"discourse.breadcrumbs.childCategories",
"discourse.breadcrumbs.firstCategory",
diff --git a/app/assets/javascripts/discourse/app/widgets/post-menu.js b/app/assets/javascripts/discourse/app/widgets/post-menu.js
deleted file mode 100644
index 9d0e1e381b2..00000000000
--- a/app/assets/javascripts/discourse/app/widgets/post-menu.js
+++ /dev/null
@@ -1,977 +0,0 @@
-import { next } from "@ember/runloop";
-import { hbs } from "ember-cli-htmlbars";
-import { Promise } from "rsvp";
-import { h } from "virtual-dom";
-import AdminPostMenu from "discourse/components/admin-post-menu";
-import DeleteTopicDisallowedModal from "discourse/components/modal/delete-topic-disallowed";
-import { smallUserAttrs } from "discourse/components/small-user-list";
-import { formattedReminderTime } from "discourse/lib/bookmark";
-import discourseLater from "discourse/lib/later";
-import { recentlyCopied, showAlert } from "discourse/lib/post-action-feedback";
-import {
- NO_REMINDER_ICON,
- WITH_REMINDER_ICON,
-} from "discourse/models/bookmark";
-import RenderGlimmer, {
- registerWidgetShim,
-} from "discourse/widgets/render-glimmer";
-import { applyDecorators, createWidget } from "discourse/widgets/widget";
-import { i18n } from "discourse-i18n";
-
-const LIKE_ACTION = 2;
-const VIBRATE_DURATION = 5;
-
-const _builders = {};
-export let apiExtraButtons = {};
-let _extraButtons = {};
-let _buttonsToRemoveCallbacks = {};
-let _buttonsToReplace = {};
-
-export function addButton(name, builder) {
- _extraButtons[name] = builder;
-}
-
-export function resetPostMenuExtraButtons() {
- for (const key of Object.keys(apiExtraButtons)) {
- delete apiExtraButtons[key];
- }
-
- _extraButtons = {};
- _buttonsToRemoveCallbacks = {};
- _buttonsToReplace = {};
-}
-
-export function removeButton(name, callback) {
- // 🏌️
- _buttonsToRemoveCallbacks[name] ??= [];
- _buttonsToRemoveCallbacks[name].push(callback || (() => true));
-}
-
-export function replaceButton(name, replaceWith) {
- _buttonsToReplace[name] = replaceWith;
-}
-
-function registerButton(name, builder) {
- _builders[name] = builder;
-}
-
-export function buildButton(name, widget) {
- let { attrs, state, siteSettings, settings, currentUser } = widget;
-
- // Return early if the button is supposed to be removed via the plugin API
- if (
- _buttonsToRemoveCallbacks[name] &&
- _buttonsToRemoveCallbacks[name].some((c) =>
- c(attrs, state, siteSettings, settings, currentUser)
- )
- ) {
- return;
- }
-
- // Look for a button replacement, build and return widget attrs if present
- let replacement = _buttonsToReplace[name];
- if (replacement && replacement?.shouldRender(widget)) {
- return {
- replaced: true,
- name: replacement.name,
- attrs: replacement.buildAttrs(widget),
- };
- }
-
- let builder = _builders[name];
- if (builder) {
- let button = builder(attrs, state, siteSettings, settings, currentUser);
- if (button && !button.id) {
- button.id = name;
- }
- return button;
- }
-}
-
-registerButton("read-count", (attrs, state) => {
- if (attrs.showReadIndicator) {
- const count = attrs.readCount;
- if (count > 0) {
- let ariaPressed = (state?.readers?.length > 0).toString();
- return {
- action: "toggleWhoRead",
- title: "post.controls.read_indicator",
- className: "button-count read-indicator",
- contents: count,
- iconRight: true,
- addContainer: false,
- translatedAriaLabel: i18n("post.sr_post_read_count_button", {
- count,
- }),
- ariaPressed,
- };
- }
- }
-});
-
-registerButton("read", (attrs) => {
- const readBySomeone = attrs.readCount > 0;
- if (attrs.showReadIndicator && readBySomeone) {
- return {
- action: "toggleWhoRead",
- title: "post.controls.read_indicator",
- icon: "book-open-reader",
- before: "read-count",
- addContainer: false,
- };
- }
-});
-
-function likeCount(attrs, state) {
- const count = attrs.likeCount;
-
- if (count > 0) {
- const title = attrs.liked
- ? count === 1
- ? "post.has_likes_title_only_you"
- : "post.has_likes_title_you"
- : "post.has_likes_title";
- let icon = attrs.yours ? "d-liked" : "";
- let addContainer = attrs.yours;
- const additionalClass = attrs.yours ? "my-likes" : "regular-likes";
-
- if (!attrs.showLike) {
- icon = attrs.yours ? "d-liked" : "d-unliked";
- addContainer = true;
- }
-
- let ariaPressed = (state?.likedUsers?.length > 0).toString();
-
- return {
- action: "toggleWhoLiked",
- title,
- className: `button-count like-count highlight-action ${additionalClass}`,
- contents: count,
- icon,
- iconRight: true,
- addContainer,
- titleOptions: { count: attrs.liked ? count - 1 : count },
- translatedAriaLabel: i18n("post.sr_post_like_count_button", { count }),
- ariaPressed,
- };
- }
-}
-
-registerButton("like-count", likeCount);
-
-registerButton(
- "like",
- (attrs, _state, _siteSettings, _settings, currentUser) => {
- if (!attrs.showLike) {
- return likeCount(attrs);
- }
-
- const className = attrs.liked ? "toggle-like has-like" : "toggle-like like";
-
- const button = {
- action: "like",
- icon: attrs.liked ? "d-liked" : "d-unliked",
- className,
- before: "like-count",
- data: {
- "post-id": attrs.id,
- },
- };
-
- // If the user has already liked the post and doesn't have permission
- // to undo that operation, then indicate via the title that they've liked it
- // and disable the button. Otherwise, set the title even if the user
- // is anonymous (meaning they don't currently have permission to like);
- // this is important for accessibility.
- if (attrs.liked && !attrs.canToggleLike) {
- button.title = "post.controls.has_liked";
- } else {
- button.title = attrs.liked
- ? "post.controls.undo_like"
- : "post.controls.like";
- }
- if (currentUser && !attrs.canToggleLike) {
- button.disabled = true;
- }
- return button;
- }
-);
-
-registerButton("flag-count", (attrs) => {
- let className = "button-count";
- if (attrs.reviewableScorePendingCount > 0) {
- className += " has-pending";
- }
- return {
- className,
- contents: h("span", attrs.reviewableScoreCount.toString()),
- url: `/review/${attrs.reviewableId}`,
- };
-});
-
-registerButton(
- "flag",
- (attrs, _state, siteSettings, _postMenuSettings, currentUser) => {
- if (
- attrs.reviewableId ||
- (attrs.canFlag && !attrs.hidden) ||
- (siteSettings.allow_all_users_to_flag_illegal_content && !currentUser)
- ) {
- const button = {
- action: "showFlags",
- title: currentUser
- ? "post.controls.flag"
- : "post.controls.anonymous_flag",
- icon: "flag",
- className: "create-flag",
- };
- if (attrs.reviewableId) {
- button.before = "flag-count";
- }
- return button;
- }
- }
-);
-
-registerButton("edit", (attrs) => {
- if (attrs.canEdit) {
- return {
- action: "editPost",
- className: "edit",
- title: "post.controls.edit",
- icon: "pencil",
- alwaysShowYours: true,
- };
- }
-});
-
-registerButton("reply-small", (attrs) => {
- if (!attrs.canCreatePost) {
- return;
- }
-
- const args = {
- action: "replyToPost",
- title: "post.controls.reply",
- icon: "reply",
- className: "reply",
- translatedAriaLabel: i18n("post.sr_reply_to", {
- post_number: attrs.post_number,
- username: attrs.username,
- }),
- };
-
- return args;
-});
-
-registerButton("wiki-edit", (attrs) => {
- if (attrs.canEdit) {
- const args = {
- action: "editPost",
- className: "edit create",
- title: "post.controls.edit",
- icon: "far-pen-to-square",
- alwaysShowYours: true,
- };
- if (!attrs.mobileView) {
- args.label = "post.controls.edit_action";
- }
- return args;
- }
-});
-
-registerButton("replies", (attrs, state, siteSettings) => {
- const count = attrs.replyCount;
-
- if (!count) {
- return;
- }
-
- let title;
- let action = "toggleRepliesBelow";
- let icon = state.repliesShown ? "chevron-up" : "chevron-down";
-
- if (siteSettings.enable_filtered_replies_view) {
- action = "toggleFilteredRepliesView";
- icon = state.filteredRepliesShown ? "chevron-up" : "chevron-down";
- title = state.filteredRepliesShown
- ? "post.view_all_posts"
- : "post.filtered_replies_hint";
- }
-
- // Omit replies if the setting `suppress_reply_directly_below` is enabled
- if (
- count === 1 &&
- attrs.replyDirectlyBelow &&
- siteSettings.suppress_reply_directly_below
- ) {
- return;
- }
-
- let ariaPressed, ariaExpanded;
-
- if (!siteSettings.enable_filtered_replies_view) {
- ariaPressed = state.repliesShown.toString();
- ariaExpanded = state.repliesShown.toString();
- }
-
- return {
- action,
- icon,
- className: "show-replies",
- titleOptions: { count },
- title,
- labelOptions: { count },
- label: attrs.mobileView ? "post.has_replies_count" : "post.has_replies",
- iconRight: !siteSettings.enable_filtered_replies_view || attrs.mobileView,
- disabled: !!attrs.deleted,
- translatedAriaLabel: i18n("post.sr_expand_replies", { count }),
- ariaExpanded,
- ariaPressed,
- ariaControls: `embedded-posts__bottom--${attrs.post_number}`,
- };
-});
-
-registerButton("share", () => {
- return {
- action: "share",
- icon: "d-post-share",
- className: "share",
- title: "post.controls.share",
- };
-});
-
-registerButton("copyLink", () => {
- return {
- action: "copyLink",
- icon: "d-post-share",
- className: "post-action-menu__copy-link",
- title: "post.controls.copy_title",
- ariaLive: "polite",
- };
-});
-
-registerButton("reply", (attrs, state, siteSettings, postMenuSettings) => {
- const args = {
- action: "replyToPost",
- title: "post.controls.reply",
- icon: "reply",
- className: "reply create fade-out",
- translatedAriaLabel: i18n("post.sr_reply_to", {
- post_number: attrs.post_number,
- username: attrs.username,
- }),
- };
-
- if (!attrs.canCreatePost) {
- return;
- }
-
- if (postMenuSettings.showReplyTitleOnMobile || !attrs.mobileView) {
- args.label = "topic.reply.title";
- }
-
- return args;
-});
-
-registerButton(
- "bookmark",
- (attrs, _state, siteSettings, _settings, currentUser) => {
- if (!attrs.canBookmark) {
- return;
- }
-
- let classNames = ["bookmark"];
- let title = "bookmarks.not_bookmarked";
- let titleOptions = { name: "" };
-
- if (attrs.bookmarked) {
- classNames.push("bookmarked");
-
- if (attrs.bookmarkReminderAt) {
- classNames.push("with-reminder");
-
- let formattedReminder = formattedReminderTime(
- attrs.bookmarkReminderAt,
- currentUser.user_option.timezone
- );
- title = "bookmarks.created_with_reminder";
- titleOptions.date = formattedReminder;
- } else {
- title = "bookmarks.created";
- }
-
- if (attrs.bookmarkName) {
- titleOptions.name = attrs.bookmarkName;
- }
- }
-
- return {
- id: attrs.bookmarked ? "unbookmark" : "bookmark",
- action: "toggleBookmark",
- title,
- titleOptions,
- className: classNames.join(" "),
- icon: attrs.bookmarkReminderAt ? WITH_REMINDER_ICON : NO_REMINDER_ICON,
- };
- }
-);
-
-registerButton("admin", (attrs) => {
- if (!attrs.canManage && !attrs.canWiki && !attrs.canEditStaffNotes) {
- return;
- }
-
- return {
- action: "openAdminMenu",
- title: "post.controls.admin",
- className: "show-post-admin-menu",
- icon: "wrench",
- sendActionEvent: true,
- };
-});
-
-registerButton("delete", (attrs) => {
- if (attrs.canRecoverTopic) {
- return {
- id: "recover_topic",
- action: "recoverPost",
- title: "topic.actions.recover",
- icon: "arrow-rotate-left",
- className: "recover",
- };
- } else if (attrs.canDeleteTopic) {
- return {
- id: "delete_topic",
- action: "deletePost",
- title: "post.controls.delete_topic",
- icon: "trash-can",
- className: "delete",
- };
- } else if (attrs.canRecover) {
- return {
- id: "recover",
- action: "recoverPost",
- title: "post.controls.undelete",
- icon: "arrow-rotate-left",
- className: "recover",
- };
- } else if (attrs.canDelete) {
- return {
- id: "delete",
- action: "deletePost",
- title: "post.controls.delete",
- icon: "trash-can",
- className: "delete",
- };
- } else if (attrs.showFlagDelete) {
- return {
- id: "delete_topic",
- action: "showDeleteTopicModal",
- title: "post.controls.delete_topic_disallowed",
- icon: "trash-can",
- className: "delete",
- };
- }
-});
-
-function _replaceButton(buttons, find, replace) {
- const idx = buttons.indexOf(find);
- if (idx !== -1) {
- buttons[idx] = replace;
- }
-}
-
-export default createWidget("post-menu", {
- tagName: "section.post-menu-area.clearfix",
- services: ["modal", "menu"],
-
- settings: {
- collapseButtons: true,
- buttonType: "flat-button",
- showReplyTitleOnMobile: false,
- },
-
- defaultState() {
- return {
- collapsed: true,
- likedUsers: [],
- readers: [],
- };
- },
-
- buildKey: (attrs) => `post-menu-${attrs.id}`,
-
- attachButton(name) {
- let buttonAttrs = buildButton(name, this);
-
- if (buttonAttrs?.component) {
- return [
- new RenderGlimmer(
- this,
- buttonAttrs.tagName,
- hbs`<@data.component
- @permanentlyDeletePost={{@data.permanentlyDeletePost}}
- @lockPost={{@data.lockPost}}
- @unlockPost={{@data.unlockPost}}
- @grantBadge={{@data.grantBadge}}
- @rebakePost={{@data.rebakePost}}
- @toggleWiki={{@data.toggleWiki}}
- @changePostOwner={{@data.changePostOwner}}
- @changeNotice={{@data.changeNotice}}
- @togglePostType={{@data.togglePostType}}
- @unhidePost={{@data.unhidePost}}
- @showPagePublish={{@data.showPagePublish}}
- @post={{@data.post}}
- @transformedPost={{@data.transformedPost}}
- @scheduleRerender={{@data.scheduleRerender}}
- />`,
- {
- component: buttonAttrs.component,
- transformedPost: this.attrs,
- post: this.findAncestorModel(),
- permanentlyDeletePost: () =>
- this.sendWidgetAction("permanentlyDeletePost"),
- lockPost: () => this.sendWidgetAction("lockPost"),
- unlockPost: () => this.sendWidgetAction("unlockPost"),
- grantBadge: () => this.sendWidgetAction("grantBadge"),
- rebakePost: () => this.sendWidgetAction("rebakePost"),
- toggleWiki: () => this.sendWidgetAction("toggleWiki"),
- changePostOwner: () => this.sendWidgetAction("changePostOwner"),
- changeNotice: () => this.sendWidgetAction("changeNotice"),
- togglePostType: () => this.sendWidgetAction("togglePostType"),
- scheduleRerender: () => this.scheduleRerender(),
- }
- ),
- ];
- }
-
- // If the button is replaced via the plugin API, we need to render the
- // replacement rather than a button
- if (buttonAttrs?.replaced) {
- return this.attach(buttonAttrs.name, buttonAttrs.attrs);
- }
-
- if (buttonAttrs) {
- let button = this.attach(this.settings.buttonType, buttonAttrs);
- if (buttonAttrs.before) {
- let before = this.attachButton(buttonAttrs.before);
- return h("div.double-button", [before, button]);
- } else if (buttonAttrs.addContainer) {
- return h("div.double-button", [button]);
- }
-
- return button;
- }
- },
-
- menuItems() {
- return this.siteSettings.post_menu.split("|").filter(Boolean);
- },
-
- html(attrs, state) {
- const { currentUser, keyValueStore, siteSettings } = this;
-
- const hiddenSetting = siteSettings.post_menu_hidden_items || "";
- const hiddenButtons = hiddenSetting
- .split("|")
- .filter((s) => !attrs.bookmarked || s !== "bookmark");
-
- if (currentUser && keyValueStore) {
- const likedPostId = keyValueStore.getInt("likedPostId");
- if (likedPostId === attrs.id) {
- keyValueStore.remove("likedPostId");
- next(() => this.sendWidgetAction("toggleLike"));
- }
- }
-
- const allButtons = [];
- let visibleButtons = [];
-
- // filter menu items based on site settings
- const orderedButtons = this.menuItems();
-
- // If the post is a wiki, make Edit more prominent
- if (attrs.wiki && attrs.canEdit) {
- _replaceButton(orderedButtons, "edit", "reply-small");
- _replaceButton(orderedButtons, "reply", "wiki-edit");
- }
-
- orderedButtons.forEach((i) => {
- const button = this.attachButton(i, attrs);
-
- if (button) {
- allButtons.push(button);
-
- if (
- (attrs.yours && button.attrs && button.attrs.alwaysShowYours) ||
- (attrs.reviewableId && i === "flag") ||
- !hiddenButtons.includes(i)
- ) {
- visibleButtons.push(button);
- }
- }
- });
-
- if (!this.settings.collapseButtons) {
- visibleButtons = allButtons;
- }
-
- let hasShowMoreButton = false;
- // Only show ellipsis if there is more than one button hidden
- // if there are no more buttons, we are not collapsed
- if (!state.collapsed || allButtons.length <= visibleButtons.length + 1) {
- visibleButtons = allButtons;
- if (state.collapsed) {
- state.collapsed = false;
- }
- } else {
- const showMore = this.attach("flat-button", {
- action: "showMoreActions",
- title: "show_more",
- className: "show-more-actions",
- icon: "ellipsis",
- });
- visibleButtons.splice(visibleButtons.length - 1, 0, showMore);
- hasShowMoreButton = true;
- }
-
- Object.values(_extraButtons).forEach((builder) => {
- let shouldAddButton = true;
-
- if (_buttonsToRemoveCallbacks[name]) {
- shouldAddButton = !_buttonsToRemoveCallbacks[name].some((c) =>
- c(
- attrs,
- this.state,
- this.siteSettings,
- this.settings,
- this.currentUser
- )
- );
- }
-
- if (shouldAddButton && builder) {
- const buttonAttrs = builder(
- attrs,
- this.state,
- this.siteSettings,
- this.settings,
- this.currentUser
- );
- if (buttonAttrs) {
- const { position, beforeButton, afterButton } = buttonAttrs;
- delete buttonAttrs.position;
- let button;
-
- if (typeof buttonAttrs.action === "function") {
- const original = buttonAttrs.action;
- const self = this;
-
- buttonAttrs.action = async function (post) {
- let showFeedback = null;
-
- if (buttonAttrs.className) {
- showFeedback = (messageKey) => {
- showAlert(post.id, buttonAttrs.className, messageKey);
- };
- }
-
- const postAttrs = {
- post,
- showFeedback,
- };
-
- if (
- !buttonAttrs.className ||
- !recentlyCopied(post.id, buttonAttrs.actionClass)
- ) {
- self.sendWidgetAction(original, postAttrs);
- }
- };
- }
-
- button = this.attach(this.settings.buttonType, buttonAttrs);
-
- const content = [];
- if (beforeButton) {
- content.push(beforeButton(h));
- }
- content.push(button);
- if (afterButton) {
- content.push(afterButton(h));
- }
- button = h("span.extra-buttons", content);
-
- if (button) {
- switch (position) {
- case "first":
- visibleButtons.unshift(button);
- break;
- case "second":
- visibleButtons.splice(1, 0, button);
- break;
- case "second-last-hidden":
- if (!state.collapsed) {
- visibleButtons.splice(visibleButtons.length - 2, 0, button);
- }
- break;
- default:
- visibleButtons.push(button);
- break;
- }
- }
- }
- }
- });
-
- const postControls = [];
-
- const repliesButton = this.attachButton("replies", attrs);
- if (repliesButton) {
- postControls.push(repliesButton);
- }
-
- const extraPostControls = applyDecorators(
- this,
- "extra-post-controls",
- attrs,
- state
- );
-
- postControls.push(extraPostControls);
-
- const extraControls = applyDecorators(this, "extra-controls", attrs, state);
- const beforeExtraControls = applyDecorators(
- this,
- "before-extra-controls",
- attrs,
- state
- );
-
- const controlsButtons = [
- ...beforeExtraControls,
- ...visibleButtons,
- ...extraControls,
- ];
-
- postControls.push(h("div.actions", controlsButtons));
-
- const contents = [
- h(
- "nav.post-controls" +
- (this.state.collapsed ? ".collapsed" : ".expanded") +
- (siteSettings.enable_filtered_replies_view
- ? ".replies-button-visible"
- : ""),
- postControls
- ),
- ];
-
- if (state.readers.length) {
- const remaining = state.totalReaders - state.readers.length;
- const description =
- remaining > 0
- ? "post.actions.people.read_capped"
- : "post.actions.people.read";
- const count = remaining > 0 ? remaining : state.totalReaders;
-
- contents.push(
- this.attach("small-user-list", {
- users: state.readers,
- addSelf: false,
- listClassName: "who-read",
- description,
- count,
- isVisible: true,
- })
- );
- }
-
- if (state.likedUsers.length) {
- const remaining = state.total - state.likedUsers.length;
- const description =
- remaining > 0
- ? "post.actions.people.like_capped"
- : "post.actions.people.like";
- const count = remaining > 0 ? remaining : state.total;
-
- contents.push(
- this.attach("small-user-list", {
- users: state.likedUsers,
- addSelf: attrs.liked && remaining === 0,
- listClassName: "who-liked",
- description,
- count,
- isVisible: true,
- })
- );
- }
- if (hasShowMoreButton) {
- contents.push(this.attach("post-user-tip-shim"));
- }
- return contents;
- },
-
- openAdminMenu(event) {
- this.menu.show(event.target, {
- identifier: "admin-post-menu",
- component: AdminPostMenu,
- modalForMobile: true,
- autofocus: true,
- data: {
- scheduleRerender: this.scheduleRerender.bind(this),
- transformedPost: this.attrs,
- post: this.findAncestorModel(),
- permanentlyDeletePost: () =>
- this.sendWidgetAction("permanentlyDeletePost"),
- lockPost: () => this.sendWidgetAction("lockPost"),
- unlockPost: () => this.sendWidgetAction("unlockPost"),
- grantBadge: () => this.sendWidgetAction("grantBadge"),
- rebakePost: () => this.sendWidgetAction("rebakePost"),
- toggleWiki: () => this.sendWidgetAction("toggleWiki"),
- changePostOwner: () => this.sendWidgetAction("changePostOwner"),
- changeNotice: () => this.sendWidgetAction("changeNotice"),
- togglePostType: () => this.sendWidgetAction("togglePostType"),
- unhidePost: () => this.sendWidgetAction("unhidePost"),
- showPagePublish: () => this.sendWidgetAction("showPagePublish"),
- },
- });
- },
-
- showDeleteTopicModal() {
- this.modal.show(DeleteTopicDisallowedModal);
- },
-
- showMoreActions() {
- this.state.collapsed = false;
- const likesPromise = !this.state.likedUsers.length
- ? this.getWhoLiked()
- : Promise.resolve();
-
- return likesPromise.then(() => {
- if (!this.state.readers.length && this.attrs.showReadIndicator) {
- return this.getWhoRead();
- }
- });
- },
-
- like() {
- const { attrs, currentUser, keyValueStore } = this;
-
- if (!currentUser) {
- keyValueStore &&
- keyValueStore.set({ key: "likedPostId", value: attrs.id });
- return this.sendWidgetAction("showLogin");
- }
-
- if (this.capabilities.userHasBeenActive && this.capabilities.canVibrate) {
- navigator.vibrate(VIBRATE_DURATION);
- }
-
- if (attrs.liked) {
- return this.sendWidgetAction("toggleLike");
- }
-
- const heart = document.querySelector(
- `.toggle-like[data-post-id="${attrs.id}"] .d-icon`
- );
- heart.closest(".toggle-like").classList.add("has-like");
- heart.classList.add("heart-animation");
-
- return new Promise((resolve) => {
- discourseLater(() => {
- this.sendWidgetAction("toggleLike").then(() => resolve());
- }, 400);
- });
- },
-
- refreshLikes() {
- if (this.state.likedUsers.length) {
- return this.getWhoLiked();
- }
- },
-
- refreshReaders() {
- if (this.state.readers.length) {
- return this.getWhoRead();
- }
- },
-
- getWhoLiked() {
- const { attrs, state } = this;
- return this.store
- .find("post-action-user", {
- id: attrs.id,
- post_action_type_id: LIKE_ACTION,
- })
- .then((users) => {
- state.likedUsers = users.map(smallUserAttrs);
- state.total = users.totalRows;
- });
- },
-
- getWhoRead() {
- const { attrs, state } = this;
-
- return this.store.find("post-reader", { id: attrs.id }).then((users) => {
- state.readers = users.map(smallUserAttrs);
- state.totalReaders = users.totalRows;
- });
- },
-
- toggleWhoLiked() {
- const state = this.state;
- if (state.likedUsers.length) {
- state.likedUsers = [];
- } else {
- return this.getWhoLiked();
- }
- },
-
- toggleWhoRead() {
- const state = this.state;
- if (this.state.readers.length) {
- state.readers = [];
- } else {
- return this.getWhoRead();
- }
- },
-});
-
-// TODO (glimmer-post-menu): Once this widget is removed the `<section>...</section>` tag needs to be added to the PostMenu component
-registerWidgetShim(
- "glimmer-post-menu",
- "section.post-menu-area.clearfix",
- hbs`
- <Post::Menu
- @canCreatePost={{@data.canCreatePost}}
- @filteredRepliesView={{@data.filteredRepliesView}}
- @nextPost={{@data.nextPost}}
- @post={{@data.post}}
- @prevPost={{@data.prevPost}}
- @repliesShown={{@data.repliesShown}}
- @showReadIndicator={{@data.showReadIndicator}}
- @changeNotice={{@data.changeNotice}}
- @changePostOwner={{@data.changePostOwner}}
- @copyLink={{@data.copyLink}}
- @deletePost={{@data.deletePost}}
- @editPost={{@data.editPost}}
- @grantBadge={{@data.grantBadge}}
- @lockPost={{@data.lockPost}}
- @permanentlyDeletePost={{@data.permanentlyDeletePost}}
- @rebakePost={{@data.rebakePost}}
- @recoverPost={{@data.recoverPost}}
- @replyToPost={{@data.replyToPost}}
- @share={{@data.share}}
- @showFlags={{@data.showFlags}}
- @showLogin={{@data.showLogin}}
- @showPagePublish={{@data.showPagePublish}}
- @toggleLike={{@data.toggleLike}}
- @togglePostType={{@data.togglePostType}}
- @toggleReplies={{@data.toggleReplies}}
- @toggleWiki={{@data.toggleWiki}}
- @unhidePost={{@data.unhidePost}}
- @unlockPost={{@data.unlockPost}}
- />`
-);
diff --git a/app/assets/javascripts/discourse/app/widgets/post.js b/app/assets/javascripts/discourse/app/widgets/post.js
index 8339a56db9d..2515247328b 100644
--- a/app/assets/javascripts/discourse/app/widgets/post.js
+++ b/app/assets/javascripts/discourse/app/widgets/post.js
@@ -6,7 +6,6 @@ import ShareTopicModal from "discourse/components/modal/share-topic";
import { dateNode } from "discourse/helpers/node";
import autoGroupFlairForUser from "discourse/lib/avatar-flair";
import { avatarUrl, translateSize } from "discourse/lib/avatar-utils";
-import { registerDeprecationHandler } from "discourse/lib/deprecated";
import { isTesting } from "discourse/lib/environment";
import { relativeAgeMediumSpan } from "discourse/lib/formatter";
import getURL, { getAbsoluteURL, getURLWithCDN } from "discourse/lib/get-url";
@@ -17,7 +16,6 @@ import {
prioritizeNameFallback,
prioritizeNameInUx,
} from "discourse/lib/settings";
-import { consolePrefix } from "discourse/lib/source-identifier";
import { transformBasicPost } from "discourse/lib/transform-post";
import DiscourseURL from "discourse/lib/url";
import {
@@ -46,19 +44,6 @@ function transformWithCallbacks(post, topicUrl, store) {
return transformed;
}
-let postMenuWidgetExtensionsAdded = null;
-let postMenuConsoleWarningLogged = false;
-
-registerDeprecationHandler((_, opts) => {
- if (opts?.id === "discourse.post-menu-widget-overrides") {
- if (!postMenuWidgetExtensionsAdded) {
- postMenuWidgetExtensionsAdded = new Set();
- }
-
- postMenuWidgetExtensionsAdded.add(consolePrefix().slice(1, -1));
- }
-});
-
export function avatarImg(wanted, attrs) {
const size = translateSize(wanted);
const url = avatarUrl(attrs.template, size);
@@ -562,36 +547,45 @@ createWidget("post-contents", {
},
};
- if (
- this.siteSettings.glimmer_post_menu_mode === "enabled" ||
- (this.siteSettings.glimmer_post_menu_mode === "auto" &&
- !postMenuWidgetExtensionsAdded)
- ) {
- if (!postMenuConsoleWarningLogged) {
- postMenuConsoleWarningLogged = true;
-
- if (!isTesting()) {
- // eslint-disable-next-line no-console
- console.log("✅ Using the new 'glimmer' post menu!");
- }
-
- if (postMenuWidgetExtensionsAdded) {
- // eslint-disable-next-line no-console
- console.warn(
- [
- "Using the new 'glimmer' post menu, even though there are themes and/or plugins using deprecated APIs (glimmer_post_menu_mode = enabled).\n" +
- "The following plugins and/or themes are using deprecated APIs, their post menu customizations are broken and may cause your site to not work properly:",
- ...Array.from(postMenuWidgetExtensionsAdded).sort(),
- // TODO (glimmer-post-menu): add link to meta topic here when the roadmap for the update is announced
- ].join("\n- ")
- );
- }
- }
-
- const filteredRepliesView =
- this.siteSettings.enable_filtered_replies_view;
- result.push(
- this.attach("glimmer-post-menu", {
+ const filteredRepliesView = this.siteSettings.enable_filtered_replies_view;
+ result.push(
+ // TODO (glimmer-post-stream):
+ // Once this widget shim is removed the `<section>...</section>` tag needs to be added to the PostMenu component
+ new RenderGlimmer(
+ this,
+ "section.post-menu-area.clearfix",
+ hbs`
+ <Post::Menu
+ @canCreatePost={{@data.canCreatePost}}
+ @filteredRepliesView={{@data.filteredRepliesView}}
+ @nextPost={{@data.nextPost}}
+ @post={{@data.post}}
+ @prevPost={{@data.prevPost}}
+ @repliesShown={{@data.repliesShown}}
+ @showReadIndicator={{@data.showReadIndicator}}
+ @changeNotice={{@data.changeNotice}}
+ @changePostOwner={{@data.changePostOwner}}
+ @copyLink={{@data.copyLink}}
+ @deletePost={{@data.deletePost}}
+ @editPost={{@data.editPost}}
+ @grantBadge={{@data.grantBadge}}
+ @lockPost={{@data.lockPost}}
+ @permanentlyDeletePost={{@data.permanentlyDeletePost}}
+ @rebakePost={{@data.rebakePost}}
+ @recoverPost={{@data.recoverPost}}
+ @replyToPost={{@data.replyToPost}}
+ @share={{@data.share}}
+ @showFlags={{@data.showFlags}}
+ @showLogin={{@data.showLogin}}
+ @showPagePublish={{@data.showPagePublish}}
+ @toggleLike={{@data.toggleLike}}
+ @togglePostType={{@data.togglePostType}}
+ @toggleReplies={{@data.toggleReplies}}
+ @toggleWiki={{@data.toggleWiki}}
+ @unhidePost={{@data.unhidePost}}
+ @unlockPost={{@data.unlockPost}}
+ />`,
+ {
canCreatePost: attrs.canCreatePost,
filteredRepliesView,
nextPost: attrs.nextPost,
@@ -626,27 +620,9 @@ createWidget("post-contents", {
toggleWiki: () => this.sendWidgetAction("toggleWiki"), // this action comes from the post stream
unhidePost: () => this.sendWidgetAction("unhidePost"), // this action comes from the post stream
unlockPost: () => this.sendWidgetAction("unlockPost"), // this action comes from the post stream
- })
- );
- } else {
- if (
- this.siteSettings.glimmer_post_menu_mode !== "disabled" &&
- postMenuWidgetExtensionsAdded &&
- !postMenuConsoleWarningLogged
- ) {
- postMenuConsoleWarningLogged = true;
- // eslint-disable-next-line no-console
- console.warn(
- [
- "Using the legacy 'widget' post menu because the following plugins and/or themes are using deprecated APIs:",
- ...Array.from(postMenuWidgetExtensionsAdded).sort(),
- // TODO (glimmer-post-menu): add link to meta topic here when the roadmap for the update is announced
- ].join("\n- ")
- );
- }
-
- result.push(this.attach("post-menu", attrs, extraState));
- }
+ }
+ )
+ );
const repliesBelow = state.repliesBelow;
if (repliesBelow.length) {
@@ -1204,7 +1180,7 @@ export default createWidget("post", {
},
});
-// TODO (glimmer-post-menu): Once this widget is removed the `<section>...</section>` tag needs to be added to the PostMenu component
+// TODO (glimmer-post-stream): Once this widget is removed the `<section>...</section>` tag needs to be added to the PostMenu component
registerWidgetShim(
"glimmer-post",
"div",
diff --git a/app/assets/javascripts/discourse/tests/acceptance/post-controls-test.js b/app/assets/javascripts/discourse/tests/acceptance/post-controls-test.js
index 419fa60dfff..c7f22600fae 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/post-controls-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/post-controls-test.js
@@ -3,85 +3,76 @@ import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n";
-["enabled", "disabled"].forEach((postMenuMode) => {
- acceptance(
- `Post controls (glimmer_post_menu_mode = ${postMenuMode})`,
- function (needs) {
- needs.settings({
- glimmer_post_menu_mode: postMenuMode,
- });
+acceptance(`Post controls`, function () {
+ test("accessibility of the likes list below the post", async function (assert) {
+ await visit("/t/internationalization-localization/280");
- test("accessibility of the likes list below the post", async function (assert) {
- await visit("/t/internationalization-localization/280");
+ assert
+ .dom("#post_2 button.like-count")
+ .hasAria("pressed", "false", "show likes button isn't pressed");
- assert
- .dom("#post_2 button.like-count")
- .hasAria("pressed", "false", "show likes button isn't pressed");
+ await click("#post_2 button.like-count");
+ assert
+ .dom("#post_2 button.like-count")
+ .hasAria("pressed", "true", "show likes button is now pressed");
- await click("#post_2 button.like-count");
- assert
- .dom("#post_2 button.like-count")
- .hasAria("pressed", "true", "show likes button is now pressed");
+ assert
+ .dom("#post_2 .small-user-list.who-liked .small-user-list-content")
+ .hasAttribute("role", "list", "likes container has list role");
- assert
- .dom("#post_2 .small-user-list.who-liked .small-user-list-content")
- .hasAttribute("role", "list", "likes container has list role");
+ assert
+ .dom("#post_2 .small-user-list.who-liked a.trigger-user-card")
+ .exists("avatars are rendered");
- assert
- .dom("#post_2 .small-user-list.who-liked a.trigger-user-card")
- .exists("avatars are rendered");
+ assert
+ .dom("#post_2 .small-user-list.who-liked a.trigger-user-card")
+ .hasAria("hidden", "false", "avatars are not aria-hidden");
+ assert
+ .dom("#post_2 .small-user-list.who-liked a.trigger-user-card")
+ .hasAttribute("role", "listitem", "avatars have listitem role");
+ });
- assert
- .dom("#post_2 .small-user-list.who-liked a.trigger-user-card")
- .hasAria("hidden", "false", "avatars are not aria-hidden");
- assert
- .dom("#post_2 .small-user-list.who-liked a.trigger-user-card")
- .hasAttribute("role", "listitem", "avatars have listitem role");
- });
+ test("accessibility of the embedded replies below the post", async function (assert) {
+ await visit("/t/internationalization-localization/280");
- test("accessibility of the embedded replies below the post", async function (assert) {
- await visit("/t/internationalization-localization/280");
+ assert
+ .dom("#post_1 button.show-replies")
+ .hasAria("pressed", "false", "show replies button isn't pressed");
+ assert
+ .dom("#post_1 button.show-replies")
+ .hasAria(
+ "label",
+ i18n("post.sr_expand_replies", { count: 1 }),
+ "show replies button has aria-label"
+ );
- assert
- .dom("#post_1 button.show-replies")
- .hasAria("pressed", "false", "show replies button isn't pressed");
- assert
- .dom("#post_1 button.show-replies")
- .hasAria(
- "label",
- i18n("post.sr_expand_replies", { count: 1 }),
- "show replies button has aria-label"
- );
+ await click("#post_1 button.show-replies");
+ assert
+ .dom("#post_1 button.show-replies")
+ .hasAria("pressed", "true", "show replies button is now pressed");
- await click("#post_1 button.show-replies");
- assert
- .dom("#post_1 button.show-replies")
- .hasAria("pressed", "true", "show replies button is now pressed");
+ // const replies = Array.from(queryAll("#post_1 .embedded-posts .reply"));
+ assert
+ .dom("#post_1 .embedded-posts .reply")
+ .exists({ count: 1 }, "replies are rendered");
- // const replies = Array.from(queryAll("#post_1 .embedded-posts .reply"));
- assert
- .dom("#post_1 .embedded-posts .reply")
- .exists({ count: 1 }, "replies are rendered");
-
- assert
- .dom("#post_1 .embedded-posts .reply")
- .hasAttribute("role", "region", "replies have region role");
- assert.dom("#post_1 .embedded-posts .reply").hasAria(
- "label",
- i18n("post.sr_embedded_reply_description", {
- post_number: 1,
- username: "somebody",
- }),
- "replies have aria-label"
- );
- assert
- .dom("#post_1 .embedded-posts .btn.collapse-up")
- .hasAria(
- "label",
- i18n("post.sr_collapse_replies"),
- "collapse button has aria-label"
- );
- });
- }
- );
+ assert
+ .dom("#post_1 .embedded-posts .reply")
+ .hasAttribute("role", "region", "replies have region role");
+ assert.dom("#post_1 .embedded-posts .reply").hasAria(
+ "label",
+ i18n("post.sr_embedded_reply_description", {
+ post_number: 1,
+ username: "somebody",
+ }),
+ "replies have aria-label"
+ );
+ assert
+ .dom("#post_1 .embedded-posts .btn.collapse-up")
+ .hasAria(
+ "label",
+ i18n("post.sr_collapse_replies"),
+ "collapse button has aria-label"
+ );
+ });
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js
index 07f925c97ce..a42edab9062 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js
@@ -19,254 +19,248 @@ import selectKit from "discourse/tests/helpers/select-kit-helper";
import { i18n } from "discourse-i18n";
["enabled", "disabled"].forEach((postStreamMode) => {
- ["enabled", "disabled"].forEach((postMenuMode) => {
- acceptance(
- `Topic (glimmer_post_stream_mode = ${postStreamMode}) (glimmer_post_menu_mode = ${postMenuMode})`,
- function (needs) {
- needs.user();
- needs.settings({
- post_menu:
- "read|like|share|flag|edit|bookmark|delete|admin|reply|copyLink",
- glimmer_post_menu_mode: postMenuMode,
- glimmer_post_stream_mode: postStreamMode,
- });
- needs.pretender((server, helper) => {
- server.get("/c/2/visible_groups.json", () =>
- helper.response(200, {
- groups: [],
- })
- );
+ acceptance(
+ `Topic (glimmer_post_stream_mode = ${postStreamMode})`,
+ function (needs) {
+ needs.user();
+ needs.settings({
+ post_menu:
+ "read|like|share|flag|edit|bookmark|delete|admin|reply|copyLink",
+ glimmer_post_stream_mode: postStreamMode,
+ });
+ needs.pretender((server, helper) => {
+ server.get("/c/2/visible_groups.json", () =>
+ helper.response(200, {
+ groups: [],
+ })
+ );
- server.get("/c/feature/find_by_slug.json", () => {
- return helper.response(200, CategoryFixtures["/c/1/show.json"]);
- });
- server.put("/posts/398/wiki", () => {
- return helper.response({});
- });
+ server.get("/c/feature/find_by_slug.json", () => {
+ return helper.response(200, CategoryFixtures["/c/1/show.json"]);
});
+ server.put("/posts/398/wiki", () => {
+ return helper.response({});
+ });
+ });
- test("Reply as new topic", async function (assert) {
- await visit("/t/internationalization-localization/280");
- await click("button.share:nth-of-type(1)");
- await click("button.new-topic");
+ test("Reply as new topic", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("button.share:nth-of-type(1)");
+ await click("button.new-topic");
- assert.dom(".d-editor-input").exists("the composer input is visible");
+ assert.dom(".d-editor-input").exists("the composer input is visible");
- assert
- .dom(".d-editor-input")
- .hasValue(
- `Continuing the discussion from [Internationalization / localization](${window.location.origin}/t/internationalization-localization/280):\n\n`,
- "fills composer with the ring string"
- );
- assert.strictEqual(
- selectKit(".category-chooser").header().value(),
- "2",
- "fills category selector with the right category"
+ assert
+ .dom(".d-editor-input")
+ .hasValue(
+ `Continuing the discussion from [Internationalization / localization](${window.location.origin}/t/internationalization-localization/280):\n\n`,
+ "fills composer with the ring string"
);
- });
+ assert.strictEqual(
+ selectKit(".category-chooser").header().value(),
+ "2",
+ "fills category selector with the right category"
+ );
+ });
- test("Reply as new message", async function (assert) {
- await visit("/t/pm-for-testing/12");
- await click("button.share:nth-of-type(1)");
- await click("button.new-topic");
+ test("Reply as new message", async function (assert) {
+ await visit("/t/pm-for-testing/12");
+ await click("button.share:nth-of-type(1)");
+ await click("button.new-topic");
- assert.dom(".d-editor-input").exists("the composer input is visible");
+ assert.dom(".d-editor-input").exists("the composer input is visible");
- assert
- .dom(".d-editor-input")
- .hasValue(
- `Continuing the discussion from [PM for testing](${window.location.origin}/t/pm-for-testing/12):\n\n`,
- "fills composer with the ring string"
- );
-
- const privateMessageUsers = selectKit("#private-message-users");
- assert.strictEqual(
- privateMessageUsers.header().value(),
- "someguy,test,Group",
- "fills up the composer correctly"
+ assert
+ .dom(".d-editor-input")
+ .hasValue(
+ `Continuing the discussion from [PM for testing](${window.location.origin}/t/pm-for-testing/12):\n\n`,
+ "fills composer with the ring string"
);
- });
- test("Share Modal", async function (assert) {
- await visit("/t/internationalization-localization/280");
- await click(".topic-post:first-child button.share");
+ const privateMessageUsers = selectKit("#private-message-users");
+ assert.strictEqual(
+ privateMessageUsers.header().value(),
+ "someguy,test,Group",
+ "fills up the composer correctly"
+ );
+ });
- assert.dom(".share-topic-modal").exists("shows the share modal");
- });
+ test("Share Modal", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click(".topic-post:first-child button.share");
- test("Copy Link Button", async function (assert) {
- await visit("/t/internationalization-localization/280");
- await click(
- ".topic-post:first-child button.post-action-menu__copy-link"
- );
+ assert.dom(".share-topic-modal").exists("shows the share modal");
+ });
- assert
- .dom(".post-action-menu__copy-link-checkmark")
- .exists("shows the Link Copied! message");
- });
+ test("Copy Link Button", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click(
+ ".topic-post:first-child button.post-action-menu__copy-link"
+ );
- test("Showing and hiding the edit controls", async function (assert) {
- await visit("/t/internationalization-localization/280");
+ assert
+ .dom(".post-action-menu__copy-link-checkmark")
+ .exists("shows the Link Copied! message");
+ });
- await click("#topic-title .d-icon-pencil");
+ test("Showing and hiding the edit controls", async function (assert) {
+ await visit("/t/internationalization-localization/280");
- assert.dom("#edit-title").exists("shows the editing controls");
- assert
- .dom(".title-wrapper .remove-featured-link")
- .doesNotExist("link to remove featured link is not shown");
+ await click("#topic-title .d-icon-pencil");
- await fillIn("#edit-title", "this is the new title");
- await click("#topic-title .cancel-edit");
- assert.dom("#edit-title").doesNotExist("hides the editing controls");
- });
+ assert.dom("#edit-title").exists("shows the editing controls");
+ assert
+ .dom(".title-wrapper .remove-featured-link")
+ .doesNotExist("link to remove featured link is not shown");
- test("Updating the topic title and category", async function (assert) {
- const categoryChooser = selectKit(".title-wrapper .category-chooser");
+ await fillIn("#edit-title", "this is the new title");
+ await click("#topic-title .cancel-edit");
+ assert.dom("#edit-title").doesNotExist("hides the editing controls");
+ });
- await visit("/t/internationalization-localization/280");
+ test("Updating the topic title and category", async function (assert) {
+ const categoryChooser = selectKit(".title-wrapper .category-chooser");
- await click("#topic-title .d-icon-pencil");
- await fillIn("#edit-title", "this is the new title");
- await categoryChooser.expand();
- await categoryChooser.selectRowByValue(4);
- await click("#topic-title .submit-edit");
+ await visit("/t/internationalization-localization/280");
- assert
- .dom("#topic-title .badge-category")
- .hasText("faq", "displays the new category");
- assert
- .dom(".fancy-title")
- .hasText("this is the new title", "displays the new title");
- });
+ await click("#topic-title .d-icon-pencil");
+ await fillIn("#edit-title", "this is the new title");
+ await categoryChooser.expand();
+ await categoryChooser.selectRowByValue(4);
+ await click("#topic-title .submit-edit");
- test("Marking a topic as wiki", async function (assert) {
- await visit("/t/internationalization-localization/280");
+ assert
+ .dom("#topic-title .badge-category")
+ .hasText("faq", "displays the new category");
+ assert
+ .dom(".fancy-title")
+ .hasText("this is the new title", "displays the new title");
+ });
- assert.dom("a.wiki").doesNotExist("does not show the wiki icon");
+ test("Marking a topic as wiki", async function (assert) {
+ await visit("/t/internationalization-localization/280");
- await click(".topic-post:nth-of-type(1) button.show-more-actions");
- await click(".topic-post:nth-of-type(1) button.show-post-admin-menu");
- await click(".btn.wiki");
+ assert.dom("a.wiki").doesNotExist("does not show the wiki icon");
- assert.dom("button.wiki").exists("shows the wiki icon");
- });
+ await click(".topic-post:nth-of-type(1) button.show-more-actions");
+ await click(".topic-post:nth-of-type(1) button.show-post-admin-menu");
+ await click(".btn.wiki");
- test("Visit topic routes", async function (assert) {
- await visit("/t/12");
+ assert.dom("button.wiki").exists("shows the wiki icon");
+ });
- assert
- .dom(".fancy-title")
- .hasText("PM for testing", "routes to the right topic");
+ test("Visit topic routes", async function (assert) {
+ await visit("/t/12");
- await visit("/t/280/20");
+ assert
+ .dom(".fancy-title")
+ .hasText("PM for testing", "routes to the right topic");
- assert
- .dom(".fancy-title")
- .hasText(
- "Internationalization / localization",
- "routes to the right topic"
- );
- });
+ await visit("/t/280/20");
- test("Updating the topic title with emojis", async function (assert) {
- await visit("/t/internationalization-localization/280");
- await click("#topic-title .d-icon-pencil");
+ assert
+ .dom(".fancy-title")
+ .hasText(
+ "Internationalization / localization",
+ "routes to the right topic"
+ );
+ });
- await fillIn("#edit-title", "emojis title :bike: :blonde_woman:t6:");
+ test("Updating the topic title with emojis", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("#topic-title .d-icon-pencil");
- await click("#topic-title .submit-edit");
+ await fillIn("#edit-title", "emojis title :bike: :blonde_woman:t6:");
- assert
- .dom(".fancy-title")
- .includesHtml("bike.png", "displays the new title with emojis");
- });
+ await click("#topic-title .submit-edit");
- test("Updating the topic title with unicode emojis", async function (assert) {
- await visit("/t/internationalization-localization/280");
- await click("#topic-title .d-icon-pencil");
+ assert
+ .dom(".fancy-title")
+ .includesHtml("bike.png", "displays the new title with emojis");
+ });
- await fillIn("#edit-title", "emojis title 👨‍🌾🙏");
+ test("Updating the topic title with unicode emojis", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("#topic-title .d-icon-pencil");
- await click("#topic-title .submit-edit");
+ await fillIn("#edit-title", "emojis title 👨‍🌾🙏");
- assert
- .dom(".fancy-title")
- .includesHtml(
- "man_farmer.png",
- "displays the new title with emojis"
- );
- });
+ await click("#topic-title .submit-edit");
- test("Updating the topic title with unicode emojis without whitespace", async function (assert) {
- this.siteSettings.enable_inline_emoji_translation = true;
- await visit("/t/internationalization-localization/280");
- await click("#topic-title .d-icon-pencil");
+ assert
+ .dom(".fancy-title")
+ .includesHtml("man_farmer.png", "displays the new title with emojis");
+ });
- await fillIn("#edit-title", "Test🙂Title");
+ test("Updating the topic title with unicode emojis without whitespace", async function (assert) {
+ this.siteSettings.enable_inline_emoji_translation = true;
+ await visit("/t/internationalization-localization/280");
+ await click("#topic-title .d-icon-pencil");
- await click("#topic-title .submit-edit");
+ await fillIn("#edit-title", "Test🙂Title");
- assert
- .dom(".fancy-title")
- .includesHtml(
- "slightly_smiling_face.png",
- "displays the new title with emojis"
- );
- });
+ await click("#topic-title .submit-edit");
- test("Suggested topics", async function (assert) {
- await visit("/t/internationalization-localization/280");
+ assert
+ .dom(".fancy-title")
+ .includesHtml(
+ "slightly_smiling_face.png",
+ "displays the new title with emojis"
+ );
+ });
- assert
- .dom("#suggested-topics-title")
- .hasText(i18n("suggested_topics.title"));
- });
+ test("Suggested topics", async function (assert) {
+ await visit("/t/internationalization-localization/280");
- test("Deleting a topic", async function (assert) {
- this.siteSettings.min_topic_views_for_delete_confirm = 10000;
- await visit("/t/internationalization-localization/280");
- await click(".topic-post:nth-of-type(1) button.show-more-actions");
- await click(".topic-post:nth-of-type(1) button.delete");
- await click(".toggle-admin-menu");
- assert.dom(".topic-admin-recover").exists("shows the recover button");
- });
+ assert
+ .dom("#suggested-topics-title")
+ .hasText(i18n("suggested_topics.title"));
+ });
- test("Deleting a popular topic displays confirmation modal", async function (assert) {
- this.siteSettings.min_topic_views_for_delete_confirm = 10;
- await visit("/t/internationalization-localization/280");
- await click(".topic-post:nth-of-type(1) button.show-more-actions");
- await click(".topic-post:nth-of-type(1) button.delete");
- assert
- .dom(".delete-topic-confirm-modal")
- .exists("shows the delete confirmation modal");
+ test("Deleting a topic", async function (assert) {
+ this.siteSettings.min_topic_views_for_delete_confirm = 10000;
+ await visit("/t/internationalization-localization/280");
+ await click(".topic-post:nth-of-type(1) button.show-more-actions");
+ await click(".topic-post:nth-of-type(1) button.delete");
+ await click(".toggle-admin-menu");
+ assert.dom(".topic-admin-recover").exists("shows the recover button");
+ });
- await click(".delete-topic-confirm-modal .btn-primary");
- assert
- .dom(".delete-topic-confirm-modal")
- .doesNotExist("hides the delete confirmation modal");
- await click(".topic-post:nth-of-type(1) button.delete");
- await click(".delete-topic-confirm-modal .btn-danger");
- await click(".toggle-admin-menu");
- assert.dom(".topic-admin-recover").exists("shows the recover button");
- });
+ test("Deleting a popular topic displays confirmation modal", async function (assert) {
+ this.siteSettings.min_topic_views_for_delete_confirm = 10;
+ await visit("/t/internationalization-localization/280");
+ await click(".topic-post:nth-of-type(1) button.show-more-actions");
+ await click(".topic-post:nth-of-type(1) button.delete");
+ assert
+ .dom(".delete-topic-confirm-modal")
+ .exists("shows the delete confirmation modal");
- test("Group category moderator posts", async function (assert) {
- await visit("/t/topic-for-group-moderators/2480");
+ await click(".delete-topic-confirm-modal .btn-primary");
+ assert
+ .dom(".delete-topic-confirm-modal")
+ .doesNotExist("hides the delete confirmation modal");
+ await click(".topic-post:nth-of-type(1) button.delete");
+ await click(".delete-topic-confirm-modal .btn-danger");
+ await click(".toggle-admin-menu");
+ assert.dom(".topic-admin-recover").exists("shows the recover button");
+ });
- assert.dom(".category-moderator").exists("has a class applied");
- assert.dom(".d-icon-shield-halved").exists("shows an icon");
- });
+ test("Group category moderator posts", async function (assert) {
+ await visit("/t/topic-for-group-moderators/2480");
+
+ assert.dom(".category-moderator").exists("has a class applied");
+ assert.dom(".d-icon-shield-halved").exists("shows an icon");
+ });
- test("Suspended user posts", async function (assert) {
- await visit("/t/topic-from-suspended-user/54077");
+ test("Suspended user posts", async function (assert) {
+ await visit("/t/topic-from-suspended-user/54077");
- assert
- .dom(".topic-post.user-suspended > #post_1")
- .exists("has a class applied");
- });
- }
- );
- });
+ assert
+ .dom(".topic-post.user-suspended > #post_1")
+ .exists("has a class applied");
+ });
+ }
+ );
acceptance(
`Topic featured links (glimmer_post_stream_mode = ${postStreamMode})`,
diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-tips-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-tips-test.js
index ddf57857aed..9e0391524f8 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/user-tips-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/user-tips-test.js
@@ -49,26 +49,16 @@ acceptance("User Tips - topic_timeline", function (needs) {
});
});
-["enabled", "disabled"].forEach((postMenuMode) => {
- acceptance(
- `User Tips - post_menu (glimmer_post_menu_mode = ${postMenuMode})`,
- function (needs) {
- needs.user();
- needs.site({ user_tips: { post_menu: 3 } });
- needs.settings({
- glimmer_post_menu_mode: postMenuMode,
- });
+acceptance(`User Tips - post_menu`, function (needs) {
+ needs.user();
+ needs.site({ user_tips: { post_menu: 3 } });
- test("Shows post menu user tip", async function (assert) {
- this.siteSettings.enable_user_tips = true;
+ test("Shows post menu user tip", async function (assert) {
+ this.siteSettings.enable_user_tips = true;
- await visit("/t/internationalization-localization/280");
- assert
- .dom(".user-tip__title")
- .hasText(i18n("user_tips.post_menu.title"));
- });
- }
- );
+ await visit("/t/internationalization-localization/280");
+ assert.dom(".user-tip__title").hasText(i18n("user_tips.post_menu.title"));
+ });
});
acceptance("User Tips - topic_notification_levels", function (needs) {
diff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
index 1dc60f98dd7..7f73e29a3d5 100644
--- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
+++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js
@@ -102,7 +102,6 @@ import {
} from "discourse/tests/helpers/site-settings";
import { resetPostClassesCallback } from "discourse/widgets/post";
import { resetDecorators as resetPostCookedDecorators } from "discourse/widgets/post-cooked";
-import { resetPostMenuExtraButtons } from "discourse/widgets/post-menu";
import { resetPostSmallActionClassesCallbacks } from "discourse/widgets/post-small-action";
import { resetDecorators } from "discourse/widgets/widget";
import I18n from "discourse-i18n";
@@ -221,7 +220,6 @@ export function testCleanup(container, app) {
resetCardClickListenerSelector();
resetComposerCustomizations();
resetQuickSearchRandomTips();
- resetPostMenuExtraButtons();
resetUserMenuProfileTabItems();
clearExtraKeyboardShortcutHelp();
clearDisabledDefaultKeyboardBindings();
diff --git a/app/assets/javascripts/discourse/tests/integration/components/post/post-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/post/post-test.gjs
index c73080b40b4..51e40b2299d 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/post/post-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/post/post-test.gjs
@@ -51,7 +51,6 @@ module("Integration | Component | Post", function (hooks) {
hooks.beforeEach(function () {
this.siteSettings.glimmer_post_stream_mode = "enabled";
- this.siteSettings.glimmer_post_menu_mode = "enabled";
this.siteSettings.post_menu_hidden_items = "";
this.store = getOwner(this).lookup("service:store");
diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-menu-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-menu-test.gjs
deleted file mode 100644
index 3f00bd9895f..00000000000
--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-menu-test.gjs
+++ /dev/null
@@ -1,238 +0,0 @@
-import { click, render } from "@ember/test-helpers";
-import { module, test } from "qunit";
-import { h } from "virtual-dom";
-import MountWidget from "discourse/components/mount-widget";
-import { withSilencedDeprecations } from "discourse/lib/deprecated";
-import { withPluginApi } from "discourse/lib/plugin-api";
-import { setupRenderingTest } from "discourse/tests/helpers/component-test";
-import { resetPostMenuExtraButtons } from "discourse/widgets/post-menu";
-import { createWidget } from "discourse/widgets/widget";
-
-module("Integration | Component | Widget | post-menu", function (hooks) {
- setupRenderingTest(hooks);
-
- hooks.afterEach(function () {
- resetPostMenuExtraButtons();
- });
-
- test("add extra button", async function (assert) {
- const self = this;
-
- this.set("args", {});
- withPluginApi("0.14.0", (api) => {
- withSilencedDeprecations("discourse.post-menu-widget-overrides", () => {
- api.addPostMenuButton("coffee", () => {
- return {
- action: "drinkCoffee",
- icon: "mug-saucer",
- className: "hot-coffee",
- title: "coffee.title",
- position: "first",
- };
- });
- });
- });
-
- await render(
- <template>
- <MountWidget @widget="post-menu" @args={{self.args}} />
- </template>
- );
-
- assert
- .dom(".actions .extra-buttons .hot-coffee")
- .exists("renders extra button");
- });
-
- test("add extra button with feedback", async function (assert) {
- const self = this;
-
- this.set("args", {});
-
- let testPost = null;
-
- withPluginApi("0.14.0", (api) => {
- withSilencedDeprecations("discourse.post-menu-widget-overrides", () => {
- api.addPostMenuButton("coffee", () => {
- return {
- action: ({ post, showFeedback }) => {
- testPost = post;
- showFeedback("coffee.drink");
- },
- icon: "mug-saucer",
- className: "hot-coffee",
- title: "coffee.title",
- position: "first",
- actionParam: { id: 123 }, // hack for testing
- };
- });
- });
- });
-
- await render(
- <template>
- <article data-post-id="123">
- <MountWidget @widget="post-menu" @args={{self.args}} />
- </article>
- </template>
- );
-
- await click(".hot-coffee");
-
- assert.strictEqual(testPost.id, 123, "callback was called with post");
- assert.dom(".post-action-feedback-button").exists("renders feedback");
-
- assert
- .dom(".actions .extra-buttons .hot-coffee")
- .exists("renders extra button");
- });
-
- test("removes button based on callback", async function (assert) {
- const self = this;
-
- this.set("args", { canCreatePost: true, canRemoveReply: true });
-
- withPluginApi("0.14.0", (api) => {
- withSilencedDeprecations("discourse.post-menu-widget-overrides", () => {
- api.removePostMenuButton("reply", (attrs) => {
- return attrs.canRemoveReply;
- });
- });
- });
-
- await render(
- <template>
- <MountWidget @widget="post-menu" @args={{self.args}} />
- </template>
- );
-
- assert.dom(".actions .reply").doesNotExist("removes reply button");
- });
-
- test("does not remove button", async function (assert) {
- const self = this;
-
- this.set("args", { canCreatePost: true, canRemoveReply: false });
-
- withPluginApi("0.14.0", (api) => {
- withSilencedDeprecations("discourse.post-menu-widget-overrides", () => {
- api.removePostMenuButton("reply", (attrs) => {
- return attrs.canRemoveReply;
- });
- });
- });
-
- await render(
- <template>
- <MountWidget @widget="post-menu" @args={{self.args}} />
- </template>
- );
-
- assert.dom(".actions .reply").exists("does not remove reply button");
- });
-
- test("removes button", async function (assert) {
- const self = this;
-
- this.set("args", { canCreatePost: true });
-
- withPluginApi("0.14.0", (api) => {
- withSilencedDeprecations("discourse.post-menu-widget-overrides", () => {
- api.removePostMenuButton("reply");
- });
- });
-
- await render(
- <template>
- <MountWidget @widget="post-menu" @args={{self.args}} />
- </template>
- );
-
- assert.dom(".actions .reply").doesNotExist("removes reply button");
- });
-
- test("removes button when any callback evaluates to true", async function (assert) {
- const self = this;
-
- this.set("args", {});
-
- withPluginApi("0.14.0", (api) => {
- withSilencedDeprecations("discourse.post-menu-widget-overrides", () => {
- api.removePostMenuButton("reply", () => true);
- api.removePostMenuButton("reply", () => false);
- });
- });
-
- await render(
- <template>
- <MountWidget @widget="post-menu" @args={{self.args}} />
- </template>
- );
-
- assert.dom(".actions .reply").doesNotExist("removes reply button");
- });
-
- createWidget("post-menu-replacement", {
- html(attrs) {
- return h("h1.post-menu-replacement", {}, attrs.id);
- },
- });
-
- test("buttons are replaced when shouldRender is true", async function (assert) {
- const self = this;
-
- this.set("args", { id: 1, canCreatePost: true });
-
- withPluginApi("0.14.0", (api) => {
- withSilencedDeprecations("discourse.post-menu-widget-overrides", () => {
- api.replacePostMenuButton("reply", {
- name: "post-menu-replacement",
- buildAttrs: (widget) => {
- return widget.attrs;
- },
- shouldRender: (widget) => widget.attrs.id === 1, // true!
- });
- });
- });
-
- await render(
- <template>
- <MountWidget @widget="post-menu" @args={{self.args}} />
- </template>
- );
-
- assert.dom("h1.post-menu-replacement").exists("replacement is rendered");
- assert
- .dom(".actions .reply")
- .doesNotExist("reply button is replaced button");
- });
-
- test("buttons are not replaced when shouldRender is false", async function (assert) {
- const self = this;
-
- this.set("args", { id: 1, canCreatePost: true, canRemoveReply: false });
-
- withPluginApi("0.14.0", (api) => {
- withSilencedDeprecations("discourse.post-menu-widget-overrides", () => {
- api.replacePostMenuButton("reply", {
- name: "post-menu-replacement",
- buildAttrs: (widget) => {
- return widget.attrs;
- },
- shouldRender: (widget) => widget.attrs.id === 102323948, // false!
- });
- });
- });
-
- await render(
- <template>
- <MountWidget @widget="post-menu" @args={{self.args}} />
- </template>
- );
-
- assert
- .dom("h1.post-menu-replacement")
- .doesNotExist("replacement is not rendered");
- assert.dom(".actions .reply").exists("reply button is present");
- });
-});
diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-stream-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-stream-test.gjs
index 488ca3090c8..6a498dd8891 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-stream-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-stream-test.gjs
@@ -6,7 +6,6 @@ import DButton from "discourse/components/d-button";
import { withSilencedDeprecations } from "discourse/lib/deprecated";
import { withPluginApi } from "discourse/lib/plugin-api";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
-import { resetPostMenuExtraButtons } from "discourse/widgets/post-menu";
function postStreamTest(name, attrs) {
test(name, async function (assert) {
@@ -21,218 +20,211 @@ function postStreamTest(name, attrs) {
}
["enabled", "disabled"].forEach((postStreamMode) => {
- ["enabled", "disabled"].forEach((postMenuMode) => {
- let lastTransformedPost = null;
-
- module(
- `Integration | Component | Widget | post-stream (glimmer_post_stream_mode = ${postStreamMode}) (glimmer_post_menu_mode = ${postMenuMode})`,
- function (hooks) {
- setupRenderingTest(hooks);
-
- hooks.beforeEach(function () {
- this.siteSettings.glimmer_post_menu_mode = postMenuMode;
- this.siteSettings.glimmer_post_stream_mode = postStreamMode;
- });
-
- hooks.afterEach(function () {
- resetPostMenuExtraButtons();
- });
-
- const CustomPostMenuButton = <template>
- <DButton
- class="hot-coffee"
- ...attributes
- @icon="mug-saucer"
- @title="coffee.title"
- />
- </template>;
-
- postStreamTest("extensibility", {
- posts() {
- withPluginApi("1.34.0", (api) => {
- api.registerValueTransformer(
- "post-menu-buttons",
- ({ value: dag, context: { post, firstButtonKey } }) => {
- dag.add("coffee", CustomPostMenuButton, {
- before: firstButtonKey,
- });
-
- // value transformers shouldn't have side effects
- // we are only doing it below for testing purposes. Do not use strategies like this in the app code
- lastTransformedPost = post;
- }
- );
-
- withSilencedDeprecations(
- "discourse.post-menu-widget-overrides",
- () => {
- api.addPostMenuButton("coffee", (transformedPost) => {
- lastTransformedPost = transformedPost;
-
- return {
- action: "drinkCoffee",
- icon: "mug-saucer",
- className: "hot-coffee",
- title: "coffee.title",
- position: "first",
- };
- });
- }
- );
- });
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic");
- topic.set("details.created_by", { id: 123 });
- topic.set("id", 1234);
-
- return [
- store.createRecord("post", {
- topic,
- id: 1,
- post_number: 1,
- user_id: 123,
- primary_group_name: "trout",
- avatar_template: "/images/avatar.png",
- }),
- ];
- },
-
- test(assert) {
- assert.dom(".post-stream").exists({ count: 1 });
- assert.dom(".topic-post").exists({ count: 1 }, "renders all posts");
- assert
- .dom(".topic-post:nth-of-type(1) button.hot-coffee")
- .exists("it transforms posts");
- assert.strictEqual(
- lastTransformedPost.topic.id,
- 1234,
- "it also transforms the topic"
+ let lastTransformedPost = null;
+
+ module(
+ `Integration | Component | Widget | post-stream (glimmer_post_stream_mode = ${postStreamMode})`,
+ function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.siteSettings.glimmer_post_stream_mode = postStreamMode;
+ });
+
+ const CustomPostMenuButton = <template>
+ <DButton
+ class="hot-coffee"
+ ...attributes
+ @icon="mug-saucer"
+ @title="coffee.title"
+ />
+ </template>;
+
+ postStreamTest("extensibility", {
+ posts() {
+ withPluginApi("1.34.0", (api) => {
+ api.registerValueTransformer(
+ "post-menu-buttons",
+ ({ value: dag, context: { post, firstButtonKey } }) => {
+ dag.add("coffee", CustomPostMenuButton, {
+ before: firstButtonKey,
+ });
+
+ // value transformers shouldn't have side effects
+ // we are only doing it below for testing purposes. Do not use strategies like this in the app code
+ lastTransformedPost = post;
+ }
);
- assert
- .dom(".actions .hot-coffee")
- .exists({ count: 1 }, "has the extended button");
- },
- });
-
- postStreamTest("basics", {
- posts() {
- const site = getOwner(this).lookup("service:site");
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic");
- topic.set("details.created_by", { id: 123 });
-
- return [
- store.createRecord("post", {
- topic,
- id: 1,
- post_number: 1,
- username: "eviltrout",
- user_id: 123,
- primary_group_name: "trout",
- avatar_template: "/images/avatar.png",
- }),
- store.createRecord("post", {
- topic,
- id: 2,
- post_number: 2,
- post_type: site.get("post_types.moderator_action"),
- }),
- store.createRecord("post", {
- topic,
- id: 3,
- post_number: 3,
- hidden: true,
- }),
- store.createRecord("post", {
- topic,
- id: 4,
- post_number: 4,
- post_type: site.get("post_types.whisper"),
- }),
- store.createRecord("post", {
- topic,
- id: 5,
- post_number: 5,
- wiki: true,
- via_email: true,
- }),
- store.createRecord("post", {
- topic,
- id: 6,
- post_number: 6,
- via_email: true,
- is_auto_generated: true,
- }),
- ];
- },
-
- async test(assert) {
- assert.dom(".post-stream").exists({ count: 1 });
- assert.dom(".topic-post").exists({ count: 6 }, "renders all posts");
-
- // look for special class bindings
- assert
- .dom(".topic-post:nth-of-type(1).topic-owner")
- .exists({ count: 1 }, "applies the topic owner class");
- assert
- .dom(".topic-post:nth-of-type(1).group-trout")
- .exists({ count: 1 }, "applies the primary group class");
- assert
- .dom(".topic-post:nth-of-type(1).regular")
- .exists({ count: 1 }, "applies the regular class");
- assert
- .dom(".topic-post:nth-of-type(2).moderator")
- .exists({ count: 1 }, "applies the moderator class");
- assert
- .dom(".topic-post:nth-of-type(3).post-hidden")
- .exists({ count: 1 }, "applies the hidden class");
- assert
- .dom(".topic-post:nth-of-type(4).whisper")
- .exists({ count: 1 }, "applies the whisper class");
- assert
- .dom(".topic-post:nth-of-type(5).wiki")
- .exists({ count: 1 }, "applies the wiki class");
-
- // it renders an article for the body with appropriate attributes
- assert.dom("article#post_2").exists({ count: 1 });
- assert.dom('article[data-user-id="123"]').exists({ count: 1 });
- assert.dom('article[data-post-id="3"]').exists({ count: 1 });
- assert.dom("article#post_5.via-email").exists({ count: 1 });
- assert.dom("article#post_6.is-auto-generated").exists({ count: 1 });
-
- assert
- .dom("article:nth-of-type(1) .main-avatar")
- .exists({ count: 1 }, "renders the main avatar");
- },
- });
-
- postStreamTest("deleted posts", {
- posts() {
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic");
- topic.set("details.created_by", { id: 123 });
-
- return [
- store.createRecord("post", {
- topic,
- id: 1,
- post_number: 1,
- deleted_at: new Date().toString(),
- }),
- ];
- },
-
- test(assert) {
- assert
- .dom(".topic-post.deleted")
- .exists({ count: 1 }, "applies the deleted class");
- assert
- .dom(".deleted-user-avatar")
- .exists({ count: 1 }, "has the trash avatar");
- },
- });
- }
- );
- });
+
+ withSilencedDeprecations(
+ "discourse.post-menu-widget-overrides",
+ () => {
+ api.addPostMenuButton("coffee", (transformedPost) => {
+ lastTransformedPost = transformedPost;
+
+ return {
+ action: "drinkCoffee",
+ icon: "mug-saucer",
+ className: "hot-coffee",
+ title: "coffee.title",
+ position: "first",
+ };
+ });
+ }
+ );
+ });
+
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic");
+ topic.set("details.created_by", { id: 123 });
+ topic.set("id", 1234);
+
+ return [
+ store.createRecord("post", {
+ topic,
+ id: 1,
+ post_number: 1,
+ user_id: 123,
+ primary_group_name: "trout",
+ avatar_template: "/images/avatar.png",
+ }),
+ ];
+ },
+
+ test(assert) {
+ assert.dom(".post-stream").exists({ count: 1 });
+ assert.dom(".topic-post").exists({ count: 1 }, "renders all posts");
+ assert
+ .dom(".topic-post:nth-of-type(1) button.hot-coffee")
+ .exists("it transforms posts");
+ assert.strictEqual(
+ lastTransformedPost.topic.id,
+ 1234,
+ "it also transforms the topic"
+ );
+ assert
+ .dom(".actions .hot-coffee")
+ .exists({ count: 1 }, "has the extended button");
+ },
+ });
+
+ postStreamTest("basics", {
+ posts() {
+ const site = getOwner(this).lookup("service:site");
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic");
+ topic.set("details.created_by", { id: 123 });
+
+ return [
+ store.createRecord("post", {
+ topic,
+ id: 1,
+ post_number: 1,
+ username: "eviltrout",
+ user_id: 123,
+ primary_group_name: "trout",
+ avatar_template: "/images/avatar.png",
+ }),
+ store.createRecord("post", {
+ topic,
+ id: 2,
+ post_number: 2,
+ post_type: site.get("post_types.moderator_action"),
+ }),
+ store.createRecord("post", {
+ topic,
+ id: 3,
+ post_number: 3,
+ hidden: true,
+ }),
+ store.createRecord("post", {
+ topic,
+ id: 4,
+ post_number: 4,
+ post_type: site.get("post_types.whisper"),
+ }),
+ store.createRecord("post", {
+ topic,
+ id: 5,
+ post_number: 5,
+ wiki: true,
+ via_email: true,
+ }),
+ store.createRecord("post", {
+ topic,
+ id: 6,
+ post_number: 6,
+ via_email: true,
+ is_auto_generated: true,
+ }),
+ ];
+ },
+
+ async test(assert) {
+ assert.dom(".post-stream").exists({ count: 1 });
+ assert.dom(".topic-post").exists({ count: 6 }, "renders all posts");
+
+ // look for special class bindings
+ assert
+ .dom(".topic-post:nth-of-type(1).topic-owner")
+ .exists({ count: 1 }, "applies the topic owner class");
+ assert
+ .dom(".topic-post:nth-of-type(1).group-trout")
+ .exists({ count: 1 }, "applies the primary group class");
+ assert
+ .dom(".topic-post:nth-of-type(1).regular")
+ .exists({ count: 1 }, "applies the regular class");
+ assert
+ .dom(".topic-post:nth-of-type(2).moderator")
+ .exists({ count: 1 }, "applies the moderator class");
+ assert
+ .dom(".topic-post:nth-of-type(3).post-hidden")
+ .exists({ count: 1 }, "applies the hidden class");
+ assert
+ .dom(".topic-post:nth-of-type(4).whisper")
+ .exists({ count: 1 }, "applies the whisper class");
+ assert
+ .dom(".topic-post:nth-of-type(5).wiki")
+ .exists({ count: 1 }, "applies the wiki class");
+
+ // it renders an article for the body with appropriate attributes
+ assert.dom("article#post_2").exists({ count: 1 });
+ assert.dom('article[data-user-id="123"]').exists({ count: 1 });
+ assert.dom('article[data-post-id="3"]').exists({ count: 1 });
+ assert.dom("article#post_5.via-email").exists({ count: 1 });
+ assert.dom("article#post_6.is-auto-generated").exists({ count: 1 });
+
+ assert
+ .dom("article:nth-of-type(1) .main-avatar")
+ .exists({ count: 1 }, "renders the main avatar");
+ },
+ });
+
+ postStreamTest("deleted posts", {
+ posts() {
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic");
+ topic.set("details.created_by", { id: 123 });
+
+ return [
+ store.createRecord("post", {
+ topic,
+ id: 1,
+ post_number: 1,
+ deleted_at: new Date().toString(),
+ }),
+ ];
+ },
+
+ test(assert) {
+ assert
+ .dom(".topic-post.deleted")
+ .exists({ count: 1 }, "applies the deleted class");
+ assert
+ .dom(".deleted-user-avatar")
+ .exists({ count: 1 }, "has the trash avatar");
+ },
+ });
+ }
+ );
});
diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test-with-glimmer-post-menu-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test-with-glimmer-post-menu-test.gjs
deleted file mode 100644
index 20b537b3070..00000000000
--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test-with-glimmer-post-menu-test.gjs
+++ /dev/null
@@ -1,1163 +0,0 @@
-import EmberObject from "@ember/object";
-import { getOwner } from "@ember/owner";
-import { click, render, triggerEvent } from "@ember/test-helpers";
-import { module, test } from "qunit";
-import MountWidget from "discourse/components/mount-widget";
-import { setupRenderingTest } from "discourse/tests/helpers/component-test";
-import { count, queryAll } from "discourse/tests/helpers/qunit-helpers";
-import { i18n } from "discourse-i18n";
-import DMenus from "float-kit/components/d-menus";
-
-module(
- "Integration | Component | Widget | post with glimmer-post-menu",
- function (hooks) {
- setupRenderingTest(hooks);
-
- hooks.beforeEach(function () {
- this.siteSettings.glimmer_post_menu_mode = "enabled";
- this.siteSettings.post_menu_hidden_items = "";
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", { id: 123 });
- const post = store.createRecord("post", {
- id: 1,
- post_number: 1,
- topic,
- like_count: 3,
- actions_summary: [{ id: 2, count: 1, hidden: false, can_act: true }],
- });
-
- this.set("post", post);
- this.set("args", {});
- });
-
- test("basic elements", async function (assert) {
- const self = this;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- archetype: "regular",
- });
-
- this.set("args", { shareUrl: "/example", post_number: 1, topic });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".names").exists("includes poster name");
- assert.dom("a.post-date").exists("includes post date");
- });
-
- test("post - links", async function (assert) {
- const self = this;
-
- this.set("args", {
- cooked:
- "<a href='http://link1.example.com/'>first link</a> and <a href='http://link2.example.com/?some=query'>second link</a>",
- linkCounts: [
- { url: "http://link1.example.com/", clicks: 1, internal: true },
- { url: "http://link2.example.com/", clicks: 2, internal: true },
- ],
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post-contents"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.strictEqual(
- queryAll("a[data-clicks='1']")[0].getAttribute("data-clicks"),
- "1"
- );
- assert.strictEqual(
- queryAll("a[data-clicks='2']")[0].getAttribute("data-clicks"),
- "2"
- );
- });
-
- test("post - onebox links", async function (assert) {
- const self = this;
-
- this.set("args", {
- cooked: `
- <p><a href="https://example.com">Other URL</a></p>
-
- <aside class="onebox twitterstatus" data-onebox-src="https://twitter.com/codinghorror">
- <header class="source">
- <a href="https://twitter.com/codinghorror" target="_blank" rel="noopener">twitter.com</a>
- </header>
- <article class="onebox-body">
- <h4><a href="https://twitter.com/codinghorror" target="_blank" rel="noopener">Jeff Atwood</a></h4>
- <div class="twitter-screen-name"><a href="https://twitter.com/codinghorror" target="_blank" rel="noopener">@codinghorror</a></div>
- </article>
- </aside>`,
- linkCounts: [
- { url: "https://example.com", clicks: 1 },
- { url: "https://twitter.com/codinghorror", clicks: 2 },
- ],
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post-contents"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.strictEqual(
- queryAll("a[data-clicks='1']")[0].getAttribute("data-clicks"),
- "1",
- "First link has correct data attribute and content"
- );
- assert.strictEqual(
- queryAll("a[data-clicks='2']")[0].getAttribute("data-clicks"),
- "2",
- "Second link has correct data attribute and content"
- );
- });
-
- test("wiki", async function (assert) {
- const self = this;
-
- this.set("args", { wiki: true, version: 2, canViewEditHistory: true });
- this.set("showHistory", () => (this.historyShown = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @showHistory={{self.showHistory}}
- />
- </template>
- );
-
- await click(".post-info .wiki");
- assert.true(
- this.historyShown,
- "clicking the wiki icon displays the post history"
- );
- });
-
- test("wiki without revision", async function (assert) {
- const self = this;
-
- this.set("args", { wiki: true, version: 1, canViewEditHistory: true });
- this.set("editPost", () => (this.editPostCalled = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @editPost={{self.editPost}}
- />
- </template>
- );
-
- await click(".post-info .wiki");
- assert.true(this.editPostCalled, "clicking wiki icon edits the post");
- });
-
- test("via-email", async function (assert) {
- const self = this;
-
- this.set("args", { via_email: true, canViewRawEmail: true });
- this.set("showRawEmail", () => (this.rawEmailShown = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @showRawEmail={{self.showRawEmail}}
- />
- </template>
- );
-
- await click(".post-info.via-email");
- assert.true(
- this.rawEmailShown,
- "clicking the envelope shows the raw email"
- );
- });
-
- test("via-email without permission", async function (assert) {
- const self = this;
-
- this.rawEmailShown = false;
- this.set("args", { via_email: true, canViewRawEmail: false });
- this.set("showRawEmail", () => (this.rawEmailShown = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @showRawEmail={{self.showRawEmail}}
- />
- </template>
- );
-
- await click(".post-info.via-email");
- assert.false(
- this.rawEmailShown,
- "clicking the envelope doesn't show the raw email"
- );
- });
-
- test("history", async function (assert) {
- const self = this;
-
- this.set("args", { version: 3, canViewEditHistory: true });
- this.set("showHistory", () => (this.historyShown = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @showHistory={{self.showHistory}}
- />
- </template>
- );
-
- await click(".post-info.edits button");
- assert.true(this.historyShown, "clicking the pencil shows the history");
- });
-
- test("history without view permission", async function (assert) {
- const self = this;
-
- this.historyShown = false;
- this.set("args", { version: 3, canViewEditHistory: false });
- this.set("showHistory", () => (this.historyShown = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @showHistory={{self.showHistory}}
- />
- </template>
- );
-
- await click(".post-info.edits");
- assert.false(
- this.historyShown,
- `clicking the pencil doesn't show the history`
- );
- });
-
- test("whisper", async function (assert) {
- const self = this;
-
- this.set("args", { isWhisper: true });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.strictEqual(count(".topic-post.whisper"), 1);
- assert.strictEqual(count(".post-info.whisper"), 1);
- });
-
- test(`read indicator`, async function (assert) {
- const self = this;
-
- this.set("args", { read: true });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".read-state.read").exists();
- });
-
- test(`unread indicator`, async function (assert) {
- const self = this;
-
- this.set("args", { read: false });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".read-state").exists();
- });
-
- test("reply directly above (suppressed)", async function (assert) {
- const self = this;
-
- this.set("args", {
- replyToUsername: "eviltrout",
- replyToAvatarTemplate: "/images/avatar.png",
- replyDirectlyAbove: true,
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom("a.reply-to-tab").doesNotExist("hides the tab");
- assert.dom(".avoid-tab").doesNotExist("doesn't have the avoid tab class");
- });
-
- test("reply a few posts above (suppressed)", async function (assert) {
- const self = this;
-
- this.set("args", {
- replyToUsername: "eviltrout",
- replyToAvatarTemplate: "/images/avatar.png",
- replyDirectlyAbove: false,
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom("a.reply-to-tab").exists("shows the tab");
- assert.strictEqual(count(".avoid-tab"), 1, "has the avoid tab class");
- });
-
- test("reply directly above", async function (assert) {
- const self = this;
-
- this.set("args", {
- replyToUsername: "eviltrout",
- replyToAvatarTemplate: "/images/avatar.png",
- replyDirectlyAbove: true,
- });
- this.siteSettings.suppress_reply_directly_above = false;
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.strictEqual(count(".avoid-tab"), 1, "has the avoid tab class");
- await click("a.reply-to-tab");
- assert.strictEqual(count("section.embedded-posts.top .cooked"), 1);
- assert.strictEqual(count("section.embedded-posts .d-icon-arrow-up"), 1);
- });
-
- test("cooked content hidden", async function (assert) {
- const self = this;
-
- this.set("args", { cooked_hidden: true, canSeeHiddenPost: true });
- this.set("expandHidden", () => (this.unhidden = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @expandHidden={{self.expandHidden}}
- />
- </template>
- );
-
- await click(".topic-body .expand-hidden");
- assert.true(this.unhidden, "triggers the action");
- });
-
- test(`cooked content hidden - can't view hidden post`, async function (assert) {
- const self = this;
-
- this.set("args", { cooked_hidden: true, canSeeHiddenPost: false });
- this.set("expandHidden", () => (this.unhidden = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @expandHidden={{self.expandHidden}}
- />
- </template>
- );
-
- assert
- .dom(".topic-body .expand-hidden")
- .doesNotExist("button is not displayed");
- });
-
- test("expand first post", async function (assert) {
- const self = this;
-
- this.set("args", { expandablePost: true });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- await click(".topic-body .expand-post");
- assert.dom(".expand-post").doesNotExist("button is gone");
- });
-
- test("can't show admin menu when you can't manage", async function (assert) {
- const self = this;
-
- this.set("args", { canManage: false });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".post-menu-area .show-post-admin-menu").doesNotExist();
- });
-
- test("show admin menu", async function (assert) {
- const self = this;
-
- this.currentUser.admin = true;
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- <DMenus />
- </template>
- );
-
- assert
- .dom("[data-content][data-identifier='admin-post-menu']")
- .doesNotExist();
-
- await click(".post-menu-area .show-post-admin-menu");
- assert.dom("[data-content][data-identifier='admin-post-menu']").exists();
-
- await triggerEvent(".post-menu-area", "pointerdown");
- assert
- .dom("[data-content][data-identifier='admin-post-menu']")
- .doesNotExist("clicking outside clears the popup");
- });
-
- test("permanently delete topic", async function (assert) {
- const self = this;
-
- this.currentUser.set("admin", true);
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- details: { can_permanently_delete: true },
- });
- const post = store.createRecord("post", {
- id: 1,
- post_number: 1,
- deleted_at: new Date().toISOString(),
- topic,
- });
-
- this.set("args", { canManage: true });
- this.set("post", post);
- this.set("permanentlyDeletePost", () => (this.deleted = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @permanentlyDeletePost={{self.permanentlyDeletePost}}
- />
- <DMenus />
- </template>
- );
-
- await click(".post-menu-area .show-post-admin-menu");
- await click(
- "[data-content][data-identifier='admin-post-menu'] .permanently-delete"
- );
- assert.true(this.deleted);
- assert
- .dom("[data-content][data-identifier='admin-post-menu']")
- .doesNotExist("also hides the menu");
- });
-
- test("permanently delete post", async function (assert) {
- const self = this;
-
- this.currentUser.set("admin", true);
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- });
- const post = store.createRecord("post", {
- id: 1,
- post_number: 2,
- deleted_at: new Date().toISOString(),
- can_permanently_delete: true,
- topic,
- });
-
- this.set("args", { canManage: true });
- this.set("post", post);
- this.set("permanentlyDeletePost", () => (this.deleted = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @permanentlyDeletePost={{self.permanentlyDeletePost}}
- />
- <DMenus />
- </template>
- );
-
- await click(".post-menu-area .show-post-admin-menu");
-
- await click(
- "[data-content][data-identifier='admin-post-menu'] .permanently-delete"
- );
- assert.true(this.deleted);
- assert
- .dom("[data-content][data-identifier='admin-post-menu']")
- .doesNotExist("also hides the menu");
- });
-
- test("toggle moderator post", async function (assert) {
- const self = this;
-
- this.currentUser.set("moderator", true);
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- });
- const post = store.createRecord("post", {
- id: 1,
- post_number: 2,
- deleted_at: new Date().toISOString(),
- can_permanently_delete: true,
- topic,
- });
-
- this.set("args", { canManage: true });
- this.set("post", post);
- this.set("togglePostType", () => (this.toggled = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @togglePostType={{self.togglePostType}}
- />
- <DMenus />
- </template>
- );
-
- await click(".post-menu-area .show-post-admin-menu");
- await click(
- "[data-content][data-identifier='admin-post-menu'] .toggle-post-type"
- );
-
- assert.true(this.toggled);
- assert
- .dom("[data-content][data-identifier='admin-post-menu']")
- .doesNotExist("also hides the menu");
- });
-
- test("rebake post", async function (assert) {
- const self = this;
-
- this.currentUser.moderator = true;
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", { id: 123 });
- const post = store.createRecord("post", {
- id: 1,
- post_number: 1,
- topic,
- });
-
- this.set("args", { canManage: true });
- this.set("post", post);
- this.set("rebakePost", () => (this.baked = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @rebakePost={{self.rebakePost}}
- />
- <DMenus />
- </template>
- );
-
- await click(".post-menu-area .show-post-admin-menu");
- await click(
- "[data-content][data-identifier='admin-post-menu'] .rebuild-html"
- );
- assert.true(this.baked);
- assert
- .dom("[data-content][data-identifier='admin-post-menu']")
- .doesNotExist("also hides the menu");
- });
-
- test("unhide post", async function (assert) {
- const self = this;
-
- let unhidden;
-
- this.currentUser.admin = true;
- this.post.hidden = true;
- this.set("args", { canManage: true });
- this.set("unhidePost", () => (unhidden = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @unhidePost={{self.unhidePost}}
- />
- <DMenus />
- </template>
- );
-
- await click(".post-menu-area .show-post-admin-menu");
-
- await click(
- "[data-content][data-identifier='admin-post-menu'] .unhide-post"
- );
-
- assert.true(unhidden);
-
- assert
- .dom("[data-content][data-identifier='admin-post-menu']")
- .doesNotExist("also hides the menu");
- });
-
- test("change owner", async function (assert) {
- const self = this;
-
- this.currentUser.admin = true;
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", { id: 123 });
- const post = store.createRecord("post", {
- id: 1,
- post_number: 1,
- hidden: true,
- topic,
- });
-
- this.set("args", { canManage: true });
- this.set("post", post);
- this.set("changePostOwner", () => (this.owned = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- @changePostOwner={{self.changePostOwner}}
- />
- <DMenus />
- </template>
- );
-
- await click(".post-menu-area .show-post-admin-menu");
- await click(
- "[data-content][data-identifier='admin-post-menu'] .change-owner"
- );
- assert.true(this.owned);
- assert
- .dom("[data-content][data-identifier='admin-post-menu']")
- .doesNotExist("also hides the menu");
- });
-
- test("shows the topic map when setting the 'topicMap' attribute", async function (assert) {
- const self = this;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", { id: 123 });
- this.set("args", { topic, post_number: 1, topicMap: true });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".topic-map").exists();
- });
-
- test("shows the topic map when no replies", async function (assert) {
- const self = this;
-
- this.siteSettings.show_topic_map_in_topics_without_replies = true;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- archetype: "regular",
- });
- this.set("args", { topic, post_number: 1 });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".topic-map").exists();
- });
-
- test("topic map - few participants", async function (assert) {
- const self = this;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- posts_count: 10,
- participant_count: 2,
- archetype: "regular",
- });
- topic.details.set("participants", [
- { username: "eviltrout" },
- { username: "codinghorror" },
- ]);
- this.set("args", {
- topic,
- post_number: 1,
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
- assert.dom(".topic-map__users-trigger").doesNotExist();
- assert.dom(".topic-map__users-list a.poster").exists({ count: 2 });
- });
-
- test("topic map - participants", async function (assert) {
- const self = this;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- posts_count: 10,
- participant_count: 6,
- archetype: "regular",
- });
- topic.postStream.setProperties({ userFilters: ["sam", "codinghorror"] });
- topic.details.set("participants", [
- { username: "eviltrout" },
- { username: "codinghorror" },
- { username: "sam" },
- { username: "zogstrip" },
- { username: "joffreyjaffeux" },
- { username: "david" },
- ]);
-
- this.set("args", {
- topic,
- post_number: 1,
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
- assert.dom(".topic-map__users-list a.poster").exists({ count: 5 });
-
- await click(".topic-map__users-trigger");
- assert
- .dom(".topic-map__users-content .topic-map__users-list a.poster")
- .exists({ count: 6 });
- });
-
- test("topic map - links", async function (assert) {
- const self = this;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- posts_count: 2,
- archetype: "regular",
- });
- topic.details.set("links", [
- { url: "http://link1.example.com", clicks: 0 },
- { url: "http://link2.example.com", clicks: 0 },
- { url: "http://link3.example.com", clicks: 0 },
- { url: "http://link4.example.com", clicks: 0 },
- { url: "http://link5.example.com", clicks: 0 },
- { url: "http://link6.example.com", clicks: 0 },
- ]);
- this.set("args", { topic, post_number: 1 });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".topic-map").exists({ count: 1 });
- assert.dom(".topic-map__links-content").doesNotExist();
- await click(".topic-map__links-trigger");
- assert.dom(".topic-map__links-content").exists({ count: 1 });
- assert.dom(".topic-map__links-content .topic-link").exists({ count: 5 });
- await click(".link-summary");
- assert.dom(".topic-map__links-content .topic-link").exists({ count: 6 });
- });
-
- test("topic map - no top reply summary", async function (assert) {
- const self = this;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- archetype: "regular",
- posts_count: 2,
- });
- this.set("args", { topic, post_number: 1 });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".topic-map").exists();
- assert.dom(".summarization-button .top-replies").doesNotExist();
- });
-
- test("topic map - has top replies summary", async function (assert) {
- const self = this;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- archetype: "regular",
- posts_count: 2,
- has_summary: true,
- });
- this.set("args", { topic, post_number: 1 });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".summarization-button .top-replies").exists({ count: 1 });
- });
-
- test("pm map", async function (assert) {
- const self = this;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", {
- id: 123,
- archetype: "private_message",
- });
- topic.details.set("allowed_users", [
- EmberObject.create({ username: "eviltrout" }),
- ]);
- this.set("args", {
- topic,
- post_number: 1,
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".topic-map__private-message-map").exists({ count: 1 });
- assert.dom(".topic-map__private-message-map .user").exists({ count: 1 });
- });
-
- test("post notice - with username", async function (assert) {
- const self = this;
-
- const twoDaysAgo = new Date();
- twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
- this.siteSettings.display_name_on_posts = false;
- this.siteSettings.prioritize_username_in_ux = true;
- this.siteSettings.old_post_notice_days = 14;
- this.set("args", {
- username: "codinghorror",
- name: "Jeff",
- created_at: new Date(),
- notice: {
- type: "returning_user",
- lastPostedAt: twoDaysAgo,
- },
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".post-notice.returning-user:not(.old)").hasText(
- i18n("post.notice.returning_user", {
- user: "codinghorror",
- time: "2 days ago",
- })
- );
- });
-
- test("post notice - with name", async function (assert) {
- const self = this;
-
- this.siteSettings.display_name_on_posts = true;
- this.siteSettings.prioritize_username_in_ux = false;
- this.siteSettings.old_post_notice_days = 14;
- this.set("args", {
- username: "codinghorror",
- name: "Jeff",
- created_at: new Date(2019, 0, 1),
- notice: { type: "new_user" },
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert
- .dom(".post-notice.old.new-user")
- .hasText(
- i18n("post.notice.new_user", { user: "Jeff", time: "Jan '10" })
- );
- });
-
- test("show group request in post", async function (assert) {
- const self = this;
-
- this.set("args", {
- username: "foo",
- requestedGroupName: "testGroup",
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".group-request a").hasText(i18n("groups.requests.handle"));
- assert
- .dom(".group-request a")
- .hasAttribute("href", "/g/testGroup/requests?filter=foo");
- });
-
- test("shows user status if enabled in site settings", async function (assert) {
- const self = this;
-
- this.siteSettings.enable_user_status = true;
- const status = {
- emoji: "tooth",
- description: "off to dentist",
- };
- const store = getOwner(this).lookup("service:store");
- const user = store.createRecord("user", { status });
- this.set("args", { user });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".user-status-message").exists();
- });
-
- test("doesn't show user status if disabled in site settings", async function (assert) {
- const self = this;
-
- this.siteSettings.enable_user_status = false;
- const status = {
- emoji: "tooth",
- description: "off to dentist",
- };
- const store = getOwner(this).lookup("service:store");
- const user = store.createRecord("user", { status });
- this.set("args", { user });
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
-
- assert.dom(".user-status-message").doesNotExist();
- });
-
- test("more actions button is displayed when multiple hidden items are configured", async function (assert) {
- const self = this;
-
- this.siteSettings.post_menu_hidden_items = "bookmark|edit|copyLink";
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
- assert.dom(".show-more-actions").exists();
- });
-
- test("hidden menu expands automatically when only one hidden item is configured", async function (assert) {
- const self = this;
-
- this.siteSettings.post_menu_hidden_items = "bookmark|edit";
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @model={{self.post}}
- @args={{self.args}}
- />
- </template>
- );
- assert.dom(".show-more-actions").doesNotExist();
- });
- }
-);
diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test.gjs
index 61e8f7df25f..f382054b876 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-test.gjs
@@ -1,5 +1,3 @@
-// deprecated in favor of ./post-test-with-glimmer-post-menu.js
-
import EmberObject from "@ember/object";
import { getOwner } from "@ember/owner";
import { click, render, triggerEvent } from "@ember/test-helpers";
@@ -14,7 +12,20 @@ module("Integration | Component | Widget | post", function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
- this.siteSettings.glimmer_post_menu_mode = "disabled";
+ this.siteSettings.post_menu_hidden_items = "";
+
+ const store = getOwner(this).lookup("service:store");
+ const topic = store.createRecord("topic", { id: 123 });
+ const post = store.createRecord("post", {
+ id: 1,
+ post_number: 1,
+ topic,
+ like_count: 3,
+ actions_summary: [{ id: 2, count: 1, hidden: false, can_act: true }],
+ });
+
+ this.set("post", post);
+ this.set("args", {});
});
test("basic elements", async function (assert) {
@@ -29,7 +40,9 @@ module("Integration | Component | Widget | post", function (hooks) {
this.set("args", { shareUrl: "/example", post_number: 1, topic });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".names").exists("includes poster name");
@@ -50,7 +63,11 @@ module("Integration | Component | Widget | post", function (hooks) {
await render(
<template>
- <MountWidget @widget="post-contents" @args={{self.args}} />
+ <MountWidget
+ @widget="post-contents"
+ @model={{self.post}}
+ @args={{self.args}}
+ />
</template>
);
@@ -82,7 +99,11 @@ module("Integration | Component | Widget | post", function (hooks) {
await render(
<template>
- <MountWidget @widget="post-contents" @args={{self.args}} />
+ <MountWidget
+ @widget="post-contents"
+ @model={{self.post}}
+ @args={{self.args}}
+ />
</template>
);
@@ -112,6 +133,7 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
+ @model={{self.post}}
@args={{self.args}}
@showHistory={{self.showHistory}}
/>
@@ -135,6 +157,7 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
+ @model={{self.post}}
@args={{self.args}}
@editPost={{self.editPost}}
/>
@@ -155,6 +178,7 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
+ @model={{self.post}}
@args={{self.args}}
@showRawEmail={{self.showRawEmail}}
/>
@@ -179,6 +203,7 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
+ @model={{self.post}}
@args={{self.args}}
@showRawEmail={{self.showRawEmail}}
/>
@@ -202,6 +227,7 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
+ @model={{self.post}}
@args={{self.args}}
@showHistory={{self.showHistory}}
/>
@@ -223,6 +249,7 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
+ @model={{self.post}}
@args={{self.args}}
@showHistory={{self.showHistory}}
/>
@@ -232,7 +259,7 @@ module("Integration | Component | Widget | post", function (hooks) {
await click(".post-info.edits");
assert.false(
this.historyShown,
- "clicking the pencil doesn't show the history"
+ `clicking the pencil doesn't show the history`
);
});
@@ -241,55 +268,20 @@ module("Integration | Component | Widget | post", function (hooks) {
this.set("args", { isWhisper: true });
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom(".topic-post.whisper").exists();
- assert.dom(".post-info.whisper").exists();
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("like count button", async function (assert) {
- const self = this;
-
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", { id: 123 });
- const post = store.createRecord("post", {
- id: 1,
- post_number: 1,
- topic,
- like_count: 3,
- actions_summary: [{ id: 2, count: 1, hidden: false, can_act: true }],
- });
- this.set("post", post);
- this.set("args", { likeCount: 1 });
-
await render(
<template>
<MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
</template>
);
- assert.dom("button.like-count").exists();
- assert.dom(".who-liked").doesNotExist();
-
- // toggle it on
- await click("button.like-count");
- assert.dom(".who-liked").exists();
- assert.dom(".who-liked a.trigger-user-card").exists();
-
- // toggle it off
- await click("button.like-count");
- assert.dom(".who-liked").doesNotExist();
- assert.dom(".who-liked a.trigger-user-card").doesNotExist();
+ assert.dom(".topic-post.whisper").exists();
+ assert.dom(".post-info.whisper").exists();
});
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("like count with no likes", async function (assert) {
+ test(`read indicator`, async function (assert) {
const self = this;
- this.set("args", { likeCount: 0 });
+ this.set("args", { read: true });
await render(
<template>
@@ -297,380 +289,6 @@ module("Integration | Component | Widget | post", function (hooks) {
</template>
);
- assert.dom("button.like-count").doesNotExist();
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("share button", async function (assert) {
- const self = this;
-
- this.siteSettings.post_menu += "|share";
- this.set("args", { shareUrl: "http://share-me.example.com" });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom(".actions button.share").exists("renders a share button");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("copy link button", async function (assert) {
- const self = this;
-
- this.set("args", { shareUrl: "http://share-me.example.com" });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert
- .dom(".actions button.post-action-menu__copy-link")
- .exists("renders a copy link button");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("liking", async function (assert) {
- const self = this;
-
- const args = { showLike: true, canToggleLike: true, id: 5 };
- this.set("args", args);
- this.set("toggleLike", () => {
- args.liked = !args.liked;
- args.likeCount = args.liked ? 1 : 0;
- });
-
- await render(
- <template>
- <MountWidget
- @widget="post-menu"
- @args={{self.args}}
- @toggleLike={{self.toggleLike}}
- />
- </template>
- );
-
- assert.dom(".actions button.like").exists();
- assert.dom(".actions button.like-count").doesNotExist();
-
- await click(".actions button.like");
- assert.dom(".actions button.like").doesNotExist();
- assert.dom(".actions button.has-like").exists();
- assert.dom(".actions button.like-count").exists();
-
- await click(".actions button.has-like");
- assert.dom(".actions button.like").exists();
- assert.dom(".actions button.has-like").doesNotExist();
- assert.dom(".actions button.like-count").doesNotExist();
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("anon liking", async function (assert) {
- const self = this;
-
- this.owner.unregister("service:current-user");
- const args = { showLike: true };
- this.set("args", args);
- this.set("showLogin", () => (this.loginShown = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post-menu"
- @args={{self.args}}
- @showLogin={{self.showLogin}}
- />
- </template>
- );
-
- assert.dom(".actions button.like").exists();
- assert.dom(".actions button.like-count").doesNotExist();
-
- assert
- .dom("button.like")
- .hasAttribute(
- "title",
- i18n("post.controls.like"),
- "shows the right button title for anonymous users"
- );
-
- await click(".actions button.like");
- assert.true(this.loginShown);
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("edit button", async function (assert) {
- const self = this;
-
- this.set("args", { canEdit: true });
- this.set("editPost", () => (this.editPostCalled = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @args={{self.args}}
- @editPost={{self.editPost}}
- />
- </template>
- );
-
- await click("button.edit");
- assert.true(this.editPostCalled, "triggered the edit action");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test(`edit button - can't edit`, async function (assert) {
- const self = this;
-
- this.set("args", { canEdit: false });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.edit").doesNotExist("button is not displayed");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("delete topic button", async function (assert) {
- const self = this;
-
- this.set("args", { canDeleteTopic: true });
- this.set("deletePost", () => (this.deletePostCalled = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @args={{self.args}}
- @deletePost={{self.deletePost}}
- />
- </template>
- );
-
- await click("button.delete");
- assert.true(this.deletePostCalled, "triggered the delete action");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test(`delete topic button - can't delete`, async function (assert) {
- const self = this;
-
- this.set("args", { canDeleteTopic: false });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.delete").doesNotExist("button is not displayed");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test(`delete topic button - can't delete when topic author without permission`, async function (assert) {
- const self = this;
-
- this.set("args", {
- canDeleteTopic: false,
- showFlagDelete: true,
- canFlag: true,
- });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- await click(".show-more-actions");
-
- assert.dom("button.create-flag").exists("button is displayed");
- assert.dom("button.delete").exists("button is displayed");
- assert
- .dom("button.delete")
- .hasAttribute(
- "title",
- i18n("post.controls.delete_topic_disallowed"),
- "shows the right button title for users without permissions"
- );
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("recover topic button", async function (assert) {
- const self = this;
-
- this.set("args", { canRecoverTopic: true });
- this.set("recoverPost", () => (this.recovered = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @args={{self.args}}
- @recoverPost={{self.recoverPost}}
- />
- </template>
- );
-
- await click("button.recover");
- assert.true(this.recovered);
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test(`recover topic button - can't recover`, async function (assert) {
- const self = this;
-
- this.set("args", { canRecoverTopic: false });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.recover").doesNotExist("button is not displayed");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("delete post button", async function (assert) {
- const self = this;
-
- this.set("args", { canDelete: true, canFlag: true });
- this.set("deletePost", () => (this.deletePostCalled = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @args={{self.args}}
- @deletePost={{self.deletePost}}
- />
- </template>
- );
-
- await click(".show-more-actions");
- await click("button.delete");
- assert.true(this.deletePostCalled, "triggered the delete action");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test(`delete post button - can't delete`, async function (assert) {
- const self = this;
-
- this.set("args", { canDelete: false });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.delete").doesNotExist("button is not displayed");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test(`delete post button - can't delete, can't flag`, async function (assert) {
- const self = this;
-
- this.set("args", {
- canDeleteTopic: false,
- showFlagDelete: false,
- canFlag: false,
- });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.delete").doesNotExist("delete button is not displayed");
- assert
- .dom("button.create-flag")
- .doesNotExist("flag button is not displayed");
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("recover post button", async function (assert) {
- const self = this;
-
- this.set("args", { canRecover: true });
- this.set("recoverPost", () => (this.recovered = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @args={{self.args}}
- @recoverPost={{self.recoverPost}}
- />
- </template>
- );
-
- await click("button.recover");
- assert.true(this.recovered);
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test(`recover post button - can't recover`, async function (assert) {
- const self = this;
-
- this.set("args", { canRecover: false });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.recover").doesNotExist("button is not displayed");
- });
-
- test(`flagging`, async function (assert) {
- const self = this;
-
- this.set("args", { canFlag: true });
- this.set("showFlags", () => (this.flagsShown = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @args={{self.args}}
- @showFlags={{self.showFlags}}
- />
- </template>
- );
-
- assert.dom("button.create-flag").exists();
-
- await click("button.create-flag");
- assert.true(this.flagsShown, "triggered the action");
- });
-
- test(`flagging: can't flag`, async function (assert) {
- const self = this;
-
- this.set("args", { canFlag: false });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.create-flag").doesNotExist();
- });
-
- test(`flagging: can't flag when post is hidden`, async function (assert) {
- const self = this;
-
- this.set("args", { canFlag: true, hidden: true });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.create-flag").doesNotExist();
- });
-
- test(`read indicator`, async function (assert) {
- const self = this;
-
- this.set("args", { read: true });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
assert.dom(".read-state.read").exists();
});
@@ -680,7 +298,9 @@ module("Integration | Component | Widget | post", function (hooks) {
this.set("args", { read: false });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".read-state").exists();
@@ -696,7 +316,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom("a.reply-to-tab").doesNotExist("hides the tab");
@@ -713,7 +335,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom("a.reply-to-tab").exists("shows the tab");
@@ -731,7 +355,9 @@ module("Integration | Component | Widget | post", function (hooks) {
this.siteSettings.suppress_reply_directly_above = false;
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".avoid-tab").exists("has the avoid tab class");
@@ -750,6 +376,7 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
+ @model={{self.post}}
@args={{self.args}}
@expandHidden={{self.expandHidden}}
/>
@@ -770,6 +397,7 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
+ @model={{self.post}}
@args={{self.args}}
@expandHidden={{self.expandHidden}}
/>
@@ -784,9 +412,7 @@ module("Integration | Component | Widget | post", function (hooks) {
test("expand first post", async function (assert) {
const self = this;
- const store = getOwner(this).lookup("service:store");
this.set("args", { expandablePost: true });
- this.set("post", store.createRecord("post", { id: 1234 }));
await render(
<template>
@@ -798,50 +424,15 @@ module("Integration | Component | Widget | post", function (hooks) {
assert.dom(".expand-post").doesNotExist("button is gone");
});
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("can't bookmark", async function (assert) {
- const self = this;
-
- this.set("args", { canBookmark: false });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.bookmark").doesNotExist();
- assert.dom("button.bookmarked").doesNotExist();
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("bookmark", async function (assert) {
- const self = this;
-
- const args = { canBookmark: true };
-
- this.set("args", args);
- this.set("toggleBookmark", () => (args.bookmarked = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @args={{self.args}}
- @toggleBookmark={{self.toggleBookmark}}
- />
- </template>
- );
-
- assert.dom(".post-menu-area .bookmark").exists();
- assert.dom("button.bookmarked").doesNotExist();
- });
-
test("can't show admin menu when you can't manage", async function (assert) {
const self = this;
this.set("args", { canManage: false });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".post-menu-area .show-post-admin-menu").doesNotExist();
@@ -850,11 +441,11 @@ module("Integration | Component | Widget | post", function (hooks) {
test("show admin menu", async function (assert) {
const self = this;
- this.set("args", { canManage: true });
+ this.currentUser.admin = true;
await render(
<template>
- <MountWidget @widget="post" @args={{self.args}} />
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
<DMenus />
</template>
);
@@ -862,6 +453,7 @@ module("Integration | Component | Widget | post", function (hooks) {
assert
.dom("[data-content][data-identifier='admin-post-menu']")
.doesNotExist();
+
await click(".post-menu-area .show-post-admin-menu");
assert.dom("[data-content][data-identifier='admin-post-menu']").exists();
@@ -895,8 +487,8 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
- @args={{self.args}}
@model={{self.post}}
+ @args={{self.args}}
@permanentlyDeletePost={{self.permanentlyDeletePost}}
/>
<DMenus />
@@ -937,8 +529,8 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
- @args={{self.args}}
@model={{self.post}}
+ @args={{self.args}}
@permanentlyDeletePost={{self.permanentlyDeletePost}}
/>
<DMenus />
@@ -981,8 +573,8 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
- @args={{self.args}}
@model={{self.post}}
+ @args={{self.args}}
@togglePostType={{self.togglePostType}}
/>
<DMenus />
@@ -1020,8 +612,8 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
- @args={{self.args}}
@model={{self.post}}
+ @args={{self.args}}
@rebakePost={{self.rebakePost}}
/>
<DMenus />
@@ -1042,26 +634,18 @@ module("Integration | Component | Widget | post", function (hooks) {
const self = this;
let unhidden;
- this.currentUser.admin = true;
- const store = getOwner(this).lookup("service:store");
- const topic = store.createRecord("topic", { id: 123 });
- const post = store.createRecord("post", {
- id: 1,
- post_number: 1,
- hidden: true,
- topic,
- });
+ this.currentUser.admin = true;
+ this.post.hidden = true;
this.set("args", { canManage: true });
- this.set("post", post);
this.set("unhidePost", () => (unhidden = true));
await render(
<template>
<MountWidget
@widget="post"
- @args={{self.args}}
@model={{self.post}}
+ @args={{self.args}}
@unhidePost={{self.unhidePost}}
/>
<DMenus />
@@ -1102,8 +686,8 @@ module("Integration | Component | Widget | post", function (hooks) {
<template>
<MountWidget
@widget="post"
- @args={{self.args}}
@model={{self.post}}
+ @args={{self.args}}
@changePostOwner={{self.changePostOwner}}
/>
<DMenus />
@@ -1120,97 +704,6 @@ module("Integration | Component | Widget | post", function (hooks) {
.doesNotExist("also hides the menu");
});
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("reply", async function (assert) {
- const self = this;
-
- this.set("args", { canCreatePost: true });
- this.set("replyToPost", () => (this.replied = true));
-
- await render(
- <template>
- <MountWidget
- @widget="post"
- @args={{self.args}}
- @replyToPost={{self.replyToPost}}
- />
- </template>
- );
-
- await click(".post-controls .create");
- assert.true(this.replied);
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("reply - without permissions", async function (assert) {
- const self = this;
-
- this.set("args", { canCreatePost: false });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom(".post-controls .create").doesNotExist();
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("replies - no replies", async function (assert) {
- const self = this;
-
- this.set("args", { replyCount: 0 });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.show-replies").doesNotExist();
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("replies - multiple replies", async function (assert) {
- const self = this;
-
- this.siteSettings.suppress_reply_directly_below = true;
- this.set("args", { replyCount: 2, replyDirectlyBelow: true });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.show-replies").exists();
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("replies - one below, suppressed", async function (assert) {
- const self = this;
-
- this.siteSettings.suppress_reply_directly_below = true;
- this.set("args", { replyCount: 1, replyDirectlyBelow: true });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- assert.dom("button.show-replies").doesNotExist();
- });
-
- // glimmer-post-menu: deprecated in favor of spec/system/post_menu_spec.rb
- test("replies - one below, not suppressed", async function (assert) {
- const self = this;
-
- this.siteSettings.suppress_reply_directly_below = false;
- this.set("args", { id: 6654, replyCount: 1, replyDirectlyBelow: true });
-
- await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
- );
-
- await click("button.show-replies");
- assert.dom("section.embedded-posts.bottom .cooked").exists();
- assert.dom("section.embedded-posts .d-icon-arrow-down").exists();
- });
-
test("shows the topic map when setting the 'topicMap' attribute", async function (assert) {
const self = this;
@@ -1219,7 +712,9 @@ module("Integration | Component | Widget | post", function (hooks) {
this.set("args", { topic, post_number: 1, topicMap: true });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".topic-map").exists();
@@ -1238,7 +733,9 @@ module("Integration | Component | Widget | post", function (hooks) {
this.set("args", { topic, post_number: 1 });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".topic-map").exists();
@@ -1264,7 +761,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".topic-map__users-trigger").doesNotExist();
assert.dom(".topic-map__users-list a.poster").exists({ count: 2 });
@@ -1296,7 +795,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".topic-map__users-list a.poster").exists({ count: 5 });
@@ -1326,7 +827,9 @@ module("Integration | Component | Widget | post", function (hooks) {
this.set("args", { topic, post_number: 1 });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".topic-map").exists({ count: 1 });
@@ -1338,7 +841,7 @@ module("Integration | Component | Widget | post", function (hooks) {
assert.dom(".topic-map__links-content .topic-link").exists({ count: 6 });
});
- test("topic map - no top reply summary", async function (assert) {
+ test("topic map - has top replies summary", async function (assert) {
const self = this;
const store = getOwner(this).lookup("service:store");
@@ -1346,18 +849,20 @@ module("Integration | Component | Widget | post", function (hooks) {
id: 123,
archetype: "regular",
posts_count: 2,
+ has_summary: true,
});
this.set("args", { topic, post_number: 1 });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
- assert.dom(".topic-map").exists();
- assert.dom(".summarization-button .top-replies").doesNotExist();
+ assert.dom(".summarization-button .top-replies").exists({ count: 1 });
});
- test("topic map - has top replies summary", async function (assert) {
+ test("topic map - no top reply summary", async function (assert) {
const self = this;
const store = getOwner(this).lookup("service:store");
@@ -1365,15 +870,17 @@ module("Integration | Component | Widget | post", function (hooks) {
id: 123,
archetype: "regular",
posts_count: 2,
- has_summary: true,
});
this.set("args", { topic, post_number: 1 });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
- assert.dom(".summarization-button .top-replies").exists({ count: 1 });
+ assert.dom(".topic-map").exists();
+ assert.dom(".summarization-button .top-replies").doesNotExist();
});
test("pm map", async function (assert) {
@@ -1393,7 +900,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".topic-map__private-message-map").exists({ count: 1 });
@@ -1419,7 +928,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".post-notice.returning-user:not(.old)").hasText(
@@ -1448,7 +959,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".post-notice.custom").hasText(
@@ -1479,7 +992,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert
@@ -1496,7 +1011,9 @@ module("Integration | Component | Widget | post", function (hooks) {
});
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".group-request a").hasText(i18n("groups.requests.handle"));
@@ -1518,7 +1035,9 @@ module("Integration | Component | Widget | post", function (hooks) {
this.set("args", { user });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".user-status-message").exists();
@@ -1537,9 +1056,37 @@ module("Integration | Component | Widget | post", function (hooks) {
this.set("args", { user });
await render(
- <template><MountWidget @widget="post" @args={{self.args}} /></template>
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
);
assert.dom(".user-status-message").doesNotExist();
});
+
+ test("more actions button is displayed when multiple hidden items are configured", async function (assert) {
+ const self = this;
+
+ this.siteSettings.post_menu_hidden_items = "bookmark|edit|copyLink";
+
+ await render(
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
+ );
+ assert.dom(".show-more-actions").exists();
+ });
+
+ test("hidden menu expands automatically when only one hidden item is configured", async function (assert) {
+ const self = this;
+
+ this.siteSettings.post_menu_hidden_items = "bookmark|edit";
+
+ await render(
+ <template>
+ <MountWidget @widget="post" @model={{self.post}} @args={{self.args}} />
+ </template>
+ );
+ assert.dom(".show-more-actions").doesNotExist();
+ });
});
diff --git a/app/assets/javascripts/discourse/tests/unit/components/post-menu-test.gjs b/app/assets/javascripts/discourse/tests/unit/components/post-menu-test.gjs
index 6c9b4fe7e5d..6afa304b1cd 100644
--- a/app/assets/javascripts/discourse/tests/unit/components/post-menu-test.gjs
+++ b/app/assets/javascripts/discourse/tests/unit/components/post-menu-test.gjs
@@ -9,7 +9,6 @@ module("Unit | Component | post-menu", function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
- this.siteSettings.glimmer_post_menu_mode = "enabled";
this.siteSettings.post_menu =
"read|like|copyLink|share|flag|edit|bookmark|delete|admin|reply";
this.siteSettings.post_menu_hidden_items = "";
diff --git a/app/assets/stylesheets/common/base/topic-post.scss b/app/assets/stylesheets/common/base/topic-post.scss
index 05a3c9aaf36..29761e9d598 100644
--- a/app/assets/stylesheets/common/base/topic-post.scss
+++ b/app/assets/stylesheets/common/base/topic-post.scss
@@ -370,7 +370,6 @@ nav.post-controls {
&.like {
// Like button with 0 likes
- &.d-hover,
&:hover {
background: var(--love-low);
@@ -387,7 +386,6 @@ nav.post-controls {
}
.discourse-no-touch & {
- &.d-hover,
&:hover {
background: var(--primary-low);
@@ -410,7 +408,6 @@ nav.post-controls {
// Like button when like count is present
.discourse-no-touch & {
- &.d-hover,
&:hover {
background: var(--primary-low);
}
@@ -419,7 +416,6 @@ nav.post-controls {
// Like count button
.discourse-no-touch & {
- &.d-hover,
&:hover {
color: var(--primary);
}
@@ -459,14 +455,7 @@ nav.post-controls {
border: none;
border-radius: var(--d-post-control-border-radius);
- .d-icon {
- // this avoids an issue where hovering off the icon
- // removes the .d-hover class from the button prematurely
- pointer-events: none;
- }
-
.discourse-no-touch & {
- &.d-hover,
&:hover,
&:focus-visible,
&:active {
@@ -475,8 +464,6 @@ nav.post-controls {
color: var(--d-post-control-text-color--hover);
}
- // TODO (glimmer-post-menu): Go over the the d-hover style and remove the unnecessary ones when glimmer-post-menu replaces the widget version
- &.delete.d-hover,
&.delete:hover,
&.delete:active,
&.delete:focus {
@@ -612,8 +599,6 @@ nav.post-controls {
}
}
-// .d-icon.heart-animation is the widget animation while .toggle-like.heart-animation is the glimmer-post-menu's
-.has-like .d-icon.heart-animation,
.toggle-like.heart-animation .d-icon {
@media (prefers-reduced-motion: no-preference) {
animation: heartBump 0.4s;
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 01ab6f9eda2..37f60f4f4f7 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2758,8 +2758,6 @@ en:
default_navigation_menu_tags: "Selected tags will be displayed under Navigation Menu's Tags section by default."
experimental_new_new_view_groups: 'Enable a new topics list that combines unread and new topics and make the "Everything" link in the sidebar link to it.'
glimmer_topic_list_mode: "Control whether the new 'glimmer' topic-list implementation is used. 'auto' will enable automatically once all your themes and plugins are ready. See <a href='https://meta.discourse.org/t/343404'>the Meta topic</a> for more information."
- glimmer_post_menu_mode: "Control whether the new 'glimmer' post menu implementation is used. 'auto' will enable automatically once all your themes and plugins are ready. This implementation is under active development, and is not intended for production use. Do not develop themes/plugins against it until the implementation is finalized and announced."
- glimmer_post_menu_groups: "Enable the new 'glimmer' post menu implementation in 'auto' mode for the specified user groups. This implementation is under active development, and is not intended for production use. Do not develop themes/plugins against it until the implementation is finalized and announced."
glimmer_post_stream_mode: "Control whether the new 'glimmer' post stream implementation is used. 'auto' will enable automatically once all your themes and plugins are ready. This implementation is under active development, and is not intended for production use. Do not develop themes/plugins against it until the implementation is finalized and announced."
glimmer_post_stream_mode_auto_groups: "Enable the new 'glimmer' post menu implementation in 'auto' mode for the specified user groups. This implementation is under active development, and is not intended for production use. Do not develop themes/plugins against it until the implementation is finalized and announced."
experimental_form_templates: "Enable the form templates feature. Manage the templates at <a href='%{base_path}/admin/customize/form-templates'>Customize / Templates</a>."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 4660362a145..2e2ae67bece 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -3552,14 +3552,6 @@ experimental:
- auto
- enabled
default: enabled
- glimmer_post_menu_mode:
- client: true
- type: enum
- choices:
- - disabled
- - auto
- - enabled
- default: enabled
glimmer_post_stream_mode_auto_groups:
client: true
type: group_list
diff --git a/db/migrate/20250206010037_remove_glimmer_post_menu_mode_setting.rb b/db/migrate/20250206010037_remove_glimmer_post_menu_mode_setting.rb
new file mode 100644
index 00000000000..8e3afd98ea1
--- /dev/null
+++ b/db/migrate/20250206010037_remove_glimmer_post_menu_mode_setting.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+class RemoveGlimmerPostMenuModeSetting < ActiveRecord::Migration[7.2]
+ def up
+ execute <<~SQL
+ DELETE FROM site_settings
+ WHERE name = 'glimmer_post_menu_mode'
+ SQL
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rb
index d11576c3836..8ad3d415c71 100644
--- a/spec/system/page_objects/pages/topic.rb
+++ b/spec/system/page_objects/pages/topic.rb
@@ -330,36 +330,35 @@ module PageObjects
end
def selector_for_post_action_button(button)
- # TODO (glimmer-post-menu): Replace the selector with the BEM format ones once the glimmer-post-menu replaces the widget post menu
case button
when :admin
- ".post-controls .show-post-admin-menu"
+ ".post-controls .post-action-menu__admin"
when :bookmark
- ".post-controls .bookmark"
+ ".post-controls .post-action-menu__bookmark"
when :copy_link, :copyLink
".post-controls .post-action-menu__copy-link"
when :delete
- ".post-controls .delete"
+ ".post-controls .post-action-menu__delete"
when :edit
- ".post-controls .edit"
+ ".post-controls .post-action-menu__edit"
when :flag
- ".post-controls .create-flag"
+ ".post-controls .post-action-menu__flag"
when :like
- ".post-controls .toggle-like"
+ ".post-controls .post-action-menu__like"
when :like_count
- ".post-controls .like-count"
+ ".post-controls .post-action-menu__like-count"
when :read
- ".post-controls .read-indicator"
+ ".post-controls .post-action-menu__read"
when :recover
- ".post-controls .recover"
+ ".post-controls .post-action-menu__recover"
when :replies
- ".post-controls .show-replies"
+ ".post-controls .post-action-menu__show-replies"
when :reply
- ".post-controls .reply"
+ ".post-controls .post-action-menu__reply"
when :share
- ".post-controls .share"
+ ".post-controls .post-action-menu__share"
when :show_more
- ".post-controls .show-more-actions"
+ ".post-controls .post-action-menu__show-more"
else
raise "Unknown post menu button type: #{button}"
end
diff --git a/spec/system/post_menu_spec.rb b/spec/system/post_menu_spec.rb
index 4036490dcdf..836a0ec4f07 100644
--- a/spec/system/post_menu_spec.rb
+++ b/spec/system/post_menu_spec.rb
@@ -13,730 +13,725 @@ describe "Post menu", type: :system do
let(:login_page) { PageObjects::Pages::Login.new }
let(:modal) { PageObjects::Modals::Base.new }
- %w[enabled disabled].each do |value|
- before do
- SiteSetting.glimmer_post_menu_mode = value
- SiteSetting.post_menu = "like|copyLink|share|flag|edit|bookmark|delete|admin|reply"
- SiteSetting.post_menu_hidden_items = "flag|bookmark|edit|delete|admin"
- end
+ before do
+ SiteSetting.post_menu = "like|copyLink|share|flag|edit|bookmark|delete|admin|reply"
+ SiteSetting.post_menu_hidden_items = "flag|bookmark|edit|delete|admin"
+ end
+
+ describe "general rendering" do
+ before { sign_in(admin) }
+
+ it "renders the expected buttons according to what is specified in the `post_menu`/`post_menu_hidden_items` settings" do
+ [
+ {
+ # skip the read button because we're not viewing a PM
+ post_menu: "like|copyLink|share|flag|edit|bookmark|delete|admin|reply",
+ post_menu_hidden_items: "flag|bookmark|edit|delete|admin",
+ },
+ {
+ post_menu: "like|copyLink|edit|bookmark|delete|admin|reply",
+ post_menu_hidden_items: "flag|admin|edit",
+ },
+ ].each do |scenario|
+ scenario => { post_menu:, post_menu_hidden_items: }
+
+ SiteSetting.post_menu = post_menu
+ SiteSetting.post_menu_hidden_items = post_menu_hidden_items
+
+ topic_page.visit_topic(post.topic)
- context "when the Glimmer post menu is #{value}" do
- describe "general rendering" do
- before { sign_in(admin) }
-
- it "renders the expected buttons according to what is specified in the `post_menu`/`post_menu_hidden_items` settings" do
- [
- {
- # skip the read button because we're not viewing a PM
- post_menu: "like|copyLink|share|flag|edit|bookmark|delete|admin|reply",
- post_menu_hidden_items: "flag|bookmark|edit|delete|admin",
- },
- {
- post_menu: "like|copyLink|edit|bookmark|delete|admin|reply",
- post_menu_hidden_items: "flag|admin|edit",
- },
- ].each do |scenario|
- scenario => { post_menu:, post_menu_hidden_items: }
-
- SiteSetting.post_menu = post_menu
- SiteSetting.post_menu_hidden_items = post_menu_hidden_items
-
- topic_page.visit_topic(post.topic)
-
- available_buttons = %w[admin bookmark copyLink delete edit flag like read reply share]
- expected_buttons = SiteSetting.post_menu.split("|")
- hidden_buttons = SiteSetting.post_menu_hidden_items.split("|")
- visible_buttons = expected_buttons - hidden_buttons
-
- visible_buttons.each do |button|
- expect(topic_page).to have_post_action_button(post, button.to_sym)
- end
- hidden_buttons.each do |button|
- expect(topic_page).to have_no_post_action_button(post, button.to_sym)
- end
-
- # expand the items and check again if all expected buttons are visible now
- topic_page.expand_post_actions(post)
- expected_buttons.each do |button|
- expect(topic_page).to have_post_action_button(post, button.to_sym)
- end
-
- # check if the buttons are in the correct order
- node_elements = topic_page.find_post_action_buttons(post).all("*")
- button_node_positions =
- expected_buttons.map do |button|
- node_elements.find_index(topic_page.find_post_action_button(post, button.to_sym))
- end
-
- expect(button_node_positions).to eq(button_node_positions.compact.sort)
-
- # verify that buttons that weren't specified int the post_menu setting weren't rendered
- (available_buttons - expected_buttons).each do |button|
- expect(topic_page).to have_no_post_action_button(post, button.to_sym)
- end
+ available_buttons = %w[admin bookmark copyLink delete edit flag like read reply share]
+ expected_buttons = SiteSetting.post_menu.split("|")
+ hidden_buttons = SiteSetting.post_menu_hidden_items.split("|")
+ visible_buttons = expected_buttons - hidden_buttons
+
+ visible_buttons.each do |button|
+ expect(topic_page).to have_post_action_button(post, button.to_sym)
+ end
+ hidden_buttons.each do |button|
+ expect(topic_page).to have_no_post_action_button(post, button.to_sym)
+ end
+
+ # expand the items and check again if all expected buttons are visible now
+ topic_page.expand_post_actions(post)
+ expected_buttons.each do |button|
+ expect(topic_page).to have_post_action_button(post, button.to_sym)
+ end
+
+ # check if the buttons are in the correct order
+ node_elements = topic_page.find_post_action_buttons(post).all("*")
+ button_node_positions =
+ expected_buttons.map do |button|
+ node_elements.find_index(topic_page.find_post_action_button(post, button.to_sym))
end
+
+ expect(button_node_positions).to eq(button_node_positions.compact.sort)
+
+ # verify that buttons that weren't specified int the post_menu setting weren't rendered
+ (available_buttons - expected_buttons).each do |button|
+ expect(topic_page).to have_no_post_action_button(post, button.to_sym)
end
end
+ end
+ end
- describe "admin" do
- before do
- SiteSetting.edit_wiki_post_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
- SiteSetting.post_menu_hidden_items = ""
- end
+ describe "admin" do
+ before do
+ SiteSetting.edit_wiki_post_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
+ SiteSetting.post_menu_hidden_items = ""
+ end
- it "displays the admin button when the user can manage the post" do
- # do not display the edit button when unlogged
- topic_page.visit_topic(post.topic)
+ it "displays the admin button when the user can manage the post" do
+ # do not display the edit button when unlogged
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :admin)
- expect(topic_page).to have_no_post_action_button(post2, :admin)
+ expect(topic_page).to have_no_post_action_button(post, :admin)
+ expect(topic_page).to have_no_post_action_button(post2, :admin)
- # display the admin button for all the posts when a moderator is logged
- sign_in(Fabricate(:moderator))
+ # display the admin button for all the posts when a moderator is logged
+ sign_in(Fabricate(:moderator))
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :admin)
- expect(topic_page).to have_post_action_button(post2, :admin)
+ expect(topic_page).to have_post_action_button(post, :admin)
+ expect(topic_page).to have_post_action_button(post2, :admin)
- # display the admin button for the all the posts when an admin is logged
- sign_in(admin)
+ # display the admin button for the all the posts when an admin is logged
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :admin)
- expect(topic_page).to have_post_action_button(post2, :admin)
- end
+ expect(topic_page).to have_post_action_button(post, :admin)
+ expect(topic_page).to have_post_action_button(post2, :admin)
+ end
- it "displays the admin button when the user can wiki the post / edit official notices" do
- # display the admin button when the user can wiki
- sign_in(Fabricate(:trust_level_4))
+ it "displays the admin button when the user can wiki the post / edit official notices" do
+ # display the admin button when the user can wiki
+ sign_in(Fabricate(:trust_level_4))
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :admin)
- expect(topic_page).to have_post_action_button(post2, :admin)
+ expect(topic_page).to have_post_action_button(post, :admin)
+ expect(topic_page).to have_post_action_button(post2, :admin)
- # display the admin button when the user can wiki
- SiteSetting.self_wiki_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
+ # display the admin button when the user can wiki
+ SiteSetting.self_wiki_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
- sign_in(user)
+ sign_in(user)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :admin)
- expect(topic_page).to have_post_action_button(post2, :admin)
- end
+ expect(topic_page).to have_no_post_action_button(post, :admin)
+ expect(topic_page).to have_post_action_button(post2, :admin)
+ end
- it "works as expected" do
- sign_in(admin)
+ it "works as expected" do
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_admin_menu
- topic_page.click_post_action_button(post, :admin)
- expect(topic_page).to have_post_admin_menu
- end
- end
+ expect(topic_page).to have_no_post_admin_menu
+ topic_page.click_post_action_button(post, :admin)
+ expect(topic_page).to have_post_admin_menu
+ end
+ end
- describe "bookmark" do
- before { SiteSetting.post_menu_hidden_items = "" }
+ describe "bookmark" do
+ before { SiteSetting.post_menu_hidden_items = "" }
- it "does not display the bookmark button when the user is anonymous" do
- topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :bookmark)
- end
+ it "does not display the bookmark button when the user is anonymous" do
+ topic_page.visit_topic(post.topic)
+ expect(topic_page).to have_no_post_action_button(post, :bookmark)
+ end
- it "works as expected" do
- sign_in(user)
+ it "works as expected" do
+ sign_in(user)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :bookmark)
+ expect(topic_page).to have_post_action_button(post, :bookmark)
- bookmark_button = topic_page.find_post_action_button(post, :bookmark)
- expect(bookmark_button[:class].split("\s")).not_to include("bookmarked")
+ bookmark_button = topic_page.find_post_action_button(post, :bookmark)
+ expect(bookmark_button[:class].split("\s")).not_to include("bookmarked")
- topic_page.click_post_action_button(post, :bookmark)
- expect(topic_page).to have_post_bookmarked(post)
- end
- end
+ topic_page.click_post_action_button(post, :bookmark)
+ expect(topic_page).to have_post_bookmarked(post)
+ end
+ end
- describe "copy link" do
- let(:cdp) { PageObjects::CDP.new }
+ describe "copy link" do
+ let(:cdp) { PageObjects::CDP.new }
- before do
- sign_in(user)
- cdp.allow_clipboard
- end
+ before do
+ sign_in(user)
+ cdp.allow_clipboard
+ end
- it "copies the absolute link to the post when clicked" do
- topic_page.visit_topic(post.topic)
- topic_page.click_post_action_button(post, :copy_link)
- cdp.clipboard_has_text?(post.full_url(share_url: true) + "?u=#{user.username}")
- end
- end
+ it "copies the absolute link to the post when clicked" do
+ topic_page.visit_topic(post.topic)
+ topic_page.click_post_action_button(post, :copy_link)
+ cdp.clipboard_has_text?(post.full_url(share_url: true) + "?u=#{user.username}")
+ end
+ end
- describe "delete / recover" do
- before { SiteSetting.post_menu_hidden_items = "" }
+ describe "delete / recover" do
+ before { SiteSetting.post_menu_hidden_items = "" }
- it "displays the delete button only when the user can delete the post" do
- # do not display the edit button when unlogged
- topic_page.visit_topic(post.topic)
+ it "displays the delete button only when the user can delete the post" do
+ # do not display the edit button when unlogged
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :delete)
- expect(topic_page).to have_no_post_action_button(post2, :delete)
+ expect(topic_page).to have_no_post_action_button(post, :delete)
+ expect(topic_page).to have_no_post_action_button(post2, :delete)
- # display the delete button only for the post that `user` can delete
- sign_in(user)
+ # display the delete button only for the post that `user` can delete
+ sign_in(user)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :delete)
- expect(topic_page).to have_post_action_button(post2, :delete)
+ expect(topic_page).to have_no_post_action_button(post, :delete)
+ expect(topic_page).to have_post_action_button(post2, :delete)
- # display the delete button for the all the posts because an admin is logged
- sign_in(admin)
+ # display the delete button for the all the posts because an admin is logged
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :delete)
- expect(topic_page).to have_post_action_button(post2, :delete)
- end
+ expect(topic_page).to have_post_action_button(post, :delete)
+ expect(topic_page).to have_post_action_button(post2, :delete)
+ end
- it "displays the recover button only when the user can recover the post" do
- PostDestroyer.new(user, post2).destroy
+ it "displays the recover button only when the user can recover the post" do
+ PostDestroyer.new(user, post2).destroy
- # do not display the edit button when unlogged
- topic_page.visit_topic(post.topic)
+ # do not display the edit button when unlogged
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :recover)
- expect(topic_page).to have_no_post_action_button(post2, :recover)
+ expect(topic_page).to have_no_post_action_button(post, :recover)
+ expect(topic_page).to have_no_post_action_button(post2, :recover)
- # display the recover button when the POST was user deleted
- # `post2` is marked for deletion and displays text (post deleted by author) but `user` as the author can
- # recover it.
- sign_in(user)
+ # display the recover button when the POST was user deleted
+ # `post2` is marked for deletion and displays text (post deleted by author) but `user` as the author can
+ # recover it.
+ sign_in(user)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :recover)
- expect(topic_page).to have_post_action_button(post2, :recover)
+ expect(topic_page).to have_no_post_action_button(post, :recover)
+ expect(topic_page).to have_post_action_button(post2, :recover)
- # do not display the recover button for other users when the post was USER deleted
- sign_in(Fabricate(:user))
- topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :recover)
- expect(topic_page).to have_no_post_action_button(post2, :recover)
+ # do not display the recover button for other users when the post was USER deleted
+ sign_in(Fabricate(:user))
+ topic_page.visit_topic(post.topic)
+ expect(topic_page).to have_no_post_action_button(post, :recover)
+ expect(topic_page).to have_no_post_action_button(post2, :recover)
- # do not display the recover button even for admins when the post was USER deleted, because the action
- # displayed for the admin is deleting the post to remove it from the post stream
- sign_in(admin)
- topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :recover)
- expect(topic_page).to have_no_post_action_button(post2, :recover)
+ # do not display the recover button even for admins when the post was USER deleted, because the action
+ # displayed for the admin is deleting the post to remove it from the post stream
+ sign_in(admin)
+ topic_page.visit_topic(post.topic)
+ expect(topic_page).to have_no_post_action_button(post, :recover)
+ expect(topic_page).to have_no_post_action_button(post2, :recover)
- # display the recover button for an admin when the post was deleted
- PostDestroyer.new(admin, post).destroy
+ # display the recover button for an admin when the post was deleted
+ PostDestroyer.new(admin, post).destroy
- sign_in(admin)
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :recover)
- end
+ expect(topic_page).to have_post_action_button(post, :recover)
+ end
- it "deletes a topic" do
- sign_in(admin)
+ it "deletes a topic" do
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_deleted_post(post)
- topic_page.click_post_action_button(post, :delete)
- expect(topic_page).to have_deleted_post(post)
- end
+ expect(topic_page).to have_no_deleted_post(post)
+ topic_page.click_post_action_button(post, :delete)
+ expect(topic_page).to have_deleted_post(post)
+ end
- it "deletes a post" do
- sign_in(admin)
+ it "deletes a post" do
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_deleted_post(post2)
- topic_page.click_post_action_button(post2, :delete)
- expect(topic_page).to have_deleted_post(post2)
- end
+ expect(topic_page).to have_no_deleted_post(post2)
+ topic_page.click_post_action_button(post2, :delete)
+ expect(topic_page).to have_deleted_post(post2)
+ end
- it "shows a flag to delete message when the user is the author but can't delete it without permission" do
- other_topic = Fabricate(:topic)
- other_p1 = Fabricate(:post, topic: other_topic, user: user)
- other_p2 = Fabricate(:post, topic: other_topic, user: Fabricate(:user))
+ it "shows a flag to delete message when the user is the author but can't delete it without permission" do
+ other_topic = Fabricate(:topic)
+ other_p1 = Fabricate(:post, topic: other_topic, user: user)
+ other_p2 = Fabricate(:post, topic: other_topic, user: Fabricate(:user))
- sign_in(user)
+ sign_in(user)
- topic_page.visit_topic(other_topic)
+ topic_page.visit_topic(other_topic)
- expect(topic_page).to have_post_action_button(other_p1, :delete)
- expect(topic_page).to have_post_action_button(other_p1, :flag)
- topic_page.click_post_action_button(other_p1, :delete)
+ expect(topic_page).to have_post_action_button(other_p1, :delete)
+ expect(topic_page).to have_post_action_button(other_p1, :flag)
+ topic_page.click_post_action_button(other_p1, :delete)
- expect(topic_page).to have_no_deleted_post(other_p1)
- expect(modal).to be_open
- expect(modal).to have_content(I18n.t("js.post.controls.delete_topic_disallowed_modal"))
- end
+ expect(topic_page).to have_no_deleted_post(other_p1)
+ expect(modal).to be_open
+ expect(modal).to have_content(I18n.t("js.post.controls.delete_topic_disallowed_modal"))
+ end
- it "recovers a topic" do
- PostDestroyer.new(admin, post).destroy
+ it "recovers a topic" do
+ PostDestroyer.new(admin, post).destroy
- sign_in(admin)
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_deleted_post(post)
- topic_page.click_post_action_button(post, :recover)
- expect(topic_page).to have_no_deleted_post(post)
- end
+ expect(topic_page).to have_deleted_post(post)
+ topic_page.click_post_action_button(post, :recover)
+ expect(topic_page).to have_no_deleted_post(post)
+ end
- it "recovers a post" do
- sign_in(admin)
+ it "recovers a post" do
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_deleted_post(post2)
- topic_page.click_post_action_button(post2, :delete)
- expect(topic_page).to have_deleted_post(post2)
+ expect(topic_page).to have_no_deleted_post(post2)
+ topic_page.click_post_action_button(post2, :delete)
+ expect(topic_page).to have_deleted_post(post2)
- topic_page.click_post_action_button(post2, :recover)
- expect(topic_page).to have_no_deleted_post(post2)
- end
- end
+ topic_page.click_post_action_button(post2, :recover)
+ expect(topic_page).to have_no_deleted_post(post2)
+ end
+ end
- describe "edit" do
- before do
- SiteSetting.edit_post_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
- SiteSetting.edit_wiki_post_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
- SiteSetting.post_menu_hidden_items = ""
- end
+ describe "edit" do
+ before do
+ SiteSetting.edit_post_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
+ SiteSetting.edit_wiki_post_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
+ SiteSetting.post_menu_hidden_items = ""
+ end
- it "displays the edit button only when the user can edit the post" do
- # do not display the edit button when unlogged
- topic_page.visit_topic(post.topic)
+ it "displays the edit button only when the user can edit the post" do
+ # do not display the edit button when unlogged
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :edit)
- expect(topic_page).to have_no_post_action_button(post2, :edit)
+ expect(topic_page).to have_no_post_action_button(post, :edit)
+ expect(topic_page).to have_no_post_action_button(post2, :edit)
- # display the edit button only for the post that `user` can edit
- sign_in(user)
+ # display the edit button only for the post that `user` can edit
+ sign_in(user)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :edit)
- expect(topic_page).to have_post_action_button(post2, :edit)
+ expect(topic_page).to have_no_post_action_button(post, :edit)
+ expect(topic_page).to have_post_action_button(post2, :edit)
- # display the edit button for the all the posts because an admin is logged
- sign_in(admin)
+ # display the edit button for the all the posts because an admin is logged
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :edit)
- expect(topic_page).to have_post_action_button(post2, :edit)
- end
+ expect(topic_page).to have_post_action_button(post, :edit)
+ expect(topic_page).to have_post_action_button(post2, :edit)
+ end
- it "displays the edit button properly when the topic is a wiki" do
- wiki_topic = Fabricate(:topic)
- wiki_post = Fabricate(:post, topic: wiki_topic, user: Fabricate(:user), wiki: true)
- non_wiki_post = Fabricate(:post, topic: wiki_topic, user: Fabricate(:user), wiki: false)
+ it "displays the edit button properly when the topic is a wiki" do
+ wiki_topic = Fabricate(:topic)
+ wiki_post = Fabricate(:post, topic: wiki_topic, user: Fabricate(:user), wiki: true)
+ non_wiki_post = Fabricate(:post, topic: wiki_topic, user: Fabricate(:user), wiki: false)
- # do not display the edit button when unlogged
- topic_page.visit_topic(wiki_post.topic)
+ # do not display the edit button when unlogged
+ topic_page.visit_topic(wiki_post.topic)
- expect(topic_page).to have_no_post_action_button(wiki_post, :edit)
- expect(topic_page).to have_no_post_action_button(non_wiki_post, :edit)
+ expect(topic_page).to have_no_post_action_button(wiki_post, :edit)
+ expect(topic_page).to have_no_post_action_button(non_wiki_post, :edit)
- # display the edit button only for the post that `user` can edit
- sign_in(user)
+ # display the edit button only for the post that `user` can edit
+ sign_in(user)
- topic_page.visit_topic(wiki_post.topic)
+ topic_page.visit_topic(wiki_post.topic)
- expect(topic_page).to have_post_action_button(wiki_post, :edit)
- expect(topic_page).to have_no_post_action_button(non_wiki_post, :edit)
- end
+ expect(topic_page).to have_post_action_button(wiki_post, :edit)
+ expect(topic_page).to have_no_post_action_button(non_wiki_post, :edit)
+ end
- it "works as expected" do
- sign_in(user)
+ it "works as expected" do
+ sign_in(user)
- topic_page.visit_topic(post2.topic)
+ topic_page.visit_topic(post2.topic)
- expect(composer).to be_closed
- topic_page.click_post_action_button(post2, :edit)
+ expect(composer).to be_closed
+ topic_page.click_post_action_button(post2, :edit)
- expect(composer).to be_opened
- expect(composer).to have_content(post2.raw)
- end
- end
+ expect(composer).to be_opened
+ expect(composer).to have_content(post2.raw)
+ end
+ end
- describe "flag" do
- before { SiteSetting.post_menu_hidden_items = "" }
+ describe "flag" do
+ before { SiteSetting.post_menu_hidden_items = "" }
- it "displays the flag button only when the user can flag the post" do
- # do not display the edit button when unlogged
- topic_page.visit_topic(post.topic)
+ it "displays the flag button only when the user can flag the post" do
+ # do not display the edit button when unlogged
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :flag)
- expect(topic_page).to have_no_post_action_button(post2, :flag)
+ expect(topic_page).to have_no_post_action_button(post, :flag)
+ expect(topic_page).to have_no_post_action_button(post2, :flag)
- # display the flag button only for the post that `user` can flag
- sign_in(user)
+ # display the flag button only for the post that `user` can flag
+ sign_in(user)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :flag)
- expect(topic_page).to have_post_action_button(post2, :flag)
+ expect(topic_page).to have_post_action_button(post, :flag)
+ expect(topic_page).to have_post_action_button(post2, :flag)
- # display the flag button for the all the posts because an admin is logged
- sign_in(admin)
+ # display the flag button for the all the posts because an admin is logged
+ sign_in(admin)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :flag)
- expect(topic_page).to have_post_action_button(post2, :flag)
- end
+ expect(topic_page).to have_post_action_button(post, :flag)
+ expect(topic_page).to have_post_action_button(post2, :flag)
+ end
- it "works as expected" do
- sign_in(user)
+ it "works as expected" do
+ sign_in(user)
- topic_page.visit_topic(post2.topic)
+ topic_page.visit_topic(post2.topic)
- expect(flag_modal).to be_closed
- topic_page.click_post_action_button(post2, :flag)
- expect(flag_modal).to be_open
- end
- end
+ expect(flag_modal).to be_closed
+ topic_page.click_post_action_button(post2, :flag)
+ expect(flag_modal).to be_open
+ end
+ end
- describe "like" do
- it "toggles liking a post" do
- unliked_post = Fabricate(:post, topic: topic, like_count: 0)
+ describe "like" do
+ it "toggles liking a post" do
+ unliked_post = Fabricate(:post, topic: topic, like_count: 0)
- sign_in(user)
+ sign_in(user)
- topic_page.visit_topic(unliked_post.topic)
+ topic_page.visit_topic(unliked_post.topic)
- expect(topic_page).to have_post_action_button(unliked_post, :like)
- like_button = topic_page.find_post_action_button(unliked_post, :like)
- expect(like_button[:class].split("\s")).to include("like")
+ expect(topic_page).to have_post_action_button(unliked_post, :like)
+ like_button = topic_page.find_post_action_button(unliked_post, :like)
+ expect(like_button[:class].split("\s")).to include("like")
- expect(topic_page).to have_no_post_action_button(unliked_post, :like_count)
+ expect(topic_page).to have_no_post_action_button(unliked_post, :like_count)
- # toggle the like on
- topic_page.click_post_action_button(unliked_post, :like)
+ # toggle the like on
+ topic_page.click_post_action_button(unliked_post, :like)
- # we need this because the find_post_action_button will target the like button on or off
- try_until_success do
- like_button = topic_page.find_post_action_button(unliked_post, :like)
- expect(like_button[:class].split("\s")).to include("has-like")
- end
+ # we need this because the find_post_action_button will target the like button on or off
+ try_until_success do
+ like_button = topic_page.find_post_action_button(unliked_post, :like)
+ expect(like_button[:class].split("\s")).to include("has-like")
+ end
- like_count_button = topic_page.find_post_action_button(unliked_post, :like_count)
- expect(like_count_button).to have_content(1)
+ like_count_button = topic_page.find_post_action_button(unliked_post, :like_count)
+ expect(like_count_button).to have_content(1)
- # toggle the like off
- topic_page.click_post_action_button(unliked_post, :like)
+ # toggle the like off
+ topic_page.click_post_action_button(unliked_post, :like)
- # we need this because the find_post_action_button will target the like button on or off
- try_until_success do
- like_button = topic_page.find_post_action_button(unliked_post, :like)
- expect(like_button[:class].split("\s")).to include("like")
- end
+ # we need this because the find_post_action_button will target the like button on or off
+ try_until_success do
+ like_button = topic_page.find_post_action_button(unliked_post, :like)
+ expect(like_button[:class].split("\s")).to include("like")
+ end
- expect(topic_page).to have_no_post_action_button(unliked_post, :like_count)
- end
+ expect(topic_page).to have_no_post_action_button(unliked_post, :like_count)
+ end
- it "displays the login dialog when the user is anonymous" do
- topic_page.visit_topic(post2.topic)
+ it "displays the login dialog when the user is anonymous" do
+ topic_page.visit_topic(post2.topic)
- expect(topic_page).to have_post_action_button(post2, :like)
- like_button = topic_page.find_post_action_button(post2, :like)
- expect(like_button[:title]).to eq(I18n.t("js.post.controls.like"))
+ expect(topic_page).to have_post_action_button(post2, :like)
+ like_button = topic_page.find_post_action_button(post2, :like)
+ expect(like_button[:title]).to eq(I18n.t("js.post.controls.like"))
- expect(topic_page).to have_no_post_action_button(post2, :like_count)
+ expect(topic_page).to have_no_post_action_button(post2, :like_count)
- # clicking on the like button should display the login modal
- topic_page.click_post_action_button(post2, :like)
+ # clicking on the like button should display the login modal
+ topic_page.click_post_action_button(post2, :like)
- expect(login_page).to be_open
- end
+ expect(login_page).to be_open
+ end
- it "renders the like count as expected" do
- topic_page.visit_topic(post.topic)
+ it "renders the like count as expected" do
+ topic_page.visit_topic(post.topic)
- # renders the like count when the it's not zero
- like_count_button = topic_page.find_post_action_button(post, :like_count)
- expect(like_count_button).to have_content(post.like_count)
+ # renders the like count when the it's not zero
+ like_count_button = topic_page.find_post_action_button(post, :like_count)
+ expect(like_count_button).to have_content(post.like_count)
- # does not render the like count when it's zero
- expect(topic_page).to have_no_post_action_button(post2, :like_count)
- end
+ # does not render the like count when it's zero
+ expect(topic_page).to have_no_post_action_button(post2, :like_count)
+ end
- it "toggles the users who liked when clicking on the like count" do
- PostActionCreator.like(user, post)
- PostActionCreator.like(admin, post)
+ it "toggles the users who liked when clicking on the like count" do
+ PostActionCreator.like(user, post)
+ PostActionCreator.like(admin, post)
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_who_liked_on_post(post)
+ expect(topic_page).to have_no_who_liked_on_post(post)
- # toggle users who liked on
- topic_page.click_post_action_button(post, :like_count)
- expect(topic_page).to have_who_liked_on_post(post, count: 2)
+ # toggle users who liked on
+ topic_page.click_post_action_button(post, :like_count)
+ expect(topic_page).to have_who_liked_on_post(post, count: 2)
- # toggle users who liked off
- topic_page.click_post_action_button(post, :like_count)
- expect(topic_page).to have_no_who_liked_on_post(post)
- end
- end
+ # toggle users who liked off
+ topic_page.click_post_action_button(post, :like_count)
+ expect(topic_page).to have_no_who_liked_on_post(post)
+ end
+ end
- describe "read" do
- fab!(:group) { Fabricate(:group, publish_read_state: true) }
- fab!(:group_user) { Fabricate(:group_user, group: group, user: user) }
- fab!(:group_user2) { Fabricate(:group_user, group: group, user: Fabricate(:user)) }
- fab!(:pm) { Fabricate(:private_message_topic, allowed_groups: [group]) }
- fab!(:pm_post1) { Fabricate(:post, topic: pm, user: user, reads: 2, created_at: 1.day.ago) }
- fab!(:pm_post2) { Fabricate(:post, topic: pm, user: group_user2.user, reads: 0) }
-
- before do
- SiteSetting.post_menu = "read|like|copyLink|share|flag|edit|bookmark|delete|admin|reply"
- sign_in(user)
- end
+ describe "read" do
+ fab!(:group) { Fabricate(:group, publish_read_state: true) }
+ fab!(:group_user) { Fabricate(:group_user, group: group, user: user) }
+ fab!(:group_user2) { Fabricate(:group_user, group: group, user: Fabricate(:user)) }
+ fab!(:pm) { Fabricate(:private_message_topic, allowed_groups: [group]) }
+ fab!(:pm_post1) { Fabricate(:post, topic: pm, user: user, reads: 2, created_at: 1.day.ago) }
+ fab!(:pm_post2) { Fabricate(:post, topic: pm, user: group_user2.user, reads: 0) }
- it "shows the read indicator when expected" do
- topic_page.visit_topic(pm)
- # it shows the read indicator on group pms where publish_read_state = true
- # when the post has reads > 0
- expect(topic_page).to have_post_action_button(pm_post1, :read)
- read_button = topic_page.find_post_action_button(pm_post1, :read)
- expect(read_button).to have_content(1)
- # don't show when the post has reads = 0
- expect(topic_page).to have_no_post_action_button(pm_post2, :read)
-
- # dont't show on regular posts
- topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :read)
- expect(topic_page).to have_no_post_action_button(post2, :read)
- end
+ before do
+ SiteSetting.post_menu = "read|like|copyLink|share|flag|edit|bookmark|delete|admin|reply"
+ sign_in(user)
+ end
- it "toggles the users who read when clicking on the read button" do
- TopicUser.update_last_read(user, pm.id, 1, 1, 1)
- TopicUser.update_last_read(admin, pm.id, 2, 1, 1)
+ it "shows the read indicator when expected" do
+ topic_page.visit_topic(pm)
+ # it shows the read indicator on group pms where publish_read_state = true
+ # when the post has reads > 0
+ expect(topic_page).to have_post_action_button(pm_post1, :read)
+ read_button = topic_page.find_post_action_button(pm_post1, :read)
+ expect(read_button).to have_content(1)
+ # don't show when the post has reads = 0
+ expect(topic_page).to have_no_post_action_button(pm_post2, :read)
+
+ # dont't show on regular posts
+ topic_page.visit_topic(post.topic)
+ expect(topic_page).to have_no_post_action_button(post, :read)
+ expect(topic_page).to have_no_post_action_button(post2, :read)
+ end
- topic_page.visit_topic(pm)
+ it "toggles the users who read when clicking on the read button" do
+ TopicUser.update_last_read(user, pm.id, 1, 1, 1)
+ TopicUser.update_last_read(admin, pm.id, 2, 1, 1)
- expect(topic_page).to have_no_who_read_on_post(pm_post1)
+ topic_page.visit_topic(pm)
- # toggle users who read on
- topic_page.click_post_action_button(pm_post1, :read)
- expect(topic_page).to have_who_read_on_post(pm_post1, count: 1)
+ expect(topic_page).to have_no_who_read_on_post(pm_post1)
- # toggle users who read off
- topic_page.click_post_action_button(pm_post1, :read)
- expect(topic_page).to have_no_who_read_on_post(pm_post1)
- end
- end
+ # toggle users who read on
+ topic_page.click_post_action_button(pm_post1, :read)
+ expect(topic_page).to have_who_read_on_post(pm_post1, count: 1)
- describe "replies" do
- fab!(:reply_to_post) do
- PostCreator.new(
- Fabricate(:user),
- raw: "Just a reply to the OP",
- topic_id: topic.id,
- reply_to_post_number: post.post_number,
- ).create
- end
- fab!(:post_with_reply, reload: true) do
- PostCreator.new(topic.user, raw: Fabricate.build(:post).raw, topic_id: topic.id).create
- end
- fab!(:reply_to_post_with_reply) do
- PostCreator.new(
- Fabricate(:user),
- raw: "A reply directly below the post",
- topic_id: topic.id,
- reply_to_post_number: post_with_reply.post_number,
- ).create
- end
+ # toggle users who read off
+ topic_page.click_post_action_button(pm_post1, :read)
+ expect(topic_page).to have_no_who_read_on_post(pm_post1)
+ end
+ end
- it "doesn't display the replies button when there are no replies" do
- topic_page.visit_topic(post.topic)
+ describe "replies" do
+ fab!(:reply_to_post) do
+ PostCreator.new(
+ Fabricate(:user),
+ raw: "Just a reply to the OP",
+ topic_id: topic.id,
+ reply_to_post_number: post.post_number,
+ ).create
+ end
+ fab!(:post_with_reply, reload: true) do
+ PostCreator.new(topic.user, raw: Fabricate.build(:post).raw, topic_id: topic.id).create
+ end
+ fab!(:reply_to_post_with_reply) do
+ PostCreator.new(
+ Fabricate(:user),
+ raw: "A reply directly below the post",
+ topic_id: topic.id,
+ reply_to_post_number: post_with_reply.post_number,
+ ).create
+ end
- expect(topic_page).to have_no_post_action_button(post2, :replies)
- end
+ it "doesn't display the replies button when there are no replies" do
+ topic_page.visit_topic(post.topic)
- it "is disabled when the post is deleted" do
- PostDestroyer.new(admin, post).destroy
+ expect(topic_page).to have_no_post_action_button(post2, :replies)
+ end
- sign_in(admin)
- topic_page.visit_topic(post.topic)
+ it "is disabled when the post is deleted" do
+ PostDestroyer.new(admin, post).destroy
- expect(topic_page).to have_post_action_button(post, :replies)
+ sign_in(admin)
+ topic_page.visit_topic(post.topic)
- replies_button = topic_page.find_post_action_button(post, :replies)
- expect(replies_button[:disabled]).to eq("true")
- end
+ expect(topic_page).to have_post_action_button(post, :replies)
- it "displays the replies when clicked" do
- topic_page.visit_topic(post.topic)
+ replies_button = topic_page.find_post_action_button(post, :replies)
+ expect(replies_button[:disabled]).to eq("true")
+ end
- expect(topic_page).to have_replies_collapsed(post)
- topic_page.click_post_action_button(post, :replies)
- expect(topic_page).to have_replies_expanded(post)
+ it "displays the replies when clicked" do
+ topic_page.visit_topic(post.topic)
- replies_button = topic_page.find_post_action_button(post, :replies)
- expect(replies_button[:ariaExpanded]).to eq("true")
- expect(replies_button[:ariaPressed]).to eq("true")
- end
+ expect(topic_page).to have_replies_collapsed(post)
+ topic_page.click_post_action_button(post, :replies)
+ expect(topic_page).to have_replies_expanded(post)
- it "is displayed correctly when the reply is directly below" do
- # it is displayed when there is only one reply directly below and the setting `suppress_reply_directly_below`
- # is disabled
- SiteSetting.suppress_reply_directly_below = false
+ replies_button = topic_page.find_post_action_button(post, :replies)
+ expect(replies_button[:ariaExpanded]).to eq("true")
+ expect(replies_button[:ariaPressed]).to eq("true")
+ end
- topic_page.visit_topic(post_with_reply.topic)
- expect(topic_page).to have_post_action_button(post_with_reply, :replies)
+ it "is displayed correctly when the reply is directly below" do
+ # it is displayed when there is only one reply directly below and the setting `suppress_reply_directly_below`
+ # is disabled
+ SiteSetting.suppress_reply_directly_below = false
- # it is not displayed when there is only one reply directly below and the setting
- # `suppress_reply_directly_below` is enabled
- SiteSetting.suppress_reply_directly_below = true
+ topic_page.visit_topic(post_with_reply.topic)
+ expect(topic_page).to have_post_action_button(post_with_reply, :replies)
- topic_page.visit_topic(post_with_reply.topic)
- expect(topic_page).to have_no_post_action_button(post_with_reply, :replies)
+ # it is not displayed when there is only one reply directly below and the setting
+ # `suppress_reply_directly_below` is enabled
+ SiteSetting.suppress_reply_directly_below = true
- # it is displayed when there is more than one reply directly below
- PostCreator.new(
- Fabricate(:user),
- raw: "A reply directly below the post",
- topic_id: topic.id,
- reply_to_post_number: post_with_reply.post_number,
- ).create
+ topic_page.visit_topic(post_with_reply.topic)
+ expect(topic_page).to have_no_post_action_button(post_with_reply, :replies)
- topic_page.visit_topic(post_with_reply.topic)
- expect(topic_page).to have_post_action_button(post_with_reply, :replies)
- end
- end
+ # it is displayed when there is more than one reply directly below
+ PostCreator.new(
+ Fabricate(:user),
+ raw: "A reply directly below the post",
+ topic_id: topic.id,
+ reply_to_post_number: post_with_reply.post_number,
+ ).create
- describe "reply" do
- before { SiteSetting.post_menu_hidden_items = "" }
+ topic_page.visit_topic(post_with_reply.topic)
+ expect(topic_page).to have_post_action_button(post_with_reply, :replies)
+ end
+ end
- it "displays the reply button only when the user can reply the post" do
- # do not display the reply button when unlogged
- topic_page.visit_topic(post.topic)
+ describe "reply" do
+ before { SiteSetting.post_menu_hidden_items = "" }
- expect(topic_page).to have_no_post_action_button(post, :reply)
- expect(topic_page).to have_no_post_action_button(post2, :reply)
+ it "displays the reply button only when the user can reply the post" do
+ # do not display the reply button when unlogged
+ topic_page.visit_topic(post.topic)
- # display the reply button when the user can reply to the post
- sign_in(user)
+ expect(topic_page).to have_no_post_action_button(post, :reply)
+ expect(topic_page).to have_no_post_action_button(post2, :reply)
- topic_page.visit_topic(post.topic)
+ # display the reply button when the user can reply to the post
+ sign_in(user)
- expect(topic_page).to have_post_action_button(post, :reply)
- expect(topic_page).to have_post_action_button(post2, :reply)
- end
+ topic_page.visit_topic(post.topic)
- it "displays the reply button less prominently when the topic is a wiki" do
- wiki_topic = Fabricate(:topic)
- wiki_post = Fabricate(:post, topic: wiki_topic, user: Fabricate(:user), wiki: true)
- non_wiki_post = Fabricate(:post, topic: wiki_topic, user: Fabricate(:user), wiki: false)
+ expect(topic_page).to have_post_action_button(post, :reply)
+ expect(topic_page).to have_post_action_button(post2, :reply)
+ end
- # do not display the reply button when unlogged
- topic_page.visit_topic(wiki_post.topic)
+ it "displays the reply button less prominently when the topic is a wiki" do
+ wiki_topic = Fabricate(:topic)
+ wiki_post = Fabricate(:post, topic: wiki_topic, user: Fabricate(:user), wiki: true)
+ non_wiki_post = Fabricate(:post, topic: wiki_topic, user: Fabricate(:user), wiki: false)
- expect(topic_page).to have_no_post_action_button(wiki_post, :reply)
- expect(topic_page).to have_no_post_action_button(non_wiki_post, :reply)
+ # do not display the reply button when unlogged
+ topic_page.visit_topic(wiki_post.topic)
- # display the reply button only for the post that `user` can reply
- sign_in(user)
+ expect(topic_page).to have_no_post_action_button(wiki_post, :reply)
+ expect(topic_page).to have_no_post_action_button(non_wiki_post, :reply)
- topic_page.visit_topic(wiki_post.topic)
+ # display the reply button only for the post that `user` can reply
+ sign_in(user)
- expect(topic_page).to have_post_action_button(wiki_post, :reply)
- expect(topic_page).to have_post_action_button(non_wiki_post, :reply)
+ topic_page.visit_topic(wiki_post.topic)
- # display the reply button less prominently for the wiki post, i.e. it's not a create button
- # and the label is not displayed
- wiki_post_reply_button = topic_page.find_post_action_button(wiki_post, :reply)
- expect(wiki_post_reply_button[:class].split("\s")).not_to include("create")
- expect(wiki_post_reply_button).to have_no_content(I18n.t("js.topic.reply.title"))
+ expect(topic_page).to have_post_action_button(wiki_post, :reply)
+ expect(topic_page).to have_post_action_button(non_wiki_post, :reply)
- # display the reply as a create button for the non-wiki post and the label should be displayed
- non_wiki_post_reply_button = topic_page.find_post_action_button(non_wiki_post, :reply)
- expect(non_wiki_post_reply_button[:class].split("\s")).to include("create")
- expect(non_wiki_post_reply_button).to have_content(I18n.t("js.topic.reply.title"))
- end
+ # display the reply button less prominently for the wiki post, i.e. it's not a create button
+ # and the label is not displayed
+ wiki_post_reply_button = topic_page.find_post_action_button(wiki_post, :reply)
+ expect(wiki_post_reply_button[:class].split("\s")).not_to include("create")
+ expect(wiki_post_reply_button).to have_no_content(I18n.t("js.topic.reply.title"))
- it "works as expected" do
- sign_in(user)
+ # display the reply as a create button for the non-wiki post and the label should be displayed
+ non_wiki_post_reply_button = topic_page.find_post_action_button(non_wiki_post, :reply)
+ expect(non_wiki_post_reply_button[:class].split("\s")).to include("create")
+ expect(non_wiki_post_reply_button).to have_content(I18n.t("js.topic.reply.title"))
+ end
- topic_page.visit_topic(post.topic)
+ it "works as expected" do
+ sign_in(user)
- expect(composer).to be_closed
- topic_page.click_post_action_button(post, :reply)
+ topic_page.visit_topic(post.topic)
- expect(composer).to be_opened
- expect(composer).to have_content("")
- end
- end
+ expect(composer).to be_closed
+ topic_page.click_post_action_button(post, :reply)
+
+ expect(composer).to be_opened
+ expect(composer).to have_content("")
+ end
+ end
- describe "share" do
- it "works as expected" do
- topic_page.visit_topic(post.topic)
+ describe "share" do
+ it "works as expected" do
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_post_action_button(post, :share)
- topic_page.click_post_action_button(post, :share)
+ expect(topic_page).to have_post_action_button(post, :share)
+ topic_page.click_post_action_button(post, :share)
- expect(page).to have_css(".d-modal.share-topic-modal")
- end
- end
+ expect(page).to have_css(".d-modal.share-topic-modal")
+ end
+ end
- describe "show more" do
- before do
- sign_in(admin)
+ describe "show more" do
+ before do
+ sign_in(admin)
- SiteSetting.post_menu = "like|copyLink|share|flag|edit|bookmark|delete|admin|reply"
- SiteSetting.post_menu_hidden_items = "flag|bookmark|edit|delete|admin"
- end
+ SiteSetting.post_menu = "like|copyLink|share|flag|edit|bookmark|delete|admin|reply"
+ SiteSetting.post_menu_hidden_items = "flag|bookmark|edit|delete|admin"
+ end
- it "is not displayed when `post_menu_hidden_items` is empty" do
- SiteSetting.post_menu_hidden_items = ""
+ it "is not displayed when `post_menu_hidden_items` is empty" do
+ SiteSetting.post_menu_hidden_items = ""
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :show_more)
- end
+ expect(topic_page).to have_no_post_action_button(post, :show_more)
+ end
- it "is not displayed when there is only one hidden button" do
- SiteSetting.post_menu_hidden_items = "admin"
+ it "is not displayed when there is only one hidden button" do
+ SiteSetting.post_menu_hidden_items = "admin"
- topic_page.visit_topic(post.topic)
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :show_more)
- end
+ expect(topic_page).to have_no_post_action_button(post, :show_more)
+ end
- it "works as expected" do
- topic_page.visit_topic(post.topic)
+ it "works as expected" do
+ topic_page.visit_topic(post.topic)
- expect(topic_page).to have_no_post_action_button(post, :flag)
- expect(topic_page).to have_no_post_action_button(post, :bookmark)
- expect(topic_page).to have_no_post_action_button(post, :edit)
- expect(topic_page).to have_no_post_action_button(post, :delete)
- expect(topic_page).to have_no_post_action_button(post, :admin)
+ expect(topic_page).to have_no_post_action_button(post, :flag)
+ expect(topic_page).to have_no_post_action_button(post, :bookmark)
+ expect(topic_page).to have_no_post_action_button(post, :edit)
+ expect(topic_page).to have_no_post_action_button(post, :delete)
+ expect(topic_page).to have_no_post_action_button(post, :admin)
- expect(topic_page).to have_post_action_button(post, :show_more)
- topic_page.click_post_action_button(post, :show_more)
+ expect(topic_page).to have_post_action_button(post, :show_more)
+ topic_page.click_post_action_button(post, :show_more)
- expect(topic_page).to have_post_action_button(post, :flag)
- expect(topic_page).to have_post_action_button(post, :bookmark)
- expect(topic_page).to have_post_action_button(post, :edit)
- expect(topic_page).to have_post_action_button(post, :delete)
- expect(topic_page).to have_post_action_button(post, :admin)
- end
- end
+ expect(topic_page).to have_post_action_button(post, :flag)
+ expect(topic_page).to have_post_action_button(post, :bookmark)
+ expect(topic_page).to have_post_action_button(post, :edit)
+ expect(topic_page).to have_post_action_button(post, :delete)
+ expect(topic_page).to have_post_action_button(post, :admin)
end
end
end