OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/spec/support/components/wysiwyg/wysiwyg_editor.rb

171 lines
4.7 KiB

module Components
class WysiwygEditor
include Capybara::DSL
include RSpec::Matchers
attr_reader :context_selector, :attachments
def initialize(context = '#content')
@context_selector = context
@attachments = ::Components::Attachments.new
end
def container
page.find("#{context_selector} .op-ckeditor--wrapper", wait: 10)
end
def editor_element
page.find("#{context_selector} #{input_selector}", wait: 10)
end
def in_editor
yield container, editor_element
end
def input_selector
'div.ck-content'
end
def set_markdown(text)
textarea = container.find('.op-ckeditor-source-element', visible: :all)
page.execute_script(
'jQuery(arguments[0]).trigger("op:ckeditor:setData", arguments[1])',
textarea.native,
text
)
end
def clear
textarea = container.find('.op-ckeditor-source-element', visible: :all)
page.execute_script(
'jQuery(arguments[0]).trigger("op:ckeditor:clear")',
textarea.native
)
end
def expect_button(label)
expect(container).to have_selector('.ck-button', visible: :all, text: label)
end
def expect_no_button(label)
expect(container).to have_no_selector('.ck-button', visible: :all, text: label)
end
def expect_value(value)
expect(editor_element.text).to eq(value)
end
def expect_supports_no_macros
expect(container)
.to have_no_selector('.ck-button', visible: :all, text: 'Macros')
end
def within_enabled_preview
click_toolbar_button 'Toggle preview mode'
begin
yield container.find('.ck-editor__preview')
ensure
click_toolbar_button 'Toggle preview mode'
end
end
##
# Create an image fixture with the optional caption
def drag_attachment(image_fixture, caption = 'Some caption')
in_editor do |container, editable|
sleep 0.5
editable.base.send_keys(:enter, 'some text', :enter, :enter)
images = editable.all('figure.image')
attachments.drag_and_drop_file(editable, image_fixture)
expect(page)
.to have_selector('figure img[src^="/api/v3/attachments/"]', count: images.length + 1, wait: 10)
expect(page).not_to have_selector('notification-upload-progress')
sleep 0.5
# Get the image uploaded last. As there is no way to distinguish between
# two uploaded images, from the perspective of the user, we do it by getting
# the id of the attachment uploaded last.
last_id = Attachment.last.id
image = find("figure img[src^=\"/api/v3/attachments/#{last_id}\"]")
# Besides testing caption functionality this also slows down clicking on the submit button
# so that the image is properly embedded
figure = image.find(:xpath, '../..')
retry_block do
# Click the figure
figure.click
sleep(0.2)
# Locate figcaption to create comment
figcaption = figure.find('figcaption')
figcaption.click
sleep(0.2)
figcaption.send_keys(caption)
# Expect caption set
figure.find('figcaption', text: caption)
end
end
end
def refocus
editor_element.first('*').click
rescue => e
warn "Failed to refocus on first editor element #{e}"
end
def insert_link(link)
click_toolbar_button /Link \([^)]+\)/
page.find('.ck-input-text').set link
page.find('.ck-button-save').click
end
def click_toolbar_button(label)
# strangely, we need visible: :all here
container.find('.ck-button', visible: :all, text: label).click
end
def type_slowly(*text)
editor_element.send_keys *text
sleep 0.5
end
def click_and_type_slowly(*text)
sleep 0.5
editor_element.click
type_slowly *text
end
def click_hover_toolbar_button(label)
page.find('.ck-toolbar .ck-button', text: label, visible: :all).click
end
def insert_macro(label)
container.find('.ck-button', visible: :all, text: 'Macros').click
container.find('.ck-button', visible: :all, text: label).click
end
def click_autocomplete(text)
page.find('.mention-list-item', text: text).click
end
Fix/update wysiwyg styles (#8844) This is a refactoring of the CSS classes in the WYSIWYG editor. The classes now use proper BEM and are almost completely independent of other CSS. It also includes small style refactorings, like a reduction of heading size in attribute fields, and an increase in heading size in all other instances. * Initial class definitions * Added more classes * Added Table of Contents basics * CkEditor applying custom CSS classes to p, h1, h2, h3, h4, h5, h6, li and blockquote * CKEditorInspector removed * op css class for headings * op css class for paragraphs * op css class for code/code block * adapt specs to altered markdown/html generation * adapt grid/budget representers to altered signature * op css class for lists * op css class for toc * op css class for links * Start working on typography css * op css class for tables * Fixing more typography, trying out larger headers * Applying custom classes to li, a, blockquote, figure, table, tr, td, th, image, codeblock, figcaption and macros * adapt specs to altered link classes * op css class for images * apply user content container class throughout application * CSS alignment custom classes applied to table * op css class for task list checkbox * Added task checkbox class * amend list checkbox class in backend * op css class for table thead element * adapt specs on image html generation * Updated table and typography styles * Update typography and figure styles * Figure overflow handling * Table alignment styles + ckEditor styles removed * rename wiki-anchor to op-uc-link_permalink * wrap table in div as well as figure * Updated code-block * Update permalinks * Fixed a lot about tables * Removed Description header from work-packages page * Fix frontend styles * Add placeholder styling, fix toc * Fixed figure print * working with table aligns * Custom class add to task lists * Custom classes applied to theads * op-uc-container custom class added to container * Codeblocks inside pre elements * Fix: single <code> and <a> tags * explicitly require overwritten gem class Apparently, the gem is not loaded yet when it is registered as a filter when in eager loading mode * adapt spec expectation to altered toc rendering * CkInspector removed * Latest ckeditor changes * remove highlight css class from wiki content * allow html pipleline to handle macros with additional classes * Fixed a lot of print css for tables * Add general print css back in * Update Table of Contents styling * Custom classes on ul, ol, li and task-lists * Revert "Custom classes on ul, ol, li and task-lists" This reverts commit 0d27d281378b324330ea2f25632de898269e2122. * Custom classes on ul, ol, li and task-lists * Custom classes on column's th * remove placeholder class when rendering * WOrking on task lists * Changing task-list classes, changed tests * Updated list styles * Remove unused todo list styles * remove checked in binstubs * Fix table of contents * adapt todo list handing in backend pipeline * adapt specs to altered css classes * Add numbers to table of contents * Better comments in table of contents * Fix: wrap single <table> with a <figure> * Fixes to todo list design * Updated todo list scss to fix nested lists * adapt selectors in table spec * Update table styles * Improve table borders more * Custom classes specs * Fix: no need to remove regular list classes when its type changes * Add modifier for inline headings * Update table editing styles * Remove break-word tests * wrap images just like tables * Update figure content styles * Fix: All tests passing (ul.op-uc-list_task-list) * div.op-uc-figure--content wrapping tables * Specs for figures wrappers div.op-uc-figure--content * Fix: add custom classes to links and codes again * Table wrapper div reverted + specs * Fix inline palceholders * Custom macro type classes * Add basic macro placeholder changes * Move heading permalink after text * Fix word-break spec * Sending figure styles to the backend (width) * extend test to take ckeditor placeholder into account * avoid adding bem classes multiple times * attempt to fix flickering spec * Removing image spinner when uploading finishes * adapt spec expectations Co-authored-by: Aleix Suau <info@macrofonoestudio.es> Co-authored-by: ulferts <jens.ulferts@googlemail.com>
4 years ago
def align_table_by_label(editor, table, label)
# Style first td in table
table
.find('.op-uc-table--row:first-of-type .op-uc-table--cell:first-of-type')
.click
# Click table toolbar
editor.click_hover_toolbar_button 'Table properties'
# Set alignment left
editor.click_hover_toolbar_button label
find('.ck-button-save').click
end
end
end