From 2f7fd7640ca303527b75992162fb19d26d9bb110 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 15 Dec 2022 10:09:20 +0000 Subject: [PATCH] Refactor age to reuse pages and questions (#1092) * Refactor age to reuse pages and questions * lint --- ...swers_summary_list_card_component.html.erb | 68 +-- app/models/form/sales/pages/person1_age.rb | 19 - app/models/form/sales/pages/person2_age.rb | 19 - app/models/form/sales/pages/person3_age.rb | 19 - app/models/form/sales/pages/person4_age.rb | 19 - app/models/form/sales/pages/person_age.rb | 29 ++ .../form/sales/questions/person1_age.rb | 16 - .../form/sales/questions/person1_age_known.rb | 31 -- .../form/sales/questions/person2_age.rb | 16 - .../form/sales/questions/person2_age_known.rb | 31 -- .../form/sales/questions/person3_age.rb | 16 - .../form/sales/questions/person3_age_known.rb | 31 -- .../form/sales/questions/person4_age.rb | 16 - .../form/sales/questions/person4_age_known.rb | 31 -- app/models/form/sales/questions/person_age.rb | 23 + .../form/sales/questions/person_age_known.rb | 38 ++ .../subsections/household_characteristics.rb | 12 +- .../form/sales/pages/person1_age_spec.rb | 37 -- .../form/sales/pages/person2_age_spec.rb | 35 -- .../form/sales/pages/person3_age_spec.rb | 35 -- .../form/sales/pages/person4_age_spec.rb | 35 -- .../form/sales/pages/person_age_spec.rb | 185 ++++++++ .../sales/questions/person1_age_known_spec.rb | 69 --- .../form/sales/questions/person1_age_spec.rb | 52 --- .../sales/questions/person2_age_known_spec.rb | 62 --- .../form/sales/questions/person2_age_spec.rb | 52 --- .../sales/questions/person3_age_known_spec.rb | 62 --- .../form/sales/questions/person3_age_spec.rb | 52 --- .../sales/questions/person4_age_known_spec.rb | 62 --- .../form/sales/questions/person4_age_spec.rb | 52 --- .../sales/questions/person_age_known_spec.rb | 400 ++++++++++++++++++ .../form/sales/questions/person_age_spec.rb | 285 +++++++++++++ .../household_characteristics_spec.rb | 4 + spec/models/form_handler_spec.rb | 4 +- 34 files changed, 1009 insertions(+), 908 deletions(-) delete mode 100644 app/models/form/sales/pages/person1_age.rb delete mode 100644 app/models/form/sales/pages/person2_age.rb delete mode 100644 app/models/form/sales/pages/person3_age.rb delete mode 100644 app/models/form/sales/pages/person4_age.rb create mode 100644 app/models/form/sales/pages/person_age.rb delete mode 100644 app/models/form/sales/questions/person1_age.rb delete mode 100644 app/models/form/sales/questions/person1_age_known.rb delete mode 100644 app/models/form/sales/questions/person2_age.rb delete mode 100644 app/models/form/sales/questions/person2_age_known.rb delete mode 100644 app/models/form/sales/questions/person3_age.rb delete mode 100644 app/models/form/sales/questions/person3_age_known.rb delete mode 100644 app/models/form/sales/questions/person4_age.rb delete mode 100644 app/models/form/sales/questions/person4_age_known.rb create mode 100644 app/models/form/sales/questions/person_age.rb create mode 100644 app/models/form/sales/questions/person_age_known.rb delete mode 100644 spec/models/form/sales/pages/person1_age_spec.rb delete mode 100644 spec/models/form/sales/pages/person2_age_spec.rb delete mode 100644 spec/models/form/sales/pages/person3_age_spec.rb delete mode 100644 spec/models/form/sales/pages/person4_age_spec.rb create mode 100644 spec/models/form/sales/pages/person_age_spec.rb delete mode 100644 spec/models/form/sales/questions/person1_age_known_spec.rb delete mode 100644 spec/models/form/sales/questions/person1_age_spec.rb delete mode 100644 spec/models/form/sales/questions/person2_age_known_spec.rb delete mode 100644 spec/models/form/sales/questions/person2_age_spec.rb delete mode 100644 spec/models/form/sales/questions/person3_age_known_spec.rb delete mode 100644 spec/models/form/sales/questions/person3_age_spec.rb delete mode 100644 spec/models/form/sales/questions/person4_age_known_spec.rb delete mode 100644 spec/models/form/sales/questions/person4_age_spec.rb create mode 100644 spec/models/form/sales/questions/person_age_known_spec.rb create mode 100644 spec/models/form/sales/questions/person_age_spec.rb diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb index 9b0c67872..d04283939 100644 --- a/app/components/check_answers_summary_list_card_component.html.erb +++ b/app/components/check_answers_summary_list_card_component.html.erb @@ -1,39 +1,41 @@ -
- <% if applicable_questions.first.check_answers_card_number != 0 && applicable_questions.first.check_answers_card_number.present? %> -
- <% if applicable_questions.first.check_answers_card_number == 1 %> -

Lead tenant

- <% end %> - <% if applicable_questions.first.check_answers_card_number > 1 %> -

Person <%= applicable_questions.first.check_answers_card_number %>

- <% end %> -
- <% end %> -
- <%= govuk_summary_list do |summary_list| %> - <% applicable_questions.each do |question| %> - <% summary_list.row do |row| %> - <% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %> - <% row.value do %> - <%= get_answer_label(question) %> - <% extra_value = question.get_extra_check_answer_value(log) %> - <% if extra_value %> - <%= extra_value %> +<% if applicable_questions.first %> +
+ <% if applicable_questions.first.check_answers_card_number != 0 && applicable_questions.first.check_answers_card_number.present? %> +
+ <% if applicable_questions.first.check_answers_card_number == 1 %> +

Lead tenant

+ <% end %> + <% if applicable_questions.first.check_answers_card_number > 1 %> +

Person <%= applicable_questions.first.check_answers_card_number %>

+ <% end %> +
+ <% end %> +
+ <%= govuk_summary_list do |summary_list| %> + <% applicable_questions.each do |question| %> + <% summary_list.row do |row| %> + <% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %> + <% row.value do %> + <%= get_answer_label(question) %> + <% extra_value = question.get_extra_check_answer_value(log) %> + <% if extra_value %> + <%= extra_value %> + <% end %> +
+ <% question.get_inferred_answers(log).each do |inferred_answer| %> + <%= inferred_answer %> + <% end %> <% end %> -
- <% question.get_inferred_answers(log).each do |inferred_answer| %> - <%= inferred_answer %> + <% if @log.collection_period_open? %> + <% row.action( + text: question.action_text(log), + href: question.action_href(log, question.page.id), + visually_hidden_text: question.check_answer_label.to_s.downcase, + ) %> <% end %> <% end %> - <% if @log.collection_period_open? %> - <% row.action( - text: question.action_text(log), - href: question.action_href(log, question.page.id), - visually_hidden_text: question.check_answer_label.to_s.downcase, - ) %> - <% end %> <% end %> <% end %> - <% end %> +
-
+<% end %> diff --git a/app/models/form/sales/pages/person1_age.rb b/app/models/form/sales/pages/person1_age.rb deleted file mode 100644 index d37533683..000000000 --- a/app/models/form/sales/pages/person1_age.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person1Age < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_1_age" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_1" => 1 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person1AgeKnown.new(nil, nil, self), - Form::Sales::Questions::Person1Age.new(nil, nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person2_age.rb b/app/models/form/sales/pages/person2_age.rb deleted file mode 100644 index 7654d6e46..000000000 --- a/app/models/form/sales/pages/person2_age.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person2Age < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_2_age" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_2" => 1 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person2AgeKnown.new(nil, nil, self), - Form::Sales::Questions::Person2Age.new(nil, nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person3_age.rb b/app/models/form/sales/pages/person3_age.rb deleted file mode 100644 index 965427e67..000000000 --- a/app/models/form/sales/pages/person3_age.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person3Age < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_3_age" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_3" => 1 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person3AgeKnown.new(nil, nil, self), - Form::Sales::Questions::Person3Age.new(nil, nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person4_age.rb b/app/models/form/sales/pages/person4_age.rb deleted file mode 100644 index 282699e44..000000000 --- a/app/models/form/sales/pages/person4_age.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Form::Sales::Pages::Person4Age < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "person_4_age" - @header = "" - @description = "" - @subsection = subsection - @depends_on = [ - { "details_known_4" => 1 }, - ] - end - - def questions - @questions ||= [ - Form::Sales::Questions::Person4AgeKnown.new(nil, nil, self), - Form::Sales::Questions::Person4Age.new(nil, nil, self), - ] - end -end diff --git a/app/models/form/sales/pages/person_age.rb b/app/models/form/sales/pages/person_age.rb new file mode 100644 index 000000000..b25284685 --- /dev/null +++ b/app/models/form/sales/pages/person_age.rb @@ -0,0 +1,29 @@ +class Form::Sales::Pages::PersonAge < ::Form::Page + def initialize(id, hsh, subsection) + super + @header = "" + @description = "" + @subsection = subsection + @depends_on = [ + { "details_known_#{person_display_number(PERSON_INDEX)}" => 1, "jointpur" => joint_purchase? ? 1 : 2 }, + ] + end + + PERSON_INDEX = { + "person_1_age" => 2, + "person_2_age" => 3, + "person_3_age" => 4, + "person_4_age" => 5, + "person_1_age_joint_purchase" => 3, + "person_2_age_joint_purchase" => 4, + "person_3_age_joint_purchase" => 5, + "person_4_age_joint_purchase" => 6, + }.freeze + + def questions + @questions ||= [ + Form::Sales::Questions::PersonAgeKnown.new("age#{person_database_number(PERSON_INDEX)}_known", nil, self), + Form::Sales::Questions::PersonAge.new("age#{person_database_number(PERSON_INDEX)}", nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/person1_age.rb b/app/models/form/sales/questions/person1_age.rb deleted file mode 100644 index aa12c948a..000000000 --- a/app/models/form/sales/questions/person1_age.rb +++ /dev/null @@ -1,16 +0,0 @@ -class Form::Sales::Questions::Person1Age < ::Form::Question - def initialize(id, hsh, page) - super - @id = "age3" - @check_answer_label = "Person 1’s age" - @header = "Age" - @type = "numeric" - @page = page - @width = 3 - @inferred_check_answers_value = { - "condition" => { "age3_known" => 1 }, - "value" => "Not known", - } - @check_answers_card_number = 3 - end -end diff --git a/app/models/form/sales/questions/person1_age_known.rb b/app/models/form/sales/questions/person1_age_known.rb deleted file mode 100644 index 3db103ab5..000000000 --- a/app/models/form/sales/questions/person1_age_known.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Form::Sales::Questions::Person1AgeKnown < ::Form::Question - def initialize(id, hsh, page) - super - @id = "age3_known" - @check_answer_label = "Person 1’s age known?" - @header = "Do you know person 1’s age?" - @type = "radio" - @answer_options = ANSWER_OPTIONS - @page = page - @hint_text = "" - @conditional_for = { - "age3" => [0], - } - @hidden_in_check_answers = { - "depends_on" => [ - { - "age3_known" => 0, - }, - { - "age3_known" => 1, - }, - ], - } - @check_answers_card_number = 3 - end - - ANSWER_OPTIONS = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }.freeze -end diff --git a/app/models/form/sales/questions/person2_age.rb b/app/models/form/sales/questions/person2_age.rb deleted file mode 100644 index a421b625a..000000000 --- a/app/models/form/sales/questions/person2_age.rb +++ /dev/null @@ -1,16 +0,0 @@ -class Form::Sales::Questions::Person2Age < ::Form::Question - def initialize(id, hsh, page) - super - @id = "age4" - @check_answer_label = "Person 2’s age" - @header = "Age" - @type = "numeric" - @page = page - @width = 3 - @inferred_check_answers_value = { - "condition" => { "age4_known" => 1 }, - "value" => "Not known", - } - @check_answers_card_number = 4 - end -end diff --git a/app/models/form/sales/questions/person2_age_known.rb b/app/models/form/sales/questions/person2_age_known.rb deleted file mode 100644 index 613312f45..000000000 --- a/app/models/form/sales/questions/person2_age_known.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Form::Sales::Questions::Person2AgeKnown < ::Form::Question - def initialize(id, hsh, page) - super - @id = "age4_known" - @check_answer_label = "Person 2’s age known?" - @header = "Do you know person 2’s age?" - @type = "radio" - @answer_options = ANSWER_OPTIONS - @page = page - @hint_text = "" - @conditional_for = { - "age4" => [0], - } - @hidden_in_check_answers = { - "depends_on" => [ - { - "age4_known" => 0, - }, - { - "age4_known" => 1, - }, - ], - } - @check_answers_card_number = 4 - end - - ANSWER_OPTIONS = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }.freeze -end diff --git a/app/models/form/sales/questions/person3_age.rb b/app/models/form/sales/questions/person3_age.rb deleted file mode 100644 index 139b4de16..000000000 --- a/app/models/form/sales/questions/person3_age.rb +++ /dev/null @@ -1,16 +0,0 @@ -class Form::Sales::Questions::Person3Age < ::Form::Question - def initialize(id, hsh, page) - super - @id = "age5" - @check_answer_label = "Person 3’s age" - @header = "Age" - @type = "numeric" - @page = page - @width = 3 - @inferred_check_answers_value = { - "condition" => { "age5_known" => 1 }, - "value" => "Not known", - } - @check_answers_card_number = 5 - end -end diff --git a/app/models/form/sales/questions/person3_age_known.rb b/app/models/form/sales/questions/person3_age_known.rb deleted file mode 100644 index 78bdff239..000000000 --- a/app/models/form/sales/questions/person3_age_known.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Form::Sales::Questions::Person3AgeKnown < ::Form::Question - def initialize(id, hsh, page) - super - @id = "age5_known" - @check_answer_label = "Person 3’s age known?" - @header = "Do you know person 3’s age?" - @type = "radio" - @answer_options = ANSWER_OPTIONS - @page = page - @hint_text = "" - @conditional_for = { - "age5" => [0], - } - @hidden_in_check_answers = { - "depends_on" => [ - { - "age5_known" => 0, - }, - { - "age5_known" => 1, - }, - ], - } - @check_answers_card_number = 5 - end - - ANSWER_OPTIONS = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }.freeze -end diff --git a/app/models/form/sales/questions/person4_age.rb b/app/models/form/sales/questions/person4_age.rb deleted file mode 100644 index bf7675026..000000000 --- a/app/models/form/sales/questions/person4_age.rb +++ /dev/null @@ -1,16 +0,0 @@ -class Form::Sales::Questions::Person4Age < ::Form::Question - def initialize(id, hsh, page) - super - @id = "age6" - @check_answer_label = "Person 4’s age" - @header = "Age" - @type = "numeric" - @page = page - @width = 3 - @inferred_check_answers_value = { - "condition" => { "age6_known" => 1 }, - "value" => "Not known", - } - @check_answers_card_number = 6 - end -end diff --git a/app/models/form/sales/questions/person4_age_known.rb b/app/models/form/sales/questions/person4_age_known.rb deleted file mode 100644 index 240e1e930..000000000 --- a/app/models/form/sales/questions/person4_age_known.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Form::Sales::Questions::Person4AgeKnown < ::Form::Question - def initialize(id, hsh, page) - super - @id = "age6_known" - @check_answer_label = "Person 4’s age known?" - @header = "Do you know person 4’s age?" - @type = "radio" - @answer_options = ANSWER_OPTIONS - @page = page - @hint_text = "" - @conditional_for = { - "age6" => [0], - } - @hidden_in_check_answers = { - "depends_on" => [ - { - "age6_known" => 0, - }, - { - "age6_known" => 1, - }, - ], - } - @check_answers_card_number = 6 - end - - ANSWER_OPTIONS = { - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }.freeze -end diff --git a/app/models/form/sales/questions/person_age.rb b/app/models/form/sales/questions/person_age.rb new file mode 100644 index 000000000..2e776b2d0 --- /dev/null +++ b/app/models/form/sales/questions/person_age.rb @@ -0,0 +1,23 @@ +class Form::Sales::Questions::PersonAge < ::Form::Question + def initialize(id, hsh, page) + super + @check_answer_label = "Person #{person_display_number(PERSON_INDEX)}’s age" + @header = "Age" + @type = "numeric" + @page = page + @width = 3 + @inferred_check_answers_value = { + "condition" => { "age#{person_database_number(PERSON_INDEX)}_known" => 1 }, + "value" => "Not known", + } + @check_answers_card_number = person_database_number(PERSON_INDEX) + end + + PERSON_INDEX = { + "age2" => 2, + "age3" => 3, + "age4" => 4, + "age5" => 5, + "age6" => 6, + }.freeze +end diff --git a/app/models/form/sales/questions/person_age_known.rb b/app/models/form/sales/questions/person_age_known.rb new file mode 100644 index 000000000..be69a84c8 --- /dev/null +++ b/app/models/form/sales/questions/person_age_known.rb @@ -0,0 +1,38 @@ +class Form::Sales::Questions::PersonAgeKnown < ::Form::Question + def initialize(id, hsh, page) + super + @check_answer_label = "Person #{person_display_number(PERSON_INDEX)}’s age known?" + @header = "Do you know person #{person_display_number(PERSON_INDEX)}’s age?" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + @hint_text = "" + @conditional_for = { + "age#{person_database_number(PERSON_INDEX)}" => [0], + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "age#{person_database_number(PERSON_INDEX)}_known" => 0, + }, + { + "age#{person_database_number(PERSON_INDEX)}_known" => 1, + }, + ], + } + @check_answers_card_number = person_database_number(PERSON_INDEX) + end + + ANSWER_OPTIONS = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }.freeze + + PERSON_INDEX = { + "age2_known" => 2, + "age3_known" => 3, + "age4_known" => 4, + "age5_known" => 5, + "age6_known" => 6, + }.freeze +end diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 65af1044b..7d6e6fb42 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -30,21 +30,25 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self), Form::Sales::Pages::NumberOfOthersInProperty.new(nil, nil, self), Form::Sales::Pages::Person1Known.new(nil, nil, self), - Form::Sales::Pages::Person1Age.new(nil, nil, self), + Form::Sales::Pages::PersonAge.new("person_1_age", nil, self), + Form::Sales::Pages::PersonAge.new("person_1_age_joint_purchase", nil, self), Form::Sales::Pages::Person1GenderIdentity.new(nil, nil, self), Form::Sales::Pages::Person1GenderIdentityJointPurchase.new(nil, nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation_joint_purchase", nil, self), Form::Sales::Pages::Person2Known.new(nil, nil, self), - Form::Sales::Pages::Person2Age.new(nil, nil, self), + Form::Sales::Pages::PersonAge.new("person_2_age", nil, self), + Form::Sales::Pages::PersonAge.new("person_2_age_joint_purchase", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation_joint_purchase", nil, self), Form::Sales::Pages::Person3Known.new(nil, nil, self), - Form::Sales::Pages::Person3Age.new(nil, nil, self), + Form::Sales::Pages::PersonAge.new("person_3_age", nil, self), + Form::Sales::Pages::PersonAge.new("person_3_age_joint_purchase", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation_joint_purchase", nil, self), Form::Sales::Pages::Person4Known.new(nil, nil, self), - Form::Sales::Pages::Person4Age.new(nil, nil, self), + Form::Sales::Pages::PersonAge.new("person_4_age", nil, self), + Form::Sales::Pages::PersonAge.new("person_4_age_joint_purchase", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation", nil, self), Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation_joint_purchase", nil, self), ] diff --git a/spec/models/form/sales/pages/person1_age_spec.rb b/spec/models/form/sales/pages/person1_age_spec.rb deleted file mode 100644 index 553a7cff4..000000000 --- a/spec/models/form/sales/pages/person1_age_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Pages::Person1Age, 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[age3_known age3]) - end - - it "has the correct id" do - expect(page.id).to eq("person_1_age") - 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 eq( - [ - { "details_known_1" => 1 }, - ], - ) - end -end diff --git a/spec/models/form/sales/pages/person2_age_spec.rb b/spec/models/form/sales/pages/person2_age_spec.rb deleted file mode 100644 index 85d2813f1..000000000 --- a/spec/models/form/sales/pages/person2_age_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Pages::Person2Age, 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[age4_known age4]) - end - - it "has the correct id" do - expect(page.id).to eq("person_2_age") - 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 eq( - [{ "details_known_2" => 1 }], - ) - end -end diff --git a/spec/models/form/sales/pages/person3_age_spec.rb b/spec/models/form/sales/pages/person3_age_spec.rb deleted file mode 100644 index 4cb16be5e..000000000 --- a/spec/models/form/sales/pages/person3_age_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Pages::Person3Age, 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[age5_known age5]) - end - - it "has the correct id" do - expect(page.id).to eq("person_3_age") - 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 eq( - [{ "details_known_3" => 1 }], - ) - end -end diff --git a/spec/models/form/sales/pages/person4_age_spec.rb b/spec/models/form/sales/pages/person4_age_spec.rb deleted file mode 100644 index 530e9ad22..000000000 --- a/spec/models/form/sales/pages/person4_age_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Pages::Person4Age, 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[age6_known age6]) - end - - it "has the correct id" do - expect(page.id).to eq("person_4_age") - 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 eq( - [{ "details_known_4" => 1 }], - ) - end -end diff --git a/spec/models/form/sales/pages/person_age_spec.rb b/spec/models/form/sales/pages/person_age_spec.rb new file mode 100644 index 000000000..21255e80e --- /dev/null +++ b/spec/models/form/sales/pages/person_age_spec.rb @@ -0,0 +1,185 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::PersonAge, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { "person_1_age" } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + 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 + + context "with a non joint purchase" do + context "and person 1" do + let(:page_id) { "person_1_age" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[age2_known age2]) + end + + it "has the correct id" do + expect(page.id).to eq("person_1_age") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "details_known_1" => 1, "jointpur" => 2 }, + ], + ) + end + end + + context "and person 2" do + let(:page_id) { "person_2_age" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[age3_known age3]) + end + + it "has the correct id" do + expect(page.id).to eq("person_2_age") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "details_known_2" => 1, "jointpur" => 2 }, + ], + ) + end + end + + context "and person 3" do + let(:page_id) { "person_3_age" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[age4_known age4]) + end + + it "has the correct id" do + expect(page.id).to eq("person_3_age") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "details_known_3" => 1, "jointpur" => 2 }, + ], + ) + end + end + + context "and person 4" do + let(:page_id) { "person_4_age" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[age5_known age5]) + end + + it "has the correct id" do + expect(page.id).to eq("person_4_age") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "details_known_4" => 1, "jointpur" => 2 }, + ], + ) + end + end + end + + context "with joint purchase" do + context "and person 1" do + let(:page_id) { "person_1_age_joint_purchase" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[age3_known age3]) + end + + it "has the correct id" do + expect(page.id).to eq("person_1_age_joint_purchase") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "details_known_1" => 1, "jointpur" => 1 }, + ], + ) + end + end + + context "and person 2" do + let(:page_id) { "person_2_age_joint_purchase" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[age4_known age4]) + end + + it "has the correct id" do + expect(page.id).to eq("person_2_age_joint_purchase") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "details_known_2" => 1, "jointpur" => 1 }, + ], + ) + end + end + + context "and person 3" do + let(:page_id) { "person_3_age_joint_purchase" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[age5_known age5]) + end + + it "has the correct id" do + expect(page.id).to eq("person_3_age_joint_purchase") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "details_known_3" => 1, "jointpur" => 1 }, + ], + ) + end + end + + context "and person 4" do + let(:page_id) { "person_4_age_joint_purchase" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[age6_known age6]) + end + + it "has the correct id" do + expect(page.id).to eq("person_4_age_joint_purchase") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { "details_known_4" => 1, "jointpur" => 1 }, + ], + ) + end + end + end +end diff --git a/spec/models/form/sales/questions/person1_age_known_spec.rb b/spec/models/form/sales/questions/person1_age_known_spec.rb deleted file mode 100644 index 98dd81056..000000000 --- a/spec/models/form/sales/questions/person1_age_known_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::Person1AgeKnown, 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("age3_known") - end - - it "has the correct header" do - expect(question.header).to eq("Do you know person 1’s age?") - end - - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Person 1’s age known?") - 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({ - "age3" => [0], - }) - end - - it "has the correct hint" do - expect(question.hint_text).to eq("") - end - - it "has the correct hidden_in_check_answers" do - expect(question.hidden_in_check_answers).to eq( - { - "depends_on" => [ - { - "age3_known" => 0, - }, - { - "age3_known" => 1, - }, - ], - }, - ) - end - - it "has the correct check_answers_card_number" do - expect(question.check_answers_card_number).to eq(3) - end -end diff --git a/spec/models/form/sales/questions/person1_age_spec.rb b/spec/models/form/sales/questions/person1_age_spec.rb deleted file mode 100644 index b904fd75f..000000000 --- a/spec/models/form/sales/questions/person1_age_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::Person1Age, 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("age3") - end - - it "has the correct header" do - expect(question.header).to eq("Age") - end - - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Person 1’s age") - 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 the correct width" do - expect(question.width).to eq(3) - end - - it "has the correct inferred check answers value" do - expect(question.inferred_check_answers_value).to eq({ - "condition" => { "age3_known" => 1 }, - "value" => "Not known", - }) - end - - it "has the correct check_answers_card_number" do - expect(question.check_answers_card_number).to eq(3) - end -end diff --git a/spec/models/form/sales/questions/person2_age_known_spec.rb b/spec/models/form/sales/questions/person2_age_known_spec.rb deleted file mode 100644 index 203ea0ecc..000000000 --- a/spec/models/form/sales/questions/person2_age_known_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::Person2AgeKnown, 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("age4_known") - end - - it "has the correct header" do - expect(question.header).to eq("Do you know person 2’s age?") - end - - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Person 2’s age known?") - 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({ - "age4" => [0], - }) - end - - it "has the correct hint" do - expect(question.hint_text).to eq("") - end - - it "has the correct hidden_in_check_answers" do - expect(question.hidden_in_check_answers).to eq( - { - "depends_on" => [{ "age4_known" => 0 }, { "age4_known" => 1 }], - }, - ) - end - - it "has the correct check_answers_card_number" do - expect(question.check_answers_card_number).to eq(4) - end -end diff --git a/spec/models/form/sales/questions/person2_age_spec.rb b/spec/models/form/sales/questions/person2_age_spec.rb deleted file mode 100644 index 2dba0d695..000000000 --- a/spec/models/form/sales/questions/person2_age_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::Person2Age, 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("age4") - end - - it "has the correct header" do - expect(question.header).to eq("Age") - end - - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Person 2’s age") - 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 the correct width" do - expect(question.width).to eq(3) - end - - it "has the correct inferred check answers value" do - expect(question.inferred_check_answers_value).to eq({ - "condition" => { "age4_known" => 1 }, - "value" => "Not known", - }) - end - - it "has the correct check_answers_card_number" do - expect(question.check_answers_card_number).to eq(4) - end -end diff --git a/spec/models/form/sales/questions/person3_age_known_spec.rb b/spec/models/form/sales/questions/person3_age_known_spec.rb deleted file mode 100644 index 8f6e4f022..000000000 --- a/spec/models/form/sales/questions/person3_age_known_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::Person3AgeKnown, 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("age5_known") - end - - it "has the correct header" do - expect(question.header).to eq("Do you know person 3’s age?") - end - - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Person 3’s age known?") - 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({ - "age5" => [0], - }) - end - - it "has the correct hint" do - expect(question.hint_text).to eq("") - end - - it "has the correct hidden_in_check_answers" do - expect(question.hidden_in_check_answers).to eq( - { - "depends_on" => [{ "age5_known" => 0 }, { "age5_known" => 1 }], - }, - ) - end - - it "has the correct check_answers_card_number" do - expect(question.check_answers_card_number).to eq(5) - end -end diff --git a/spec/models/form/sales/questions/person3_age_spec.rb b/spec/models/form/sales/questions/person3_age_spec.rb deleted file mode 100644 index 50ec25c3f..000000000 --- a/spec/models/form/sales/questions/person3_age_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::Person3Age, 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("age5") - end - - it "has the correct header" do - expect(question.header).to eq("Age") - end - - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Person 3’s age") - 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 the correct width" do - expect(question.width).to eq(3) - end - - it "has the correct inferred check answers value" do - expect(question.inferred_check_answers_value).to eq({ - "condition" => { "age5_known" => 1 }, - "value" => "Not known", - }) - end - - it "has the correct check_answers_card_number" do - expect(question.check_answers_card_number).to eq(5) - end -end diff --git a/spec/models/form/sales/questions/person4_age_known_spec.rb b/spec/models/form/sales/questions/person4_age_known_spec.rb deleted file mode 100644 index 559ef62b5..000000000 --- a/spec/models/form/sales/questions/person4_age_known_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::Person4AgeKnown, 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("age6_known") - end - - it "has the correct header" do - expect(question.header).to eq("Do you know person 4’s age?") - end - - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Person 4’s age known?") - 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({ - "age6" => [0], - }) - end - - it "has the correct hint" do - expect(question.hint_text).to eq("") - end - - it "has the correct hidden_in_check_answers" do - expect(question.hidden_in_check_answers).to eq( - { - "depends_on" => [{ "age6_known" => 0 }, { "age6_known" => 1 }], - }, - ) - end - - it "has the correct check_answers_card_number" do - expect(question.check_answers_card_number).to eq(6) - end -end diff --git a/spec/models/form/sales/questions/person4_age_spec.rb b/spec/models/form/sales/questions/person4_age_spec.rb deleted file mode 100644 index d1c6ebead..000000000 --- a/spec/models/form/sales/questions/person4_age_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Sales::Questions::Person4Age, 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("age6") - end - - it "has the correct header" do - expect(question.header).to eq("Age") - end - - it "has the correct check_answer_label" do - expect(question.check_answer_label).to eq("Person 4’s age") - 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 the correct width" do - expect(question.width).to eq(3) - end - - it "has the correct inferred check answers value" do - expect(question.inferred_check_answers_value).to eq({ - "condition" => { "age6_known" => 1 }, - "value" => "Not known", - }) - end - - it "has the correct check_answers_card_number" do - expect(question.check_answers_card_number).to eq(6) - end -end diff --git a/spec/models/form/sales/questions/person_age_known_spec.rb b/spec/models/form/sales/questions/person_age_known_spec.rb new file mode 100644 index 000000000..d7e6e1a2a --- /dev/null +++ b/spec/models/form/sales/questions/person_age_known_spec.rb @@ -0,0 +1,400 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { "age3_known" } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + before do + allow(page).to receive(:id).and_return("person_1_age") + end + + it "has correct page" do + expect(question.page).to eq(page) + 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 the correct hint" do + expect(question.hint_text).to eq("") + end + + context "with a non joint purchase" do + context "and person 1" do + let(:question_id) { "age2_known" } + + before do + allow(page).to receive(:id).and_return("person_1_age") + end + + it "has the correct id" do + expect(question.id).to eq("age2_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know person 1’s age?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 1’s age known?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "age2" => [0], + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + { + "depends_on" => [ + { + "age2_known" => 0, + }, + { + "age2_known" => 1, + }, + ], + }, + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(2) + end + end + + context "and person 2" do + let(:question_id) { "age3_known" } + + before do + allow(page).to receive(:id).and_return("person_2_age") + end + + it "has the correct id" do + expect(question.id).to eq("age3_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know person 2’s age?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 2’s age known?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "age3" => [0], + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + { + "depends_on" => [ + { + "age3_known" => 0, + }, + { + "age3_known" => 1, + }, + ], + }, + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(3) + end + end + + context "and person 3" do + let(:question_id) { "age4_known" } + + before do + allow(page).to receive(:id).and_return("person_3_age") + end + + it "has the correct id" do + expect(question.id).to eq("age4_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know person 3’s age?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 3’s age known?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "age4" => [0], + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + { + "depends_on" => [ + { + "age4_known" => 0, + }, + { + "age4_known" => 1, + }, + ], + }, + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(4) + end + end + + context "and person 4" do + let(:question_id) { "age5_known" } + + before do + allow(page).to receive(:id).and_return("person_4_age") + end + + it "has the correct id" do + expect(question.id).to eq("age5_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know person 4’s age?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 4’s age known?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "age5" => [0], + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + { + "depends_on" => [ + { + "age5_known" => 0, + }, + { + "age5_known" => 1, + }, + ], + }, + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(5) + end + end + end + + context "with a joint purchase" do + context "and person 1" do + let(:question_id) { "age3_known" } + + before do + allow(page).to receive(:id).and_return("person_1_age_joint_purchase") + end + + it "has the correct id" do + expect(question.id).to eq("age3_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know person 1’s age?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 1’s age known?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "age3" => [0], + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + { + "depends_on" => [ + { + "age3_known" => 0, + }, + { + "age3_known" => 1, + }, + ], + }, + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(3) + end + end + + context "and person 2" do + let(:question_id) { "age4_known" } + + before do + allow(page).to receive(:id).and_return("person_2_age_joint_purchase") + end + + it "has the correct id" do + expect(question.id).to eq("age4_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know person 2’s age?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 2’s age known?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "age4" => [0], + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + { + "depends_on" => [ + { + "age4_known" => 0, + }, + { + "age4_known" => 1, + }, + ], + }, + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(4) + end + end + + context "and person 3" do + let(:question_id) { "age5_known" } + + before do + allow(page).to receive(:id).and_return("person_3_age_joint_purchase") + end + + it "has the correct id" do + expect(question.id).to eq("age5_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know person 3’s age?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 3’s age known?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "age5" => [0], + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + { + "depends_on" => [ + { + "age5_known" => 0, + }, + { + "age5_known" => 1, + }, + ], + }, + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(5) + end + end + + context "and person 4" do + let(:question_id) { "age6_known" } + + before do + allow(page).to receive(:id).and_return("person_4_age_joint_purchase") + end + + it "has the correct id" do + expect(question.id).to eq("age6_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know person 4’s age?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 4’s age known?") + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "age6" => [0], + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq( + { + "depends_on" => [ + { + "age6_known" => 0, + }, + { + "age6_known" => 1, + }, + ], + }, + ) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(6) + end + end + end +end diff --git a/spec/models/form/sales/questions/person_age_spec.rb b/spec/models/form/sales/questions/person_age_spec.rb new file mode 100644 index 000000000..3db41e806 --- /dev/null +++ b/spec/models/form/sales/questions/person_age_spec.rb @@ -0,0 +1,285 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::PersonAge, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { "age3" } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + before do + allow(page).to receive(:id).and_return("person_1_age") + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct header" do + expect(question.header).to eq("Age") + 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 + + context "with not a joint purchase" do + context "and person 1" do + let(:question_id) { "age2" } + + before do + allow(page).to receive(:id).and_return("person_1_age") + end + + it "has the correct id" do + expect(question.id).to eq("age2") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 1’s age") + end + + it "has the correct width" do + expect(question.width).to eq(3) + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to eq({ + "condition" => { "age2_known" => 1 }, + "value" => "Not known", + }) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(2) + end + end + + context "and person 2" do + let(:question_id) { "age3" } + + before do + allow(page).to receive(:id).and_return("person_2_age") + end + + it "has the correct id" do + expect(question.id).to eq("age3") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 2’s age") + end + + it "has the correct width" do + expect(question.width).to eq(3) + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to eq({ + "condition" => { "age3_known" => 1 }, + "value" => "Not known", + }) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(3) + end + end + + context "and person 3" do + let(:question_id) { "age4" } + + before do + allow(page).to receive(:id).and_return("person_3_age") + end + + it "has the correct id" do + expect(question.id).to eq("age4") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 3’s age") + end + + it "has the correct width" do + expect(question.width).to eq(3) + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to eq({ + "condition" => { "age4_known" => 1 }, + "value" => "Not known", + }) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(4) + end + end + + context "and person 4" do + let(:question_id) { "age5" } + + before do + allow(page).to receive(:id).and_return("person_4_age") + end + + it "has the correct id" do + expect(question.id).to eq("age5") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 4’s age") + end + + it "has the correct width" do + expect(question.width).to eq(3) + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to eq({ + "condition" => { "age5_known" => 1 }, + "value" => "Not known", + }) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(5) + end + end + end + + context "with a joint purchase" do + context "and person 1" do + let(:question_id) { "age3" } + + before do + allow(page).to receive(:id).and_return("person_1_age_joint_purchase") + end + + it "has the correct id" do + expect(question.id).to eq("age3") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 1’s age") + end + + it "has the correct width" do + expect(question.width).to eq(3) + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to eq({ + "condition" => { "age3_known" => 1 }, + "value" => "Not known", + }) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(3) + end + end + + context "and person 2" do + let(:question_id) { "age4" } + + before do + allow(page).to receive(:id).and_return("person_2_age_joint_purchase") + end + + it "has the correct id" do + expect(question.id).to eq("age4") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 2’s age") + end + + it "has the correct width" do + expect(question.width).to eq(3) + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to eq({ + "condition" => { "age4_known" => 1 }, + "value" => "Not known", + }) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(4) + end + end + + context "and person 3" do + let(:question_id) { "age5" } + + before do + allow(page).to receive(:id).and_return("person_3_age_joint_purchase") + end + + it "has the correct id" do + expect(question.id).to eq("age5") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 3’s age") + end + + it "has the correct width" do + expect(question.width).to eq(3) + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to eq({ + "condition" => { "age5_known" => 1 }, + "value" => "Not known", + }) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(5) + end + end + + context "and person 4" do + let(:question_id) { "age6" } + + before do + allow(page).to receive(:id).and_return("person_4_age_joint_purchase") + end + + it "has the correct id" do + expect(question.id).to eq("age6") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Person 4’s age") + end + + it "has the correct width" do + expect(question.width).to eq(3) + end + + it "has the correct inferred check answers value" do + expect(question.inferred_check_answers_value).to eq({ + "condition" => { "age6_known" => 1 }, + "value" => "Not known", + }) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(6) + end + end + end +end diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index 1d0bdbbcb..3fbf55d5b 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -36,20 +36,24 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model number_of_others_in_property person_1_known person_1_age + person_1_age_joint_purchase person_1_gender_identity person_1_gender_identity_joint_purchase person_1_working_situation person_1_working_situation_joint_purchase person_2_known person_2_age + person_2_age_joint_purchase person_2_working_situation person_2_working_situation_joint_purchase person_3_known person_3_age + person_3_age_joint_purchase person_3_working_situation person_3_working_situation_joint_purchase person_4_known person_4_age + person_4_age_joint_purchase person_4_working_situation person_4_working_situation_joint_purchase ], diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 0e3ba2505..380fcd31f 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -52,14 +52,14 @@ RSpec.describe FormHandler do it "is able to load a current sales form" do form = form_handler.get_form("current_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(64) + expect(form.pages.count).to eq(68) expect(form.name).to eq("2022_2023_sales") end it "is able to load a previous sales form" do form = form_handler.get_form("previous_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(64) + expect(form.pages.count).to eq(68) expect(form.name).to eq("2021_2022_sales") end end