Browse Source

A bit grim but I guess it works

pull/708/head
baarkerlounger 3 years ago
parent
commit
325a3a751a
  1. 8
      app/controllers/form_controller.rb
  2. 2
      spec/features/form/form_navigation_spec.rb
  3. 3
      spec/features/form/progressive_total_field_spec.rb
  4. 1
      spec/features/form/saving_data_spec.rb

8
app/controllers/form_controller.rb

@ -53,6 +53,7 @@ class FormController < ApplicationController
messages.each { |message| @case_log.errors.add field.to_sym, message } messages.each { |message| @case_log.errors.add field.to_sym, message }
end end
end end
session["fields"].each { |field, value| @case_log[field] = value } if session["fields"]
@subsection = @case_log.form.subsection_for_page(page) @subsection = @case_log.form.subsection_for_page(page)
@page = @case_log.form.get_page(page.id) @page = @case_log.form.get_page(page.id)
if @page.routed_to?(@case_log, current_user) if @page.routed_to?(@case_log, current_user)
@ -127,23 +128,28 @@ private
end end
def mandatory_questions_with_no_response(responses_for_page) def mandatory_questions_with_no_response(responses_for_page)
session["fields"] = {}
calc_questions = @page.questions.map(&:result_field)
@page.questions.select do |question| @page.questions.select do |question|
next if calc_questions.include?(question.id)
question_is_required?(question) && question_missing_response?(responses_for_page, question) question_is_required?(question) && question_missing_response?(responses_for_page, question)
end end
end end
def question_is_required?(question) def question_is_required?(question)
CaseLog::OPTIONAL_FIELDS.exclude?(question.id) && CaseLog::OPTIONAL_FIELDS.exclude?(question.id) &&
@page.questions.map(&:result_field).exclude?(question.id) &&
@page.subsection.applicable_questions(@case_log).map(&:id).include?(question.id) @page.subsection.applicable_questions(@case_log).map(&:id).include?(question.id)
end end
def question_missing_response?(responses_for_page, question) def question_missing_response?(responses_for_page, question)
if %w[checkbox validation_override].include?(question.type) if %w[checkbox validation_override].include?(question.type)
question.answer_options.keys.reject { |x| x.match(/divider/) }.all? do |option| question.answer_options.keys.reject { |x| x.match(/divider/) }.all? do |option|
session["fields"][option] = @case_log[option] = params["case_log"][question.id].include?(option) ? 1 : 0
params["case_log"][question.id].exclude?(option) params["case_log"][question.id].exclude?(option)
end end
else else
session["fields"][question.id] = @case_log[question.id] = responses_for_page[question.id]
responses_for_page[question.id].nil? || responses_for_page[question.id].blank? responses_for_page[question.id].nil? || responses_for_page[question.id].blank?
end end
end end

2
spec/features/form/form_navigation_spec.rb

@ -139,7 +139,7 @@ RSpec.describe "Form Navigation" do
context "when the page has a main and conditional question" do context "when the page has a main and conditional question" do
context "when the conditional question is required but not answered" do context "when the conditional question is required but not answered" do
xit "shows a validation error for the conditional question", js: true do it "shows a validation error for the conditional question", js: true do
visit("/logs/#{id}/armed-forces") visit("/logs/#{id}/armed-forces")
choose("case-log-armedforces-1-field", allow_label_click: true) choose("case-log-armedforces-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")

3
spec/features/form/progressive_total_field_spec.rb

@ -41,6 +41,9 @@ RSpec.describe "Accessible Automcomplete" do
expect(find("#case-log-tcharge-field").value).to eq("5600.00") expect(find("#case-log-tcharge-field").value).to eq("5600.00")
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_selector(".govuk-error-summary") expect(page).to have_selector(".govuk-error-summary")
fill_in("case-log-scharge-field", with: nil)
fill_in("case-log-pscharge-field", with: nil)
fill_in("case-log-supcharg-field-error", with: nil)
fill_in("case-log-brent-field", with: 500) fill_in("case-log-brent-field", with: 500)
expect(find("#case-log-tcharge-field").value).to eq("500.00") expect(find("#case-log-tcharge-field").value).to eq("500.00")
fill_in("case-log-supcharg-field-error", with: 50) fill_in("case-log-supcharg-field-error", with: 50)

1
spec/features/form/saving_data_spec.rb

@ -26,7 +26,6 @@ RSpec.describe "Form Saving Data" do
tenancycode: { type: "text", answer: "BZ737", path: "tenant-code-test" }, tenancycode: { type: "text", answer: "BZ737", path: "tenant-code-test" },
age1: { type: "numeric", answer: 25, path: "person_1_age" }, age1: { type: "numeric", answer: 25, path: "person_1_age" },
sex1: { type: "radio", answer: { "F" => "Female" }, path: "person_1_gender" }, sex1: { type: "radio", answer: { "F" => "Female" }, path: "person_1_gender" },
hhmemb: { type: "numeric", answer: 3, path: "household_number_of_members" },
} }
end end

Loading…
Cancel
Save