15 changed files with 306 additions and 2 deletions
@ -0,0 +1,16 @@
|
||||
class Form::Sales::Pages::Buyer1Income < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "buyer_1_income" |
||||
@header = "" |
||||
@description = "" |
||||
@subsection = subsection |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::Buyer1IncomeKnown.new(nil, nil, self), |
||||
Form::Sales::Questions::Buyer1Income.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
@ -0,0 +1,14 @@
|
||||
class Form::Sales::Questions::Buyer1Income < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "income1" |
||||
@check_answer_label = "Buyer 1’s gross annual income" |
||||
@header = "Buyer 1’s gross annual income" |
||||
@type = "numeric" |
||||
@page = page |
||||
@min = 0 |
||||
@step = 1 |
||||
@width = 5 |
||||
@prefix = "£" |
||||
end |
||||
end |
@ -0,0 +1,32 @@
|
||||
class Form::Sales::Questions::Buyer1IncomeKnown < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "income1nk" |
||||
@check_answer_label = "Buyer 1’s gross annual income" |
||||
@header = "Do you know buyer 1’s annual income?" |
||||
@type = "radio" |
||||
@answer_options = ANSWER_OPTIONS |
||||
@page = page |
||||
@hint_text = "What counts as income? |
||||
|
||||
You should include any income from: |
||||
employment |
||||
pensions |
||||
investments |
||||
Universal Credit |
||||
|
||||
Don't include: |
||||
National Insurance (NI) contributions and tax |
||||
housing benefit |
||||
child benefit |
||||
council tax support" |
||||
@conditional_for = { |
||||
"income1" => [0], |
||||
} |
||||
end |
||||
|
||||
ANSWER_OPTIONS = { |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
}.freeze |
||||
end |
@ -0,0 +1,12 @@
|
||||
class Form::Sales::Sections::Finances < ::Form::Section |
||||
def initialize(id, hsh, form) |
||||
super |
||||
@id = "finances" |
||||
@label = "Finances" |
||||
@description = "" |
||||
@form = form |
||||
@subsections = [ |
||||
Form::Sales::Subsections::IncomeBenefitsAndOutgoings.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
@ -0,0 +1,15 @@
|
||||
class Form::Sales::Subsections::IncomeBenefitsAndOutgoings < ::Form::Subsection |
||||
def initialize(id, hsh, section) |
||||
super |
||||
@id = "income_benefits_and_outgoings" |
||||
@label = "Income, benefits and outgoings" |
||||
@section = section |
||||
@depends_on = [{ "setup" => "completed" }] |
||||
end |
||||
|
||||
def pages |
||||
@pages ||= [ |
||||
Form::Sales::Pages::Buyer1Income.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
@ -0,0 +1,6 @@
|
||||
class AddIncome1ToSalesLog < ActiveRecord::Migration[7.0] |
||||
change_table :sales_logs, bulk: true do |t| |
||||
t.column :income1, :int |
||||
t.column :income1nk, :int |
||||
end |
||||
end |
@ -0,0 +1,33 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::Buyer1Income, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection) } |
||||
|
||||
let(:page_id) { nil } |
||||
let(:page_definition) { nil } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
|
||||
it "has correct subsection" do |
||||
expect(page.subsection).to eq(subsection) |
||||
end |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[income1nk income1]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("buyer_1_income") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to eq("") |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to be_nil |
||||
end |
||||
end |
@ -0,0 +1,51 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::Buyer1IncomeKnown, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("income1nk") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Do you know buyer 1’s annual income?") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Buyer 1’s gross annual income") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("radio") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to eq({ |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
}) |
||||
end |
||||
|
||||
it "has correct conditional for" do |
||||
expect(question.conditional_for).to eq({ |
||||
"income1" => [0], |
||||
}) |
||||
end |
||||
|
||||
# TODO |
||||
xit "has the correct hint" do |
||||
expect(question.hint_text).to eq("") |
||||
end |
||||
end |
@ -0,0 +1,53 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::Buyer1Income, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("income1") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Buyer 1’s gross annual income") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Buyer 1’s gross annual income") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("numeric") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
it "has correct width" do |
||||
expect(question.width).to eq(5) |
||||
end |
||||
|
||||
it "has correct step" do |
||||
expect(question.step).to eq(1) |
||||
end |
||||
|
||||
it "has correct prefix" do |
||||
expect(question.prefix).to eq("£") |
||||
end |
||||
|
||||
it "has correct min" do |
||||
expect(question.min).to eq(0) |
||||
end |
||||
end |
@ -0,0 +1,33 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Sections::Finances, type: :model do |
||||
subject(:section) { described_class.new(section_id, section_definition, form) } |
||||
|
||||
let(:section_id) { nil } |
||||
let(:section_definition) { nil } |
||||
let(:form) { instance_double(Form) } |
||||
|
||||
it "has correct form" do |
||||
expect(section.form).to eq(form) |
||||
end |
||||
|
||||
it "has correct subsections" do |
||||
expect(section.subsections.map(&:id)).to eq( |
||||
%w[ |
||||
income_benefits_and_outgoings |
||||
], |
||||
) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(section.id).to eq("finances") |
||||
end |
||||
|
||||
it "has the correct label" do |
||||
expect(section.label).to eq("Finances") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(section.description).to eq("") |
||||
end |
||||
end |
@ -0,0 +1,33 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndOutgoings, type: :model do |
||||
subject(:subsection) { described_class.new(subsection_id, subsection_definition, section) } |
||||
|
||||
let(:subsection_id) { nil } |
||||
let(:subsection_definition) { nil } |
||||
let(:section) { instance_double(Form::Sales::Sections::Household) } |
||||
|
||||
it "has correct section" do |
||||
expect(subsection.section).to eq(section) |
||||
end |
||||
|
||||
it "has correct pages" do |
||||
expect(subsection.pages.map(&:id)).to eq( |
||||
%w[ |
||||
buyer_1_income |
||||
], |
||||
) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(subsection.id).to eq("income_benefits_and_outgoings") |
||||
end |
||||
|
||||
it "has the correct label" do |
||||
expect(subsection.label).to eq("Income, benefits and outgoings") |
||||
end |
||||
|
||||
it "has correct depends on" do |
||||
expect(subsection.depends_on).to eq([{ "setup" => "completed" }]) |
||||
end |
||||
end |
Loading…
Reference in new issue