Browse Source

check questions instead of page names for get answered questions total

pull/25/head
Kat 3 years ago committed by MadeTech Dushan
parent
commit
336aaea1e0
  1. 7
      app/helpers/check_answers_helper.rb
  2. 18
      spec/helpers/check_answers_helper_spec.rb

7
app/helpers/check_answers_helper.rb

@ -1,10 +1,9 @@
module CheckAnswersHelper module CheckAnswersHelper
def get_answered_questions_total(subsection_pages, case_log) def get_answered_questions_total(subsection_pages, case_log)
questions = [] questions = subsection_pages.values.map do |page|
subsection_pages.keys.each do |page| page["questions"].keys
questions << page
end end
return questions.count {|question| !(case_log[question].blank?)} return questions.count {|questions_for_page| questions_for_page.none? { |question| case_log[question].blank?}}
end end

18
spec/helpers/check_answers_helper_spec.rb

@ -0,0 +1,18 @@
require "rails_helper"
RSpec.describe CheckAnswersHelper do
describe "Get answered questions total" do
let!(:case_log) { FactoryBot.create(:case_log) }
@form = Form.new(2021, 2022)
subsection_pages = @form.pages_for_subsection("income_and_benefits")
it "returns 0 if no questions are answered" do
expect(get_answered_questions_total(subsection_pages, case_log)).to equal(0)
end
it "returns 0 if only 1 question on a page gets answered" do
case_log["net_income"] = "123"
expect(get_answered_questions_total(subsection_pages, case_log)).to equal(0)
end
end
end
Loading…
Cancel
Save