FIX: generates markdown from pasting link (#21241)

After removing `TextareaTextManipulation` from `ChatComposer` and using `TextareaInteractor` as a proxy, one function has been forgotten: `paste(event)` which is not available in glimmer components anymore, and even less avaiable now that the mixin is not tied to a component anymore but a real DOM node. As a solution we now add a manual paste event listener which will call `paste(event)`.
This commit is contained in:
Joffrey JAFFEUX
2023-04-26 10:05:48 +02:00
committed by GitHub
parent 1e08afa8d4
commit 427fa36edd
3 changed files with 57 additions and 8 deletions

View File

@ -262,4 +262,35 @@ RSpec.describe "Chat composer", type: :system, js: true do
expect(find(".chat-composer__input").value).to eq("bb")
end
end
context "when pasting link over selected text" do
before do
channel_1.add(current_user)
sign_in(current_user)
end
it "outputs a markdown link" do
modifier = /darwin/i =~ RbConfig::CONFIG["host_os"] ? :command : :control
select_text = <<-JS
const element = document.querySelector(arguments[0]);
element.focus();
element.setSelectionRange(0, element.value.length)
JS
chat.visit_channel(channel_1)
find("body").send_keys("https://www.discourse.org")
page.execute_script(select_text, ".chat-composer__input")
page.send_keys [modifier, "c"]
page.send_keys [:backspace]
find("body").send_keys("discourse")
page.execute_script(select_text, ".chat-composer__input")
page.send_keys [modifier, "v"]
expect(find(".chat-composer__input").value).to eq("[discourse](https://www.discourse.org)")
end
end
end