Browse Source

Route to check your answers after any changes are made to the scheme. Display change for all editable fields

pull/797/head
Kat 3 years ago
parent
commit
45abb2d221
  1. 6
      app/controllers/schemes_controller.rb
  2. 4
      app/helpers/check_answers_helper.rb
  3. 4
      app/views/schemes/_scheme_summary_list_row.html.erb
  4. 2
      app/views/schemes/check_answers.html.erb
  5. 76
      spec/features/schemes_spec.rb

6
app/controllers/schemes_controller.rb

@ -57,8 +57,8 @@ class SchemesController < ApplicationController
if @scheme.errors.empty? && @scheme.update(scheme_params)
if scheme_params[:confirmed] == "true"
@scheme.locations.each {|location| location.update!(confirmed:true)}
end
if check_answers
redirect_to scheme_path(@scheme)
elsif check_answers
if confirm_secondary_page? page
redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true")
else
@ -180,7 +180,7 @@ private
scheme_details_path(@scheme)
end
when "edit-name"
scheme_path(@scheme)
scheme_check_answers_path(@scheme)
when "check-answers"
schemes_path(scheme_id: @scheme.id)
end

4
app/helpers/check_answers_helper.rb

@ -11,6 +11,10 @@ module CheckAnswersHelper
end
end
def can_change_scheme_answer?(attribute_name, scheme)
editable_attributes = current_user.support? ? ["Name", "Confidential information", "Housing stock owned by"] : ["Name", "Confidential information"]
!scheme.confirmed? || editable_attributes.include?(attribute_name)
end
private
def answered_questions_count(subsection, case_log, current_user)

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

@ -1,4 +1,4 @@
<div class="<%= "govuk-summary-list__row #{scheme.confirmed? && attribute[:name] != 'Name' ? 'govuk-summary-list__row--no-actions' : ''}" %>">
<div class="<%= "govuk-summary-list__row #{scheme.confirmed? && !["Name", "Confidential information", "Housing stock owned by"].include?(attribute[:name]) ? 'govuk-summary-list__row--no-actions' : ''}" %>">
<dt class="govuk-summary-list__key">
<%= attribute[:name].to_s %>
</dt>
@ -14,7 +14,7 @@
<%= details_html(attribute) %>
</dd>
<% end %>
<% if !scheme.confirmed? || attribute[:name] == "Name" %>
<% if can_change_scheme_answer?(attribute[:name], scheme) %>
<dd class="govuk-summary-list__actions">
<a class="govuk-link" href="<%= change_link %>">Change</a>
</dd>

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

@ -10,7 +10,7 @@
<dl class="govuk-summary-list">
<% @scheme.check_details_attributes.each do |attr| %>
<% next if current_user.data_coordinator? && attr[:name] == ("owned by") %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_details_path(@scheme, check_answers: true) } %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: @scheme.confirmed? ? scheme_edit_name_path(@scheme) : scheme_details_path(@scheme, check_answers: true) } %>
<% end %>
<% if !@scheme.arrangement_type_same? %>
<% @scheme.check_support_services_provider_attributes.each do |attr| %>

76
spec/features/schemes_spec.rb

@ -284,6 +284,27 @@ RSpec.describe "Schemes scheme Features" do
expect(page).not_to have_button("Create scheme")
end
it "allows you to edit the newly added location" do
click_link 'Locations'
expect(page).to have_link(nil , href: /edit/)
end
context "when you click save" do
it "takes you to view location tab and displays a banner" do
click_button "Save"
expect(page.current_url.split("/").last).to eq("locations")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("udpated")
end
it "does not let you edit the saved location" do
click_button "Save"
click_link "Back"
click_link 'Change'
expect(page.current_url.split("/").last).to eq("edit-name")
end
end
context "when you click to view the scheme details" do
before do
click_link("Scheme")
@ -451,6 +472,7 @@ RSpec.describe "Schemes scheme Features" do
it "lets me check my answers after adding a location" do
fill_in_and_save_location
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content "Check your changes before creating this scheme"
end
@ -704,9 +726,10 @@ RSpec.describe "Schemes scheme Features" do
click_button "Save changes"
end
it "lets me see amended details on the show page" do
it "lets me see amended details on the check answers page" do
expect(page).to have_content "FooBar"
expect(page).to have_current_path("/schemes/#{scheme.id}")
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
assert_selector "a", text: "Change", count: 3
end
end
end
@ -846,6 +869,55 @@ RSpec.describe "Schemes scheme Features" do
end
end
context "when I am signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) }
let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation_id: user.organisation_id) }
let!(:scheme_to_search) { FactoryBot.create(:scheme) }
before do
visit("/logs")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: user.password)
click_button("Sign in")
end
context "when editing a scheme" do
context "when I visit schemes page" do
before do
visit("schemes")
end
context "when I click to see individual scheme" do
let(:scheme) { schemes.first }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do
click_link(scheme.service_name)
end
context "when I click to change scheme name" do
before do
click_link("Change", href: "/schemes/#{scheme.id}/edit-name", match: :first)
end
context "when I edit details" do
before do
fill_in "Scheme name", with: "FooBar"
check "This scheme contains confidential information"
click_button "Save changes"
end
it "lets me see amended details on the check answers page" do
expect(page).to have_content "FooBar"
expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers")
expect(page).to have_link("Change", href: /schemes\/#{scheme.id}\/edit-name/, count: 2)
end
end
end
end
end
end
end
context "when selecting a scheme" do
let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) }
let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation, managing_organisation: user.organisation, arrangement_type: "The same organisation that owns the housing stock") }

Loading…
Cancel
Save