2023-02-22 22:30:16 -05:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-01-07 19:38:14 -05:00
|
|
|
|
describe "Post selection | Fast edit", type: :system do
|
2023-02-22 22:30:16 -05:00
|
|
|
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
|
|
|
|
let(:fast_editor) { PageObjects::Components::FastEditor.new }
|
2024-12-10 05:49:47 -05:00
|
|
|
|
|
2023-11-09 17:47:59 -05:00
|
|
|
|
fab!(:topic)
|
2024-12-10 05:49:47 -05:00
|
|
|
|
|
|
|
|
|
fab!(:post) { Fabricate(:post, topic:) }
|
|
|
|
|
fab!(:post_2) { Fabricate(:post, topic:, raw: "It ‘twas a great’ “time”!") }
|
|
|
|
|
fab!(:spanish_post) { Fabricate(:post, topic:, raw: "Hola Juan, ¿cómo estás?") }
|
|
|
|
|
fab!(:chinese_post) { Fabricate(:post, topic:, raw: "这是一个测试") }
|
|
|
|
|
fab!(:post_with_emoji) { Fabricate(:post, topic:, raw: "Good morning :wave:!") }
|
2024-05-24 12:06:29 -04:00
|
|
|
|
fab!(:post_with_quote) do
|
|
|
|
|
Fabricate(
|
|
|
|
|
:post,
|
2024-12-10 05:49:47 -05:00
|
|
|
|
topic:,
|
2024-05-24 12:06:29 -04:00
|
|
|
|
raw: "[quote]\n#{post_2.raw}\n[/quote]\n\nBelle journée, n'est-ce pas ?",
|
|
|
|
|
)
|
|
|
|
|
end
|
2024-12-10 05:49:47 -05:00
|
|
|
|
|
2023-02-22 22:30:16 -05:00
|
|
|
|
fab!(:current_user) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
|
|
before { sign_in(current_user) }
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
def css(post) = "#{topic_page.post_by_number_selector(post.post_number)} .cooked p"
|
|
|
|
|
|
|
|
|
|
context "when text is selected" do
|
|
|
|
|
before do
|
2023-02-22 22:30:16 -05:00
|
|
|
|
topic_page.visit_topic(topic)
|
2024-12-10 05:49:47 -05:00
|
|
|
|
select_text_range(css(post), 0, 5)
|
|
|
|
|
end
|
2023-02-22 22:30:16 -05:00
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
it "opens context menu" do
|
2023-02-22 22:30:16 -05:00
|
|
|
|
expect(topic_page.fast_edit_button).to be_visible
|
|
|
|
|
end
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
context "when clicking the fast edit button" do
|
|
|
|
|
before { topic_page.click_fast_edit_button }
|
2023-02-22 22:30:16 -05:00
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
it "opens the fast editor" do
|
|
|
|
|
expect(topic_page.fast_edit_input).to be_visible
|
|
|
|
|
end
|
2023-02-22 22:30:16 -05:00
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
context "when entering some text and clicking the save button" do
|
|
|
|
|
before do
|
|
|
|
|
fast_editor.fill_content("Howdy")
|
|
|
|
|
fast_editor.save
|
|
|
|
|
end
|
2023-02-22 22:30:16 -05:00
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
it "saves changes" do
|
|
|
|
|
expect(page).to have_selector(css(post), text: "Howdy world")
|
|
|
|
|
end
|
2023-02-22 22:30:16 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-24 12:06:29 -04:00
|
|
|
|
context "when text selected is inside a quote" do
|
|
|
|
|
it "opens the composer directly" do
|
|
|
|
|
topic_page.visit_topic(topic)
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
select_text_range(css(post_with_quote), 5, 10)
|
2024-05-24 12:06:29 -04:00
|
|
|
|
topic_page.click_fast_edit_button
|
|
|
|
|
|
|
|
|
|
expect(topic_page).to have_expanded_composer
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-02-22 22:30:16 -05:00
|
|
|
|
context "when editing text that has strange characters" do
|
2024-12-10 05:49:47 -05:00
|
|
|
|
it "saves when paragraph contains apostrophes" do
|
2023-02-22 22:30:16 -05:00
|
|
|
|
topic_page.visit_topic(topic)
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
select_text_range(css(post_2), 19, 4)
|
2023-02-22 22:30:16 -05:00
|
|
|
|
topic_page.click_fast_edit_button
|
|
|
|
|
|
|
|
|
|
fast_editor.fill_content("day")
|
|
|
|
|
fast_editor.save
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
expect(page).to have_selector(css(post_2), text: "It ‘twas a great’ “day”!")
|
2023-02-22 22:30:16 -05:00
|
|
|
|
end
|
2024-01-31 05:26:43 -05:00
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
it "saves when text contains diacritics" do
|
2024-01-31 05:26:43 -05:00
|
|
|
|
topic_page.visit_topic(topic)
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
select_text_range(css(spanish_post), 11, 12)
|
2024-01-31 05:26:43 -05:00
|
|
|
|
|
|
|
|
|
topic_page.click_fast_edit_button
|
|
|
|
|
|
|
|
|
|
fast_editor.fill_content("¿está todo bien?")
|
|
|
|
|
fast_editor.save
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
expect(page).to have_selector(css(spanish_post), text: "Hola Juan, ¿está todo bien?")
|
2024-01-31 05:26:43 -05:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "saves when text contains CJK ranges" do
|
|
|
|
|
topic_page.visit_topic(topic)
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
select_text_range(css(chinese_post), 0, 2)
|
2024-01-31 05:26:43 -05:00
|
|
|
|
topic_page.click_fast_edit_button
|
|
|
|
|
|
|
|
|
|
fast_editor.fill_content("今天")
|
|
|
|
|
fast_editor.save
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
expect(page).to have_selector(css(chinese_post), text: "今天一个测试")
|
2024-01-31 05:26:43 -05:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "saves when text contains emoji" do
|
|
|
|
|
topic_page.visit_topic(topic)
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
select_text_range(css(post_with_emoji), 5, 7)
|
2024-01-31 05:26:43 -05:00
|
|
|
|
topic_page.click_fast_edit_button
|
|
|
|
|
|
|
|
|
|
fast_editor.fill_content("day")
|
|
|
|
|
fast_editor.save
|
|
|
|
|
|
2024-12-10 05:49:47 -05:00
|
|
|
|
# NOTE: the emoji isn't picked up by the "text:" selector
|
|
|
|
|
expect(page).to have_selector(css(post_with_emoji), text: "Good day !")
|
|
|
|
|
# So we also check the raw content to ensure it's been saved correctly
|
|
|
|
|
expect(post_with_emoji.reload.raw).to eq "Good day :wave:!"
|
2024-01-31 05:26:43 -05:00
|
|
|
|
end
|
2023-02-22 22:30:16 -05:00
|
|
|
|
end
|
|
|
|
|
end
|