Browse Source

shuffle schemes feature tests

pull/767/head
Kat 3 years ago
parent
commit
1c2327931e
  1. 59
      spec/features/form/helpers.rb
  2. 531
      spec/features/schemes_spec.rb

59
spec/features/form/helpers.rb

@ -22,4 +22,63 @@ module Helpers
fill_in("user[password]", with: user.password) fill_in("user[password]", with: user.password)
click_button("Sign in") click_button("Sign in")
end 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 end

531
spec/features/schemes_spec.rb

@ -1,6 +1,8 @@
require "rails_helper" require "rails_helper"
require_relative "form/helpers"
RSpec.describe "Schemes scheme Features" do RSpec.describe "Schemes scheme Features" do
include Helpers
context "when viewing list of schemes" do context "when viewing list of schemes" do
context "when I am signed as a coordinator user and there are schemes in the database" 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) } 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") click_button("Submit")
end 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 context "when viewing list of schemes" do
it "displays the link to the schemes" do before do
expect(page).to have_link("Schemes", href: "/schemes") click_link "Schemes", href: "/schemes"
end end
context "when I click schemes" do it "shows a list of schemes" do
before do schemes.each do |scheme|
click_link "Schemes", href: "/schemes" expect(page).to have_content(scheme.id)
end expect(page).to have_link(scheme.service_name)
expect(page).to have_content(scheme.primary_client_group)
it "shows list of schemes" do
schemes.each do |scheme|
expect(page).to have_content(scheme.id)
end
end end
end
context "when I search for a specific scheme" do it "displays a search bar" 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_field("search") expect(page).to have_content("Search by scheme name, code or postcode")
expect(page).to have_content("Search by scheme name, code or postcode") expect(page).to have_button("Search")
expect(page).to have_button("Search") end
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
context "when I want to clear results" do it "allows searching the schemes by scheme code" do
it "there is link to clear the search results" do fill_in("search", with: scheme_to_search.id_to_display)
expect(page).to have_link("Clear search") click_button("Search")
end expect(page).to have_content(scheme_to_search.id_to_display)
end
it "displays all schemes after I clear the search results" do it "allows clearing the search results" do
click_link("Clear search") fill_in("search", with: scheme_to_search.id_to_display)
expect(page).to have_content(scheme_to_search.id_to_display) click_button("Search")
schemes.each do |scheme| click_link("Clear search")
expect(page).to have_content(scheme.id_to_display) expect(page).to have_content(scheme_to_search.id_to_display)
end schemes.each do |scheme|
end expect(page).to have_content(scheme.id_to_display)
end
end
end end
end end
end end
context "when viewing individual scheme" do context "when viewing individual scheme" do
let!(:schemes) { FactoryBot.create_list(:scheme, 5) }
context "when I visit schemes page" do context "when I visit schemes page" do
before do before do
visit("schemes") visit("schemes")
end 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 context "when I click to see individual scheme" do
let(:scheme) { schemes.first } let(:scheme) { schemes.first }
@ -222,6 +208,9 @@ RSpec.describe "Schemes scheme Features" do
end end
context "when creating a new scheme" do context "when creating a new scheme" do
let!(:organisation) { FactoryBot.create(:organisation, name: "FooBar") }
let(:scheme) { Scheme.first }
before do before do
Scheme.destroy_all Scheme.destroy_all
click_link "Schemes", href: "/schemes" 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?" expect(page).to have_content "Who provides the support services used by this scheme?"
end end
context "when I fill in scheme details and I press save I see primary client group section" do it "lets me fill in the primary client group" do
let(:scheme) { Scheme.first } fill_in_and_save_scheme_details
expect(page).to have_content "What client group is this scheme intended for?"
before do end
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 confirm the secondary group" do it "allows to navigate back and fill in the scheme details" do
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group") fill_in_and_save_scheme_details
expect(page).to have_content "Does this scheme provide for another client group?" click_link "Back"
end 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 primary client group question after amending scheme details" do
it "returns to the secondary client group question" do fill_in_and_save_scheme_details
click_button "Save and continue" click_link "Back"
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group") click_button "Save and continue"
end expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group")
end end
end
context "when I select the secondary group" do it "allows confirming if the scheme provides for secondary group details" do
before do fill_in_and_save_scheme_details
choose "Homeless families with support needs" fill_in_and_save_primary_client_group
click_button "Save and continue" expect(page).to have_content "Does this scheme provide for another client group?"
end end
it "lets me select level of support" do it "allows amending primary client group after navigating back from secondary client group confirmation question" do
expect(page).to have_content "What support does this scheme provide?" fill_in_and_save_scheme_details
end 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 it "returns to the secondary group details confirmation question after amending primary client group" do
before do fill_in_and_save_scheme_details
click_link "Back" fill_in_and_save_primary_client_group
end 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 it "allows selecting secondary client group if the scheme provides for it" do
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group") fill_in_and_save_scheme_details
expect(page).to have_content "What is the other client group?" fill_in_and_save_primary_client_group
end 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 "allows amending secondary client group confirmation question after navigating from secondary client group question" do
it "returns to the support question" do fill_in_and_save_scheme_details
click_button "Save and continue" fill_in_and_save_primary_client_group
expect(page).to have_current_path("/schemes/#{scheme.id}/support") fill_in_and_save_secondary_client_group_confirmation
end click_link "Back"
end expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group")
end expect(page).to have_content "Does this scheme provide for another client group?"
end
context "when I select the support answers" do it "returns to the secondary group details question after amending secondary group details confirmation" do
before do fill_in_and_save_scheme_details
choose "Low level" fill_in_and_save_primary_client_group
choose "Very short stay" fill_in_and_save_secondary_client_group_confirmation
click_button "Save and continue" click_link "Back"
end click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group")
end
it "lets me add location" do it "allows selecting the level of support" do
expect(page).to have_content "Add a location to this scheme" fill_in_and_save_scheme_details
end 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 it "allows amending secondary client group question after navigating from level of support" do
before do fill_in_and_save_scheme_details
click_link "Back" fill_in_and_save_primary_client_group
end 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 it "returns to the level of support question after amending secondary group details" do
expect(page).to have_current_path("/schemes/#{scheme.id}/support") fill_in_and_save_scheme_details
expect(page).to have_content "What support does this scheme provide?" fill_in_and_save_primary_client_group
end 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 context "when adding a location" do
it "returns to the add location page" do before do
click_button "Save and continue" create_and_save_a_scheme
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new") end
end
end
end
context "when I add location to the scheme" do it "lets me add location" do
before do expect(page).to have_content "Add a location to this scheme"
fill_in "Postcode", with: "SW1P 4DF" end
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 it "lets me navigate back to support questions" do
expect(page).to have_content "Check your changes before creating this scheme" click_link "Back"
end 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 it "returns to the add location page after amending the support question" do
before do click_link "Back"
click_link "Locations" click_button "Save and continue"
end expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new")
end
it "displays information about locations" do it "lets me check my answers after adding a location" do
expect(page).to have_content "Locations" fill_in_and_save_location
expect(page).to have_content "#{scheme.locations.count} location" expect(page).to have_content "Check your changes before creating this scheme"
end end
it "displays information about newly created location" do it "lets me check my answers after adding a second location" do
expect(page).to have_content "SW1P4DF" fill_in_and_save_location
expect(page).to have_content "Some name" click_link "Add a location"
expect(page).to have_content "Self-contained house" fill_in_and_save_second_location
expect(page).to have_content "None" expect(page).to have_content "Check your changes before creating this scheme"
end end
end end
context "and I select to add another location a scheme" do context "when viewing locations" do
before do before do
click_link "Add a location" create_and_save_a_scheme
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 fill_in_and_save_location
expect(page).to have_content "Check your changes before creating this scheme" click_link "Locations"
end end
context "when I select to view locations" do it "displays information about a single location" do
before do expect(page).to have_content "Locations"
click_link "Locations" expect(page).to have_content "#{scheme.locations.count} location"
end end
it "displays information about another location" do it "displays information about the first created location" do
expect(page).to have_content "Locations" expect(page).to have_content "SW1P4DF"
expect(page).to have_content "#{scheme.locations.count} location" expect(page).to have_content "Some name"
end expect(page).to have_content "Self-contained house"
expect(page).to have_content "None"
end
it "displays information about newly created location" do it "displays information about another location" do
expect(page).to have_content "XX11XX" click_link "Add a location"
expect(page).to have_content "Other name" fill_in_and_save_second_location
expect(page).to have_content "Self-contained house" expect(page).to have_content "Locations"
end expect(page).to have_content "#{scheme.locations.count} location"
end
context "when changing location details" do it "displays information about newly created location" do
before do click_link "Add a location"
click_link "XX11XX" fill_in_and_save_second_location
fill_in "Postcode", with: "ZZ1 1ZZ" expect(page).to have_content "XX11XX"
choose "location-mobility-type-wheelchair-user-standard-field" expect(page).to have_content "Other name"
click_button "Save and continue" expect(page).to have_content "Self-contained house"
end end
end
it "displays changed location" do context "when changing location details" do
expect(page).to have_content "Locations" before do
expect(page).to have_content "#{scheme.locations.count} location" create_and_save_a_scheme
expect(page).to have_content "ZZ11ZZ" fill_in_and_save_second_location
expect(page).to have_content("Wheelchair-user standard") click_link "Locations"
end end
end
end
end
context "when changing answers" do it "displays changed location" do
it "displays change links" do click_link "XX11XX"
assert_selector "a", text: "Change", count: 13 fill_in "Postcode", with: "ZZ1 1ZZ"
end 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 context "when changing scheme answers" do
before do before do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first) create_and_save_a_scheme
end fill_in_and_save_location
end
it "allows changing details questions" do it "displays change links" do
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true") assert_selector "a", text: "Change", count: 13
end
fill_in "Scheme name", with: "Example" it "allows changing details questions" do
click_button "Save and continue" 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") fill_in "Scheme name", with: "Example"
expect(page).to have_content "Example" click_button "Save and continue"
end
context "when I press the back button" do expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
before do expect(page).to have_content "Example"
click_link "Back" end
end
it "lets me select the support answers" do it "lets me select the support answers after navigating back" do
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
expect(page).to have_content "Check your changes before creating this scheme" click_link "Back"
end expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
end 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 before do
click_link "Create scheme" create_and_save_a_scheme
end fill_in_and_save_location
click_link "Create scheme"
end
it "adds scheme to the list of schemes" do it "adds scheme to the list of schemes" do
expect(page).to have_content "Supported housing schemes" expect(page).to have_content "Supported housing schemes"
expect(page).to have_content scheme.id_to_display expect(page).to have_content scheme.id_to_display
expect(page).to have_content scheme.service_name 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
expect(page).to have_content "#{scheme.owning_organisation.name} has been created." expect(page).to have_content "#{scheme.owning_organisation.name} has been created."
end
end
end
end
end
end
end end
end end

Loading…
Cancel
Save