Commit 2338785e authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Use wait_for_requests to wait all JS request

parent 7f31768a
Pipeline #8460681 passed with stages
in 153 minutes and 39 seconds
......@@ -4,7 +4,7 @@ import VueResource from 'vue-resource';
Vue.use(VueResource);
// Maintain a global counter for active requests
// see: spec/support/wait_for_vue_resource.rb
// see: spec/support/wait_for_requests.rb
Vue.http.interceptors.push((request, next) => {
window.activeVueResources = window.activeVueResources || 0;
window.activeVueResources += 1;
......
---
title: Use wait_for_requests for both ajax and Vue requests
merge_request:
author:
class Spinach::Features::EventFilters < Spinach::FeatureSteps
include WaitForAjax
include WaitForRequests
include SharedAuthentication
include SharedPaths
include SharedProject
......@@ -73,20 +73,20 @@ class Spinach::Features::EventFilters < Spinach::FeatureSteps
end
When 'I click "push" event filter' do
wait_for_ajax
wait_for_requests
click_link("Push events")
wait_for_ajax
wait_for_requests
end
When 'I click "team" event filter' do
wait_for_ajax
wait_for_requests
click_link("Team")
wait_for_ajax
wait_for_requests
end
When 'I click "merge" event filter' do
wait_for_ajax
wait_for_requests
click_link("Merge events")
wait_for_ajax
wait_for_requests
end
end
......@@ -3,7 +3,7 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps
include SharedPaths
include SharedProject
include SharedUser
include WaitForAjax
include WaitForRequests
step '"John Doe" is a developer of project "Shop"' do
project.team << [john_doe, :developer]
......@@ -140,7 +140,7 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps
step 'I should be directed to the corresponding page' do
page.should have_css('.identifier', text: 'Merge Request !1')
# Merge request page loads and issues a number of Ajax requests
wait_for_ajax
wait_for_requests
end
def should_see_todo(position, title, body, state: :pending)
......
class Spinach::Features::GroupMembers < Spinach::FeatureSteps
include WaitForAjax
include WaitForRequests
include SharedAuthentication
include SharedPaths
include SharedGroup
......@@ -58,7 +58,7 @@ class Spinach::Features::GroupMembers < Spinach::FeatureSteps
click_link 'Developer'
end
wait_for_ajax
wait_for_requests
end
end
......
class Spinach::Features::GroupMilestones < Spinach::FeatureSteps
include WaitForAjax
include WaitForRequests
include SharedAuthentication
include SharedPaths
include SharedGroup
......@@ -91,7 +91,7 @@ class Spinach::Features::GroupMilestones < Spinach::FeatureSteps
end
step 'I should see the list of labels' do
wait_for_ajax
wait_for_requests
page.within('#tab-labels') do
expect(page).to have_content 'bug'
......
......@@ -3,7 +3,7 @@ class Spinach::Features::ProjectBuildsArtifacts < Spinach::FeatureSteps
include SharedProject
include SharedBuilds
include RepoHelpers
include WaitForAjax
include WaitForRequests
step 'I click artifacts download button' do
click_link 'Download'
......@@ -79,7 +79,7 @@ class Spinach::Features::ProjectBuildsArtifacts < Spinach::FeatureSteps
step 'I click a link to file within build artifacts' do
page.within('.tree-table') { find_link('ci_artifacts.txt').click }
wait_for_ajax
wait_for_requests
end
step 'I see a download link' do
......
......@@ -4,8 +4,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
include SharedNote
include SharedPaths
include Select2Helper
include WaitForVueResource
include WaitForAjax
include WaitForRequests
step 'I am a member of project "Shop"' do
@project = ::Project.find_by(name: "Shop")
......@@ -34,7 +33,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
expect(page).to have_content @merge_request.source_branch
expect(page).to have_content @merge_request.target_branch
wait_for_vue_resource
wait_for_requests
end
step 'I fill out a "Merge Request On Forked Project" merge request' do
......@@ -48,7 +47,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
first('.dropdown-target-project a', text: @project.path_with_namespace)
first('.js-source-branch').click
wait_for_ajax
wait_for_requests
first('.dropdown-source-branch .dropdown-content a', text: 'fix').click
click_button "Compare branches and continue"
......
......@@ -7,11 +7,10 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
include SharedMarkdown
include SharedDiffNote
include SharedUser
include WaitForAjax
include WaitForVueResource
include WaitForRequests
after do
wait_for_ajax if javascript_test?
wait_for_requests if javascript_test?
end
step 'I click link "New Merge Request"' do
......@@ -46,23 +45,23 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
page.within '.merge-request' do
expect(page).to have_content "Wiki Feature"
end
wait_for_vue_resource
wait_for_requests
end
step 'I should see closed merge request "Bug NS-04"' do
expect(page).to have_content "Bug NS-04"
expect(page).to have_content "Closed by"
wait_for_vue_resource
wait_for_requests
end
step 'I should see merge request "Bug NS-04"' do
expect(page).to have_content "Bug NS-04"
wait_for_vue_resource
wait_for_requests
end
step 'I should see merge request "Feature NS-05"' do
expect(page).to have_content "Feature NS-05"
wait_for_vue_resource
wait_for_requests
end
step 'I should not see "master" branch' do
......@@ -99,7 +98,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step 'I click button "Unsubscribe"' do
click_on "Unsubscribe"
wait_for_ajax
wait_for_requests
end
step 'I click link "Close"' do
......@@ -353,7 +352,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step 'I should see a discussion by user "John Doe" has started on diff' do
# Trigger a refresh of notes
execute_script("$(document).trigger('visibilitychange');")
wait_for_ajax
wait_for_requests
page.within(".notes .discussion") do
page.should have_content "#{user_exists("John Doe").name} #{user_exists("John Doe").to_reference} started a discussion"
page.should have_content sample_commit.line_code_path
......@@ -363,12 +362,12 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step 'I should see a badge of "1" next to the discussion link' do
expect_discussion_badge_to_have_counter("1")
wait_for_vue_resource
wait_for_requests
end
step 'I should see a badge of "0" next to the discussion link' do
expect_discussion_badge_to_have_counter("0")
wait_for_vue_resource
wait_for_requests
end
step 'I should see a discussion has started on commit diff' do
......@@ -376,7 +375,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion on commit"
page.should have_content sample_commit.line_code_path
page.should have_content "Line is wrong"
wait_for_vue_resource
wait_for_requests
end
end
......@@ -384,7 +383,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
page.within(".notes .discussion") do
page.should have_content "#{current_user.name} #{current_user.to_reference} started a discussion on commit"
page.should have_content "One comment to rule them all"
wait_for_vue_resource
wait_for_requests
end
end
......@@ -410,7 +409,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step 'I should see merged request' do
page.within '.status-box' do
expect(page).to have_content "Merged"
wait_for_vue_resource
wait_for_requests
end
end
......@@ -422,7 +421,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
page.within '.status-box' do
expect(page).to have_content "Open"
end
wait_for_vue_resource
wait_for_requests
end
step 'I click link "Hide inline discussion" of the third file' do
......@@ -446,7 +445,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step 'I should see a comment like "Line is wrong" in the third file' do
page.within '.files>div:nth-child(3) .note-body > .note-text' do
expect(page).to have_visible_content "Line is wrong"
wait_for_vue_resource
wait_for_requests
end
end
......@@ -470,7 +469,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
click_button "Comment"
end
wait_for_ajax
wait_for_requests
page.within ".files>div:nth-child(2) .note-body > .note-text" do
expect(page).to have_content "Line is correct"
......@@ -485,7 +484,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
click_button "Comment"
end
wait_for_ajax
wait_for_requests
end
step 'I should still see a comment like "Line is correct" in the second file' do
......@@ -514,7 +513,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step 'I should see comments on the side-by-side diff page' do
page.within '.files>div:nth-child(2) .parallel .note-body > .note-text' do
expect(page).to have_visible_content "Line is correct"
wait_for_vue_resource
wait_for_requests
end
end
......@@ -538,7 +537,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step 'I should see new target branch changes' do
expect(page).to have_content 'Request to merge fix into feature'
expect(page).to have_content 'changed target branch from merge-test to feature'
wait_for_ajax
wait_for_requests
end
step 'I click on "Email Patches"' do
......@@ -572,7 +571,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
expect(page).to have_content /([0-9]+ commits behind)/
end
wait_for_vue_resource
wait_for_requests
end
step 'I should not see the diverged commits count' do
......@@ -580,7 +579,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
expect(page).not_to have_content /([0-9]+ commit[s]? behind)/
end
wait_for_vue_resource
wait_for_requests
end
def merge_request
......@@ -597,7 +596,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
click_button "Comment"
end
wait_for_ajax
wait_for_requests
page.within(".notes_holder", visible: true) do
expect(page).to have_content message
......
class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps
include LoginHelpers
include GitlabRoutingHelper
include WaitForVueResource
include WaitForRequests
step 'I am on the Merge Request detail page' do
visit merge_request_path(@merge_request)
......@@ -24,7 +24,7 @@ class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps
# Wait for View Resource requests to complete so they don't blow up if they are
# only handled after `DatabaseCleaner` has already run
wait_for_vue_resource
wait_for_requests
end
step 'I should not see the Remove Source Branch button' do
......@@ -32,7 +32,7 @@ class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps
# Wait for View Resource requests to complete so they don't blow up if they are
# only handled after `DatabaseCleaner` has already run
wait_for_vue_resource
wait_for_requests
end
step 'There is an open Merge Request' do
......
class Spinach::Features::RevertMergeRequests < Spinach::FeatureSteps
include LoginHelpers
include GitlabRoutingHelper
include WaitForVueResource
include WaitForRequests
step 'I click on the revert button' do
find("a[href='#modal-revert-commit']").click
......@@ -16,7 +16,7 @@ class Spinach::Features::RevertMergeRequests < Spinach::FeatureSteps
step 'I should see the revert merge request notice' do
page.should have_content('The merge request has been successfully reverted.')
wait_for_vue_resource
wait_for_requests
end
step 'I should not see the revert button' do
......
......@@ -2,7 +2,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
include WaitForAjax
include WaitForRequests
step 'change project settings' do
fill_in 'project_name_edit', with: 'NewName'
......@@ -87,7 +87,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps
end
step 'I should see project "Shop" README' do
wait_for_ajax
wait_for_requests
page.within('.readme-holder') do
expect(page).to have_content 'testme'
end
......
......@@ -2,7 +2,7 @@ class Spinach::Features::ProjectMilestone < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
include WaitForAjax
include WaitForRequests
step 'milestone has issue "Bugfix1" with labels: "bug", "feature"' do
project = Project.find_by(name: "Shop")
......@@ -35,7 +35,7 @@ class Spinach::Features::ProjectMilestone < Spinach::FeatureSteps
end
step 'I should see the labels "bug", "enhancement" and "feature"' do
wait_for_ajax
wait_for_requests
page.within('#tab-issues') do
expect(page).to have_content 'bug'
......
......@@ -3,7 +3,7 @@ class Spinach::Features::ProjectSnippets < Spinach::FeatureSteps
include SharedProject
include SharedNote
include SharedPaths
include WaitForAjax
include WaitForRequests
step 'project "Shop" have "Snippet one" snippet' do
create(:project_snippet,
......@@ -59,7 +59,7 @@ class Spinach::Features::ProjectSnippets < Spinach::FeatureSteps
find('.ace_editor').native.send_keys 'Content of snippet three'
end
click_button "Create snippet"
wait_for_ajax
wait_for_requests
end
step 'I should see snippet "Snippet three"' do
......@@ -81,7 +81,7 @@ class Spinach::Features::ProjectSnippets < Spinach::FeatureSteps
fill_in "note_note", with: "Good snippet!"
click_button "Comment"
end
wait_for_ajax
wait_for_requests
end
step 'I should see comment "Good snippet!"' do
......
......@@ -4,7 +4,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
include SharedProject
include SharedPaths
include RepoHelpers
include WaitForAjax
include WaitForRequests
step "I don't have write access" do
@project = create(:project, :repository, name: "Other Project", path: "other-project")
......@@ -37,12 +37,12 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
end
step 'I should see its content' do
wait_for_ajax
wait_for_requests
expect(page).to have_content old_gitignore_content
end
step 'I should see its new content' do
wait_for_ajax
wait_for_requests
expect(page).to have_content new_gitignore_content
end
......
......@@ -5,7 +5,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedMarkdown
include WaitForAjax
include WaitForRequests
step 'I own project "Delta"' do
@project = ::Project.find_by(name: "Delta")
......@@ -35,7 +35,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
step 'I should see correct document rendered' do
expect(current_path).to eq namespace_project_blob_path(@project.namespace, @project, "markdown/doc/api/README.md")
wait_for_ajax
wait_for_requests
expect(page).to have_content "All API requests require authentication"
end
......@@ -65,7 +65,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
step 'I should see correct maintenance file rendered' do
expect(current_path).to eq namespace_project_blob_path(@project.namespace, @project, "markdown/doc/raketasks/maintenance.md")
wait_for_ajax
wait_for_requests
expect(page).to have_content "bundle exec rake gitlab:env:info RAILS_ENV=production"
end
......@@ -97,7 +97,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
step 'I see correct file rendered' do
expect(current_path).to eq namespace_project_blob_path(@project.namespace, @project, "markdown/doc/api/README.md")
wait_for_ajax
wait_for_requests
expect(page).to have_content "Contents"
expect(page).to have_link "Users"
expect(page).to have_link "Rake tasks"
......@@ -120,7 +120,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
When 'I visit markdown branch' do
visit namespace_project_tree_path(@project.namespace, @project, "markdown")
wait_for_ajax
wait_for_requests
end
When 'I visit markdown branch "README.md" blob' do
......@@ -143,7 +143,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
step 'I see correct file rendered in markdown branch' do
expect(current_path).to eq namespace_project_blob_path(@project.namespace, @project, "markdown/doc/api/README.md")
wait_for_ajax
wait_for_requests
expect(page).to have_content "Contents"
expect(page).to have_link "Users"
expect(page).to have_link "Rake tasks"
......@@ -151,7 +151,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
step 'I should see correct document rendered for markdown branch' do
expect(current_path).to eq namespace_project_blob_path(@project.namespace, @project, "markdown/doc/api/README.md")
wait_for_ajax
wait_for_requests
expect(page).to have_content "All API requests require authentication"
end
......@@ -169,7 +169,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
# Expected link contents
step 'The link with text "empty" should have url "tree/markdown"' do
wait_for_ajax
wait_for_requests
find('a', text: /^empty$/)['href'] == current_host + namespace_project_tree_path(@project.namespace, @project, "markdown")
end
......@@ -205,7 +205,7 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
end
step 'The link with text "ID" should have url "blob/markdown/README.mdID"' do
wait_for_ajax
wait_for_requests
find('a', text: /^#id$/)['href'] == current_host + namespace_project_blob_path(@project.namespace, @project, "markdown/README.md") + '#id'
end
......@@ -300,12 +300,12 @@ class Spinach::Features::ProjectSourceMarkdownRender < Spinach::FeatureSteps
step 'I should see the correct markdown' do
expect(current_path).to eq namespace_project_blob_path(@project.namespace, @project, "markdown/doc/api/users.md")
wait_for_ajax
wait_for_requests
expect(page).to have_content "List users"
end
step 'Header "Application details" should have correct id and link' do
wait_for_ajax
wait_for_requests
header_should_have_correct_id_and_link(2, 'Application details', 'application-details')
end
......
module SharedActiveTab
include Spinach::DSL
include WaitForAjax
include WaitForRequests
after do
wait_for_ajax if javascript_test?
wait_for_requests if javascript_test?
end
def ensure_active_main_tab(content)
......
module SharedDiffNote
include Spinach::DSL
include RepoHelpers
include WaitForAjax
include WaitForRequests
after do
wait_for_ajax if javascript_test?
wait_for_requests if javascript_test?
end
step 'I cancel the diff comment' do
......
module SharedNote
include Spinach::DSL
include WaitForAjax
include WaitForRequests
after do
wait_for_ajax if javascript_test?
wait_for_requests if javascript_test?
end
step 'I delete a comment' do
......@@ -25,7 +25,7 @@ module SharedNote
click_button "Comment"
end
wait_for_ajax
wait_for_requests
end
step 'I preview a comment text like "Bug fixed :smile:"' do
......@@ -40,7 +40,7 @@ module SharedNote
click_button "Comment"
end
wait_for_ajax
wait_for_requests
end
step 'I write a comment like ":+1: Nice"' do
......@@ -127,7 +127,7 @@ module SharedNote
click_button "Comment"
end
wait_for_ajax
wait_for_requests
end
step 'The comment with the header should not have an ID' do
......
......@@ -2,7 +2,7 @@ module SharedPaths
include Spinach::DSL
include RepoHelpers
include DashboardHelper
include WaitForVueResource
include WaitForRequests
step 'I visit new project page' do
visit new_project_path
......@@ -378,28 +378,28 @@ module SharedPaths
step 'I visit merge request page "Bug NS-04"' do
visit merge_request_path("Bug NS-04")
wait_for_vue_resource
wait_for_requests
end
step 'I visit merge request page "Bug NS-05"' do
visit merge_request_path("Bug NS-05")
wait_for_vue_resource
wait_for_requests
end
step 'I visit merge request page "Bug NS-07"' do
visit merge_request_path("Bug NS-07")
wait_for_vue_resource
wait_for_requests
end
step 'I visit merge request page "Bug NS-08"' do
visit merge_request_path("Bug NS-08")
wait_for_vue_resource
wait_for_requests
end
step 'I visit merge request page "Bug CO-01"' do
mr = MergeRequest.find_by(title: "Bug CO-01")
visit namespace_project_merge_request_path(mr.target_project.namespace, mr.target_project, mr)
wait_for_vue_resource
wait_for_requests
end
step 'I visit project "Shop" merge requests page' do
......
......@@ -3,7 +3,7 @@ class Spinach::Features::Snippets < Spinach::FeatureSteps
include SharedPaths
include SharedProject
include SharedSnippet
include WaitForAjax
include WaitForRequests
step 'I click link "Personal snippet one"' do
click_link "Personal snippet one"
......@@ -30,7 +30,7 @@ class Spinach::Features::Snippets < Spinach::FeatureSteps
find('.ace_editor').native.send_keys 'Content of snippet three'
end
click_button "Create snippet"
wait_for_ajax
wait_for_requests
end
step 'I submit new internal snippet' do
......
......@@ -10,7 +10,7 @@ if ENV['CI']
Knapsack::Adapters::SpinachAdapter.bind
end
%w(select2_helper test_env repo_helpers wait_for_ajax wait_for_requests sidekiq wait_for_vue_resource).each do |f|
%w(select2_helper test_env repo_helpers wait_for_requests sidekiq).each do |f|
require Rails.root.join('spec', 'support', f)
end
......@@ -33,7 +33,7 @@ end
Spinach.hooks.after_scenario do |scenario_data, step_definitions|
if scenario_data.tags.include?('javascript')
include WaitForRequests
wait_for_requests_complete
block_and_wait_for_requests_complete
end
end
......