Browse Source

WIP passing feature tests

juris_katrina_test
JG 3 years ago
parent
commit
687dc3d14a
  1. 17
      app/controllers/schemes_controller.rb
  2. 2
      app/views/schemes/check_answers.html.erb
  3. 4
      app/views/schemes/edit_name.html.erb
  4. 308
      spec/features/schemes_spec.rb

17
app/controllers/schemes_controller.rb

@ -26,8 +26,9 @@ class SchemesController < ApplicationController
def create
@scheme = Scheme.new(scheme_params)
if @scheme.save
if @scheme.support_services_provider.eql?"The same organisation that owns the housing stock"
if scheme_params[:support_services_provider] == "The same organisation that owns the housing stock"
redirect_to scheme_primary_client_group_path(@scheme)
else
redirect_to scheme_support_services_provider_path(@scheme)
@ -135,7 +136,11 @@ private
when "support"
new_location_path
when "details"
if @scheme.support_services_provider.eql?"The same organisation that owns the housing stock"
scheme_primary_client_group_path(@scheme)
else
scheme_support_services_provider_path(@scheme)
end
when "edit-name"
scheme_path(@scheme)
end
@ -156,11 +161,15 @@ private
:support_services_provider,
:intended_stay)
required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive]
same_org_providing_support = required_params[:support_services_provider] == "The same organisation that owns the housing stock"
full_params = same_org_providing_support ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params
full_params[:sensitive] = full_params[:sensitive].to_i if full_params[:sensitive]
if current_user.data_coordinator?
required_params[:owning_organisation_id] = current_user.organisation_id
full_params[:owning_organisation_id] = current_user.organisation_id
end
required_params
full_params
end
def search_term

2
app/views/schemes/check_answers.html.erb

@ -13,7 +13,7 @@
<%= summary_list.row do |row| %>
<% row.key { attr[:name].eql?("Registered under Care Standards Act 2000") ? "Registered under Care Standards Act 2000" : attr[:name].to_s.humanize } %>
<% row.value { details_html(attr) } %>
<% row.action(text: "Change", href: scheme_edit_name_path(scheme_id: @scheme.id)) if attr[:edit] %>
<% row.action(text: "Change", href: scheme_edit_name_path(scheme_id: @scheme.id, check_answers: true)) if attr[:edit] %>
<% end %>
<% end %>
<% end %>

4
app/views/schemes/edit_name.html.erb

@ -40,6 +40,10 @@
<%= f.hidden_field :page, value: "edit-name" %>
<% if request.query_parameters["check_answers"] %>
<%= f.hidden_field :check_answers, value: "true" %>
<% end %>
<%= f.govuk_submit "Save changes" %>
</div>
</div>

308
spec/features/schemes_spec.rb

@ -271,7 +271,6 @@ RSpec.describe "Schemes scheme Features" 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 "Which organisation manages this scheme"
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?"
@ -480,155 +479,22 @@ RSpec.describe "Schemes scheme Features" do
context "when changing answers" do
it "displays change links" do
assert_selector "a", text: "Change", count: 12
assert_selector "a", text: "Change", count: 3
end
context "when changing details" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
click_link("Change", href: "/schemes/#{scheme.id}/edit-name?check_answers=true", match: :first)
end
it "allows changing details questions" do
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
expect(page).to have_current_path("/schemes/#{scheme.id}/edit-name?check_answers=true")
fill_in "Scheme name", with: "Example"
choose "Direct access hostel"
choose "Yes – registered care home providing nursing care"
click_button "Save and continue"
click_button "Save changes"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Example"
expect(page).to have_content "Yes – registered care home providing nursing care"
end
context "when I press the back button" do
before do
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
context "when changing primary client group" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/primary-client-group?check_answers=true")
end
it "allows changing primary-client-group question" do
expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group?check_answers=true")
choose "Older people with support needs"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Older people with support needs"
end
context "when I press the back button" do
before do
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
context "when changing confirm secondary group answer" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true")
end
it "allows changing confirm-secondary-client-group question to yes" do
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true")
choose "Yes"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true")
choose "People at risk of domestic violence"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "People at risk of domestic violence"
end
context "when I press the back button" do
before do
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
context "when allows changing confirm-secondary-client-group question to no" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true")
end
it "allows changing confirm-secondary-client-group question to no" do
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true")
choose "No"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).not_to have_content "Secondary client group"
end
end
context "when changing secondary-client-group question" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/secondary-client-group?check_answers=true")
end
it "allows changing secondary-client-group question" do
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true")
choose "People at risk of domestic violence"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "People at risk of domestic violence"
end
context "when I press the back button" do
before do
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
context "when changing support questions" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/support?check_answers=true", match: :first)
end
it "allows changing support questions" do
expect(page).to have_current_path("/schemes/#{scheme.id}/support?check_answers=true")
choose "Resettlement support"
choose "Medium stay"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new")
expect(page).to have_content "Add a location to this scheme"
end
context "when I press the back button" do
@ -667,6 +533,7 @@ RSpec.describe "Schemes scheme Features" do
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"
@ -699,9 +566,19 @@ RSpec.describe "Schemes scheme Features" do
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")
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
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
@ -790,6 +667,12 @@ RSpec.describe "Schemes scheme Features" do
context "when I select the support answers" 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-wheelchair-adaptation-no-field"
choose "location-add-another-location-no-field"
choose "Floating support"
choose "Very short stay"
click_button "Save and continue"
@ -819,8 +702,9 @@ RSpec.describe "Schemes scheme Features" do
context "when I add location to the scheme" do
before do
click_link "Add a location"
fill_in "Postcode", with: "SW1P 4DF"
fill_in "Location name (optional)", with: "Some name"
fill_in "Name (optional)", with: "Some name"
fill_in "Total number of units at this location", with: 1
choose "Self-contained house"
choose "location-wheelchair-adaptation-no-field"
@ -853,7 +737,7 @@ RSpec.describe "Schemes scheme Features" do
before do
click_link "Add a location"
fill_in "Postcode", with: "XX1 1XX"
fill_in "Location name (optional)", with: "Other name"
fill_in "Name (optional)", with: "Other name"
fill_in "Total number of units at this location", with: 2
choose "Self-contained house"
choose "location-wheelchair-adaptation-no-field"
@ -899,155 +783,22 @@ RSpec.describe "Schemes scheme Features" do
context "when changing answers" do
it "displays change links" do
assert_selector "a", text: "Change", count: 12
assert_selector "a", text: "Change", count: 3
end
context "when changing details" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first)
click_link("Change", href: "/schemes/#{scheme.id}/edit-name?check_answers=true", match: :first)
end
it "allows changing details questions" do
expect(page).to have_current_path("/schemes/#{scheme.id}/details?check_answers=true")
expect(page).to have_current_path("/schemes/#{scheme.id}/edit-name?check_answers=true")
fill_in "Scheme name", with: "Example"
choose "Direct access hostel"
choose "Yes – registered care home providing nursing care"
click_button "Save and continue"
click_button "Save changes"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Example"
expect(page).to have_content "Yes – registered care home providing nursing care"
end
context "when I press the back button" do
before do
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
context "when changing primary client group" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/primary-client-group?check_answers=true")
end
it "allows changing primary-client-group question" do
expect(page).to have_current_path("/schemes/#{scheme.id}/primary-client-group?check_answers=true")
choose "Older people with support needs"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Older people with support needs"
end
context "when I press the back button" do
before do
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
context "when changing confirm secondary group answer" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true")
end
it "allows changing confirm-secondary-client-group question to yes" do
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true")
choose "Yes"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true")
choose "People at risk of domestic violence"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "People at risk of domestic violence"
end
context "when I press the back button" do
before do
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
context "when allows changing confirm-secondary-client-group question to no" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true")
end
it "allows changing confirm-secondary-client-group question to no" do
expect(page).to have_current_path("/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true")
choose "No"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).not_to have_content "Secondary client group"
end
end
context "when changing secondary-client-group question" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/secondary-client-group?check_answers=true")
end
it "allows changing secondary-client-group question" do
expect(page).to have_current_path("/schemes/#{scheme.id}/secondary-client-group?check_answers=true")
choose "People at risk of domestic violence"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "People at risk of domestic violence"
end
context "when I press the back button" do
before do
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
context "when changing support questions" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/support?check_answers=true", match: :first)
end
it "allows changing support questions" do
expect(page).to have_current_path("/schemes/#{scheme.id}/support?check_answers=true")
choose "Resettlement support"
choose "Medium stay"
click_button "Save and continue"
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/new")
expect(page).to have_content "Add a location to this scheme"
end
context "when I press the back button" do
@ -1085,6 +836,7 @@ RSpec.describe "Schemes scheme Features" do
end
end
end
end
context "when editing a scheme" do
context "when I visit schemes page" do

Loading…
Cancel
Save