Commit c9931302 authored by Florie Guibert's avatar Florie Guibert

Rspec wait_for_requests helper waits for graphQL requests

parent 88e3fdc4
...@@ -35,6 +35,16 @@ export default (resolvers = {}, config = {}) => { ...@@ -35,6 +35,16 @@ export default (resolvers = {}, config = {}) => {
batchMax: config.batchMax || 10, batchMax: config.batchMax || 10,
}; };
const requestCounterLink = new ApolloLink((operation, forward) => {
window.pendingApolloRequests = window.pendingApolloRequests || 0;
window.pendingApolloRequests += 1;
return forward(operation).map((response) => {
window.pendingApolloRequests -= 1;
return response;
});
});
const uploadsLink = ApolloLink.split( const uploadsLink = ApolloLink.split(
(operation) => operation.getContext().hasUpload || operation.getContext().isSingleRequest, (operation) => operation.getContext().hasUpload || operation.getContext().isSingleRequest,
createUploadLink(httpOptions), createUploadLink(httpOptions),
...@@ -63,7 +73,12 @@ export default (resolvers = {}, config = {}) => { ...@@ -63,7 +73,12 @@ export default (resolvers = {}, config = {}) => {
return new ApolloClient({ return new ApolloClient({
typeDefs: config.typeDefs, typeDefs: config.typeDefs,
link: ApolloLink.from([performanceBarLink, new StartupJSLink(), uploadsLink]), link: ApolloLink.from([
requestCounterLink,
performanceBarLink,
new StartupJSLink(),
uploadsLink,
]),
cache: new InMemoryCache({ cache: new InMemoryCache({
...config.cacheConfig, ...config.cacheConfig,
freezeResults: config.assumeImmutableResults, freezeResults: config.assumeImmutableResults,
......
...@@ -8,7 +8,8 @@ RSpec.describe 'epics swimlanes sidebar', :js do ...@@ -8,7 +8,8 @@ RSpec.describe 'epics swimlanes sidebar', :js do
let_it_be(:project, reload: true) { create(:project, :public, group: group) } let_it_be(:project, reload: true) { create(:project, :public, group: group) }
let_it_be(:board) { create(:board, project: project) } let_it_be(:board) { create(:board, project: project) }
let_it_be(:list) { create(:list, board: board, position: 0) } let_it_be(:label) { create(:label, project: project, name: 'Label 1') }
let_it_be(:list) { create(:list, board: board, label: label, position: 0) }
let_it_be(:epic1) { create(:epic, group: group) } let_it_be(:epic1) { create(:epic, group: group) }
let_it_be(:issue1, reload: true) { create(:issue, project: project) } let_it_be(:issue1, reload: true) { create(:issue, project: project) }
...@@ -27,8 +28,6 @@ RSpec.describe 'epics swimlanes sidebar', :js do ...@@ -27,8 +28,6 @@ RSpec.describe 'epics swimlanes sidebar', :js do
page.find('.dropdown-toggle').click page.find('.dropdown-toggle').click
page.find('.dropdown-item', text: 'Epic').click page.find('.dropdown-item', text: 'Epic').click
end end
wait_for_all_requests
end end
context 'notifications subscription' do context 'notifications subscription' do
......
...@@ -161,7 +161,7 @@ RSpec.describe 'group epic roadmap', :js do ...@@ -161,7 +161,7 @@ RSpec.describe 'group epic roadmap', :js do
before do before do
create_list(:epic, 2, group: group, start_date: 10.days.ago, end_date: 1.day.ago) create_list(:epic, 2, group: group, start_date: 10.days.ago, end_date: 1.day.ago)
visit group_roadmap_path(group) visit group_roadmap_path(group)
wait_for_requests
execute_script("gon.roadmap_epics_limit = 1;") execute_script("gon.roadmap_epics_limit = 1;")
end end
......
...@@ -52,6 +52,6 @@ module WaitForRequests ...@@ -52,6 +52,6 @@ module WaitForRequests
end end
def finished_all_ajax_requests? def finished_all_ajax_requests?
Capybara.page.evaluate_script('window.pendingRequests || window.pendingRailsUJSRequests || 0').zero? # rubocop:disable Style/NumericPredicate Capybara.page.evaluate_script('window.pendingRequests || window.pendingApolloRequests || window.pendingRailsUJSRequests || 0').zero? # rubocop:disable Style/NumericPredicate
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment