Merge branch 'fix-random-test' into 'master'

Fix random failing test - delete attachment

Make sure we wait for AJAX request to finish before end test and cleanup
database

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>

cc @rspeicher @DouweM 

Fixes #3885 

See merge request !2007
This commit is contained in:
Dmitriy Zaporozhets 2015-12-08 00:02:40 +00:00
commit e02940e329
3 changed files with 16 additions and 4 deletions

View file

@ -369,8 +369,8 @@ class @Notes
note = $(this).closest(".note")
note.find(".note-attachment").remove()
note.find(".note-body > .note-text").show()
note.find(".js-note-attachment-delete").hide()
note.find(".note-edit-form").hide()
note.find(".note-header").show()
note.find(".current-note-edit-form").remove()
###
Called when clicking on the "reply" button for a diff line.

View file

@ -2,6 +2,7 @@ require 'spec_helper'
describe 'Comments', feature: true do
include RepoHelpers
include WaitForAjax
describe 'On a merge request', js: true, feature: true do
let!(:merge_request) { create(:merge_request) }
@ -123,8 +124,8 @@ describe 'Comments', feature: true do
it 'removes the attachment div and resets the edit form' do
find('.js-note-attachment-delete').click
is_expected.not_to have_css('.note-attachment')
expect(find('.current-note-edit-form', visible: false)).
not_to be_visible
is_expected.not_to have_css('.current-note-edit-form')
wait_for_ajax
end
end
end

View file

@ -0,0 +1,11 @@
module WaitForAjax
def wait_for_ajax
Timeout.timeout(Capybara.default_wait_time) do
loop until finished_all_ajax_requests?
end
end
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
end