Browse Source

Conditional suffix only applies to check answers

pull/273/head
baarkerlounger 3 years ago committed by MadeTech Dushan
parent
commit
f1c2f6ba67
  1. 6
      app/models/form/question.rb
  2. 2
      app/views/form/_numeric_question.html.erb
  3. 6
      config/forms/2021_2022.json
  4. 6
      spec/fixtures/forms/2021_2022.json
  5. 23
      spec/views/form/page_view_spec.rb

6
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

2
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)
%>

6
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": {

6
spec/fixtures/forms/2021_2022.json vendored

@ -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": {

23
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

Loading…
Cancel
Save