diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 8e23ac340..fed58b71e 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -26,9 +26,13 @@ module CheckAnswersHelper form.next_page(page_name) end - def create_update_answer_link(question_title, case_log, form) + def create_update_answer_link(question_title, question_info, case_log, form) page = form.page_for_question(question_title) - link_name = case_log[question_title].blank? ? "Answer" : "Change" + link_name = if question_info["type"] == "checkbox" + question_info["answer_options"].keys.any? { |key| case_log[key] == "Yes" } ? "Change" : "Answer" + else + case_log[question_title].blank? ? "Answer" : "Change" + end link_to(link_name, "/case_logs/#{case_log.id}/#{page}", class: "govuk-link").html_safe end diff --git a/app/views/form/_check_answers_table.html.erb b/app/views/form/_check_answers_table.html.erb index 69ff5cae2..972a3dd58 100644 --- a/app/views/form/_check_answers_table.html.erb +++ b/app/views/form/_check_answers_table.html.erb @@ -7,7 +7,7 @@ <%= form.get_answer_label(@case_log, question_title) %>
- <%= create_update_answer_link(question_title, @case_log, form) %> + <%= create_update_answer_link(question_title, question_info, @case_log, form) %>
diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 76e5b0d6d..f8e877e36 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -301,6 +301,19 @@ RSpec.describe "Test Features" do expect(page).to have_link("Change", href: "/case_logs/#{empty_case_log.id}/person_1_age") end + it "should have a change link for answered questions" do + visit("/case_logs/#{empty_case_log.id}/household_needs/check_answers") + assert_selector "a", text: /Answer\z/, count: 4 + assert_selector "a", text: "Change", count: 0 + visit("/case_logs/#{empty_case_log.id}/accessibility_requirements") + check("case-log-accessibility-requirements-housingneeds-c-field") + click_button("Save and continue") + visit("/case_logs/#{empty_case_log.id}/household_needs/check_answers") + assert_selector "a", text: /Answer\z/, count: 3 + assert_selector "a", text: "Change", count: 1 + expect(page).to have_link("Change", href: "/case_logs/#{empty_case_log.id}/accessibility_requirements") + end + it "should have a link pointing to the first question if no questions are answered" do visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers") expect(page).to have_content("You answered 0 of 4 questions")