Browse Source

Display correct answer/change link for the checkboxes in the checck answers page (#99)

pull/101/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
79def05518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/helpers/check_answers_helper.rb
  2. 2
      app/views/form/_check_answers_table.html.erb
  3. 13
      spec/features/case_log_spec.rb

11
app/helpers/check_answers_helper.rb

@ -37,9 +37,14 @@ module CheckAnswersHelper
form.next_page(page_name)
end
def create_update_answer_link(case_log_answer, case_log_id, page)
link_name = case_log_answer.blank? ? "Answer" : "Change"
link_to(link_name, "/case_logs/#{case_log_id}/#{page}", class: "govuk-link").html_safe
def create_update_answer_link(case_log, question_title, page, form)
question = form.questions_for_page(page)[question_title]
link_name = if question["type"] == "checkbox"
question["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
def create_next_missing_question_link(case_log_id, subsection, case_log, form)

2
app/views/form/_check_answers_table.html.erb

@ -7,7 +7,7 @@
<%= form.get_answer_label(@case_log, question_title) %>
</dd>
<dd class="govuk-summary-list__actions">
<%= create_update_answer_link(@case_log[question_title], @case_log.id, page)%>
<%= create_update_answer_link(@case_log, question_title, page, form)%>
</dd>
</div>
</dl>

13
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")

Loading…
Cancel
Save