Browse Source

shuffle schemes feature tests (#767)

* shuffle schemes feature tests

* Move schemes helper methods to a separate file

* Update and remove repeated tests from schemes feature tests

* lint
pull/772/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
2ed736bd1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 84
      spec/features/schemes_helpers.rb
  2. 537
      spec/features/schemes_spec.rb

84
spec/features/schemes_helpers.rb

@ -0,0 +1,84 @@
module SchemesHelpers
def fill_in_number_question(case_log_id, question, value, path)
visit("/logs/#{case_log_id}/#{path}")
fill_in("case-log-#{question.to_s.dasherize}-field", with: value)
click_button("Save and continue")
end
def answer_all_questions_in_income_subsection(case_log)
visit("/logs/#{case_log.id}/net-income")
fill_in("case-log-earnings-field", with: 18_000)
choose("case-log-incfreq-2-field")
click_button("Save and continue")
choose("case-log-benefits-0-field")
click_button("Save and continue")
choose("case-log-hb-1-field")
click_button("Save and continue")
end
def sign_in(user)
visit("/logs")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: user.password)
click_button("Sign in")
end
def fill_in_and_save_scheme_details(answers = {})
fill_in "Scheme name", with: "FooBar"
check "This scheme contains confidential information"
choose "Direct access hostel"
choose "Yes – registered care home providing nursing care"
select organisation_name, from: "scheme-owning-organisation-id-field"
choose answers["housing_stock_owners"].presence || "The same organisation that owns the housing stock"
click_button "Save and continue"
end
def fill_in_and_save_primary_client_group
choose "Homeless families with support needs"
click_button "Save and continue"
end
def fill_in_and_save_secondary_client_group_confirmation
choose "Yes"
click_button "Save and continue"
end
def fill_in_and_save_secondary_client_group
choose "Homeless families with support needs"
click_button "Save and continue"
end
def fill_in_and_save_support
choose "Low level"
choose "Very short stay"
click_button "Save and continue"
end
def fill_in_and_save_location
fill_in "Postcode", with: "SW1P 4DF"
fill_in "Location name (optional)", with: "Some name"
fill_in "Total number of units at this location", with: 1
choose "Self-contained house"
choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue"
end
def fill_in_and_save_second_location
fill_in "Postcode", with: "XX1 1XX"
fill_in "Location name (optional)", with: "Other name"
fill_in "Total number of units at this location", with: 2
choose "Self-contained house"
choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue"
end
def create_and_save_a_scheme
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
fill_in_and_save_secondary_client_group_confirmation
fill_in_and_save_secondary_client_group
fill_in_and_save_support
end
end

537
spec/features/schemes_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
require_relative "schemes_helpers"
RSpec.describe "Schemes scheme Features" do
include SchemesHelpers
context "when viewing list of schemes" do
context "when I am signed as a coordinator user and there are schemes in the database" do
let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) }
@ -88,45 +90,38 @@ RSpec.describe "Schemes scheme Features" do
click_button("Submit")
end
context "when viewing list of schemes" do
it "displays the link to the schemes" do
it "allows navigating to the schemes from the home page" do
expect(page).to have_link("Schemes", href: "/schemes")
end
context "when I click schemes" do
context "when viewing list of schemes" do
before do
click_link "Schemes", href: "/schemes"
end
it "shows list of schemes" do
it "shows a list of schemes" do
schemes.each do |scheme|
expect(page).to have_content(scheme.id)
expect(page).to have_link(scheme.service_name)
expect(page).to have_content(scheme.primary_client_group)
end
end
context "when I search for a specific scheme" do
it "there is a search bar with a message and search button for schemes" do
it "displays a search bar" do
expect(page).to have_field("search")
expect(page).to have_content("Search by scheme name, code or postcode")
expect(page).to have_button("Search")
end
context "when I fill in search information and press the search button" do
before do
it "allows searching the schemes by scheme code" do
fill_in("search", with: scheme_to_search.id_to_display)
click_button("Search")
end
it "displays scheme matching the scheme code" do
expect(page).to have_content(scheme_to_search.id_to_display)
end
context "when I want to clear results" do
it "there is link to clear the search results" do
expect(page).to have_link("Clear search")
end
it "displays all schemes after I clear the search results" do
it "allows clearing the search results" do
fill_in("search", with: scheme_to_search.id_to_display)
click_button("Search")
click_link("Clear search")
expect(page).to have_content(scheme_to_search.id_to_display)
schemes.each do |scheme|
@ -134,24 +129,15 @@ RSpec.describe "Schemes scheme Features" do
end
end
end
end
end
end
end
context "when viewing individual scheme" do
let!(:schemes) { FactoryBot.create_list(:scheme, 5) }
context "when I visit schemes page" do
before do
visit("schemes")
end
it "shows list of links to schemes" do
schemes.each do |scheme|
expect(page).to have_link(scheme.service_name)
expect(page).to have_content(scheme.primary_client_group)
end
end
context "when I click to see individual scheme" do
let(:scheme) { schemes.first }
@ -222,7 +208,11 @@ RSpec.describe "Schemes scheme Features" do
end
context "when creating a new scheme" do
let(:organisation_name) { "FooBar" }
let(:scheme) { Scheme.first }
before do
FactoryBot.create(:organisation, name: organisation_name)
Scheme.destroy_all
click_link "Schemes", href: "/schemes"
end
@ -233,8 +223,6 @@ RSpec.describe "Schemes scheme Features" do
end
context "when I press create a new scheme" do
let!(:organisation) { FactoryBot.create(:organisation, name: "FooBar") }
before do
click_link "Create a new supported housing scheme"
end
@ -249,29 +237,14 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "Who provides the support services used by this scheme?"
end
context "when I fill in scheme details and I press save I see primary client group section" do
let(:scheme) { Scheme.first }
before do
fill_in "Scheme name", with: "FooBar"
check "This scheme contains confidential information"
choose "Direct access hostel"
choose "Yes – registered care home providing nursing care"
select organisation.name, from: "scheme-owning-organisation-id-field"
choose "The same organisation that owns the housing stock"
click_button "Save and continue"
end
it "lets me fill in the scheme details" do
it "lets me fill in the primary client group" do
fill_in_and_save_scheme_details
expect(page).to have_content "What client group is this scheme intended for?"
end
context "when I press the back button" do
before do
it "allows to navigate back and fill in the scheme details" do
fill_in_and_save_scheme_details
click_link "Back"
end
it "lets me fill in the scheme details" do
expect(page).to have_current_path("/schemes/#{scheme.id}/details")
expect(page).to have_content "Scheme name"
expect(page).to have_content "This scheme contains confidential information"
@ -280,221 +253,189 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?"
end
context "when we amend scheme details" do
it "returns to the primary client group question" do
it "returns to the primary client group question after amending scheme details" do
fill_in_and_save_scheme_details
click_link "Back"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group")
end
end
end
context "when I select primary client group details" do
before do
choose "Homeless families with support needs"
click_button "Save and continue"
end
it "lets me confirm if I want to select secondary group details" do
it "allows confirming if the scheme provides for secondary group details" do
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
expect(page).to have_content "Does this scheme provide for another client group?"
end
context "when I press the back button" do
before do
it "allows amending primary client group after navigating back from secondary client group confirmation question" do
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
click_link "Back"
end
it "lets me select the primary client group" do
expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group")
expect(page).to have_content "What client group is this scheme intended for?"
end
context "when we amend primary client group" do
it "returns to the confirm secondary client group question" do
it "returns to the secondary group details confirmation question after amending primary client group" do
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
click_link "Back"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group")
end
end
end
context "when I confirm the secondary group" do
before do
choose "Yes"
click_button "Save and continue"
end
it "lets me select secondary client group" do
it "allows selecting secondary client group if the scheme provides for it" do
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
fill_in_and_save_secondary_client_group_confirmation
expect(page).to have_content "What is the other client group?"
end
context "when I press the back button" do
before do
it "allows amending secondary client group confirmation question after navigating from secondary client group question" do
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
fill_in_and_save_secondary_client_group_confirmation
click_link "Back"
end
it "lets me confirm the secondary group" do
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group")
expect(page).to have_content "Does this scheme provide for another client group?"
end
context "when we amend confirm secondary client" do
it "returns to the secondary client group question" do
it "returns to the secondary group details question after amending secondary group details confirmation" do
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
fill_in_and_save_secondary_client_group_confirmation
click_link "Back"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group")
end
end
end
context "when I select the secondary group" do
before do
choose "Homeless families with support needs"
click_button "Save and continue"
end
it "lets me select level of support" do
it "allows selecting the level of support" do
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
fill_in_and_save_secondary_client_group_confirmation
fill_in_and_save_secondary_client_group
expect(page).to have_content "What support does this scheme provide?"
end
context "when I press the back button" do
before do
it "allows amending secondary client group question after navigating from level of support" do
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
fill_in_and_save_secondary_client_group_confirmation
fill_in_and_save_secondary_client_group
click_link "Back"
end
it "lets me select the secondary group" do
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group")
expect(page).to have_content "What is the other client group?"
end
context "when we amend secondary client" do
it "returns to the support question" do
it "returns to the level of support question after amending secondary group details" do
fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group
fill_in_and_save_secondary_client_group_confirmation
fill_in_and_save_secondary_client_group
click_link "Back"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/support")
end
end
end
context "when I select the support answers" do
context "when adding a location" do
before do
choose "Low level"
choose "Very short stay"
click_button "Save and continue"
create_and_save_a_scheme
end
it "lets me add location" do
expect(page).to have_content "Add a location to this scheme"
end
context "when I press the back button" do
before do
it "lets me navigate back to support questions" do
click_link "Back"
end
it "lets me select the secondary group" do
expect(page).to have_current_path("/schemes/#{scheme.id}/support")
expect(page).to have_content "What support does this scheme provide?"
end
context "when I amend support" do
it "returns to the add location page" do
it "returns to the add location page after amending the support question" do
click_link "Back"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new")
end
end
end
context "when I add location to the scheme" do
before do
fill_in "Postcode", with: "SW1P 4DF"
fill_in "Location name (optional)", with: "Some name"
fill_in "Total number of units at this location", with: 1
choose "Self-contained house"
choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue"
it "lets me check my answers after adding a location" do
fill_in_and_save_location
expect(page).to have_content "Check your changes before creating this scheme"
end
it "lets me check my answers" do
it "lets me check my answers after adding a second location" do
fill_in_and_save_location
click_link "Add a location"
fill_in_and_save_second_location
expect(page).to have_content "Check your changes before creating this scheme"
end
end
context "when I select to view locations" do
context "when viewing locations" do
before do
create_and_save_a_scheme
fill_in_and_save_location
click_link "Locations"
end
it "displays information about locations" do
it "displays information about a single location" do
expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} location"
end
it "displays information about newly created location" do
it "displays information about the first created location" do
expect(page).to have_content "SW1P4DF"
expect(page).to have_content "Some name"
expect(page).to have_content "Self-contained house"
expect(page).to have_content "None"
end
end
context "and I select to add another location a scheme" do
before do
click_link "Add a location"
fill_in "Postcode", with: "XX1 1XX"
fill_in "Location name (optional)", with: "Other name"
fill_in "Total number of units at this location", with: 2
choose "Self-contained house"
choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue"
end
it "lets me check my answers" do
expect(page).to have_content "Check your changes before creating this scheme"
end
context "when I select to view locations" do
before do
click_link "Locations"
end
it "displays information about another location" do
click_link "Add a location"
fill_in_and_save_second_location
expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} location"
end
it "displays information about newly created location" do
click_link "Add a location"
fill_in_and_save_second_location
expect(page).to have_content "XX11XX"
expect(page).to have_content "Other name"
expect(page).to have_content "Self-contained house"
end
end
context "when changing location details" do
before do
create_and_save_a_scheme
fill_in_and_save_second_location
click_link "Locations"
end
it "displays changed location" do
click_link "XX11XX"
fill_in "Postcode", with: "ZZ1 1ZZ"
choose "location-mobility-type-wheelchair-user-standard-field"
click_button "Save and continue"
end
it "displays changed location" do
expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} location"
expect(page).to have_content "ZZ11ZZ"
expect(page).to have_content("Wheelchair-user standard")
end
end
end
context "when changing scheme answers" do
before do
create_and_save_a_scheme
fill_in_and_save_location
end
context "when changing answers" do
it "displays change links" do
assert_selector "a", text: "Change", count: 13
end
context "when changing details" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
end
it "allows changing details questions" do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
fill_in "Scheme name", with: "Example"
@ -504,21 +445,18 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "Example"
end
context "when I press the back button" do
before do
it "lets me select the support answers after navigating back" do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
click_link "Back"
end
it "lets me select the support answers" do
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Check your changes before creating this scheme"
end
end
end
end
context "and I select to create a scheme" do
context "when selecting 'create a scheme'" do
before do
create_and_save_a_scheme
fill_in_and_save_location
click_link "Create scheme"
end
@ -530,37 +468,21 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "#{scheme.owning_organisation.name} has been created."
end
end
end
end
end
end
end
end
context "when I fill in scheme details indicating that supported services provided by a different organisation and I press save I see primary client group section" do
let(:scheme) { Scheme.first }
let!(:another_organisation) { FactoryBot.create(:organisation, name: "Another Org") }
before do
fill_in "Scheme name", with: "FooBar"
check "This scheme contains confidential information"
choose "Direct access hostel"
choose "Yes – registered care home providing nursing care"
select organisation.name, from: "scheme-owning-organisation-id-field"
choose "Another registered housing provider"
click_button "Save and continue"
fill_in_and_save_scheme_details({ "housing_stock_owners" => "Another registered housing provider" })
end
it "lets me fill in the managing organisation details" do
expect(page).to have_content "Which organisation provides the support services used by this scheme?"
end
context "when I press the back button" do
before do
it "lets me fill in the scheme details after navigating back" do
click_link "Back"
end
it "lets me fill in the scheme details" do
expect(page).to have_current_path("/schemes/#{scheme.id}/details")
expect(page).to have_content "Scheme name"
expect(page).to have_content "This scheme contains confidential information"
@ -569,228 +491,35 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?"
end
context "when we amend scheme details" do
it "returns to the primary client group question" do
it "returns to the support service provider after amending the question" do
click_link "Back"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/support-services-provider")
end
end
end
context "when I select organisation providing support for scheme" do
before do
it "lets the primary client group to be selected" do
select another_organisation.name, from: "scheme-managing-organisation-id-field"
click_button "Save and continue"
end
it "lets me select the primary client group" do
expect(page).to have_content "What client group is this scheme intended for?"
end
context "when I select primary client group details" do
before do
choose "Homeless families with support needs"
click_button "Save and continue"
end
it "lets me confirm if I want to select secondary group details" do
expect(page).to have_content "Does this scheme provide for another client group?"
end
context "when I press the back button" do
context "when changing scheme answers" do
before do
click_link "Back"
end
it "lets me select the primary client group" do
expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group")
expect(page).to have_content "What client group is this scheme intended for?"
end
context "when we amend primary client group" do
it "returns to the confirm secondary client group question" do
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group")
end
end
end
context "when I confirm the secondary group" do
before do
choose "Yes"
click_button "Save and continue"
end
it "lets me select secondary client group" do
expect(page).to have_content "What is the other client group?"
end
context "when I press the back button" do
before do
click_link "Back"
end
it "lets me confirm the secondary group" do
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group")
expect(page).to have_content "Does this scheme provide for another client group?"
end
context "when we amend confirm secondary client" do
it "returns to the secondary client group question" do
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group")
end
end
end
context "when I select the secondary group" do
before do
choose "Homeless families with support needs"
click_button "Save and continue"
end
it "lets me select level of support" do
expect(page).to have_content "What support does this scheme provide?"
end
context "when I press the back button" do
before do
click_link "Back"
end
it "lets me select the secondary group" do
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group")
expect(page).to have_content "What is the other client group?"
end
context "when we amend secondary client" do
it "returns to the support question" do
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/support")
end
end
end
context "when I select the support answers" do
before do
choose "Low level"
choose "Very short stay"
click_button "Save and continue"
end
it "lets me add location" do
expect(page).to have_content "Add a location to this scheme"
end
context "when I press the back button" do
before do
click_link "Back"
end
it "lets me select the secondary group" do
expect(page).to have_current_path("/schemes/#{scheme.id}/support")
expect(page).to have_content "What support does this scheme provide?"
end
context "when I amend support" do
it "returns to the add location page" do
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new")
end
end
end
context "when I add location to the scheme" do
before do
fill_in "Postcode", with: "SW1P 4DF"
fill_in "Location name (optional)", with: "Some name"
fill_in "Total number of units at this location", with: 1
choose "Self-contained house"
choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue"
end
it "lets me check my answers" do
expect(page).to have_content "Check your changes before creating this scheme"
end
context "when I select to view locations" do
before do
click_link "Locations"
end
it "displays information about locations" do
expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} location"
end
it "displays information about newly created location" do
expect(page).to have_content "SW1P4DF"
expect(page).to have_content "Some name"
expect(page).to have_content "Self-contained house"
end
end
context "and I select to add another location a scheme" do
before do
click_link "Add a location"
fill_in "Postcode", with: "XX1 1XX"
fill_in "Location name (optional)", with: "Other name"
fill_in "Total number of units at this location", with: 2
choose "Self-contained house"
choose "location-add-another-location-no-field"
choose "location-mobility-type-none-field"
click_button "Save and continue"
end
it "lets me check my answers" do
expect(page).to have_content "Check your changes before creating this scheme"
end
context "when I select to view locations" do
before do
click_link "Locations"
end
it "displays information about another location" do
expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} location"
end
it "displays information about newly created location" do
expect(page).to have_content "XX11XX"
expect(page).to have_content "Other name"
expect(page).to have_content "Self-contained house"
end
context "when changing location details" do
before do
click_link "XX11XX"
fill_in "Postcode", with: "ZZ1 1ZZ"
select another_organisation.name, from: "scheme-managing-organisation-id-field"
click_button "Save and continue"
fill_in_and_save_primary_client_group
fill_in_and_save_secondary_client_group_confirmation
fill_in_and_save_secondary_client_group
fill_in_and_save_support
fill_in_and_save_location
end
it "displays changed location" do
expect(page).to have_content "Locations"
expect(page).to have_content "#{scheme.locations.count} location"
expect(page).to have_content "ZZ11ZZ"
end
end
end
end
context "when changing answers" do
it "displays change links" do
assert_selector "a", text: "Change", count: 13
end
context "when changing details" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
end
it "allows changing details questions" do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
fill_in "Scheme name", with: "Example"
@ -800,41 +529,15 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "Example"
end
context "when I press the back button" do
before do
it "lets me select the support answers after navigating back" do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
click_link "Back"
end
it "lets me select the support answers" do
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Check your changes before creating this scheme"
end
end
end
end
context "and I select to create a scheme" do
before do
click_link "Create scheme"
end
it "adds scheme to the list of schemes" do
expect(page).to have_content "Supported housing schemes"
expect(page).to have_content scheme.id_to_display
expect(page).to have_content scheme.service_name
expect(page).to have_content scheme.owning_organisation.name
expect(page).to have_content scheme.managing_organisation.name
expect(page).to have_content "#{scheme.owning_organisation.name} has been created."
end
end
end
end
end
end
end
end
end
end
end
context "when editing a scheme" do

Loading…
Cancel
Save