refactor wait_for_requests, add slow_requests block helper
This commit is contained in:
parent
187a4f6c81
commit
ed3b23fec9
9 changed files with 64 additions and 50 deletions
|
@ -43,11 +43,11 @@ describe 'Dropdown assignee', :js do
|
|||
end
|
||||
|
||||
it 'should show loading indicator when opened' do
|
||||
Gitlab::Testing::RequestBlockerMiddleware.slow_requests!
|
||||
filtered_search.set('assignee:')
|
||||
slow_requests do
|
||||
filtered_search.set('assignee:')
|
||||
|
||||
expect(page).to have_css('#js-dropdown-assignee .filter-dropdown-loading', visible: true)
|
||||
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
|
||||
expect(page).to have_css('#js-dropdown-assignee .filter-dropdown-loading', visible: true)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should hide loading indicator when loaded' do
|
||||
|
|
|
@ -51,11 +51,11 @@ describe 'Dropdown author', :js do
|
|||
end
|
||||
|
||||
it 'should show loading indicator when opened' do
|
||||
Gitlab::Testing::RequestBlockerMiddleware.slow_requests!
|
||||
filtered_search.set('author:')
|
||||
slow_requests do
|
||||
filtered_search.set('author:')
|
||||
|
||||
expect(page).to have_css('#js-dropdown-author .filter-dropdown-loading', visible: true)
|
||||
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
|
||||
expect(page).to have_css('#js-dropdown-author .filter-dropdown-loading', visible: true)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should hide loading indicator when loaded' do
|
||||
|
|
|
@ -70,11 +70,11 @@ describe 'Dropdown emoji', :js do
|
|||
end
|
||||
|
||||
it 'should show loading indicator when opened' do
|
||||
Gitlab::Testing::RequestBlockerMiddleware.slow_requests!
|
||||
filtered_search.set('my-reaction:')
|
||||
slow_requests do
|
||||
filtered_search.set('my-reaction:')
|
||||
|
||||
expect(page).to have_css('#js-dropdown-my-reaction .filter-dropdown-loading', visible: true)
|
||||
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
|
||||
expect(page).to have_css('#js-dropdown-my-reaction .filter-dropdown-loading', visible: true)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should hide loading indicator when loaded' do
|
||||
|
|
|
@ -66,12 +66,12 @@ describe 'Dropdown label', :js do
|
|||
end
|
||||
|
||||
it 'shows loading indicator when opened and hides it when loaded' do
|
||||
Gitlab::Testing::RequestBlockerMiddleware.slow_requests!
|
||||
filtered_search.set('label:')
|
||||
slow_requests do
|
||||
filtered_search.set('label:')
|
||||
|
||||
expect(page).to have_css("#{js_dropdown_label} .filter-dropdown-loading", visible: true)
|
||||
expect(page).to have_css("#{js_dropdown_label} .filter-dropdown-loading", visible: true)
|
||||
end
|
||||
expect(find(js_dropdown_label)).not_to have_css('.filter-dropdown-loading')
|
||||
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
|
||||
end
|
||||
|
||||
it 'loads all the labels when opened' do
|
||||
|
|
|
@ -50,11 +50,11 @@ describe 'Dropdown milestone', :js do
|
|||
end
|
||||
|
||||
it 'should show loading indicator when opened' do
|
||||
Gitlab::Testing::RequestBlockerMiddleware.slow_requests!
|
||||
filtered_search.set('milestone:')
|
||||
slow_requests do
|
||||
filtered_search.set('milestone:')
|
||||
|
||||
expect(page).to have_css('#js-dropdown-milestone .filter-dropdown-loading', visible: true)
|
||||
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
|
||||
expect(page).to have_css('#js-dropdown-milestone .filter-dropdown-loading', visible: true)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should hide loading indicator when loaded' do
|
||||
|
|
|
@ -179,7 +179,7 @@ describe 'User browses files' do
|
|||
click_button('Upload file')
|
||||
end
|
||||
|
||||
block_and_wait_for_requests_complete
|
||||
wait_for_all_requests
|
||||
|
||||
visit(project_blob_path(project, 'new_branch_name/logo_sample.svg'))
|
||||
|
||||
|
|
|
@ -21,24 +21,12 @@ feature 'User uploads file to note' do
|
|||
end
|
||||
|
||||
context 'uploading is in progress' do
|
||||
before do
|
||||
Gitlab::Testing::RequestBlockerMiddleware.slow_requests!
|
||||
end
|
||||
|
||||
after do
|
||||
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
|
||||
end
|
||||
|
||||
it 'shows "Cancel" button on uploading', :js do
|
||||
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
||||
|
||||
expect(page).to have_button('Cancel')
|
||||
end
|
||||
|
||||
it 'cancels uploading on clicking to "Cancel" button', :js do
|
||||
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
||||
slow_requests do
|
||||
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
||||
|
||||
click_button 'Cancel'
|
||||
click_button 'Cancel'
|
||||
end
|
||||
|
||||
expect(page).to have_button('Attach a file')
|
||||
expect(page).not_to have_button('Cancel')
|
||||
|
@ -46,16 +34,20 @@ feature 'User uploads file to note' do
|
|||
end
|
||||
|
||||
it 'shows "Attaching a file" message on uploading 1 file', :js do
|
||||
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
||||
slow_requests do
|
||||
dropzone_file([Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
||||
|
||||
expect(page).to have_selector('.attaching-file-message', visible: true, text: 'Attaching a file -')
|
||||
expect(page).to have_selector('.attaching-file-message', visible: true, text: 'Attaching a file -')
|
||||
end
|
||||
end
|
||||
|
||||
it 'shows "Attaching 2 files" message on uploading 2 file', :js do
|
||||
dropzone_file([Rails.root.join('spec', 'fixtures', 'video_sample.mp4'),
|
||||
Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
||||
slow_requests do
|
||||
dropzone_file([Rails.root.join('spec', 'fixtures', 'video_sample.mp4'),
|
||||
Rails.root.join('spec', 'fixtures', 'dk.png')], 0, false)
|
||||
|
||||
expect(page).to have_selector('.attaching-file-message', visible: true, text: 'Attaching 2 files -')
|
||||
expect(page).to have_selector('.attaching-file-message', visible: true, text: 'Attaching 2 files -')
|
||||
end
|
||||
end
|
||||
|
||||
it 'shows error message, "retry" and "attach a new file" link a if file is too big', :js do
|
||||
|
|
|
@ -9,7 +9,7 @@ module InspectRequests
|
|||
|
||||
yield
|
||||
|
||||
block_and_wait_for_requests_complete
|
||||
wait_for_all_requests
|
||||
Gitlab::Testing::RequestInspectorMiddleware.requests
|
||||
ensure
|
||||
Gitlab::Testing::RequestInspectorMiddleware.stop_logging!
|
||||
|
|
|
@ -1,25 +1,47 @@
|
|||
require_relative './wait_for_requests'
|
||||
|
||||
module WaitForRequests
|
||||
extend self
|
||||
|
||||
# This is inspired by http://www.salsify.com/blog/engineering/tearing-capybara-ajax-tests
|
||||
def block_and_wait_for_requests_complete
|
||||
block_requests { wait_for_all_requests }
|
||||
end
|
||||
|
||||
# Block all requests inside block with 503 response
|
||||
def block_requests
|
||||
Gitlab::Testing::RequestBlockerMiddleware.block_requests!
|
||||
wait_for('pending requests complete') do
|
||||
Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? && finished_all_requests?
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
|
||||
end
|
||||
|
||||
# Slow down requests inside block by injecting `sleep 0.2` before each response
|
||||
def slow_requests
|
||||
Gitlab::Testing::RequestBlockerMiddleware.slow_requests!
|
||||
yield
|
||||
ensure
|
||||
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
|
||||
end
|
||||
|
||||
# Wait for client-side AJAX requests
|
||||
def wait_for_requests
|
||||
wait_for('JS requests') { finished_all_requests? }
|
||||
wait_for('JS requests complete') { finished_all_js_requests? }
|
||||
end
|
||||
|
||||
# Wait for active Rack requests and client-side AJAX requests
|
||||
def wait_for_all_requests
|
||||
wait_for('pending requests complete') do
|
||||
finished_all_rack_reqiests? &&
|
||||
finished_all_js_requests?
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def finished_all_requests?
|
||||
def finished_all_rack_reqiests?
|
||||
Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero?
|
||||
end
|
||||
|
||||
def finished_all_js_requests?
|
||||
return true unless javascript_test?
|
||||
|
||||
finished_all_ajax_requests? &&
|
||||
|
|
Loading…
Reference in a new issue