Browse Source

Push fixes #11

pull/264/head
Stéphane Meny 3 years ago
parent
commit
91bf7e210a
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 34
      spec/models/form/page_spec.rb

34
spec/models/form/page_spec.rb

@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Page, type: :model do RSpec.describe Form::Page, type: :model do
subject { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:case_log) { FactoryBot.build(:case_log) } let(:case_log) { FactoryBot.build(:case_log) }
let(:form) { case_log.form } let(:form) { case_log.form }
@ -15,63 +15,63 @@ RSpec.describe Form::Page, type: :model do
let(:page_definition) { subsection_definition["pages"][page_id] } let(:page_definition) { subsection_definition["pages"][page_id] }
it "has an id" do it "has an id" do
expect(subject.id).to eq(page_id) expect(page.id).to eq(page_id)
end end
it "has a header" do it "has a header" do
expect(subject.header).to eq("Test header") expect(page.header).to eq("Test header")
end end
it "has a description" do it "has a description" do
expect(subject.description).to eq("Some extra text for the page") expect(page.description).to eq("Some extra text for the page")
end end
it "has questions" do it "has questions" do
expected_questions = %w[earnings incfreq] expected_questions = %w[earnings incfreq]
expect(subject.questions.map(&:id)).to eq(expected_questions) expect(page.questions.map(&:id)).to eq(expected_questions)
end end
it "has soft validations" do it "has soft validations" do
expected_soft_validations = %w[override_net_income_validation] expected_soft_validations = %w[override_net_income_validation]
expect(subject.soft_validations.map(&:id)).to eq(expected_soft_validations) expect(page.soft_validations.map(&:id)).to eq(expected_soft_validations)
end end
it "has a soft_validation helper" do it "has a soft_validation helper" do
expect(subject.has_soft_validations?).to be true expect(page.has_soft_validations?).to be true
end end
it "has expected form responses" do it "has expected form responses" do
expected_responses = %w[earnings incfreq override_net_income_validation] expected_responses = %w[earnings incfreq override_net_income_validation]
expect(subject.expected_responses.map(&:id)).to eq(expected_responses) expect(page.expected_responses.map(&:id)).to eq(expected_responses)
end end
context "page with conditional questions" do context "with a page having conditional questions" do
let(:page_id) { "housing_benefit" } let(:page_id) { "housing_benefit" }
it "knows which questions are not conditional" do it "knows which questions are not conditional" do
expected_non_conditional_questions = %w[hb] expected_non_conditional_questions = %w[hb]
expect(subject.non_conditional_questions.map(&:id)) expect(page.non_conditional_questions.map(&:id))
.to eq(expected_non_conditional_questions) .to eq(expected_non_conditional_questions)
end end
end end
context "for a given case log" do context "with a case log" do
let(:case_log) { FactoryBot.build(:case_log, :in_progress) } let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
it "knows if it's been routed to" do it "knows if it's been routed to" do
expect(subject.routed_to?(case_log)).to be true expect(page.routed_to?(case_log)).to be true
end end
context "given routing conditions" do context "with routing conditions" do
let(:page_id) { "dependent_page" } let(:page_id) { "dependent_page" }
it "evaluates not met conditions correctly" do it "evaluates not met conditions correctly" do
expect(subject.routed_to?(case_log)).to be false expect(page.routed_to?(case_log)).to be false
end end
it "evaluates not conditions correctly" do it "evaluates not conditions correctly" do
case_log.incfreq = "Weekly" case_log.incfreq = "Weekly"
expect(subject.routed_to?(case_log)).to be true expect(page.routed_to?(case_log)).to be true
end end
end end
@ -82,8 +82,8 @@ RSpec.describe Form::Page, type: :model do
let(:completed_case_log) { FactoryBot.build(:case_log, :completed, incfreq: "Weekly") } let(:completed_case_log) { FactoryBot.build(:case_log, :completed, incfreq: "Weekly") }
it "evaluates the sections dependencies" do it "evaluates the sections dependencies" do
expect(subject.routed_to?(case_log)).to be false expect(page.routed_to?(case_log)).to be false
expect(subject.routed_to?(completed_case_log)).to be true expect(page.routed_to?(completed_case_log)).to be true
end end
end end
end end

Loading…
Cancel
Save