summaryrefslogtreecommitdiff
path: root/spec/support/dropzone_helper.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2017-02-24 16:37:32 -0500
committerRobert Speicher <rspeicher@gmail.com>2017-02-24 16:41:27 -0500
commit2858bc20378907325cb2f9487f31d335a5568677 (patch)
treee44bcfe20a80b17c0947fe07e1cd4976c35a3576 /spec/support/dropzone_helper.rb
parenta8c62dfe5c01ed08f170c1d41a39d5167b09631b (diff)
downloadgitlab-ce-2858bc20378907325cb2f9487f31d335a5568677.tar.gz
Add feature specs for three types of user uploadsrs-uploaders
Diffstat (limited to 'spec/support/dropzone_helper.rb')
-rw-r--r--spec/support/dropzone_helper.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/support/dropzone_helper.rb b/spec/support/dropzone_helper.rb
new file mode 100644
index 00000000000..984ec7d2741
--- /dev/null
+++ b/spec/support/dropzone_helper.rb
@@ -0,0 +1,37 @@
+module DropzoneHelper
+ # Provides a way to perform `attach_file` for a Dropzone-based file input
+ #
+ # This is accomplished by creating a standard HTML file input on the page,
+ # performing `attach_file` on that field, and then triggering the appropriate
+ # Dropzone events to perform the actual upload.
+ #
+ # This method waits for the upload to complete before returning.
+ def dropzone_file(file_path)
+ # Generate a fake file input that Capybara can attach to
+ page.execute_script <<-JS.strip_heredoc
+ var fakeFileInput = window.$('<input/>').attr(
+ {id: 'fakeFileInput', type: 'file'}
+ ).appendTo('body');
+
+ window._dropzoneComplete = false;
+ JS
+
+ # Attach the file to the fake input selector with Capybara
+ attach_file('fakeFileInput', file_path)
+
+ # Manually trigger a Dropzone "drop" event with the fake input's file list
+ page.execute_script <<-JS.strip_heredoc
+ var fileList = [$('#fakeFileInput')[0].files[0]];
+ var e = jQuery.Event('drop', { dataTransfer : { files : fileList } });
+
+ var dropzone = $('.div-dropzone')[0].dropzone;
+ dropzone.on('queuecomplete', function() {
+ window._dropzoneComplete = true;
+ });
+ dropzone.listeners[0].events.drop(e);
+ JS
+
+ # Wait until Dropzone's fired `queuecomplete`
+ loop until page.evaluate_script('window._dropzoneComplete === true')
+ end
+end