Skip to content

Commit

Permalink
Replace study mode radio buttons with check boxes when editing a course
Browse files Browse the repository at this point in the history
  • Loading branch information
elceebee committed May 17, 2024
1 parent 7852132 commit 477c1e8
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/controllers/publish/courses/study_mode_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def update
def study_mode_params
return { study_mode: nil } if params[:publish_course_study_mode_form].blank?

params.require(:publish_course_study_mode_form).permit(*CourseStudyModeForm::FIELDS)
params.require(:publish_course_study_mode_form).permit(study_mode: [])
end

def current_step
Expand Down
2 changes: 1 addition & 1 deletion app/forms/publish/course_study_mode_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def valid_before_save
end

def compute_fields
course.attributes.symbolize_keys.slice(*FIELDS).merge(new_attributes)
{ study_mode: new_attributes[:study_mode]&.compact_blank&.sort&.join('_or_') }
end
end
end
20 changes: 12 additions & 8 deletions app/views/publish/courses/study_mode/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@

<%= f.govuk_error_summary %>

<%= f.govuk_radio_buttons_fieldset(:study_mode, legend: { text: "#{render CaptionText.new(text: course.name_and_code)} Full time or part time?".html_safe, tag: "h1", size: "l" }) do %>
<% course.edit_course_options["study_modes"].each_with_index do |study_mode, index| %>
<%= f.govuk_radio_button(
:study_mode,
study_mode,
label: { text: t("edit_options.study_modes.#{study_mode}.label") },
link_errors: index.zero?
) %>
<%= f.govuk_check_boxes_fieldset :study_mode,
hint: { text: t("publish.providers.study_mode.form.select_all_that_apply") },
legend: { text: "#{render CaptionText.new(text: course.name_and_code)} #{t('publish.providers.study_mode.form.study_pattern')}".html_safe,
tag: "h1",
size: "l" } do %>
<% course.edit_course_options[:study_modes].each_with_index do |value, index| %>
<%= f.govuk_check_box :study_mode,
value,
label: { text: t("edit_options.study_modes.#{value}.label") },
checked: course.study_mode.in?([value, "full_time_or_part_time"]),
link_errors: index.zero? %>

<% end %>
<% end %>

Expand Down
2 changes: 2 additions & 0 deletions app/views/publish/shared/_errors.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%# locals: (error_id: nil) -%>

<% if @errors && @errors.any? %>
<div class="govuk-error-summary" aria-labelledby="error-summary-title" role="alert" tabindex="-1" data-module="govuk-error-summary" data-ga-event-form="error">
<h2 class="govuk-error-summary__title" id="error-summary-title">
Expand Down
49 changes: 45 additions & 4 deletions spec/features/publish/courses/editing_course_study_mode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,31 @@
given_i_am_authenticated_as_a_provider_user
end

scenario 'i can update the course study mode' do
scenario 'I can update the course study mode to both full time and part time' do
and_there_is_a_part_time_course_i_want_to_edit
when_i_visit_the_course_study_mode_page
then_i_see_part_time_selected

and_i_choose_a_full_time_study_mode
and_i_submit
then_i_should_see_a_success_message
and_the_course_study_mode_is_updated
and_the_course_study_mode_is_updated_to_full_or_part_time

when_i_visit_the_course_study_mode_page
then_i_see_both_part_time_and_full_time_selected
end

scenario 'I can change the course study mode from part time to full time' do
and_there_is_a_part_time_course_i_want_to_edit
when_i_visit_the_course_study_mode_page
and_i_choose_a_full_time_study_mode
and_i_deselect_part_time_study_mode
and_i_submit
then_i_should_see_a_success_message
and_the_course_study_mode_is_updated_to_full_time

when_i_visit_the_course_study_mode_page
then_i_see_full_time_selected
end

scenario 'updating with invalid data' do
Expand Down Expand Up @@ -43,7 +61,11 @@ def when_i_visit_the_course_study_mode_page
end

def and_i_choose_a_full_time_study_mode
publish_course_study_mode_edit_page.full_time.choose
publish_course_study_mode_edit_page.full_time.click
end

def and_i_deselect_part_time_study_mode
publish_course_study_mode_edit_page.part_time.click
end

def and_i_submit
Expand All @@ -54,10 +76,29 @@ def then_i_should_see_a_success_message
expect(page).to have_content(I18n.t('success.saved', value: 'Full time or part time'))
end

def and_the_course_study_mode_is_updated
def then_i_see_part_time_selected
expect(publish_course_study_mode_edit_page.part_time.checked?).to be true
expect(publish_course_study_mode_edit_page.full_time.checked?).to be false
end

def then_i_see_both_part_time_and_full_time_selected
expect(publish_course_study_mode_edit_page.part_time.checked?).to be true
expect(publish_course_study_mode_edit_page.full_time.checked?).to be true
end

def and_the_course_study_mode_is_updated_to_full_or_part_time
expect(course.reload).to be_full_time_or_part_time
end

def and_the_course_study_mode_is_updated_to_full_time
expect(course.reload).to be_full_time
end

def then_i_see_full_time_selected
expect(publish_course_study_mode_edit_page.full_time.checked?).to be true
expect(publish_course_study_mode_edit_page.part_time.checked?).to be false
end

def then_i_should_see_an_error_message
expect(publish_course_study_mode_edit_page.error_messages)
.to include('You must choose a study pattern. Select all that apply.')
Expand Down
2 changes: 1 addition & 1 deletion spec/features/publish/courses/new_funding_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def provider

def then_i_am_met_with_the_full_or_part_time_page(funding_type)
expect(page).to have_current_path("/publish/organisations/#{provider.provider_code}/#{Settings.current_recruitment_cycle_year}/courses/full-part-time/new#{selected_params(funding_type)}")
expect(page).to have_content('Full time or part time')
expect(page).to have_content('Study pattern')
end

def then_i_am_met_with_errors
Expand Down
2 changes: 1 addition & 1 deletion spec/features/publish/e2e/new_course_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def select_apprenticeship(course_creation_params, next_page:)
end

def select_study_mode(course_creation_params, next_page:)
course_creation_params[:study_mode] = 'full_time'
course_creation_params[:study_mode] = ['full_time']

publish_courses_new_study_mode_page.study_mode_fields.full_time.click
publish_courses_new_study_mode_page.continue.click
Expand Down
28 changes: 24 additions & 4 deletions spec/forms/publish/course_study_mode_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,43 @@ module Publish

describe '#save!' do
it 'does not call the course.ensure_site_statuses_match_study_mode' do
expect(course).to receive(:changed?)
expect(course).not_to receive(:ensure_site_statuses_match_study_mode)
subject.save!
expect(subject.save!).to be false
end
end
end

context 'when params are study mode is part_time' do
let(:params) { { study_mode: 'part_time' } }
let(:params) { { study_mode: ['part_time'] } }

describe '#save!' do
it 'does calls the course.ensure_site_statuses_match_study_mode' do
expect(course).to receive(:changed?)
expect(course).not_to receive(:ensure_site_statuses_match_study_mode)
subject.save!

expect(course.study_mode).to eq 'part_time'
end
end
end

context 'when params are study mode is both part time and full time' do
let(:params) { { study_mode: %w[full_time part_time] } }

it 'does calls the course.ensure_site_statuses_match_study_mode' do
subject.save!

expect(course.study_mode).to eq 'full_time_or_part_time'
end
end

context 'when params are study mode is full time' do
let(:params) { { study_mode: ['full_time'] } }

it 'does calls the course.ensure_site_statuses_match_study_mode' do
subject.save!

expect(course.study_mode).to eq 'full_time'
end
end
end
end
22 changes: 14 additions & 8 deletions spec/services/courses/creation_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'level' => 'primary',
'qualification' => 'qts',
'start_date' => "September #{recruitment_cycle.year}",
'study_mode' => 'full_time',
'study_mode' => ['full_time'],
'sites_ids' => [site.id],
'study_sites_ids' => [study_site.id],
'subjects_ids' => [primary_subject.id],
Expand All @@ -40,7 +40,7 @@
end

it 'create the primary course' do
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'subjects_ids', 'course_code').each do |key, value|
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'subjects_ids', 'course_code', 'study_mode').each do |key, value|
expect(subject.public_send(key)).to eq(value)
end

Expand All @@ -50,6 +50,7 @@
expect(subject.subjects.map(&:id)).to eq([primary_subject.id])
expect(subject.course_code).to be_nil
expect(subject.name).to eq('Primary (SEND)')
expect(subject.study_mode).to eq 'full_time'
expect(subject.errors).to be_empty
end

Expand All @@ -59,7 +60,7 @@
end

it 'create the primary course' do
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'subjects_ids', 'course_code').each do |key, value|
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'subjects_ids', 'course_code', 'study_mode').each do |key, value|
expect(subject.public_send(key)).to eq(value)
end

Expand All @@ -70,6 +71,7 @@
expect(subject.course_code).not_to be_nil
expect(subject.course_code).not_to eq('D0CK')
expect(subject.name).to eq('Primary (SEND)')
expect(subject.study_mode).to eq 'full_time'
expect(subject.errors).to be_empty
end
end
Expand All @@ -87,7 +89,7 @@
'level' => 'secondary',
'qualification' => 'pgce_with_qts',
'start_date' => "September #{recruitment_cycle.year}",
'study_mode' => 'part_time',
'study_mode' => ['part_time'],
'sites_ids' => [site.id],
'study_sites_ids' => [study_site.id],
'subjects_ids' => [secondary_subject.id],
Expand All @@ -96,7 +98,7 @@
end

it 'create the secondary course' do
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'subjects_ids', 'course_code').each do |key, value|
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'subjects_ids', 'course_code', 'study_mode').each do |key, value|
expect(subject.send(key)).to eq(value)
end

Expand All @@ -106,6 +108,7 @@
expect(subject.subjects.map(&:id)).to eq([secondary_subject.id])
expect(subject.course_code).to be_nil
expect(subject.name).to eq('Biology')
expect(subject.study_mode).to eq 'part_time'
expect(subject.errors).to be_empty
end

Expand All @@ -115,7 +118,7 @@
end

it 'create the secondary course' do
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'subjects_ids', 'course_code').each do |key, value|
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'subjects_ids', 'course_code', 'study_mode').each do |key, value|
expect(subject.public_send(key)).to eq(value)
end

Expand All @@ -126,6 +129,7 @@
expect(subject.course_code).not_to be_nil
expect(subject.course_code).not_to eq('D0CK')
expect(subject.name).to eq('Biology')
expect(subject.study_mode).to eq 'part_time'
expect(subject.errors).to be_empty
end
end
Expand All @@ -141,7 +145,7 @@
'level' => 'further_education',
'qualification' => 'pgde',
'start_date' => "September #{recruitment_cycle.year}",
'study_mode' => 'full_time_or_part_time',
'study_mode' => %w[full_time part_time],
'sites_ids' => [site.id],
'study_sites_ids' => [study_site.id]
}
Expand All @@ -159,6 +163,7 @@
expect(subject.english).to eq('not_required')
expect(subject.maths).to eq('not_required')
expect(subject.science).to eq('not_required')
expect(subject.study_mode).to eq 'full_time_or_part_time'
end

context 'next_available_course_code is true' do
Expand All @@ -167,7 +172,7 @@
end

it 'create the further_education course' do
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'course_code').each do |key, value|
valid_course_params.except('is_send', 'sites_ids', 'study_sites_ids', 'course_code', 'study_mode').each do |key, value|
expect(subject.send(key)).to eq(value)
end

Expand All @@ -183,6 +188,7 @@
expect(subject.english).to eq('not_required')
expect(subject.maths).to eq('not_required')
expect(subject.science).to eq('not_required')
expect(subject.study_mode).to eq 'full_time_or_part_time'
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/support/feature_helpers/new_course_param_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def accredited_provider_params
'course[funding_type]' => 'fee',
'course[level]' => 'secondary',
'course[is_send]' => '0',
'course[study_mode]' => 'full_time',
'course[study_mode][]' => 'full_time',
'course[age_range_in_years]' => '11_to_16',
'course[subjects_ids][]' => '2',
'commit' => 'Continue'
Expand All @@ -29,7 +29,7 @@ def applications_open_from_params
'course[funding_type]' => 'fee',
'course[level]' => 'secondary',
'course[is_send]' => '0',
'course[study_mode]' => 'full_time',
'course[study_mode][]' => 'full_time',
'course[age_range_in_years]' => '11_to_16',
'course[subjects_ids][]' => '2',
'commit' => 'Continue'
Expand Down Expand Up @@ -61,7 +61,7 @@ def schools_params
'course[is_send]' => '0',
'course[level]' => 'primary',
'course[qualification]' => 'qts',
'course[study_mode]' => 'full_time',
'course[study_mode][]' => 'full_time',
'course[subjects_ids][]' => '2'
}
end
Expand All @@ -76,7 +76,7 @@ def confirmation_params(provider)
'course[level]' => 'secondary',
'course[qualification]' => 'pgde_with_qts',
'course[start_date]' => "October #{provider.recruitment_cycle_year.to_i - 1}",
'course[study_mode]' => 'full_time_or_part_time',
'course[study_mode][]' => 'full_time_or_part_time',
'course[subjects_ids][]' => '30',
'course[sites_ids][]' => provider.sites.first.id
}
Expand All @@ -89,7 +89,7 @@ def start_date_params(provider)
'course[funding_type]' => 'fee',
'course[level]' => 'secondary',
'course[is_send]' => '0',
'course[study_mode]' => 'full_time',
'course[study_mode][]' => 'full_time',
'course[age_range_in_years]' => '11_to_16',
'course[subjects_ids][]' => '30',
'course[applications_open_from]' => '2021-10-12'
Expand Down
5 changes: 2 additions & 3 deletions spec/support/page_objects/publish/course_study_mode_edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ class CourseStudyModeEdit < PageObjects::Base

sections :errors, Sections::ErrorLink, '.govuk-error-summary__list li>a'

element :full_time, '#publish-course-study-mode-form-study-mode-full-time-field'
element :part_time, '#publish-course-study-mode-form-study-mode-part-time-field'
element :full_or_part_time, '#publish-course-study-mode-form-study-mode-full-time-or-part-time-field'
element :full_time, '[value="full_time"]'
element :part_time, '[value="part_time"]'

element :submit, 'button.govuk-button[type="submit"]'

Expand Down
4 changes: 2 additions & 2 deletions spec/support/page_objects/publish/courses/new_study_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class NewStudyMode < PageObjects::Base
set_url '/publish/organisations/{provider_code}/{recruitment_cycle_year}/courses/full-part-time/new{?query*}'

section :study_mode_fields, '[data-qa="course__study_mode"]' do
element :full_time, '#course-study-mode-full-time-field'
element :part_time, '#course-study-mode-part-time-field'
element :full_time, '[value="full_time"]'
element :part_time, '[value="part_time"]'
end

element :continue, '[data-qa="course__save"]'
Expand Down

0 comments on commit 477c1e8

Please sign in to comment.