debian-mirror-gitlab/spec/features/uploads/user_uploads_file_to_note_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
2020-06-23 00:09:42 +05:30
RSpec.describe 'User uploads file to note' do
2017-08-17 22:00:37 +05:30
include DropzoneHelper
let(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, creator: user, namespace: user.namespace) }
let(:issue) { create(:issue, project: project, author: user) }
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
before do
sign_in(user)
visit project_issue_path(project, issue)
2018-03-17 18:26:18 +05:30
wait_for_requests
2017-09-10 17:25:29 +05:30
end
context 'before uploading' do
2018-03-17 18:26:18 +05:30
it 'shows "Attach a file" button', :js do
2017-09-10 17:25:29 +05:30
expect(page).to have_button('Attach a file')
expect(page).not_to have_selector('.uploading-progress-container', visible: true)
end
end
2020-04-08 14:13:33 +05:30
context 'uploading is in progress', :capybara_ignore_server_errors do
2018-03-17 18:26:18 +05:30
it 'cancels uploading on clicking to "Cancel" button', :js do
slow_requests do
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
click_button 'Cancel'
end
2017-09-10 17:25:29 +05:30
expect(page).to have_button('Attach a file')
expect(page).not_to have_button('Cancel')
expect(page).not_to have_selector('.uploading-progress-container', visible: true)
end
2018-03-17 18:26:18 +05:30
it 'shows "Attaching a file" message on uploading 1 file', :js do
slow_requests do
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
expect(page).to have_selector('.attaching-file-message', visible: true, text: 'Attaching a file -')
end
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
it 'shows "Attaching 2 files" message on uploading 2 file', :js do
slow_requests do
dropzone_file([Rails.root.join('spec', 'fixtures', 'video_sample.mp4'),
Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
expect(page).to have_selector('.attaching-file-message', visible: true, text: 'Attaching 2 files -')
end
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
it 'shows error message, "retry" and "attach a new file" link a if file is too big', :js do
2017-09-10 17:25:29 +05:30
dropzone_file([Rails.root.join('spec', 'fixtures', 'video_sample.mp4')], 0.01)
error_text = 'File is too big (0.06MiB). Max filesize: 0.01MiB.'
expect(page).to have_selector('.uploading-error-message', visible: true, text: error_text)
2021-01-29 00:20:46 +05:30
expect(page).to have_button('Try again', visible: true)
expect(page).to have_button('attach a new file', visible: true)
2017-09-10 17:25:29 +05:30
expect(page).not_to have_button('Attach a file')
end
end
context 'uploading is complete' do
2018-03-17 18:26:18 +05:30
it 'shows "Attach a file" button on uploading complete', :js do
2017-09-10 17:25:29 +05:30
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')])
wait_for_requests
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(page).to have_button('Attach a file')
expect(page).not_to have_selector('.uploading-progress-container', visible: true)
end
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
it 'they see the attached file', :js do
2017-09-10 17:25:29 +05:30
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')])
click_button 'Comment'
wait_for_requests
2017-08-17 22:00:37 +05:30
2021-01-29 00:20:46 +05:30
expect(find('a.no-attachment-icon img.js-lazy-loaded[alt="dk"]')['src'])
2017-09-10 17:25:29 +05:30
.to match(%r{/#{project.full_path}/uploads/\h{32}/dk\.png$})
end
2017-08-17 22:00:37 +05:30
end
end