Skip to content

Commit ca2bf8a

Browse files
author
John Pinto
committed
Fix for failing Rubocop tests.
Changes: - To deal with missing favicon.ico error ( ActionController::RoutingError: No route matches [GET] "/favicon.ico") : added config/routes_test.rb to add a route will return an empty response with a 200 OK status code when the browser requests the favicon.ico file. Then for test purpopses we add the lines to config/encvironments/test.rb: # Add config/routes_test.rb to routes config.paths['config/routes.rb'] << Rails.root.join('config/routes_test.rb') - The other outstanding errors arose because in the test environment we sometimes encounter errors like (Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted: # Element <input type="submit" name="commit" value="Change affiliation" class="btn btn-secondary" data-disable-with="Change affiliation"> # is not clickable at point (101, 203). Other element would receive the click: <div id="ui-id-2" tabindex="-1" class="ui-menu-item-wrapper">...</div>). To get round this we use JS to click on element using code like this: change_affiliation_input_button = find('input[value="Change affiliation"]') execute_script('arguments[0].click();', change_affiliation_input_button)
1 parent 0f805f6 commit ca2bf8a

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

config/environments/test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
# config.action_view.annotate_rendered_view_with_filenames = true
6363

6464
config.i18n.enforce_available_locales = false
65+
66+
# Add config/routes_test.rb to routes
67+
config.paths['config/routes.rb'] << Rails.root.join('config/routes_test.rb')
6568
end
6669

6770
# Used by Rails' routes url_helpers (typically when including a link in an email)

config/routes_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
Rails.application.routes.draw do
4+
# Define your test-specific routes here
5+
6+
# This route will return an empty response with a 200 OK status code
7+
# when the browser requests the favicon.ico file.
8+
get '/favicon.ico', to: proc { |_env| [200, {}, ['']] }
9+
end

spec/features/super_admins/merge_org_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@
4545
expect(page).to have_text('Merge Organisations')
4646
choose_suggestion('org_org_name', @to_org)
4747

48-
click_button 'Analyze'
48+
# rubocop:disable Layout/LineLength
49+
# Using JS to click on button as click_button 'Analyze' fails due to error like
50+
# Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted:
51+
# Element <button name="button" type="submit" class="btn btn-primary">...</button> is not clickable at point (86, 349).
52+
# Other element would receive the click: <div id="ui-id-2" tabindex="-1" class="ui-menu-item-wrapper">...</div>
53+
# So replacing click_button 'Analyze'with
54+
# rubocop:enable Layout/LineLength
55+
analyze_button = find('button', text: 'Analyze')
56+
execute_script('arguments[0].click();', analyze_button)
57+
4958
# Wait for response
5059
sleep(0.3)
5160
expect(page).to have_text('Summary:')

spec/features/templates/templates_upgrade_customisations_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@
5252

5353
# Move to the other funder Org's Templates
5454
choose_suggestion('superadmin_user_org_name', funder)
55-
click_button('Change affiliation')
55+
56+
# rubocop:disable Layout/LineLength
57+
# Using JS to click as click_button "Change affiliation" fails due to error like
58+
# Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted:
59+
# Element <input type="submit" name="commit" value="Change affiliation" class="btn btn-secondary" data-disable-with="Change affiliation">
60+
# is not clickable at point (101, 203). Other element would receive the click: <div id="ui-id-2" tabindex="-1" class="ui-menu-item-wrapper">...</div>
61+
# So replacing click_button('Change affiliation')
62+
# rubocop:enable Layout/LineLength
63+
change_affiliation_input_button = find('input[value="Change affiliation"]')
64+
execute_script('arguments[0].click();', change_affiliation_input_button)
5665

5766
# Edit the original Template
5867
click_link "#{funder.name} Templates"

0 commit comments

Comments
 (0)