Browse Source

Add hint text to numeric question

pull/21/head
Matthew Phelan 3 years ago
parent
commit
4a43c58ddc
  1. 3
      app/views/questions/_numeric_question.html.erb
  2. 44
      spec/views/questions/_numeric_question.html.erb_spec.rb

3
app/views/questions/_numeric_question.html.erb

@ -1,4 +1,7 @@
<div class="govuk-form-group"> <div class="govuk-form-group">
<label for="numeric_input"><%= label %></label> <label for="numeric_input"><%= label %></label>
<div id="numeric_hint" class="govuk-hint">
<%= hint_text %>
</div>
<input id="numeric_input" class="govuk-input govuk-input--width-20" type="number" min=<%= minimum %> max=<%= maximum %> /> <input id="numeric_input" class="govuk-input govuk-input--width-20" type="number" min=<%= minimum %> max=<%= maximum %> />
</div> </div>

44
spec/views/questions/_numeric_question.html.erb_spec.rb

@ -1,25 +1,31 @@
describe 'questions/_numeric_question.html.erb' do describe "questions/_numeric_question.html.erb" do
context 'when given a label and value constraints' do context "when given a label, value constraints and hint text" do
let(:label) { "Test Label" } let(:label) { "Test Label" }
let(:min) { "1" } let(:min) { "1" }
let(:max) { "150" } let(:max) { "150" }
let(:locals) { {label: label, minimum: min, maximum: max} } let(:hint_text) { "Some text that describes the question in more detail" }
let(:locals) { { label: label, minimum: min, maximum: max, hint_text: hint_text } }
before(:each) do before(:each) do
render :partial => 'numeric_question', locals: locals render partial: "numeric_question", locals: locals
end end
it 'displays a numeric entry field with a label' do it "displays a numeric entry field with a label" do
expect(rendered).to have_selector('//input[@type="number"]') expect(rendered).to have_selector('//input[@type="number"]')
expect(rendered).to have_selector("//label[contains('#{label}')]") expect(rendered).to have_selector("//label[contains('#{label}')]")
end end
it 'validates for a given minimum input' do it "validates for a given minimum input" do
expect(rendered).to have_selector("//input[@min=#{min}]") expect(rendered).to have_selector("//input[@min=#{min}]")
end end
it "validates for a given maximum input" do
expect(rendered).to have_selector("//input[@max=#{max}]")
end
it 'validates for a given maximum input' do it "displays hint text" do
expect(rendered).to have_selector("//input[@max=#{max}]") expect(rendered).to have_selector("//div[@class='govuk-hint']")
end expect(rendered).to have_css("#numeric_hint", text: hint_text.to_s)
end end
end
end end
Loading…
Cancel
Save