Commit 40a412f6 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch '299505-rspec-wait_for_requests-should-wait-for-graphql-request' into 'master'

Rspec wait_for_requests helper waits for graphQL requests [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!52294
parents dae85d23 b98fbe8c
......@@ -35,6 +35,16 @@ export default (resolvers = {}, config = {}) => {
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(
(operation) => operation.getContext().hasUpload || operation.getContext().isSingleRequest,
createUploadLink(httpOptions),
......@@ -63,7 +73,12 @@ export default (resolvers = {}, config = {}) => {
return new ApolloClient({
typeDefs: config.typeDefs,
link: ApolloLink.from([performanceBarLink, new StartupJSLink(), uploadsLink]),
link: ApolloLink.from([
requestCounterLink,
performanceBarLink,
new StartupJSLink(),
uploadsLink,
]),
cache: new InMemoryCache({
...config.cacheConfig,
freezeResults: config.assumeImmutableResults,
......
......@@ -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(: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(:issue1, reload: true) { create(:issue, project: project) }
......@@ -22,17 +23,11 @@ RSpec.describe 'epics swimlanes sidebar', :js do
visit project_boards_path(project)
wait_for_requests
page.within('.board-swimlanes-toggle-wrapper') do
page.find('.dropdown-toggle').click
page.find('.dropdown-item', text: 'Epic').click
end
wait_for_all_requests
end
context 'notifications subscription' do
it 'displays notifications toggle' do
load_epic_boards
click_first_issue_card
page.within('[data-testid="sidebar-notifications"]') do
......@@ -43,6 +38,7 @@ RSpec.describe 'epics swimlanes sidebar', :js do
end
it 'shows toggle as on then as off as user toggles to subscribe and unsubscribe' do
load_epic_boards
click_first_issue_card
toggle = find('[data-testid="notification-subscribe-toggle"]')
......@@ -59,6 +55,8 @@ RSpec.describe 'epics swimlanes sidebar', :js do
context 'when notifications have been disabled' do
before do
project.update_attribute(:emails_disabled, true)
load_epic_boards
end
it 'displays a message that notifications have been disabled' do
......@@ -74,6 +72,7 @@ RSpec.describe 'epics swimlanes sidebar', :js do
context 'time tracking' do
it 'displays time tracking feature with default message' do
load_epic_boards
click_first_issue_card
page.within('[data-testid="time-tracker"]') do
......@@ -86,6 +85,8 @@ RSpec.describe 'epics swimlanes sidebar', :js do
before do
issue1.timelogs.create!(time_spent: 3600, user: user)
load_epic_boards
click_first_issue_card
end
......@@ -101,6 +102,8 @@ RSpec.describe 'epics swimlanes sidebar', :js do
before do
issue1.update!(time_estimate: 3600)
load_epic_boards
click_first_issue_card
end
......@@ -117,6 +120,8 @@ RSpec.describe 'epics swimlanes sidebar', :js do
issue1.update!(time_estimate: 3600)
issue1.timelogs.create!(time_spent: 1800, user: user)
load_epic_boards
click_first_issue_card
end
......@@ -141,6 +146,8 @@ RSpec.describe 'epics swimlanes sidebar', :js do
# 3600+3600*24 = 1d 1h or 25h
issue1.timelogs.create!(time_spent: 3600 + 3600 * 24, user: user)
load_epic_boards
click_first_issue_card
end
......@@ -157,4 +164,13 @@ RSpec.describe 'epics swimlanes sidebar', :js do
first("[data-testid='board_card']").click
end
end
def load_epic_boards
page.within('.board-swimlanes-toggle-wrapper') do
page.find('.dropdown-toggle').click
page.find('.dropdown-item', text: 'Epic').click
end
wait_for_all_requests
end
end
......@@ -161,7 +161,7 @@ RSpec.describe 'group epic roadmap', :js do
before do
create_list(:epic, 2, group: group, start_date: 10.days.ago, end_date: 1.day.ago)
visit group_roadmap_path(group)
wait_for_requests
execute_script("gon.roadmap_epics_limit = 1;")
end
......
......@@ -52,6 +52,6 @@ module WaitForRequests
end
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
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