Skip to content

Commit

Permalink
Add remaining fields to Personal Details edit page
Browse files Browse the repository at this point in the history
- Add second nationality field
- Add conditionally revealed `english_language_details` and `other_language_details`
  • Loading branch information
tvararu authored and Wen Ting Wang committed Oct 10, 2019
1 parent 0dec665 commit c1e9c4b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions app/models/candidate_interface/personal_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 22 additions & 3 deletions app/views/candidate_interface/personal_details/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

<details class="govuk-details" data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
Add another nationality
</span>
</summary>
<div class="govuk-details__text">
<%= f.govuk_text_field 'nationalities', label: { text: t('application_form.personal_details.second_nationality.label') }, multiple: true %>
</div>
</details>

<%= 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 %>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/application_form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 0 additions & 10 deletions spec/models/candidate_interface/personal_details_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1e9c4b

Please sign in to comment.