DEV: refactor morphed preview specs

This commit is contained in:
Régis Hanol 2024-04-09 20:25:05 +02:00
parent 84d4dca4ab
commit 4b043a2a82
3 changed files with 46 additions and 56 deletions

View File

@ -1,16 +1,16 @@
# frozen_string_literal: true
describe "Composer Preview", type: :system do
describe "Morphed Composer Preview", type: :system do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
let(:composer) { PageObjects::Components::Composer.new }
before { sign_in user }
it "keeps details element open when morphing content" do
before do
SiteSetting.enable_diffhtml_preview = true
sign_in user
visit("/new-topic")
end
it "keeps details element open" do
composer.type_content <<~MD
[details=Velcro]
What a rip-off!

View File

@ -0,0 +1,41 @@
# frozen_string_literal: true
describe "Morphed Composer Preview", type: :system do
fab!(:user) { Fabricate(:user, username: "bob", refresh_auto_groups: true) }
let(:composer) { PageObjects::Components::Composer.new }
before do
SiteSetting.enable_diffhtml_preview = true
sign_in user
visit("/new-topic")
end
it "correctly morphs code blocks" do
composer.fill_content <<~MD
```js
const = {
id: t.name,
text: t.name,
name: t.name,
```
MD
within(composer.preview) { expect(find("code.lang-js")).to have_text("const = {") }
composer.move_cursor_after("const")
composer.type_content("ant")
within(composer.preview) { expect(find("code.lang-js")).to have_text("constant = {") }
end
it "correctly morphs mentions" do
composer.fill_content("@bob text")
within(composer.preview) { expect(find("a.mention")).to have_text("@bob") }
composer.select_all
composer.type_content("@system")
within(composer.preview) { expect(find("a.mention")).to have_text("@system") }
end
end

View File

@ -1,51 +0,0 @@
# frozen_string_literal: true
describe "Composer Preview", type: :system do
fab!(:user) { Fabricate(:user, username: "bob", refresh_auto_groups: true) }
let(:composer) { PageObjects::Components::Composer.new }
before { sign_in user }
it "correctly updates code blocks in diffhtml preview" do
SiteSetting.enable_diffhtml_preview = true
visit("/latest")
find("#create-topic").click
expect(composer).to have_composer_input
composer.fill_content <<~MD
```rb
const = {
id: t.name,
text: t.name,
name: t.name,
```
MD
within(composer.preview) { expect(find("code.language-ruby")).to have_content("const = {") }
composer.move_cursor_after("const")
composer.type_content("ant")
within(composer.preview) { expect(find("code.language-ruby")).to have_content("constant = {") }
end
it "correctly updates mentions in diffhtml preview" do
SiteSetting.enable_diffhtml_preview = true
visit("/latest")
find("#create-topic").click
expect(composer).to have_composer_input
composer.fill_content <<~MD
@bob text
MD
within(composer.preview) { expect(page.find("a.mention")).to have_text("@bob") }
composer.select_all
composer.type_content("@system")
within(composer.preview) { expect(page.find("a.mention")).to have_text("@system") }
end
end