Browse Source

CLDC-891: Add hidden text to change links (and answer links) (#222)

* Add hidden text to change links

This was missing, the hidden text users the check answer label so that the
two will be consistent with each other.

* update chsnge link test

* Update app/models/form/question.rb

Co-authored-by: Paul Robert Lloyd <paulrobertlloyd@users.noreply.github.com>

* Update app/models/form/question.rb

Co-authored-by: Paul Robert Lloyd <paulrobertlloyd@users.noreply.github.com>

* update change link test

* update answer links too

* add hidden text for answer links

* fix failing tests

* update answer link with hidden text creation is now less repetetive

Co-authored-by: Paul Robert Lloyd <paulrobertlloyd@users.noreply.github.com>
pull/225/head
Dushan 3 years ago committed by GitHub
parent
commit
d582a571d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/models/form/question.rb
  2. 10
      spec/features/form/check_answers_page_spec.rb
  3. 4
      spec/models/form/question_spec.rb

11
app/models/form/question.rb

@ -69,11 +69,12 @@ class Form::Question
end
def update_answer_link_name(case_log)
if type == "checkbox"
answer_options.keys.any? { |key| case_log[key] == "Yes" } ? "Change" : "Answer"
else
case_log[id].blank? ? "Answer" : "Change"
end
link_type = if type == "checkbox"
answer_options.keys.any? { |key| case_log[key] == "Yes" } ? "Change" : "Answer"
else
case_log[id].blank? ? "Answer" : "Change"
end
"#{link_type}<span class=\"govuk-visually-hidden\"> #{check_answer_label.to_s.downcase}</span>".html_safe
end
def completed?(case_log)

10
spec/features/form/check_answers_page_spec.rb

@ -59,9 +59,11 @@ RSpec.describe "Form Check Answers Page" do
expect(page).to have_content("Non-binary")
end
# Regex explanation: match the string "Answer" but not if it's follow by "the missing questions"
# This way only the links in the table will get picked up
it "should have an answer link for questions missing an answer" do
visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers")
assert_selector "a", text: /Answer\z/, count: 4
assert_selector "a", text: /Answer (?!the missing questions)/, count: 4
assert_selector "a", text: "Change", count: 0
expect(page).to have_link("Answer", href: "/logs/#{empty_case_log.id}/person-1-age")
end
@ -69,20 +71,20 @@ RSpec.describe "Form Check Answers Page" do
it "should have a change link for answered questions" do
fill_in_number_question(empty_case_log.id, "age1", 28, "person-1-age")
visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers")
assert_selector "a", text: /Answer\z/, count: 3
assert_selector "a", text: /Answer (?!the missing questions)/, count: 3
assert_selector "a", text: "Change", count: 1
expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/person-1-age")
end
it "should have a change link for answered questions" do
visit("/logs/#{empty_case_log.id}/household-needs/check-answers")
assert_selector "a", text: /Answer\z/, count: 5
assert_selector "a", text: /Answer (?!the missing questions)/, count: 5
assert_selector "a", text: "Change", count: 0
visit("/logs/#{empty_case_log.id}/accessibility-requirements")
check("case-log-accessibility-requirements-housingneeds-c-field")
click_button("Save and continue")
visit("/logs/#{empty_case_log.id}/household-needs/check-answers")
assert_selector "a", text: /Answer\z/, count: 4
assert_selector "a", text: /Answer (?!the missing questions)/, count: 4
assert_selector "a", text: "Change", count: 1
expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/accessibility-requirements")
end

4
spec/models/form/question_spec.rb

@ -105,9 +105,9 @@ RSpec.describe Form::Question, type: :model do
end
it "has an update answer link text helper" do
expect(subject.update_answer_link_name(case_log)).to eq("Answer")
expect(subject.update_answer_link_name(case_log)).to eq("Answer<span class=\"govuk-visually-hidden\"> income</span>")
case_log[question_id] = 5
expect(subject.update_answer_link_name(case_log)).to eq("Change")
expect(subject.update_answer_link_name(case_log)).to eq("Change<span class=\"govuk-visually-hidden\"> income</span>")
end
context "when type is date" do

Loading…
Cancel
Save