Browse Source

Update hidden_in_check_answers for managing organisation (#1046)

* Hide managing organisation question in check answers if it was not routed to

* Add a routed_to check to the default hidden_in_check_answers
pull/1055/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
e16051f1aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/form/lettings/questions/managing_organisation.rb
  2. 4
      app/models/form/question.rb
  3. 2
      spec/features/lettings_log_spec.rb
  4. 19
      spec/models/form/lettings/questions/managing_organisation_spec.rb

4
app/models/form/lettings/questions/managing_organisation.rb

@ -45,9 +45,9 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
true true
end end
def hidden_in_check_answers?(_log, user = nil) def hidden_in_check_answers?(log, user = nil)
@current_user = user @current_user = user
@current_user.nil? @current_user.nil? || !@page.routed_to?(log, user)
end end
def enabled def enabled

4
app/models/form/question.rb

@ -86,11 +86,11 @@ class Form::Question
conditional_on.all? { |condition| evaluate_condition(condition, log) } conditional_on.all? { |condition| evaluate_condition(condition, log) }
end end
def hidden_in_check_answers?(log, _current_user = nil) def hidden_in_check_answers?(log, current_user = nil)
if hidden_in_check_answers.is_a?(Hash) if hidden_in_check_answers.is_a?(Hash)
form.depends_on_met(hidden_in_check_answers["depends_on"], log) form.depends_on_met(hidden_in_check_answers["depends_on"], log)
else else
hidden_in_check_answers hidden_in_check_answers || !page.routed_to?(log, current_user)
end end
end end

2
spec/features/lettings_log_spec.rb

@ -89,7 +89,7 @@ RSpec.describe "Lettings Log Features" do
log_id = page.current_path.scan(/\d/).join log_id = page.current_path.scan(/\d/).join
visit("lettings-logs/#{log_id}/setup/check-answers") visit("lettings-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Housing provider #{support_user.organisation.name}") expect(page).to have_content("Housing provider #{support_user.organisation.name}")
expect(page).to have_content("You have answered 3 of 9 questions") expect(page).to have_content("You have answered 2 of 8 questions")
end end
end end
end end

19
spec/models/form/lettings/questions/managing_organisation_spec.rb

@ -142,6 +142,10 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end end
describe "#hidden_in_check_answers?" do describe "#hidden_in_check_answers?" do
before do
allow(page).to receive(:routed_to?).and_return(true)
end
context "when user present" do context "when user present" do
let(:user) { create(:user) } let(:user) { create(:user) }
@ -151,11 +155,22 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end end
context "when user not provided" do context "when user not provided" do
let(:user) { create(:user, :support) }
it "is not hidden in check answers" do it "is not hidden in check answers" do
expect(question.hidden_in_check_answers?(nil)).to be true expect(question.hidden_in_check_answers?(nil)).to be true
end end
end end
context "when the page is not routed to" do
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) }
let(:log) { create(:lettings_log, owning_organisation: user.organisation) }
before do
allow(page).to receive(:routed_to?).and_return(false)
end
it "is hidden in check answers" do
expect(question.hidden_in_check_answers?(log, user)).to be true
end
end
end end
end end

Loading…
Cancel
Save