2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2017-02-24 21:37:32 +00:00
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'User uploads file to note' do
|
2017-02-24 21:37:32 +00:00
|
|
|
include DropzoneHelper
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project, creator: user, namespace: user.namespace) }
|
2017-05-16 08:52:17 +00:00
|
|
|
let(:issue) { create(:issue, project: project, author: user) }
|
2017-02-24 21:37:32 +00:00
|
|
|
|
2017-05-16 08:52:17 +00:00
|
|
|
before do
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_in(user)
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_issue_path(project, issue)
|
2017-07-20 21:27:45 +00:00
|
|
|
wait_for_requests
|
2017-05-16 08:52:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'before uploading' do
|
2022-07-26 09:09:02 +00:00
|
|
|
it 'shows "Attach a file or image" button', :js do
|
|
|
|
expect(page).to have_selector('[data-testid="button-attach-file"]')
|
2017-05-16 08:52:17 +00:00
|
|
|
expect(page).not_to have_selector('.uploading-progress-container', visible: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-10 18:08:17 +00:00
|
|
|
context 'uploading is in progress', :capybara_ignore_server_errors do
|
2017-10-03 08:35:01 +00:00
|
|
|
it 'cancels uploading on clicking to "Cancel" button', :js do
|
2017-11-02 20:34:30 +00:00
|
|
|
slow_requests do
|
|
|
|
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
2017-05-16 08:52:17 +00:00
|
|
|
|
2017-11-02 20:34:30 +00:00
|
|
|
click_button 'Cancel'
|
|
|
|
end
|
2017-05-16 08:52:17 +00:00
|
|
|
|
2022-07-26 09:09:02 +00:00
|
|
|
expect(page).to have_selector('[data-testid="button-attach-file"]')
|
2017-05-16 08:52:17 +00:00
|
|
|
expect(page).not_to have_button('Cancel')
|
|
|
|
expect(page).not_to have_selector('.uploading-progress-container', visible: true)
|
|
|
|
end
|
|
|
|
|
2017-10-03 08:35:01 +00:00
|
|
|
it 'shows "Attaching a file" message on uploading 1 file', :js do
|
2017-11-02 20:34:30 +00:00
|
|
|
slow_requests do
|
|
|
|
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
2017-05-16 08:52:17 +00:00
|
|
|
|
2017-11-02 20:34:30 +00:00
|
|
|
expect(page).to have_selector('.attaching-file-message', visible: true, text: 'Attaching a file -')
|
|
|
|
end
|
2017-05-16 08:52:17 +00:00
|
|
|
end
|
|
|
|
|
2017-10-03 08:35:01 +00:00
|
|
|
it 'shows "Attaching 2 files" message on uploading 2 file', :js do
|
2017-11-02 20:34:30 +00:00
|
|
|
slow_requests do
|
|
|
|
dropzone_file([Rails.root.join('spec', 'fixtures', 'video_sample.mp4'),
|
|
|
|
Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
2017-05-16 08:52:17 +00:00
|
|
|
|
2017-11-02 20:34:30 +00:00
|
|
|
expect(page).to have_selector('.attaching-file-message', visible: true, text: 'Attaching 2 files -')
|
|
|
|
end
|
2017-05-16 08:52:17 +00:00
|
|
|
end
|
|
|
|
|
2017-10-03 08:35:01 +00:00
|
|
|
it 'shows error message, "retry" and "attach a new file" link a if file is too big', :js do
|
2017-05-16 08:52:17 +00:00
|
|
|
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)
|
2020-10-30 12:08:44 +00:00
|
|
|
expect(page).to have_button('Try again', visible: true)
|
|
|
|
expect(page).to have_button('attach a new file', visible: true)
|
2017-05-16 08:52:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'uploading is complete' do
|
2022-07-26 09:09:02 +00:00
|
|
|
it 'shows "Attach a file or image" button on uploading complete', :js do
|
2017-05-16 08:52:17 +00:00
|
|
|
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')])
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-16 08:52:17 +00:00
|
|
|
|
2022-07-26 09:09:02 +00:00
|
|
|
expect(page).to have_selector('[data-testid="button-attach-file"]')
|
2017-05-16 08:52:17 +00:00
|
|
|
expect(page).not_to have_selector('.uploading-progress-container', visible: true)
|
|
|
|
end
|
2017-02-24 21:37:32 +00:00
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'they see the attached file', :js do
|
2017-05-16 08:52:17 +00:00
|
|
|
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')])
|
|
|
|
click_button 'Comment'
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-02-24 21:37:32 +00:00
|
|
|
|
2020-11-16 15:09:23 +00:00
|
|
|
expect(find('a.no-attachment-icon img.js-lazy-loaded[alt="dk"]')['src'])
|
2017-05-16 08:52:17 +00:00
|
|
|
.to match(%r{/#{project.full_path}/uploads/\h{32}/dk\.png$})
|
|
|
|
end
|
2017-02-24 21:37:32 +00:00
|
|
|
end
|
|
|
|
end
|