From 1aaac595fd9661113db3b2133a1154896a5c3f82 Mon Sep 17 00:00:00 2001 From: Lori Bailey <44073106+elceebee@users.noreply.github.com> Date: Thu, 13 Jun 2024 14:18:02 +0100 Subject: [PATCH 1/4] Remove unused methodsfrom specs --- .../editing_course_about_this_course_copy_content_spec.rb | 5 ----- .../editing_course_school_placements_copy_content_spec.rb | 5 ----- 2 files changed, 10 deletions(-) diff --git a/spec/features/publish/courses/editing_course_about_this_course_copy_content_spec.rb b/spec/features/publish/courses/editing_course_about_this_course_copy_content_spec.rb index 0eee9ad3b0..5f15e72451 100644 --- a/spec/features/publish/courses/editing_course_about_this_course_copy_content_spec.rb +++ b/spec/features/publish/courses/editing_course_about_this_course_copy_content_spec.rb @@ -94,11 +94,6 @@ def when_i_click_on_the_link_in_the_warning_box click_on 'About this course' end - def then_the_focus_is_on_the_input - about = find_field 'About this course' - expect(about.focus?).to be true - end - def when_i_visit_the_about_this_course_edit_page visit about_this_course_publish_provider_recruitment_cycle_course_path( provider.provider_code, diff --git a/spec/features/publish/courses/editing_course_school_placements_copy_content_spec.rb b/spec/features/publish/courses/editing_course_school_placements_copy_content_spec.rb index d3cb25cab5..8ccd9e22b6 100644 --- a/spec/features/publish/courses/editing_course_school_placements_copy_content_spec.rb +++ b/spec/features/publish/courses/editing_course_school_placements_copy_content_spec.rb @@ -88,11 +88,6 @@ def then_i_do_not_see_copied_course_data expect(find_field('How placements work').value).to eq @course.enrichments.first.how_school_placements_work end - def then_the_focus_is_on_the_input - about = find_field 'Interview process' - expect(about.focus?).to be true - end - def when_i_visit_the_school_placements_edit_page visit school_placements_publish_provider_recruitment_cycle_course_path( provider.provider_code, From 722d3d5962f21443e9b31918d3da70441ae96fe2 Mon Sep 17 00:00:00 2001 From: Lori Bailey <44073106+elceebee@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:24:33 +0100 Subject: [PATCH 2/4] Fetch course list for copy content option --- .../courses/about_this_course_controller.rb | 1 + .../courses/gcse_requirements_controller.rb | 1 + .../courses/interview_process_controller.rb | 1 + .../courses/school_placements_controller.rb | 1 + ...rse_about_this_course_copy_content_spec.rb | 27 ++++- ...rse_gcse_requirements_copy_content_spec.rb | 106 ++++++++++++++++++ ...rse_interview_process_copy_content_spec.rb | 23 ++++ ...rse_school_placements_copy_content_spec.rb | 23 ++++ 8 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 spec/features/publish/courses/editing_course_gcse_requirements_copy_content_spec.rb diff --git a/app/controllers/publish/courses/about_this_course_controller.rb b/app/controllers/publish/courses/about_this_course_controller.rb index 722a3080eb..df3ff9d451 100644 --- a/app/controllers/publish/courses/about_this_course_controller.rb +++ b/app/controllers/publish/courses/about_this_course_controller.rb @@ -24,6 +24,7 @@ def update redirect_to redirect_path else + fetch_course_list_to_copy_from render :edit end end diff --git a/app/controllers/publish/courses/gcse_requirements_controller.rb b/app/controllers/publish/courses/gcse_requirements_controller.rb index d828386b5a..d0b605019d 100644 --- a/app/controllers/publish/courses/gcse_requirements_controller.rb +++ b/app/controllers/publish/courses/gcse_requirements_controller.rb @@ -29,6 +29,7 @@ def update @gcse_requirements_form.save(course) redirect_to publish_provider_recruitment_cycle_course_path else + fetch_course_list_to_copy_from @errors = @gcse_requirements_form.errors.messages render :edit end diff --git a/app/controllers/publish/courses/interview_process_controller.rb b/app/controllers/publish/courses/interview_process_controller.rb index a3726d99a6..8a1030b0b7 100644 --- a/app/controllers/publish/courses/interview_process_controller.rb +++ b/app/controllers/publish/courses/interview_process_controller.rb @@ -23,6 +23,7 @@ def update redirect_to redirect_path else + fetch_course_list_to_copy_from render :edit end end diff --git a/app/controllers/publish/courses/school_placements_controller.rb b/app/controllers/publish/courses/school_placements_controller.rb index 3be72dd242..dc1e291ba4 100644 --- a/app/controllers/publish/courses/school_placements_controller.rb +++ b/app/controllers/publish/courses/school_placements_controller.rb @@ -29,6 +29,7 @@ def update redirect_to preview_or_course_description else + fetch_course_list_to_copy_from render :edit end end diff --git a/spec/features/publish/courses/editing_course_about_this_course_copy_content_spec.rb b/spec/features/publish/courses/editing_course_about_this_course_copy_content_spec.rb index 5f15e72451..6bfb24d528 100644 --- a/spec/features/publish/courses/editing_course_about_this_course_copy_content_spec.rb +++ b/spec/features/publish/courses/editing_course_about_this_course_copy_content_spec.rb @@ -13,7 +13,7 @@ and_i_select_the_other_course_from_the_copy_content_dropdown then_i_see_the_copied_course_data - then_i_see_the_warning_that_changes_are_not_saved + and_i_see_the_warning_that_changes_are_not_saved and_the_warning_has_a_link_to_the_about_course_input_field end end @@ -29,6 +29,16 @@ and_i_do_not_see_the_warning_that_changes_are_not_saved end + scenario 'copy course content options are available after validation' do + given_i_am_authenticated_as_a_provider_user + and_there_is_a_course_i_want_to_edit + and_there_is_a_course_with_data_i_want_to_copy + + when_i_visit_the_about_this_course_edit_page + when_i_submit_without_data + then_i_can_still_copy_content_from_another_course + end + private def given_i_am_authenticated_as_a_provider_user @@ -43,6 +53,18 @@ def and_there_is_a_course_with_data_i_want_to_copy course_to_copy('About this other course') end + def when_i_submit_without_data + fill_in 'About this course', with: '' + click_on 'Update about this course' + end + + def then_i_can_still_copy_content_from_another_course + when_i_select_the_other_course_from_the_copy_content_dropdown + + then_i_see_the_copied_course_data + and_i_see_the_warning_that_changes_are_not_saved + end + def and_there_is_a_course_without_data_i_try_to_copy course_to_copy(nil) end @@ -64,8 +86,9 @@ def and_i_select_the_other_course_from_the_copy_content_dropdown click_on 'Copy content' end + alias_method :when_i_select_the_other_course_from_the_copy_content_dropdown, :and_i_select_the_other_course_from_the_copy_content_dropdown - def then_i_see_the_warning_that_changes_are_not_saved + def and_i_see_the_warning_that_changes_are_not_saved expect(page).to have_content 'Your changes are not yet saved' expect(page).to have_content "We have copied this field from #{copied_course_name_and_code}." expect(page).to have_link 'About this course' diff --git a/spec/features/publish/courses/editing_course_gcse_requirements_copy_content_spec.rb b/spec/features/publish/courses/editing_course_gcse_requirements_copy_content_spec.rb new file mode 100644 index 0000000000..053067f53a --- /dev/null +++ b/spec/features/publish/courses/editing_course_gcse_requirements_copy_content_spec.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +require 'rails_helper' + +feature 'Editing GCSE requirements section, copying content from another course' do + scenario 'source course has gces requirements data to copy' do + given_i_am_authenticated_as_a_provider_user + and_there_is_a_course_i_want_to_edit + and_there_is_a_course_with_data_i_want_to_copy + + when_i_visit_the_gcse_requirements_edit_page + and_i_select_the_other_course_from_the_copy_content_dropdown + + then_i_see_the_copied_course_data + and_i_see_the_warning_that_changes_are_not_saved + end + + scenario 'copy course content options are available after validation' do + given_i_am_authenticated_as_a_provider_user + and_there_is_a_course_i_want_to_edit + and_there_is_a_course_with_data_i_want_to_copy + + when_i_visit_the_gcse_requirements_edit_page + when_i_submit_without_data + then_i_can_still_copy_content_from_another_course + end + + private + + def given_i_am_authenticated_as_a_provider_user + given_i_am_authenticated(user: create(:user, :with_provider)) + end + + def and_there_is_a_course_i_want_to_edit + given_a_course_exists + end + + def when_i_submit_without_data + click_on 'Update GCSEs and equivalency tests' + end + + def then_i_can_still_copy_content_from_another_course + when_i_select_the_other_course_from_the_copy_content_dropdown + + then_i_see_the_copied_course_data + and_i_see_the_warning_that_changes_are_not_saved + end + + def and_there_is_a_course_with_data_i_want_to_copy + @copied_course ||= create( + :course, + provider: current_user.providers.first, + accept_pending_gcse: true, + accept_gcse_equivalency: true, + accept_english_gcse_equivalency: false, + accept_maths_gcse_equivalency: true, + accept_science_gcse_equivalency: false, + additional_gcse_equivalencies: 'Some text about gcse equivalences' + ) + end + + def copied_course_name_and_code + "#{@copied_course.name} (#{@copied_course.course_code})" + end + + def and_i_select_the_other_course_from_the_copy_content_dropdown + select copied_course_name_and_code, from: 'Copy from' + + click_on 'Copy content' + end + alias_method :when_i_select_the_other_course_from_the_copy_content_dropdown, :and_i_select_the_other_course_from_the_copy_content_dropdown + + def and_i_see_the_warning_that_changes_are_not_saved + expect(page).to have_content 'Your changes are not yet saved' + expect(page).to have_content "We’ve copied these fields from #{copied_course_name_and_code}:" + expect(page).to have_link 'Accept pending GCSE' + expect(page).to have_link 'Accept GCSE equivalency' + expect(page).to have_link 'Accept Maths GCSE equivalency' + expect(page).to have_link 'Additional GCSE equivalencies' + expect(page).to have_content 'Please check them and make your changes before saving.' + end + + def then_i_see_the_copied_course_data + expect(page.find('[data-qa="gcse_requirements__pending_gcse_yes_radio"]')).to be_checked + expect(page.find('[data-qa="gcse_requirements__gcse_equivalency_yes_radio"]')).to be_checked + expect( + find_field( + 'Details about equivalency tests you offer or accept' + ).value + ).to eq 'Some text about gcse equivalences' + expect(find_field('English')).not_to be_checked + expect(find_field('Maths')).to be_checked + end + + def when_i_visit_the_gcse_requirements_edit_page + visit gcses_pending_or_equivalency_tests_publish_provider_recruitment_cycle_course_path( + provider.provider_code, + course.recruitment_cycle_year, + course.course_code + ) + end + + def provider + @provider ||= @current_user.providers.first + end +end diff --git a/spec/features/publish/courses/editing_course_interview_process_copy_content_spec.rb b/spec/features/publish/courses/editing_course_interview_process_copy_content_spec.rb index 377b606c57..ca47531f63 100644 --- a/spec/features/publish/courses/editing_course_interview_process_copy_content_spec.rb +++ b/spec/features/publish/courses/editing_course_interview_process_copy_content_spec.rb @@ -29,6 +29,16 @@ and_i_do_not_see_the_warning_that_changes_are_not_saved end + scenario 'copy course content options are available after validation' do + given_i_am_authenticated_as_a_provider_user + and_there_is_a_course_i_want_to_edit + and_there_is_a_course_with_data_i_want_to_copy + + when_i_visit_the_interview_process_edit_page + when_i_submit_with_too_many_words + then_i_can_still_copy_content_from_another_course + end + private def given_i_am_authenticated_as_a_provider_user @@ -47,6 +57,18 @@ def and_there_is_a_course_without_data_i_try_to_copy course_to_copy(nil) end + def when_i_submit_with_too_many_words + fill_in 'Interview process', with: Faker::Lorem.sentence(word_count: 251) + click_on 'Update interview process' + end + + def then_i_can_still_copy_content_from_another_course + when_i_select_the_other_course_from_the_copy_content_dropdown + + then_i_see_the_copied_course_data + and_i_see_the_warning_that_changes_are_not_saved + end + def course_to_copy(interview_process) @copied_course ||= create( :course, @@ -64,6 +86,7 @@ def and_i_select_the_other_course_from_the_copy_content_dropdown click_on 'Copy content' end + alias_method :when_i_select_the_other_course_from_the_copy_content_dropdown, :and_i_select_the_other_course_from_the_copy_content_dropdown def and_i_see_the_warning_that_changes_are_not_saved expect(page).to have_content 'Your changes are not yet saved' diff --git a/spec/features/publish/courses/editing_course_school_placements_copy_content_spec.rb b/spec/features/publish/courses/editing_course_school_placements_copy_content_spec.rb index 8ccd9e22b6..0bae16a17c 100644 --- a/spec/features/publish/courses/editing_course_school_placements_copy_content_spec.rb +++ b/spec/features/publish/courses/editing_course_school_placements_copy_content_spec.rb @@ -27,6 +27,16 @@ and_i_do_not_see_the_warning_that_changes_are_not_saved end + scenario 'copy course content options are available after validation' do + given_i_am_authenticated_as_a_provider_user + and_there_is_a_course_i_want_to_edit + and_there_is_a_course_with_data_i_want_to_copy + + when_i_visit_the_school_placements_edit_page + when_i_submit_without_data + then_i_can_still_copy_content_from_another_course + end + private def given_i_am_authenticated_as_a_provider_user @@ -37,6 +47,18 @@ def and_there_is_a_course_i_want_to_edit given_a_course_exists(enrichments: [build(:course_enrichment, :published)]) end + def when_i_submit_without_data + fill_in 'How placements work', with: '' + click_on 'Update how placements work' + end + + def then_i_can_still_copy_content_from_another_course + when_i_select_the_other_course_from_the_copy_content_dropdown + + then_i_see_the_copied_course_data + and_i_see_the_warning_that_changes_are_not_saved + end + def and_there_is_a_course_with_data_i_want_to_copy course_to_copy('About this other course') end @@ -62,6 +84,7 @@ def and_i_select_the_other_course_from_the_copy_content_dropdown click_on 'Copy content' end + alias_method :when_i_select_the_other_course_from_the_copy_content_dropdown, :and_i_select_the_other_course_from_the_copy_content_dropdown def and_i_see_the_warning_that_changes_are_not_saved expect(page).to have_content 'Your changes are not yet saved' From 9e9f6b1dfb9925dd6cc7ce601ff268857787fcc5 Mon Sep 17 00:00:00 2001 From: Lori Bailey <44073106+elceebee@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:06:48 +0100 Subject: [PATCH 3/4] Refactor copy content partials to shared component --- ..._course_content_warning_component.html.erb | 23 +++++ .../copy_course_content_warning_component.rb | 34 +++++++ .../subject_requirements_controller.rb | 1 + app/services/courses/copy.rb | 10 +- ...copy_about_course_content_warning.html.erb | 30 ------ .../courses/about_this_course/edit.html.erb | 6 +- .../subject_requirements/edit.html.erb | 6 +- app/views/publish/courses/fees/edit.html.erb | 6 +- .../courses/gcse_requirements/edit.html.erb | 6 +- ...interview_process_content_warning.html.erb | 30 ------ .../courses/interview_process/edit.html.erb | 8 +- ...school_placements_content_warning.html.erb | 30 ------ .../courses/school_placements/edit.html.erb | 6 +- config/locales/en.yml | 18 ++-- ...ourse_content_warning_component_preview.rb | 32 ++++++ ...y_course_content_warning_component_spec.rb | 45 +++++++++ ...rse_about_this_course_copy_content_spec.rb | 2 +- ...rse_gcse_requirements_copy_content_spec.rb | 24 ++++- ...rse_interview_process_copy_content_spec.rb | 2 +- ...rse_school_placements_copy_content_spec.rb | 2 +- ..._subject_requirements_copy_content_spec.rb | 99 +++++++++++++++++++ 21 files changed, 302 insertions(+), 118 deletions(-) create mode 100644 app/components/providers/copy_course_content_warning_component.html.erb create mode 100644 app/components/providers/copy_course_content_warning_component.rb delete mode 100644 app/views/publish/courses/about_this_course/_copy_about_course_content_warning.html.erb delete mode 100644 app/views/publish/courses/interview_process/_copy_interview_process_content_warning.html.erb delete mode 100644 app/views/publish/courses/school_placements/_copy_school_placements_content_warning.html.erb create mode 100644 spec/components/providers/copy_course_content_warning_component_preview.rb create mode 100644 spec/components/providers/copy_course_content_warning_component_spec.rb create mode 100644 spec/features/publish/courses/editing_course_subject_requirements_copy_content_spec.rb diff --git a/app/components/providers/copy_course_content_warning_component.html.erb b/app/components/providers/copy_course_content_warning_component.html.erb new file mode 100644 index 0000000000..0b73931979 --- /dev/null +++ b/app/components/providers/copy_course_content_warning_component.html.erb @@ -0,0 +1,23 @@ +<% if field_links.present? %> + <%= govuk_notification_banner( + title_text: t("notification_banner.warning"), + classes: "govuk-notification-banner--warning", + html_attributes: { + data: { qa: "copy-course-warning" }, + role: "alert" + } + ) do |notification_banner| %> + <% notification_banner.with_heading( + text: t("components.providers.copy_course_content_warning_component.changes_not_saved") + ) %> +
+ <%= copied_fields_from %> +
+<%= please_check_changes %>
+ <% end %> +<% end %> diff --git a/app/components/providers/copy_course_content_warning_component.rb b/app/components/providers/copy_course_content_warning_component.rb new file mode 100644 index 0000000000..4de1c11e35 --- /dev/null +++ b/app/components/providers/copy_course_content_warning_component.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Providers + class CopyCourseContentWarningComponent < ApplicationComponent + include I18n + def initialize(copied_fields, form_identifier, source_course, **) + super(**) + @copied_fields = copied_fields + @form_identifier = form_identifier + @source_course = source_course + end + + def field_links + @copied_fields.map do |name, field| + [name, "##{@form_identifier}-#{field.gsub('_', '-')}-field"] + end + end + + def please_check_changes + translation_base = 'components.providers.copy_course_content_warning_component.please_check_changes' + t("#{translation_base}.#{plural? ? 'plural' : 'singular'}") + end + + def copied_fields_from + translation_base = 'components.providers.copy_course_content_warning_component.copied_fields_from' + t("#{translation_base}.#{plural? ? 'plural' : 'singular'}", + name_and_code: "#{@source_course.name} (#{@source_course.course_code})") + end + + def plural? + @copied_fields.length > 1 + end + end +end diff --git a/app/controllers/publish/courses/degrees/subject_requirements_controller.rb b/app/controllers/publish/courses/degrees/subject_requirements_controller.rb index 11b8c9f31b..cfdd122671 100644 --- a/app/controllers/publish/courses/degrees/subject_requirements_controller.rb +++ b/app/controllers/publish/courses/degrees/subject_requirements_controller.rb @@ -32,6 +32,7 @@ def update redirect_to preview_publish_provider_recruitment_cycle_course_path(provider.provider_code, course.recruitment_cycle_year, course.course_code) else set_backlink + fetch_course_list_to_copy_from @errors = @subject_requirements_form.errors.messages render :edit end diff --git a/app/services/courses/copy.rb b/app/services/courses/copy.rb index 48d6e43d66..a844325e0b 100644 --- a/app/services/courses/copy.rb +++ b/app/services/courses/copy.rb @@ -3,11 +3,11 @@ module Courses class Copy GCSE_FIELDS = [ - ['Accept pending GCSE', 'accept_pending_gcse'], - ['Accept GCSE equivalency', 'accept_gcse_equivalency'], - ['Accept English GCSE equivalency', 'accept_english_gcse_equivalency'], - ['Accept Maths GCSE equivalency', 'accept_maths_gcse_equivalency'], - ['Additional GCSE equivalencies', 'additional_gcse_equivalencies'] + ['Accept pending GCSE', 'accept_pending_gcse', 'accept-pending-gcse-true'], + ['Accept GCSE equivalency', 'accept_gcse_equivalency', 'accept-gcse-equivalency-true'], + ['Accept English GCSE equivalency', 'accept_english_gcse_equivalency', 'accept-english-gcse-equivalency-english'], + ['Accept Maths GCSE equivalency', 'accept_maths_gcse_equivalency', 'accept-maths-gcse-equivalency-maths'], + ['Additional GCSE equivalencies', 'additional_gcse_equivalencies', 'additional-gcse-equivalencies'] ].freeze SUBJECT_REQUIREMENTS_FIELDS = [ diff --git a/app/views/publish/courses/about_this_course/_copy_about_course_content_warning.html.erb b/app/views/publish/courses/about_this_course/_copy_about_course_content_warning.html.erb deleted file mode 100644 index b7a49ecbca..0000000000 --- a/app/views/publish/courses/about_this_course/_copy_about_course_content_warning.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -<%= govuk_notification_banner( - title_text: t("notification_banner.warning"), - classes: "govuk-notification-banner--warning", - html_attributes: { - data: { qa: "copy-course-warning" }, - role: "alert" - } - ) do |notification_banner| %> - <% notification_banner.with_heading(text: t("publish.providers.about_course.edit.changes_not_saved")) %> -- <%= t( - "publish.providers.about_course.edit.copied_fields_from", - name_and_code: "#{@source_course.name} (#{@source_course.course_code})" - ) %> -
-- <%= t("publish.providers.about_course.edit.please_check_changes") %> -
-<% end %> diff --git a/app/views/publish/courses/about_this_course/edit.html.erb b/app/views/publish/courses/about_this_course/edit.html.erb index 884841d64b..7a091ab8b7 100644 --- a/app/views/publish/courses/about_this_course/edit.html.erb +++ b/app/views/publish/courses/about_this_course/edit.html.erb @@ -4,7 +4,11 @@ ) %> <% if params[:copy_from].present? && @copied_fields.any? %> - <%= render partial: "copy_about_course_content_warning" %> + <%= render Providers::CopyCourseContentWarningComponent.new( + @copied_fields, + "publish-course-about-this-course-form", + @source_course + ) %> <% end %>- <%= t( - "publish.providers.interview_process.edit.copied_fields_from", - name_and_code: "#{@source_course.name} (#{@source_course.course_code})" - ) %> -
-- <%= t("publish.providers.interview_process.edit.please_check_changes") %> -
-<% end %> diff --git a/app/views/publish/courses/interview_process/edit.html.erb b/app/views/publish/courses/interview_process/edit.html.erb index cfae64f2f1..b1971958bf 100644 --- a/app/views/publish/courses/interview_process/edit.html.erb +++ b/app/views/publish/courses/interview_process/edit.html.erb @@ -3,8 +3,12 @@ @interview_process_form.errors.any? ) %> -<% if params[:copy_from].present? && @copied_fields.any? %> - <%= render partial: "copy_interview_process_content_warning" %> +<% if params[:copy_from].present? %> + <%= render Providers::CopyCourseContentWarningComponent.new( + @copied_fields, + "publish-course-interview-process-form", + @source_course + ) %> <% end %>- <%= t( - "publish.providers.school_placements.edit.copied_fields_from", - name_and_code: "#{@source_course.name} (#{@source_course.course_code})" - ) %> -
-- <%= t("publish.providers.school_placements.edit.please_check_changes") %> -
-<% end %> diff --git a/app/views/publish/courses/school_placements/edit.html.erb b/app/views/publish/courses/school_placements/edit.html.erb index 00072c6123..db20125b88 100644 --- a/app/views/publish/courses/school_placements/edit.html.erb +++ b/app/views/publish/courses/school_placements/edit.html.erb @@ -4,7 +4,11 @@ ) %> <% if params[:copy_from].present? && @copied_fields.any? %> - <%= render partial: "copy_school_placements_content_warning", locals: { copied_fields: @copied_fields } %> + <%= render Providers::CopyCourseContentWarningComponent.new( + @copied_fields, + "publish-course-school-placements-form", + @source_course + ) %> <% end %>Include information about: