diff --git a/spec/features/form/helpers.rb b/spec/features/form/helpers.rb index 546404af9..2cb784966 100644 --- a/spec/features/form/helpers.rb +++ b/spec/features/form/helpers.rb @@ -22,4 +22,63 @@ module Helpers fill_in("user[password]", with: user.password) click_button("Sign in") end + + def fill_in_and_save_scheme_details + 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 + + 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 diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index aa80a3b99..59a387e98 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" +require_relative "form/helpers" RSpec.describe "Schemes scheme Features" do + include Helpers 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,70 +90,54 @@ RSpec.describe "Schemes scheme Features" do click_button("Submit") end + it "allows navigating to the schemes from the home page" do + expect(page).to have_link("Schemes", href: "/schemes") + end + context "when viewing list of schemes" do - it "displays the link to the schemes" do - expect(page).to have_link("Schemes", href: "/schemes") + before do + click_link "Schemes", href: "/schemes" end - context "when I click schemes" do - before do - click_link "Schemes", href: "/schemes" - end - - it "shows list of schemes" do - schemes.each do |scheme| - expect(page).to have_content(scheme.id) - end + 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 - 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 - 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 + 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 want to clear results" do - it "there is link to clear the search results" do - expect(page).to have_link("Clear search") - end + it "allows searching the schemes by scheme code" do + fill_in("search", with: scheme_to_search.id_to_display) + click_button("Search") + expect(page).to have_content(scheme_to_search.id_to_display) + end - it "displays all schemes after I clear the search results" do - click_link("Clear search") - expect(page).to have_content(scheme_to_search.id_to_display) - schemes.each do |scheme| - expect(page).to have_content(scheme.id_to_display) - end - end - end - end + 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| + expect(page).to have_content(scheme.id_to_display) 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,6 +208,9 @@ RSpec.describe "Schemes scheme Features" do end context "when creating a new scheme" do + let!(:organisation) { FactoryBot.create(:organisation, name: "FooBar") } + let(:scheme) { Scheme.first } + before do Scheme.destroy_all click_link "Schemes", href: "/schemes" @@ -249,291 +238,235 @@ 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 - expect(page).to have_content "What client group is this scheme intended for?" - end - - context "when I press the back button" do - before 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" - expect(page).to have_content "What is this type of scheme?" - expect(page).to have_content "Who provides the support services used by this scheme?" - 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 - 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 - expect(page).to have_content "Does this scheme provide for another client group?" - end - - context "when I press the back button" 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 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 - 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 + it "allows to navigate back and fill in the scheme details" do + fill_in_and_save_scheme_details + click_link "Back" + 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" + expect(page).to have_content "What is this type of scheme?" + expect(page).to have_content "Who provides the support services used by this scheme?" + expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" + 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 + 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 - context "when I select the secondary group" do - before do - choose "Homeless families with support needs" - click_button "Save and continue" - end + 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 - it "lets me select level of support" do - expect(page).to have_content "What support does this scheme provide?" - end + 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" + 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 I press the back button" do - before do - click_link "Back" - end + 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 - 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 + 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 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 + 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" + 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 I select the support answers" do - before do - choose "Low level" - choose "Very short stay" - click_button "Save and continue" - end + 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 - it "lets me add location" do - expect(page).to have_content "Add a location to this scheme" - end + 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 - click_link "Back" - end + 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" + expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group") + expect(page).to have_content "What is the other client group?" + 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 + 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 - 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 adding a location" do + before do + create_and_save_a_scheme + 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 add location" do + expect(page).to have_content "Add a location to this scheme" + end - it "lets me check my answers" do - expect(page).to have_content "Check your changes before creating this scheme" - end + it "lets me navigate back to support questions" do + click_link "Back" + 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 select to view locations" do - before do - click_link "Locations" - end + 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 - it "displays information about locations" do - expect(page).to have_content "Locations" - expect(page).to have_content "#{scheme.locations.count} location" - end + 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 "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" - expect(page).to have_content "None" - end - end + 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 "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 + context "when viewing locations" do + before do + create_and_save_a_scheme - it "lets me check my answers" do - expect(page).to have_content "Check your changes before creating this scheme" - end + fill_in_and_save_location + click_link "Locations" + end - context "when I select to view locations" do - before do - click_link "Locations" - end + 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 another location" do - expect(page).to have_content "Locations" - expect(page).to have_content "#{scheme.locations.count} location" - end + 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 - 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 + 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 - context "when changing location details" do - before 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 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 - 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 - end + context "when changing location details" do + before do + create_and_save_a_scheme + fill_in_and_save_second_location + click_link "Locations" + end - context "when changing answers" do - it "displays change links" do - assert_selector "a", text: "Change", count: 13 - 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" + 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 - context "when changing details" do - before do - click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first) - end + context "when changing scheme answers" do + before do + create_and_save_a_scheme + fill_in_and_save_location + end - it "allows changing details questions" do - expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true") + it "displays change links" do + assert_selector "a", text: "Change", count: 13 + end - fill_in "Scheme name", with: "Example" - click_button "Save and continue" + 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") - expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") - expect(page).to have_content "Example" - end + fill_in "Scheme name", with: "Example" + click_button "Save and continue" - context "when I press the back button" do - before do - click_link "Back" - end + expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") + expect(page).to have_content "Example" + 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 + 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" + 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 - context "and I select to create a scheme" do - before do - click_link "Create scheme" - end + context "when selecting 'create a scheme'" do + before do + create_and_save_a_scheme + fill_in_and_save_location + 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.owning_organisation.name} has been created." - end - end - end - end - end - 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.owning_organisation.name} has been created." end end