Browse Source

CLDC-512: Display answered fields (#38)

* Add tests for prepopulating answered questions

* Move test values to the factory
pull/40/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
e095e94009
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      spec/factories/case_log.rb
  2. 22
      spec/features/case_log_spec.rb
  3. 2
      spec/helpers/tasklist_helper_spec.rb

2
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 }

22
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('_', ' ')}")

2
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

Loading…
Cancel
Save