From e095e940092b7abcb9fe2175a15ec81b4beaae0d Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:15:06 +0100 Subject: [PATCH] CLDC-512: Display answered fields (#38) * Add tests for prepopulating answered questions * Move test values to the factory --- spec/factories/case_log.rb | 2 ++ spec/features/case_log_spec.rb | 22 ++++++++++++++++------ spec/helpers/tasklist_helper_spec.rb | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index e2f132c53..d55408242 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -5,6 +5,8 @@ FactoryBot.define do status { 0 } tenant_code { "TH356" } postcode { "SW2 6HI" } + previous_postcode { "P0 5ST" } + tenant_age { "12" } end trait :submitted do status { 1 } diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index b86320615..238897c94 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -15,6 +15,12 @@ RSpec.describe "Test Features" do household_number_of_other_members: { type: "numeric", answer: 2 }, } + def fill_in_number_question(case_log_id, question, value) + visit("/case_logs/#{case_log_id}/#{question}") + fill_in("case-log-#{question.to_s.dasherize}-field", with: value) + click_button("Save and continue") + end + def answer_all_questions_in_income_subsection visit("/case_logs/#{empty_case_log.id}/net_income") fill_in("case-log-net-income-field", with: 18_000) @@ -130,6 +136,16 @@ RSpec.describe "Test Features" do fill_in("case-log-support-charge-field", with: 4) expect(page).to have_field("case-log-total-charge-field", with: "10") end + + it "displays number answers in inputs if they are already saved" do + visit("/case_logs/#{id}/previous_postcode") + expect(page).to have_field("case-log-previous-postcode-field", with: "P0 5ST") + end + + it "displays text answers in inputs if they are already saved" do + visit("/case_logs/#{id}/tenant_age") + expect(page).to have_field("case-log-tenant-age-field", with: "12") + end end describe "Back link directs correctly" do @@ -164,12 +180,6 @@ RSpec.describe "Test Features" do let(:subsection) { "household_characteristics" } context "when the user needs to check their answers for a subsection" do - def fill_in_number_question(case_log_id, question, value) - visit("/case_logs/#{case_log_id}/#{question}") - fill_in("case-log-#{question.to_s.dasherize}-field", with: value) - click_button("Save and continue") - end - it "can be visited by URL" do visit("case_logs/#{id}/#{subsection}/check_answers") expect(page).to have_content("Check the answers you gave for #{subsection.tr('_', ' ')}") diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index b8fbaae0f..ec07092f6 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -73,7 +73,7 @@ RSpec.describe TasklistHelper do it "returns the number of sections in progress" do @form = Form.new(2021, 2022) - expect(get_sections_count(@form, case_log, :in_progress)).to eq(1) + expect(get_sections_count(@form, case_log, :in_progress)).to eq(2) end it "returns 0 for invalid state" do