зеркало из
https://github.com/rs-pro/activeadmin-quill_editor.git
synced 2026-08-28 15:36:17 +03:00
- Use have_css instead of have_selector (Capybara/RSpec/HaveSelector) - Fix argument alignment in multi-line method calls - Break long line into multiple lines to respect 120 character limit - Use single quotes for strings without interpolation 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
174 строки
6.0 KiB
Ruby
174 строки
6.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
using StringCleanMultiline
|
|
|
|
RSpec.describe 'Quill editor' do
|
|
let(:author) { Author.create!(email: 'some_email@example.com', name: 'John Doe', age: 30) }
|
|
let(:post) do
|
|
Post.create!(title: 'Test', author: author, description: '<p>Some content</p>', summary: '<p>Post summary</p>')
|
|
end
|
|
|
|
let(:submit_button) { find('#post_submit_action [type="submit"]') }
|
|
|
|
context 'with a Quill editor' do
|
|
let(:edit_page) do
|
|
path = edit_admin_post_path(post)
|
|
Admin::Posts::EditPage.new(path: path)
|
|
end
|
|
let(:editor) { edit_page.lookup_editor(editor_container: '#post_description_input') }
|
|
let(:input_field) { find('#post_description[data-aa-quill-editor]') }
|
|
|
|
before do
|
|
edit_page.load
|
|
end
|
|
|
|
it 'initializes the editor', :aggregate_failures do
|
|
expect(editor.content_element).to be_present
|
|
expect(editor.content).to eq('<p>Some content</p>')
|
|
expect(input_field).to be_present
|
|
end
|
|
|
|
it 'edits some content using the editor' do
|
|
editor.select_all
|
|
editor.toggle_link
|
|
editor.tooltip_editing.send_keys(['https://blocknot.es', :return])
|
|
|
|
editor << :right << :return << 'More content'
|
|
editor.toggle_bold
|
|
editor << 'Some bold'
|
|
editor.toggle_italic
|
|
editor << 'Some italic'
|
|
editor.toggle_underline
|
|
editor << 'Some underline' << :return
|
|
|
|
editor.toggle_blockquote
|
|
editor << 'blockquote enabled' << :return
|
|
editor.toggle_blockquote
|
|
|
|
editor.toggle_code_block
|
|
editor << 'code block enabled' << :return
|
|
editor.toggle_code_block
|
|
|
|
editor << 'Some text'
|
|
editor.toggle_sub
|
|
editor << 'sub text'
|
|
editor.toggle_sub
|
|
editor << ' More text'
|
|
editor.toggle_super
|
|
editor << 'sup text'
|
|
editor.toggle_super
|
|
editor << :return
|
|
|
|
editor.open_dropdown(:align).toggle_align_right
|
|
editor << 'Text aligned on the right'
|
|
|
|
expect(editor.content).to eq <<~HTML.clean_multiline
|
|
<p><a href="https://blocknot.es" rel="noopener noreferrer" target="_blank">Some content</a></p>
|
|
<p>More content<strong>Some bold<em>Some italic<u>Some underline</u></em></strong></p>
|
|
<blockquote>blockquote enabled</blockquote>
|
|
<div class="ql-code-block-container" spellcheck="false">
|
|
<div class="ql-code-block">code block enabled</div>
|
|
</div>
|
|
<p>Some text<sub>sub text</sub> More text<sup>sup text</sup></p>
|
|
<p class="ql-align-right">Text aligned on the right</p>
|
|
HTML
|
|
end
|
|
|
|
it 'updates the field when submitting', :aggregate_failures do
|
|
editor.toggle_bold
|
|
editor << 'More content'
|
|
|
|
before = '<p>Some content</p>'
|
|
after = '<p><strong>More content</strong>Some content</p>'
|
|
expect { submit_button.click }.to change { post.reload.description }.from(before).to(after)
|
|
|
|
expect(page).to have_content('was successfully updated')
|
|
end
|
|
end
|
|
|
|
context 'with 2 Quill editors' do
|
|
let(:edit_page) do
|
|
path = edit_admin_post_path(post)
|
|
Admin::Posts::EditPage.new(path: path)
|
|
end
|
|
let(:first_editor) { edit_page.lookup_editor(editor_container: '#post_description_input') }
|
|
let(:second_editor) { edit_page.lookup_editor(editor_container: '#post_summary_input') }
|
|
|
|
before do
|
|
edit_page.load
|
|
end
|
|
|
|
it 'updates some HTML content for 2 fields', :aggregate_failures do
|
|
# Check the initial states
|
|
expect(first_editor.content).to eq('<p>Some content</p>')
|
|
expect(second_editor.content).to eq('<p>Post summary</p>')
|
|
|
|
# Add some content to both the editors
|
|
first_editor.toggle_bold
|
|
first_editor << 'Some bold'
|
|
|
|
second_editor.toggle_italic
|
|
second_editor << 'Some italic'
|
|
|
|
# Check that both the fields change
|
|
before = '<p>Some content</p>'
|
|
after = '<p><strong>Some bold</strong>Some content</p>'
|
|
expect { submit_button.click }.to change { post.reload.description }.from(before).to(after)
|
|
|
|
expect(post.summary).to eq '<p><em>Some italic</em>Post summary</p>'
|
|
end
|
|
end
|
|
|
|
context 'with a Quill editor in a nested resource' do
|
|
let(:edit_page) do
|
|
path = edit_admin_author_path(author)
|
|
Admin::Authors::EditPage.new(path: path)
|
|
end
|
|
let(:submit_button) { find('#author_submit_action [type="submit"]') }
|
|
|
|
before do
|
|
post
|
|
edit_page.load
|
|
end
|
|
|
|
it 'updates some HTML content of a new nested resource', :aggregate_failures do
|
|
# Count initial posts
|
|
initial_post_count = all('[id^="author_posts_attributes_"][id$="_title"]').count
|
|
|
|
click_on 'Add New Post'
|
|
|
|
# Wait for new fields to appear
|
|
expect(page).to have_css('[id^="author_posts_attributes_"][id$="_title"]',
|
|
count: initial_post_count + 1, wait: 5)
|
|
|
|
first_editor = edit_page.lookup_editor(editor_container: '#author_posts_attributes_0_description_input')
|
|
expect(first_editor.content).to eq('<p>Some content</p>')
|
|
|
|
# Find all post title fields and get the last one (newly added)
|
|
title_fields = all('[id^="author_posts_attributes_"][id$="_title"]')
|
|
new_title_field = title_fields.last
|
|
|
|
# Only fill the title if the field is empty (new post)
|
|
if new_title_field.value.empty?
|
|
new_title_field.fill_in(with: 'Some title')
|
|
|
|
# Extract the index from the field ID
|
|
new_editor_id = new_title_field[:id].match(/posts_attributes_(\d+)_title/)[1]
|
|
container_id = "#author_posts_attributes_#{new_editor_id}_description_input"
|
|
second_editor = edit_page.lookup_editor(editor_container: container_id)
|
|
|
|
# Clear any existing content and add new content
|
|
second_editor.clear
|
|
second_editor.toggle_underline
|
|
second_editor << 'Some underline'
|
|
|
|
expect { submit_button.click }.to change(Post, :count).by(1)
|
|
expect(Post.last.description).to eq '<p><u>Some underline</u></p>'
|
|
else
|
|
# If Add New Post didn't work, skip this test for older AA versions
|
|
skip 'Add New Post functionality not working properly in this ActiveAdmin version'
|
|
end
|
|
end
|
|
end
|
|
end
|