Skip to content

Commit

Permalink
ADD: Rich text editor image upload system tests (#7273)
Browse files Browse the repository at this point in the history
Part of #5316
  • Loading branch information
VladimirMikulic authored and jywarren committed Jan 17, 2020
1 parent 834fa15 commit ed47903
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: { desired_capabilities: caps }

# https://web.archive.org/web/20170730200309/http://blog.paulrugelhiatt.com/rails/testing/capybara/dropzonejs/2014/12/29/test-dropzonejs-file-uploads-with-capybara.html
def drop_in_dropzone(file_path)
def drop_in_dropzone(file_path, dropzoneSelector)
# Generate a fake input element
page.execute_script <<-JS
fakeFileInput = window.$('<input/>').attr(
Expand All @@ -29,7 +29,7 @@ def drop_in_dropzone(file_path)
value: new FakeDataTransferObject(fileToDrop)
});
var dropzoneArea = document.querySelector('.dropzone');
var dropzoneArea = document.querySelector('#{dropzoneSelector}');
// Transfer the image to the dropzone area
dropzoneArea.files = dataTransfer.files;
// Emit the fake "drop" event
Expand Down
2 changes: 1 addition & 1 deletion test/system/comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def setup
reply_preview_button = page.all('#post_comment')[0]

# Upload the image
drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png")
drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", ".dropzone")

# Wait for image upload to finish
wait_for_ajax
Expand Down
2 changes: 1 addition & 1 deletion test/system/post_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def assert_page_does_not_reload(message = "page should not reload")
visit '/wiki/new'

# Upload the image
drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png")
drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", ".dropzone")

# Wait for image upload to finish
wait_for_ajax
Expand Down
45 changes: 45 additions & 0 deletions test/system/rich_text_editor_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require "application_system_test_case"
# https://guides.rubyonrails.org/testing.html#implementing-a-system-test

class RichTextEditorTest < ApplicationSystemTestCase
Capybara.default_max_wait_time = 60

def setup
visit '/'

find('.nav-link.loginToggle').click()
fill_in('username-login', with: 'jeff')
fill_in('password-signup', with: 'secretive')

find('.login-modal-form #login-button').click()
end

test 'thumbnail image drag and drop upload' do
visit '/post'

# Upload the image
drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", '.ple-drag-drop')

# Wait for image upload to finish
wait_for_ajax

is_image_url_undefined = page.evaluate_script("$('.ple-drag-drop').attr('style').includes('url(\"undefined\"')")

# Make sure that image has been uploaded
assert_equal( is_image_url_undefined, false )
end

test 'main textarea image drag and drop upload' do
visit '/post'

# Upload the image
drop_in_dropzone("#{Rails.root.to_s}/public/images/pl.png", '.wk-container-drop')

# Wait for image upload to finish
wait_for_ajax

# Make sure that image has been uploaded
page.assert_selector('.wk-wysiwyg img', count: 1)
end

end

0 comments on commit ed47903

Please sign in to comment.