Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create upload helper in wysiwyg component #6790

Merged
merged 1 commit into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions spec/features/boards/attachment_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
18 changes: 4 additions & 14 deletions spec/features/wiki/attachment_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 21 additions & 1 deletion spec/support/components/wysiwyg/wysiwyg_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down