Skip to content

Commit

Permalink
Fix for failing Rubocop tests.
Browse files Browse the repository at this point in the history
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 purposes 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)
  • Loading branch information
John Pinto committed Apr 9, 2024
1 parent 0f805f6 commit 55321d0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
# config.action_view.annotate_rendered_view_with_filenames = true

config.i18n.enforce_available_locales = false

# Add config/routes_test.rb to routes
config.paths['config/routes.rb'] << Rails.root.join('config/routes_test.rb')
end

# Used by Rails' routes url_helpers (typically when including a link in an email)
Expand Down
9 changes: 9 additions & 0 deletions config/routes_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

Rails.application.routes.draw do
# Define your test-specific routes here

# This route will return an empty response with a 200 OK status code
# when the browser requests the favicon.ico file.
get '/favicon.ico', to: proc { |_env| [200, {}, ['']] }
end
11 changes: 10 additions & 1 deletion spec/features/super_admins/merge_org_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@
expect(page).to have_text('Merge Organisations')
choose_suggestion('org_org_name', @to_org)

click_button 'Analyze'
# rubocop:disable Layout/LineLength
# Using JS to click on button as click_button 'Analyze' fails due to error like
# Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted:
# Element <button name="button" type="submit" class="btn btn-primary">...</button> is not clickable at point (86, 349).
# Other element would receive the click: <div id="ui-id-2" tabindex="-1" class="ui-menu-item-wrapper">...</div>
# So replacing click_button 'Analyze'with
# rubocop:enable Layout/LineLength
analyze_button = find('button', text: 'Analyze')
execute_script('arguments[0].click();', analyze_button)

# Wait for response
sleep(0.3)
expect(page).to have_text('Summary:')
Expand Down
11 changes: 10 additions & 1 deletion spec/features/templates/templates_upgrade_customisations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@

# Move to the other funder Org's Templates
choose_suggestion('superadmin_user_org_name', funder)
click_button('Change affiliation')

# rubocop:disable Layout/LineLength
# Using JS to click as click_button "Change affiliation" fails due to error 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>
# So replacing click_button('Change affiliation')
# rubocop:enable Layout/LineLength
change_affiliation_input_button = find('input[value="Change affiliation"]')
execute_script('arguments[0].click();', change_affiliation_input_button)

# Edit the original Template
click_link "#{funder.name} Templates"
Expand Down

0 comments on commit 55321d0

Please sign in to comment.