diff --git a/app/models/form.rb b/app/models/form.rb index aa029bab8..3ed172ace 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -26,6 +26,9 @@ class Form < ApplicationRecord "tenant_age" => "tenant_gender", "tenant_gender" => "tenant_ethnic_group", "tenant_ethnic_group" => "tenant_nationality", + "tenant_nationality" => "economic_status", + "economic_status" => "other_household_members", + "other_household_members" => "other_household_members", "previous_housing_situation" => "previous_housing_situation", }.freeze diff --git a/app/views/form/questions/economic_status.erb b/app/views/form/questions/economic_status.erb new file mode 100644 index 000000000..3ffd86d18 --- /dev/null +++ b/app/views/form/questions/economic_status.erb @@ -0,0 +1,26 @@ +<% economic_statuses = [ + OpenStruct.new(id: 0, ethnicity: "Part-time - Less than 30 hours"), + OpenStruct.new(id: 1, ethnicity: "Full-time - 30 hours or more"), + OpenStruct.new(id: 2, ethnicity: "In government training into work, such as New Deal"), + OpenStruct.new(id: 3, ethnicity: "Jobseeker"), + OpenStruct.new(id: 4, ethnicity: "Retired"), + OpenStruct.new(id: 5, ethnicity: "Not seeking work"), + OpenStruct.new(id: 6, ethnicity: "Full-time student"), + OpenStruct.new(id: 7, ethnicity: "Unable to work because of long term sick or disability"), + OpenStruct.new(id: 8, ethnicity: "Child under 16"), + OpenStruct.new(id: 9, ethnicity: "Other"), + OpenStruct.new(id: 10, ethnicity: "Prefer not to say") +] %> + +<% previous_question = Form.previous_question("economic_status") %> +<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> + Back +<% end %> +<%= turbo_frame_tag "case_log_form", target: "_top" do %> + <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= f.govuk_collection_radio_buttons :economic_status, economic_statuses, :id, :ethnicity, legend: { text: "Which of these best describes the tenant's working situation?", size: "l" } %> + <%= f.hidden_field :previous_question, value: :economic_status %> + <%= f.hidden_field :case_log_id, value: case_log_id %> + <%= f.govuk_submit "Save and continue" %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/form/questions/other_household_members.erb b/app/views/form/questions/other_household_members.erb new file mode 100644 index 000000000..1bc601818 --- /dev/null +++ b/app/views/form/questions/other_household_members.erb @@ -0,0 +1,17 @@ +<% previous_question = Form.previous_question("other_household_members") %> +<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> + Back +<% end %> + +<%= turbo_frame_tag "case_log_form", target: "_top" do %> + <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= f.govuk_number_field :other_household_members, + hint: { text: "The maximum number of others is 7" }, + label: { text: "How many other people are there in the household?", size: "l"}, + min: 0, max: 7, step: 1, width: 20 + %> + <%= f.hidden_field :previous_question, value: :other_household_members %> + <%= f.hidden_field :case_log_id, value: case_log_id %> + <%= f.govuk_submit "Save and continue" %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/form/questions/tenant_ethnic_group.erb b/app/views/form/questions/tenant_ethnic_group.erb new file mode 100644 index 000000000..237a34640 --- /dev/null +++ b/app/views/form/questions/tenant_ethnic_group.erb @@ -0,0 +1,35 @@ +<% ethnic_groups = [ + OpenStruct.new(id: 0, ethnicity: "White: English/Scottish/Welsh/Northern Irish/British"), + OpenStruct.new(id: 1, ethnicity: "White: Irish"), + OpenStruct.new(id: 2, ethnicity: "White: Gypsy/Irish Traveller"), + OpenStruct.new(id: 3, ethnicity: "White: Other"), + OpenStruct.new(id: 4, ethnicity: "Mixed: White & Black Caribbean"), + OpenStruct.new(id: 5, ethnicity: "Mixed: White & Black African"), + OpenStruct.new(id: 6, ethnicity: "Mixed: White & Asian"), + OpenStruct.new(id: 7, ethnicity: "Mixed: Other"), + OpenStruct.new(id: 8, ethnicity: "Asian or Asian British: Indian"), + OpenStruct.new(id: 9, ethnicity: "Asian or Asian British: Pakistani"), + OpenStruct.new(id: 10, ethnicity: "Asian or Asian British: Bangladeshi"), + OpenStruct.new(id: 11, ethnicity: "Asian or Asian British: Chinese"), + OpenStruct.new(id: 12, ethnicity: "Asian or Asian British: Other"), + OpenStruct.new(id: 13, ethnicity: "Black: Caribbean"), + OpenStruct.new(id: 14, ethnicity: "Black: African"), + OpenStruct.new(id: 15, ethnicity: "Black: Other"), + OpenStruct.new(id: 16, ethnicity: "Other Ethnic Group: Arab"), + OpenStruct.new(id: 17, ethnicity: "Other Ethnic Group: Other"), + OpenStruct.new(id: 18, ethnicity: "Prefer not to say") +] %> + +<% previous_question = Form.previous_question("tenant_ethnic_group") %> +<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> + Back +<% end %> + +<%= turbo_frame_tag "case_log_form", target: "_top" do %> + <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= f.govuk_collection_radio_buttons :tenant_ethnic_group, ethnic_groups, :id, :ethnicity, legend: { text: "What is the tenant’s ethnic group?", size: "l" } %> + <%= f.hidden_field :previous_question, value: :tenant_ethnic_group %> + <%= f.hidden_field :case_log_id, value: case_log_id %> + <%= f.govuk_submit "Save and continue" %> + <% end %> +<% end %> diff --git a/app/views/form/questions/tenant_nationality.erb b/app/views/form/questions/tenant_nationality.erb new file mode 100644 index 000000000..3ea00a9ba --- /dev/null +++ b/app/views/form/questions/tenant_nationality.erb @@ -0,0 +1,32 @@ +<% nationalities = [ + OpenStruct.new(id: 0, ethnicity: "UK national resident in UK"), + OpenStruct.new(id: 1, ethnicity: "A current or former reserve in the UK Armed Forces (exc. National Service)"), + OpenStruct.new(id: 2, ethnicity: "UK national returning from residence overseas"), + OpenStruct.new(id: 3, ethnicity: "Czech Republic"), + OpenStruct.new(id: 4, ethnicity: "Estonia"), + OpenStruct.new(id: 5, ethnicity: "Hungary"), + OpenStruct.new(id: 6, ethnicity: "Latvia"), + OpenStruct.new(id: 7, ethnicity: "Lithuania"), + OpenStruct.new(id: 8, ethnicity: "Poland"), + OpenStruct.new(id: 9, ethnicity: "Slovakia"), + OpenStruct.new(id: 10, ethnicity: "Bulgaria"), + OpenStruct.new(id: 11, ethnicity: "Romania"), + OpenStruct.new(id: 12, ethnicity: "Ireland"), + OpenStruct.new(id: 13, ethnicity: "Other EU Economic Area (EEA country)"), + OpenStruct.new(id: 14, ethnicity: "Any other country"), + OpenStruct.new(id: 15, ethnicity: "Prefer not to say") +] %> + +<% previous_question = Form.previous_question("tenant_nationality") %> +<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> + Back +<% end %> + +<%= turbo_frame_tag "case_log_form", target: "_top" do %> + <%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <%= f.govuk_collection_radio_buttons :tenant_nationality, nationalities, :id, :ethnicity, legend: { text: "What is the tenant’s ethnic group?", size: "l" } %> + <%= f.hidden_field :previous_question, value: :tenant_nationality %> + <%= f.hidden_field :case_log_id, value: case_log_id %> + <%= f.govuk_submit "Save and continue" %> + <% end %> +<% end %> diff --git a/db/migrate/20210922103729_add_household_characteristics_to_case_logs.rb b/db/migrate/20210922103729_add_household_characteristics_to_case_logs.rb new file mode 100644 index 000000000..da0df1907 --- /dev/null +++ b/db/migrate/20210922103729_add_household_characteristics_to_case_logs.rb @@ -0,0 +1,36 @@ +class AddHouseholdCharacteristicsToCaseLogs < ActiveRecord::Migration[6.1] + def change + change_table :case_logs, bulk: true do |t| + t.column :economic_status, :string + t.column :number_of_other_members, :integer + t.column :person_2_relationship, :string + t.column :person_2_age, :integer + t.column :person_2_gender, :string + t.column :person_2_economic, :string + t.column :person_3_relationship, :string + t.column :person_3_age, :integer + t.column :person_3_gender, :string + t.column :person_3_economic, :string + t.column :person_4_relationship, :string + t.column :person_4_age, :integer + t.column :person_4_gender, :string + t.column :person_4_economic, :string + t.column :person_5_relationship, :string + t.column :person_5_age, :integer + t.column :person_5_gender, :string + t.column :person_5_economic, :string + t.column :person_6_relationship, :string + t.column :person_6_age, :integer + t.column :person_6_gender, :string + t.column :person_6_economic, :string + t.column :person_7_relationship, :string + t.column :person_7_age, :integer + t.column :person_7_gender, :string + t.column :person_7_economic, :string + t.column :person_8_relationship, :string + t.column :person_8_age, :integer + t.column :person_8_gender, :string + t.column :person_8_economic, :string + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 393bcbc9d..8ef9e2c72 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_14_101759) do +ActiveRecord::Schema.define(version: 2021_09_22_103729) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -27,6 +27,36 @@ ActiveRecord::Schema.define(version: 2021_09_14_101759) do t.string "previous_housing_situation" t.integer "prior_homelessness" t.string "armed_forces" + t.string "economic_status" + t.integer "number_of_other_members" + t.string "person_2_relationship" + t.integer "person_2_age" + t.string "person_2_gender" + t.string "person_2_economic" + t.string "person_3_relationship" + t.integer "person_3_age" + t.string "person_3_gender" + t.string "person_3_economic" + t.string "person_4_relationship" + t.integer "person_4_age" + t.string "person_4_gender" + t.string "person_4_economic" + t.string "person_5_relationship" + t.integer "person_5_age" + t.string "person_5_gender" + t.string "person_5_economic" + t.string "person_6_relationship" + t.integer "person_6_age" + t.string "person_6_gender" + t.string "person_6_economic" + t.string "person_7_relationship" + t.integer "person_7_age" + t.string "person_7_gender" + t.string "person_7_economic" + t.string "person_8_relationship" + t.integer "person_8_age" + t.string "person_8_gender" + t.string "person_8_economic" end end diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 7b24baa74..da82e50f0 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -3,6 +3,7 @@ RSpec.describe "Test Features" do let!(:case_log) { FactoryBot.create(:case_log) } let(:id) { case_log.id } let(:status) { case_log.status } + pages = ['tenant_code', 'tenant_age', 'tenant_gender', 'tenant_ethnic_group', 'tenant_nationality', 'economic_status', 'other_household_members'] describe "Create new log" do it "redirects to the task list for the new log" do @@ -53,4 +54,15 @@ RSpec.describe "Test Features" do expect(page).to have_field("tenant-code-field") end end + + describe "Form flow is correct" do + it "given an ordered list of pages make sure each leads to the next one in order" do + pages[0..-2].each_with_index { + |val, index| + visit("/case_logs/#{id}/#{val}") + click_button("Save and continue") + expect(page).to have_current_path("/case_logs/#{id}/#{pages[index+1]}") + } + end + end end