From 477c1e8bca82aafb05d7e1a296eb5aa990d97b04 Mon Sep 17 00:00:00 2001
From: Lori Bailey <44073106+elceebee@users.noreply.github.com>
Date: Thu, 16 May 2024 17:15:59 +0100
Subject: [PATCH] Replace study mode radio buttons with check boxes when
editing a course
---
.../publish/courses/study_mode_controller.rb | 2 +-
app/forms/publish/course_study_mode_form.rb | 2 +-
.../publish/courses/study_mode/edit.html.erb | 20 +++++---
app/views/publish/shared/_errors.html.erb | 2 +
.../courses/editing_course_study_mode_spec.rb | 49 +++++++++++++++++--
.../publish/courses/new_funding_type_spec.rb | 2 +-
spec/features/publish/e2e/new_course_spec.rb | 2 +-
.../publish/course_study_mode_form_spec.rb | 28 +++++++++--
.../services/courses/creation_service_spec.rb | 22 ++++++---
.../new_course_param_helper.rb | 10 ++--
.../publish/course_study_mode_edit.rb | 5 +-
.../publish/courses/new_study_mode.rb | 4 +-
12 files changed, 110 insertions(+), 38 deletions(-)
diff --git a/app/controllers/publish/courses/study_mode_controller.rb b/app/controllers/publish/courses/study_mode_controller.rb
index af4c203602..259d8855d8 100644
--- a/app/controllers/publish/courses/study_mode_controller.rb
+++ b/app/controllers/publish/courses/study_mode_controller.rb
@@ -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
diff --git a/app/forms/publish/course_study_mode_form.rb b/app/forms/publish/course_study_mode_form.rb
index 6b056434cd..f7ea897544 100644
--- a/app/forms/publish/course_study_mode_form.rb
+++ b/app/forms/publish/course_study_mode_form.rb
@@ -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
diff --git a/app/views/publish/courses/study_mode/edit.html.erb b/app/views/publish/courses/study_mode/edit.html.erb
index f9994a7707..1f2079e621 100644
--- a/app/views/publish/courses/study_mode/edit.html.erb
+++ b/app/views/publish/courses/study_mode/edit.html.erb
@@ -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 %>
diff --git a/app/views/publish/shared/_errors.html.erb b/app/views/publish/shared/_errors.html.erb
index b4bdaedda4..9e5f8a1984 100644
--- a/app/views/publish/shared/_errors.html.erb
+++ b/app/views/publish/shared/_errors.html.erb
@@ -1,3 +1,5 @@
+<%# locals: (error_id: nil) -%>
+
<% if @errors && @errors.any? %>
diff --git a/spec/features/publish/courses/editing_course_study_mode_spec.rb b/spec/features/publish/courses/editing_course_study_mode_spec.rb
index c7256a300f..2a10105608 100644
--- a/spec/features/publish/courses/editing_course_study_mode_spec.rb
+++ b/spec/features/publish/courses/editing_course_study_mode_spec.rb
@@ -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
@@ -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
@@ -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.')
diff --git a/spec/features/publish/courses/new_funding_type_spec.rb b/spec/features/publish/courses/new_funding_type_spec.rb
index d8a9e7b70c..714fda29e5 100644
--- a/spec/features/publish/courses/new_funding_type_spec.rb
+++ b/spec/features/publish/courses/new_funding_type_spec.rb
@@ -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
diff --git a/spec/features/publish/e2e/new_course_spec.rb b/spec/features/publish/e2e/new_course_spec.rb
index 4b11173bd9..5eb1bd23c1 100644
--- a/spec/features/publish/e2e/new_course_spec.rb
+++ b/spec/features/publish/e2e/new_course_spec.rb
@@ -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
diff --git a/spec/forms/publish/course_study_mode_form_spec.rb b/spec/forms/publish/course_study_mode_form_spec.rb
index 275e8befcb..9b522a648a 100644
--- a/spec/forms/publish/course_study_mode_form_spec.rb
+++ b/spec/forms/publish/course_study_mode_form_spec.rb
@@ -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
diff --git a/spec/services/courses/creation_service_spec.rb b/spec/services/courses/creation_service_spec.rb
index 5f55980e0c..4e3fbd1bc9 100644
--- a/spec/services/courses/creation_service_spec.rb
+++ b/spec/services/courses/creation_service_spec.rb
@@ -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],
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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],
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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]
}
@@ -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
@@ -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
@@ -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
diff --git a/spec/support/feature_helpers/new_course_param_helper.rb b/spec/support/feature_helpers/new_course_param_helper.rb
index ce2ce6471f..c780bef491 100644
--- a/spec/support/feature_helpers/new_course_param_helper.rb
+++ b/spec/support/feature_helpers/new_course_param_helper.rb
@@ -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'
@@ -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'
@@ -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
@@ -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
}
@@ -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'
diff --git a/spec/support/page_objects/publish/course_study_mode_edit.rb b/spec/support/page_objects/publish/course_study_mode_edit.rb
index 168bba136c..0c8c3a43e1 100644
--- a/spec/support/page_objects/publish/course_study_mode_edit.rb
+++ b/spec/support/page_objects/publish/course_study_mode_edit.rb
@@ -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"]'
diff --git a/spec/support/page_objects/publish/courses/new_study_mode.rb b/spec/support/page_objects/publish/courses/new_study_mode.rb
index fcec549af2..27c3f7d5da 100644
--- a/spec/support/page_objects/publish/courses/new_study_mode.rb
+++ b/spec/support/page_objects/publish/courses/new_study_mode.rb
@@ -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"]'