From 7a215965da3f60c0077d86edd4b97ac75c5d67ea Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Mon, 13 Sep 2021 11:36:27 +0100 Subject: [PATCH] Add min and max to numeric question partial --- .../questions/_numeric_question.html.erb | 2 +- .../_numeric_question.html.erb_spec.rb | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/views/questions/_numeric_question.html.erb b/app/views/questions/_numeric_question.html.erb index f9aff6327..400df305b 100644 --- a/app/views/questions/_numeric_question.html.erb +++ b/app/views/questions/_numeric_question.html.erb @@ -1,4 +1,4 @@
- + max=<%= maximum %> />
\ No newline at end of file diff --git a/spec/views/questions/_numeric_question.html.erb_spec.rb b/spec/views/questions/_numeric_question.html.erb_spec.rb index f1c03bd0d..97519ff7e 100644 --- a/spec/views/questions/_numeric_question.html.erb_spec.rb +++ b/spec/views/questions/_numeric_question.html.erb_spec.rb @@ -1,11 +1,25 @@ describe 'questions/_numeric_question.html.erb' do - context 'when given a label' do + context 'when given a label and value constraints' do let(:label) { "Test Label" } + let(:min) { "1" } + let(:max) { "150" } + let(:locals) { {label: label, minimum: min, maximum: max} } - it 'displays a numeric entry field' do - render :partial => 'numeric_question', locals: { label: label } + before(:each) do + render :partial => 'numeric_question', locals: locals + end + + it 'displays a numeric entry field with a label' do expect(rendered).to have_selector('//input[@type="number"]') expect(rendered).to have_selector("//label[contains('#{label}')]") end + + it 'validates for a given minimum input' do + expect(rendered).to have_selector("//input[@min=#{min}]") + end + + it 'validates for a given maximum input' do + expect(rendered).to have_selector("//input[@max=#{max}]") + end end end \ No newline at end of file