Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions spec/features/annotations/annotations_editing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
end
expect do
click_link 'Customise'
# `org_admin_template_path(Template.last)` would be preferred over %r{#{org_admin_templates_path}/\d+}
# However, the test is currently evaluating Template.count prior to the new Template being created
expect(page).to have_current_path(%r{#{org_admin_templates_path}/\d+})
end.to change { Template.count }.by(1)

# New Template created
Expand All @@ -53,7 +56,13 @@
# NOTE: This is question 2, since Annotation was copied upon clicking "Customise"
within("#edit_question_#{template.question_ids.last}") do
# Expect it to destroy the newly cleared Annotation
expect { click_button 'Save' }.not_to change { Annotation.count }
expect do
click_button 'Save'
current_path = org_admin_template_phase_path(template,
template.phases.first) +
"?section=#{template.phases.first.sections.first.id}"
expect(page).to have_current_path(current_path)
end.not_to change { Annotation.count }
end
expect(annotation.text).to eql('Foo bar')
expect(Annotation.order('created_at').last.text).to eql('<p>Noo bar</p>')
Expand All @@ -67,6 +76,9 @@
end
expect do
click_link 'Customise'
# `org_admin_template_path(Template.last)` would be preferred over %r{#{org_admin_templates_path}/\d+}
# However, the test is currently evaluating Template.count prior to the new Template being created
expect(page).to have_current_path(%r{#{org_admin_templates_path}/\d+})
end.to change { Template.count }.by(1)
template = Template.last
click_link 'Customise phase'
Expand All @@ -79,7 +91,13 @@
# NOTE: This is question 2, since Annotation was copied upon clicking "Customise"
within("#edit_question_#{template.question_ids.last}") do
# Expect it to destroy the newly cleared Annotation
expect { click_button 'Save' }.to change { Annotation.count }.by(-1)
expect do
click_button 'Save'
current_path = org_admin_template_phase_path(template,
template.phases.first) +
"?section=#{template.phases.first.sections.first.id}"
expect(page).to have_current_path(current_path)
end.to change { Annotation.count }.by(-1)
end
expect(page).not_to have_errors
end
Expand Down
1 change: 1 addition & 0 deletions spec/features/feedback_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
end

# Expectations
expect(page).to have_content('Feedback has been requested.')
expect(plan.reload).to be_feedback_requested
expect(ActionMailer::Base.deliveries).to have_exactly(1).item
end
Expand Down
1 change: 1 addition & 0 deletions spec/features/plans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
click_button 'Create plan'

# Expectations
expect(page).to have_content('Successfully created the plan.')
expect(@user.plans).to be_one
@plan = Plan.last
expect(current_path).to eql(plan_path(@plan))
Expand Down
1 change: 1 addition & 0 deletions spec/features/registrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
click_button 'Create account'

# Expectations
expect(page).to have_text('Welcome! You have signed up successfully.')
expect(current_path).to eql(plans_path)
expect(page).to have_text(user_attributes[:firstname])
expect(page).to have_text(user_attributes[:surname])
Expand Down
1 change: 1 addition & 0 deletions spec/features/sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
click_button 'Sign in'

# Expectation
expect(page).to have_content('Signed in successfully.')
expect(current_path).to eql(plans_path)
expect(page).to have_text(user.firstname)
expect(page).to have_text(user.surname)
Expand Down
1 change: 1 addition & 0 deletions spec/features/templates/templates_copying_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
end

# Expectations
expect(page).to have_content('Template was successfully copied.')
expect(Template.count).to eql(2)
new_template = Template.last
expect(new_template.title).to include(parent_template.title)
Expand Down
8 changes: 8 additions & 0 deletions spec/features/templates/templates_editings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@

scenario "Admin edits a Template's existing question", :js do
click_link 'Customisable Templates'
expect(page).to have_current_path(customisable_org_admin_templates_path)
within("#template_#{template.id}") do
click_button 'Actions'
end
click_link 'Customise'
# `org_admin_template_path(Template.last)` would be preferred over %r{#{org_admin_templates_path}/\d+}
# However, the test is currently evaluating Template.count prior to the new Template being created
expect(page).to have_current_path(%r{#{org_admin_templates_path}/\d+})
# New template created
template = Template.last
within("#phase_#{template.phase_ids.first}") do
Expand All @@ -42,6 +46,10 @@
tinymce_fill_in(:"question_annotations_attributes_annotation_#{$1}_text", with: 'Foo bar')
# rubocop:enable Lint/UselessAssignment, Style/PerlBackrefs
click_button 'Save'
current_path = org_admin_template_phase_path(template,
template.phases.first) +
"?section=#{template.phases.first.sections.first.id}"
expect(page).to have_current_path(current_path)
end
# Make sure annotation has been updated
expect(Question.find(template.question_ids.first).annotations.first.text).to eql('<p>Foo bar</p>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
click_link('Customisable Templates')

click_button 'Actions'
expect { click_link 'Customise' }.to change { Template.count }.by(1)
expect do
click_link 'Customise'
# `org_admin_template_path(Template.last)` would be preferred over %r{#{org_admin_templates_path}/\d+}
# However, the test is currently evaluating Template.count prior to the new Template being created
expect(page).to have_current_path(%r{#{org_admin_templates_path}/\d+})
end.to change { Template.count }.by(1)

customized_template = Template.last

Expand All @@ -48,6 +53,7 @@
# Publish our customisation
click_button 'Actions'
click_link 'Publish'
expect(page).to have_text('Your customisation has been published')
expect(customized_template.reload.published?).to eql(true)

# Move to the other funder Org's Templates
Expand Down Expand Up @@ -88,6 +94,7 @@

click_button 'Actions'
click_link 'Publish changes'
expect(page).to have_text('Your template has been published')
expect(new_funder_template.reload.published?).to eql(true)

# Go back to the original Org...
Expand Down
18 changes: 0 additions & 18 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,3 @@
config.include Devise::Test::ControllerHelpers, type: :view
config.include Pundit::Matchers, type: :policy
end

Capybara.register_driver :headless_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options
)
end

Capybara.javascript_driver = :headless_chrome
Capybara.default_driver = :headless_chrome
# Configure Capybara to wait longer for elements to appear
Capybara.default_max_wait_time = 20
33 changes: 26 additions & 7 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,45 @@
# Use Puma as the webserver for feature tests
Capybara.server = :puma, { Silent: true }

# Use the fast rack_test driver for non-feature tests by default
Capybara.default_driver = :rack_test

# Create a custom driver based on Capybara's :selenium_chrome_headless driver
# This resolves a ElementClickInterceptedError when executing `click_button 'Sign in'` with DMP Assistant
Capybara.register_driver :selenium_chrome_headless_add_window_size do |app|
Capybara.register_driver :selenium_chrome_headless_custom do |app|
# Get a copy of the default options for Capybara's :selenium_chrome_headless driver
options = Capybara.drivers[:selenium_chrome_headless].call.options[:options].dup
options.add_argument('--window-size=1920,1080') # default window-size is only (800x600)
# Increasing window size resolves ElementClickInterceptedError (default window-size is only (800x600))
options.add_argument('--window-size=1920,1080')
# Create a new Selenium driver with the customised options
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

# Use the fast rack_test driver for non-feature tests by default
Capybara.default_driver = :rack_test

Capybara.javascript_driver = :selenium_chrome_headless_custom

# Configure Capybara to wait longer for elements to appear
Capybara.default_max_wait_time = 10

RSpec.configure do |config|
config.before(:each, type: :feature, js: false) do
Capybara.use_default_driver
end

# Use the Selenium headless Chrome driver for feature tests
config.before(:each, type: :feature, js: true) do
Capybara.current_driver = :selenium_chrome_headless_add_window_size
Capybara.current_driver = :selenium_chrome_headless_custom
add_invalid_element_error
end
end

# Mitigate the following error by having Capybara retry an action when it occurs:
# - Selenium::WebDriver::Error::UnknownError:
# - unknown error: unhandled inspector error:
# - {"code":-32000,"message":"Node with given id does not belong to the document"}
# Source: https://github.com/teamcapybara/capybara/issues/2800#issuecomment-2728801284
def add_invalid_element_error
return unless page.driver.respond_to?(:invalid_element_errors)

page.driver.invalid_element_errors.tap do |errors|
errors << Selenium::WebDriver::Error::UnknownError unless errors.include?(Selenium::WebDriver::Error::UnknownError)
end
end
1 change: 1 addition & 0 deletions spec/support/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ def sign_in_as_user(user)
fill_in 'Password', with: user.password.presence || 'password'
click_button 'Sign in'
end
expect(page).to have_content('Signed in successfully.')
end
end
Loading