From c1e9c4bb4f187bc82fd8687d37e1f3c5482d0364 Mon Sep 17 00:00:00 2001 From: Theodor Vararu Date: Wed, 9 Oct 2019 16:15:26 +0100 Subject: [PATCH] Add remaining fields to Personal Details edit page - Add second nationality field - Add conditionally revealed `english_language_details` and `other_language_details` --- .../personal_details_controller.rb | 2 +- .../personal_details_form.rb | 9 +------ .../personal_details/edit.html.erb | 25 ++++++++++++++++--- config/locales/application_form.yml | 4 +++ .../personal_details_form_spec.rb | 10 -------- ...andidate_entering_personal_details_spec.rb | 7 +++++- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/app/controllers/candidate_interface/personal_details_controller.rb b/app/controllers/candidate_interface/personal_details_controller.rb index d3e5a2beb11..1bccd570d7d 100644 --- a/app/controllers/candidate_interface/personal_details_controller.rb +++ b/app/controllers/candidate_interface/personal_details_controller.rb @@ -15,7 +15,7 @@ def update def personal_details_params params.require(:candidate_interface_personal_details_form).permit( :first_name, :last_name, :"date_of_birth(3i)", :"date_of_birth(2i)", - :"date_of_birth(1i)", :nationality, :english_main_language + :"date_of_birth(1i)", :english_main_language, nationalities: [] ) .transform_keys { |key| dob_field_to_attribute(key) } end diff --git a/app/models/candidate_interface/personal_details_form.rb b/app/models/candidate_interface/personal_details_form.rb index 2518be99b29..61c317de5a2 100644 --- a/app/models/candidate_interface/personal_details_form.rb +++ b/app/models/candidate_interface/personal_details_form.rb @@ -2,18 +2,11 @@ module CandidateInterface class PersonalDetailsForm include ActiveModel::Model - attr_accessor :first_name, :last_name, :day, :month, :year, :nationality, + attr_accessor :first_name, :last_name, :day, :month, :year, :nationalities, :english_main_language def name "#{first_name} #{last_name}" end - - def english_main_language_options - [ - OpenStruct.new(id: 'yes', name: 'Yes'), - OpenStruct.new(id: 'no', name: 'No'), - ] - end end end diff --git a/app/views/candidate_interface/personal_details/edit.html.erb b/app/views/candidate_interface/personal_details/edit.html.erb index 3a5daaa326b..e69b38d9955 100644 --- a/app/views/candidate_interface/personal_details/edit.html.erb +++ b/app/views/candidate_interface/personal_details/edit.html.erb @@ -19,9 +19,28 @@ <%= f.govuk_date_field :date_of_birth, date_of_birth: true, legend: { text: t('application_form.personal_details.date_of_birth.label'), tag: 'span' }, hint_text: t('application_form.personal_details.date_of_birth.hint_text') %> - <%= f.govuk_text_field :nationality, label: { text: t('application_form.personal_details.nationality.label'), size: 'm' } %> - - <%= f.govuk_collection_radio_buttons :english_main_language, @personal_details_form.english_main_language_options, :id, :name, legend: { text: t('application_form.personal_details.english_main_language.label') } %> + <%= f.govuk_text_field 'nationalities', label: { text: t('application_form.personal_details.nationality.label'), size: 'm' }, multiple: true %> + +
+ + + Add another nationality + + +
+ <%= f.govuk_text_field 'nationalities', label: { text: t('application_form.personal_details.second_nationality.label') }, multiple: true %> +
+
+ + <%= f.govuk_radio_buttons_fieldset :english_main_language, legend: { size: 'm', text: t('application_form.personal_details.english_main_language.label') } do %> + <%= f.govuk_radio_button :english_main_language, 'yes', label: { text: 'Yes' } do %> + <%= f.govuk_text_area :english_language_details, label: { text: t('application_form.personal_details.english_main_language.yes_label') }, max_words: 200 %> + <% end %> + + <%= f.govuk_radio_button :english_main_language, 'no', label: { text: 'No' } do %> + <%= f.govuk_text_area :other_language_details, label: { text: t('application_form.personal_details.english_main_language.no_label') }, max_words: 200 %> + <% end %> + <% end %> <%= f.govuk_submit 'Continue' %> <% end %> diff --git a/config/locales/application_form.yml b/config/locales/application_form.yml index 91ae8c535bb..52d57eef4f8 100644 --- a/config/locales/application_form.yml +++ b/config/locales/application_form.yml @@ -14,6 +14,10 @@ en: hint_text: For example, 31 3 1980 nationality: label: Nationality + second_nationality: + label: Second nationality english_main_language: label: Is English your main language? + yes_label: If you are bilingual or very familiar with languages other than English, you can tell us about them here. + no_label: Please tell us about your English language qualifications (including grades or scores), and give details of other languages you are fluent in. complete_form_button: Continue diff --git a/spec/models/candidate_interface/personal_details_form_spec.rb b/spec/models/candidate_interface/personal_details_form_spec.rb index b27ad2a6a05..5fd0ffef62b 100644 --- a/spec/models/candidate_interface/personal_details_form_spec.rb +++ b/spec/models/candidate_interface/personal_details_form_spec.rb @@ -8,14 +8,4 @@ expect(personal_details.name).to eq('Bruce Wayne') end end - - describe '#english_main_language_options' do - it 'returns an array of OpenStructs with id and name' do - personal_details = CandidateInterface::PersonalDetailsForm.new - - expect(personal_details.english_main_language_options).to all(be_an(OpenStruct)) - expect(personal_details.english_main_language_options[0]).to have_attributes(id: 'yes', name: 'Yes') - expect(personal_details.english_main_language_options[1]).to have_attributes(id: 'no', name: 'No') - end - end end diff --git a/spec/system/candidate_interface/candidate_entering_personal_details_spec.rb b/spec/system/candidate_interface/candidate_entering_personal_details_spec.rb index 3b8ef5e2424..51ae569cd5c 100644 --- a/spec/system/candidate_interface/candidate_entering_personal_details_spec.rb +++ b/spec/system/candidate_interface/candidate_entering_personal_details_spec.rb @@ -46,9 +46,14 @@ def when_i_fill_in_the_form fill_in 'Month', with: '4' fill_in 'Year', with: '1937' - fill_in t('application_form.personal_details.nationality.label'), with: 'English' + fill_in t('application_form.personal_details.nationality.label'), with: 'British' + find('details').click + within('details') do + fill_in t('application_form.personal_details.second_nationality.label'), with: 'American' # TODO replace with translation + end choose 'Yes' + fill_in 'If you are bilingual or very familiar with languages other than English, you can tell us about them here.', with: "I'm great at Galactic Basic so English is a piece of cake", match: :prefer_exact click_button t('application_form.personal_details.complete_form_button') end