From f1c2f6ba67c161ffe9e8116393827ab41c719bcb Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 7 Feb 2022 13:40:28 +0000 Subject: [PATCH] Conditional suffix only applies to check answers --- app/models/form/question.rb | 6 +++--- app/views/form/_numeric_question.html.erb | 2 +- config/forms/2021_2022.json | 6 +++--- spec/fixtures/forms/2021_2022.json | 6 +++--- spec/views/form/page_view_spec.rb | 23 +++++++++++++++++++++-- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 267209e85..9be3d1680 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -148,8 +148,8 @@ private end ANSWER_SUFFIX_LABELS = { - "Weekly" => " every week", - "Monthly" => " every month", - "Yearly" => " every year", + "Weekly": " every week", + "Monthly": " every month", + "Yearly": " every year", }.freeze end diff --git a/app/views/form/_numeric_question.html.erb b/app/views/form/_numeric_question.html.erb index 606d2294c..1e9702310 100644 --- a/app/views/form/_numeric_question.html.erb +++ b/app/views/form/_numeric_question.html.erb @@ -7,6 +7,6 @@ min: question.min, max: question.max, step: question.step, width: question.width, :readonly => question.read_only?, prefix_text: question.prefix.to_s, - suffix_text: question.suffix.to_s, + suffix_text: question.suffix.is_a?(String) ? question.suffix : nil, **stimulus_html_attributes(question) %> diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index d1ebe74f7..0946bc00e 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -2327,9 +2327,9 @@ "width": 5, "prefix": "£", "suffix": [ - { "label": "every week", "depends_on" : { "incfreq": "Weekly"} }, - { "label": "every month", "depends_on" : { "incfreq": "Monthly"} }, - { "label": "every month", "depends_on" : { "incfreq": "Yearly"} } + { "label": "every week", "depends_on" : { "incfreq": "Weekly" } }, + { "label": "every month", "depends_on" : { "incfreq": "Monthly" } }, + { "label": "every month", "depends_on" : { "incfreq": "Yearly" } } ] }, "incfreq": { diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index e509df0af..e675ccea5 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -359,9 +359,9 @@ "width": 5, "prefix": "£", "suffix": [ - { "label": "every week", "depends_on" : { "incfreq": "Weekly"} }, - { "label": "every month", "depends_on" : { "incfreq": "Monthly"} }, - { "label": "every month", "depends_on" : { "incfreq": "Yearly"} } + { "label": "every week", "depends_on" : { "incfreq": "Weekly" } }, + { "label": "every month", "depends_on" : { "incfreq": "Monthly" } }, + { "label": "every month", "depends_on" : { "incfreq": "Yearly" } } ] }, "incfreq": { diff --git a/spec/views/form/page_view_spec.rb b/spec/views/form/page_view_spec.rb index e75f650cf..5f653dfa6 100644 --- a/spec/views/form/page_view_spec.rb +++ b/spec/views/form/page_view_spec.rb @@ -1,5 +1,4 @@ require "rails_helper" -require_relative "../../request_helper" RSpec.describe "form/page" do let(:case_log) { FactoryBot.create(:case_log, :in_progress) } @@ -19,7 +18,6 @@ RSpec.describe "form/page" do end before do - RequestHelper.stub_http_requests assign(:case_log, case_log) assign(:page, page) assign(:subsection, subsection) @@ -70,6 +68,27 @@ RSpec.describe "form/page" do expect(rendered).to match(/govuk-input__suffix/) expect(rendered).to match("every week") end + + context "when the suffix is conditional and not a string" do + let(:question_attributes) do + { + type: "numeric", + prefix: "£", + suffix: [ + { "label": "every week", "depends_on": { "incfreq": "Weekly" } }, + { "label": "every month", "depends_on": { "incfreq": "Monthly" } }, + { "label": "every month", "depends_on": { "incfreq": "Yearly" } }, + ], + } + end + + it "does not render the suffix" do + expect(rendered).not_to match(/govuk-input__suffix/) + expect(rendered).not_to match("every week") + expect(rendered).not_to match("every month") + expect(rendered).not_to match("every year") + end + end end context "with a question containing extra guidance" do