Browse Source

Display LA correctly

CLDC-2068-request-and-validate-UPRN
Jack S 2 years ago
parent
commit
58c3e9c2df
  1. 2
      app/models/form/sales/questions/address_line1.rb
  2. 2
      app/models/form/sales/questions/property_local_authority.rb
  3. 24
      spec/helpers/question_view_helper_spec.rb
  4. 30
      spec/models/form/sales/questions/address_line1_spec.rb
  5. 12
      spec/models/form/sales/questions/property_local_authority_spec.rb

2
app/models/form/sales/questions/address_line1.rb

@ -28,6 +28,8 @@ class Form::Sales::Questions::AddressLine1 < ::Form::Question
end
def get_extra_check_answer_value(log)
return unless log.is_la_inferred?
la = LocalAuthority.find_by(code: log.la)&.name
la.presence

2
app/models/form/sales/questions/property_local_authority.rb

@ -13,6 +13,6 @@ class Form::Sales::Questions::PropertyLocalAuthority < ::Form::Question
end
def hidden_in_check_answers?(log, _current_user = nil)
log.saledate && log.saledate.year >= 2023
log.saledate && log.saledate.year >= 2023 && log.is_la_inferred?
end
end

24
spec/helpers/question_view_helper_spec.rb

@ -44,9 +44,15 @@ RSpec.describe QuestionViewHelper do
describe "legend" do
subject(:question_view_helper) { legend(question, page_header, conditional) }
question_stub = Struct.new(:header) do
def question_number_string(_conditional)
nil
let(:question_stub) do
Struct.new(:header) do
def question_number_string(_conditional)
nil
end
def plain_label
nil
end
end
end
@ -83,7 +89,17 @@ RSpec.describe QuestionViewHelper do
end
context "when viewing a question with a plain label" do
let(:question) { OpenStruct.new(header: "Some question header", plain_label: true) }
let(:question_stub) do
Struct.new(:header) do
def question_number_string(_conditional)
nil
end
def plain_label
true
end
end
end
it "returns an options hash with nil size" do
expect(question_view_helper).to eq({ size: nil, tag: "div", text: "Some question header" })

30
spec/models/form/sales/questions/address_line1_spec.rb

@ -42,4 +42,34 @@ RSpec.describe Form::Sales::Questions::AddressLine1, type: :model do
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to be_nil
end
describe "has the correct get_extra_check_answer_value" do
context "when la is not present" do
let(:log) { create(:sales_log, la: nil) }
it "returns nil" do
expect(question.get_extra_check_answer_value(log)).to be_nil
end
end
context "when la is present but not inferred" do
let(:log) { create(:sales_log, la: "E09000003", is_la_inferred: false) }
it "returns nil" do
expect(question.get_extra_check_answer_value(log)).to be_nil
end
end
context "when la is present but inferred" do
let(:log) { create(:sales_log, la: "E09000003") }
before do
allow(log).to receive(:is_la_inferred?).and_return(true)
end
it "returns the la" do
expect(question.get_extra_check_answer_value(log)).to eq("Barnet")
end
end
end
end

12
spec/models/form/sales/questions/property_local_authority_spec.rb

@ -680,6 +680,18 @@ RSpec.describe Form::Sales::Questions::PropertyLocalAuthority, type: :model do
context "when saledate.year >= 2023" do
let(:log) { build(:sales_log, saledate: Time.zone.parse("2023-07-01")) }
it "returns true" do
expect(question.hidden_in_check_answers?(log)).to eq(false)
end
end
context "when saledate.year >= 2023 and la inferred" do
let(:log) { build(:sales_log, saledate: Time.zone.parse("2023-07-01")) }
before do
allow(log).to receive(:is_la_inferred?).and_return(true)
end
it "returns true" do
expect(question.hidden_in_check_answers?(log)).to eq(true)
end

Loading…
Cancel
Save