From b92993fceea107c6f1cbc04eac6008827a61a000 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Tue, 2 Jan 2024 19:23:41 +1000 Subject: [PATCH] FIX: Post copy link not working (#25086) Followup to c6cb3196718ba2dde8e799f5d9cdd999f3116d1f, the actionCallback function was double-wrapped with () => {} which meant that copyClipboard did not return a promise. --- .../javascripts/discourse/app/widgets/post.js | 9 +++++--- spec/system/page_objects/pages/topic.rb | 2 ++ spec/system/post_menu_spec.rb | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 spec/system/post_menu_spec.rb diff --git a/app/assets/javascripts/discourse/app/widgets/post.js b/app/assets/javascripts/discourse/app/widgets/post.js index de2bf0eaf3e57e..a624a1c0725150 100644 --- a/app/assets/javascripts/discourse/app/widgets/post.js +++ b/app/assets/javascripts/discourse/app/widgets/post.js @@ -22,7 +22,10 @@ import RawHtml from "discourse/widgets/raw-html"; import { applyDecorators, createWidget } from "discourse/widgets/widget"; import { isTesting } from "discourse-common/config/environment"; import { avatarUrl, translateSize } from "discourse-common/lib/avatar-utils"; -import getURL, { getURLWithCDN } from "discourse-common/lib/get-url"; +import getURL, { + getAbsoluteURL, + getURLWithCDN, +} from "discourse-common/lib/get-url"; import { iconNode } from "discourse-common/lib/icon-library"; import I18n from "discourse-i18n"; @@ -653,7 +656,7 @@ createWidget("post-contents", { const post = this.findAncestorModel(); const postId = post.id; - let actionCallback = () => clipboardCopy(post.shareUrl); + let actionCallback = () => clipboardCopy(getAbsoluteURL(post.shareUrl)); // Can't use clipboard in JS tests. if (isTesting()) { @@ -664,7 +667,7 @@ createWidget("post-contents", { postId, actionClass: "post-action-menu__copy-link", messageKey: "post.controls.link_copied", - actionCallback: () => actionCallback, + actionCallback, errorCallback: () => this.share(), }); }, diff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rb index 2061ff5ce538b6..54a8344937e83b 100644 --- a/spec/system/page_objects/pages/topic.rb +++ b/spec/system/page_objects/pages/topic.rb @@ -86,6 +86,8 @@ def click_post_action_button(post, button) post_by_number(post).find(".post-controls .reply").click when :flag post_by_number(post).find(".post-controls .create-flag").click + when :copy_link + post_by_number(post).find(".post-controls .post-action-menu__copy-link").click end end diff --git a/spec/system/post_menu_spec.rb b/spec/system/post_menu_spec.rb new file mode 100644 index 00000000000000..2755df4775c1a1 --- /dev/null +++ b/spec/system/post_menu_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +describe "Post menu", type: :system, js: true do + fab!(:current_user) { Fabricate(:user) } + fab!(:post) + + let(:topic_page) { PageObjects::Pages::Topic.new } + + before { sign_in(current_user) } + + describe "copy link" do + let(:cdp) { PageObjects::CDP.new } + + before { cdp.allow_clipboard } + + xit "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) + expect(cdp.read_clipboard).to eq(post.full_url + "?u=#{current_user.username}") + end + end +end