From 4623fecf7ad9624a691bab6038698d72da6aac63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 29 Oct 2018 13:35:13 +0100 Subject: [PATCH] Create upload helper in wysiwyg component --- .../features/boards/attachment_upload_spec.rb | 19 ++-------------- spec/features/wiki/attachment_upload_spec.rb | 18 ++++----------- .../attachments/attachment_upload_spec.rb | 11 +--------- .../components/wysiwyg/wysiwyg_editor.rb | 22 ++++++++++++++++++- 4 files changed, 28 insertions(+), 42 deletions(-) diff --git a/spec/features/boards/attachment_upload_spec.rb b/spec/features/boards/attachment_upload_spec.rb index 2946c53b5b66..0f8095643d05 100644 --- a/spec/features/boards/attachment_upload_spec.rb +++ b/spec/features/boards/attachment_upload_spec.rb @@ -57,15 +57,7 @@ create_page.set_subject 'A new message' # adding an image - editor.in_editor do |container, editable| - editable.base.send_keys('Some text') - - attachments.drag_and_drop_file(editable, image_fixture) - - # Besides testing caption functionality this also slows down clicking on the submit button - # so that the image is properly embedded - editable.find('figure.image figcaption').base.send_keys('Image uploaded on creation') - end + editor.drag_attachment image_fixture, 'Image uploaded on creation' expect(page).to have_selector('attachment-list-item', text: 'image.png') expect(page).not_to have_selector('notification-upload-progress') @@ -80,14 +72,7 @@ click_on "Edit" end - editor.in_editor do |container, editable| - editable.base.send_keys(:page_up, 'some text', :enter, :enter, :enter) - attachments.drag_and_drop_file(editable, image_fixture) - - # Besides testing caption functionality this also slows down clicking on the submit button - # so that the image is properly embedded - editable.find('figure.image figcaption').base.send_keys('Image uploaded the second time') - end + editor.drag_attachment image_fixture, 'Image uploaded the second time' expect(page).to have_selector('attachment-list-item', text: 'image.png', count: 2) expect(page).not_to have_selector('notification-upload-progress') diff --git a/spec/features/wiki/attachment_upload_spec.rb b/spec/features/wiki/attachment_upload_spec.rb index b9de1baf440f..972d56ac84df 100644 --- a/spec/features/wiki/attachment_upload_spec.rb +++ b/spec/features/wiki/attachment_upload_spec.rb @@ -51,13 +51,7 @@ visit project_wiki_path(project, 'test') # adding an image - editor.in_editor do |container, editable| - attachments.drag_and_drop_file(editable, image_fixture) - - # Besides testing caption functionality this also slows down clicking on the submit button - # so that the image is properly embedded - editable.find('figure.image figcaption').base.send_keys('Image uploaded the first time') - end + editor.drag_attachment image_fixture, 'Image uploaded the first time' expect(page).to have_selector('attachment-list-item', text: 'image.png') expect(page).not_to have_selector('notification-upload-progress') @@ -75,16 +69,12 @@ # Replace one image with a named attachment URL (Regression #28381) editor.set_markdown "![my-first-image](image.png)\n\nText that prevents the two images colliding" - editor.in_editor do |container, editable| + editor.drag_attachment image_fixture, 'Image uploaded the second time' + + editor.in_editor do |container, _| # Expect URL is mapped to the correct URL expect(container).to have_selector('img[src^="/api/v3/attachments/"') expect(container).to have_no_selector('img[src="image.png"]') - - attachments.drag_and_drop_file(editable, image_fixture) - - # Besides testing caption functionality this also slows down clicking on the submit button - # so that the image is properly embedded - editable.find('figure.image figcaption').base.send_keys('Image uploaded the second time') end expect(page).to have_selector('attachment-list-item', text: 'image.png', count: 2) diff --git a/spec/features/work_packages/attachments/attachment_upload_spec.rb b/spec/features/work_packages/attachments/attachment_upload_spec.rb index 1d64280a740c..7b9526713178 100644 --- a/spec/features/work_packages/attachments/attachment_upload_spec.rb +++ b/spec/features/work_packages/attachments/attachment_upload_spec.rb @@ -42,16 +42,7 @@ editor.expect_button 'Insert image' - attachments.drag_and_drop_file(target, image_fixture) - - editor.in_editor do |container, editable| - expect(editable).to have_selector('img[src*="/api/v3/attachments/"]', wait: 20) - end - - # Besides testing caption functionality this also slows down clicking on the submit button - # so that the image is properly embedded - page.find('figure.image figcaption').base.send_keys('Some image caption') - expect(page).not_to have_selector('notification-upload-progress') + editor.drag_attachment image_fixture, 'Some image caption' field.submit_by_click diff --git a/spec/support/components/wysiwyg/wysiwyg_editor.rb b/spec/support/components/wysiwyg/wysiwyg_editor.rb index 3b7030a34cbc..fb4b669f0fe2 100644 --- a/spec/support/components/wysiwyg/wysiwyg_editor.rb +++ b/spec/support/components/wysiwyg/wysiwyg_editor.rb @@ -2,10 +2,12 @@ module Components class WysiwygEditor include Capybara::DSL include RSpec::Matchers - attr_reader :context_selector + attr_reader :context_selector, :attachments + def initialize(context = '#content') @context_selector = context + @attachments = ::Components::Attachments.new end def container @@ -62,6 +64,24 @@ def within_enabled_preview end end + def drag_attachment(image_fixture, caption = 'Some caption') + in_editor do |container, editable| + editable.base.send_keys(:page_up, 'some text', :enter, :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') + + # Besides testing caption functionality this also slows down clicking on the submit button + # so that the image is properly embedded + editable.all('figure.image figcaption').map { |el| el.base.send_keys(caption) } + end + end + def click_toolbar_button(label) # strangely, we need visible: :all here container.find('.ck-button', visible: :all, text: label).click