Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
2858bc20
Commit
2858bc20
authored
Feb 24, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add feature specs for three types of user uploads
parent
a8c62dfe
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
112 additions
and
29 deletions
+112
-29
spec/features/issues_spec.rb
spec/features/issues_spec.rb
+3
-29
spec/features/uploads/user_uploads_avatar_to_group_spec.rb
spec/features/uploads/user_uploads_avatar_to_group_spec.rb
+26
-0
spec/features/uploads/user_uploads_avatar_to_profile_spec.rb
spec/features/uploads/user_uploads_avatar_to_profile_spec.rb
+24
-0
spec/features/uploads/user_uploads_file_to_note_spec.rb
spec/features/uploads/user_uploads_file_to_note_spec.rb
+22
-0
spec/support/dropzone_helper.rb
spec/support/dropzone_helper.rb
+37
-0
No files found.
spec/features/issues_spec.rb
View file @
2858bc20
require
'spec_helper'
describe
'Issues'
,
feature:
true
do
include
DropzoneHelper
include
IssueHelpers
include
SortingHelper
include
WaitForAjax
...
...
@@ -570,19 +571,13 @@ describe 'Issues', feature: true do
end
it
'uploads file when dragging into textarea'
do
drop_in_dropzone
test_image_file
# Wait for the file to upload
sleep
1
dropzone_file
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'banana_sample.gif'
)
expect
(
page
.
find_field
(
"issue_description"
).
value
).
to
have_content
'banana_sample'
end
it
'adds double newline to end of attachment markdown'
do
drop_in_dropzone
test_image_file
# Wait for the file to upload
sleep
1
dropzone_file
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'banana_sample.gif'
)
expect
(
page
.
find_field
(
"issue_description"
).
value
).
to
match
/\n\n$/
end
...
...
@@ -665,25 +660,4 @@ describe 'Issues', feature: true do
end
end
end
def
drop_in_dropzone
(
file_path
)
# Generate a fake input selector
page
.
execute_script
<<-
JS
var fakeFileInput = window.$('<input/>').attr(
{id: 'fakeFileInput', type: 'file'}
).appendTo('body');
JS
# Attach the file to the fake input selector with Capybara
attach_file
(
"fakeFileInput"
,
file_path
)
# Add the file to a fileList array and trigger the fake drop event
page
.
execute_script
<<-
JS
var fileList = [$('#fakeFileInput')[0].files[0]];
var e = jQuery.Event('drop', { dataTransfer : { files : fileList } });
$('.div-dropzone')[0].dropzone.listeners[0].events.drop(e);
JS
end
def
test_image_file
File
.
join
(
Rails
.
root
,
'spec'
,
'fixtures'
,
'banana_sample.gif'
)
end
end
spec/features/uploads/user_uploads_avatar_to_group_spec.rb
0 → 100644
View file @
2858bc20
require
'rails_helper'
feature
'User uploads avatar to group'
,
feature:
true
do
scenario
'they see the new avatar'
do
user
=
create
(
:user
)
group
=
create
(
:group
)
group
.
add_owner
(
user
)
login_as
(
user
)
visit
edit_group_path
(
group
)
attach_file
(
'group_avatar'
,
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'dk.png'
),
visible:
false
)
click_button
'Save group'
visit
group_path
(
group
)
expect
(
page
).
to
have_selector
(
%Q(img[src$="/uploads/group/avatar/
#{
group
.
id
}
/dk.png"])
)
# Cheating here to verify something that isn't user-facing, but is important
expect
(
group
.
reload
.
avatar
.
file
).
to
exist
end
end
spec/features/uploads/user_uploads_avatar_to_profile_spec.rb
0 → 100644
View file @
2858bc20
require
'rails_helper'
feature
'User uploads avatar to profile'
,
feature:
true
do
scenario
'they see their new avatar'
do
user
=
create
(
:user
)
login_as
(
user
)
visit
profile_path
attach_file
(
'user_avatar'
,
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'dk.png'
),
visible:
false
)
click_button
'Update profile settings'
visit
user_path
(
user
)
expect
(
page
).
to
have_selector
(
%Q(img[src$="/uploads/user/avatar/
#{
user
.
id
}
/dk.png"])
)
# Cheating here to verify something that isn't user-facing, but is important
expect
(
user
.
reload
.
avatar
.
file
).
to
exist
end
end
spec/features/uploads/user_uploads_file_to_note_spec.rb
0 → 100644
View file @
2858bc20
require
'rails_helper'
feature
'User uploads file to note'
,
feature:
true
do
include
DropzoneHelper
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
,
creator:
user
,
namespace:
user
.
namespace
)
}
scenario
'they see the attached file'
,
js:
true
do
issue
=
create
(
:issue
,
project:
project
,
author:
user
)
login_as
(
user
)
visit
namespace_project_issue_path
(
project
.
namespace
,
project
,
issue
)
dropzone_file
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'dk.png'
))
click_button
'Comment'
wait_for_ajax
expect
(
find
(
'a.no-attachment-icon img[alt="dk"]'
)[
'src'
])
.
to
match
(
%r{/
#{
project
.
full_path
}
/uploads/
\h
{32}/dk
\.
png$}
)
end
end
spec/support/dropzone_helper.rb
0 → 100644
View file @
2858bc20
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment