Browse Source

Update check answer label

pull/98/head
baarkerlounger 4 years ago
parent
commit
42b57fd326
  1. 8
      app/helpers/check_answers_helper.rb
  2. 2
      app/views/form/_check_answers_table.html.erb
  3. 13
      spec/features/case_log_spec.rb

8
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

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(question_title, @case_log, form) %>
<%= create_update_answer_link(question_title, question_info, @case_log, 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