Skip to content

Commit

Permalink
Merge pull request #4284 from DFE-Digital/1749-ensure-back-links-redi…
Browse files Browse the repository at this point in the history
…rect-correctly-on-tda-courses-part-2

[1749] Ensure back links redirect correctly on TDA courses
  • Loading branch information
avinhurry authored Jun 19, 2024
2 parents d13e28a + 7a007a7 commit 42d4ead
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 66 deletions.
28 changes: 23 additions & 5 deletions app/controllers/publish/courses/study_mode_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ def appropriate_visa_path
if @course.student_visa?
student_visa_sponsorship_publish_provider_recruitment_cycle_course_path(provider_code: course.provider_code,
recruitment_cycle_year: course.recruitment_cycle_year,
course_code: course.course_code)
course_code: course.course_code,
previous_tda_course: true)
else
skilled_worker_visa_sponsorship_publish_provider_recruitment_cycle_course_path(provider_code: course.provider_code,
recruitment_cycle_year: course.recruitment_cycle_year,
course_code: course.course_code)
course_code: course.course_code,
previous_tda_course: true)
end
end

def appropriate_visa_new_path
if @course.student_visa?
new_publish_provider_recruitment_cycle_courses_student_visa_sponsorship_path(path_params)
if previous_tda_course_path?
sponsorship_path_with_previous_tda_course
else
new_publish_provider_recruitment_cycle_courses_skilled_worker_visa_sponsorship_path(path_params)
sponsorship_path_without_previous_tda_course
end
end

Expand All @@ -89,6 +91,22 @@ def errors
def previous_tda_course_path?
params[:previous_tda_course] == 'true'
end

def sponsorship_path_with_previous_tda_course
if @course.student_visa?
new_publish_provider_recruitment_cycle_courses_student_visa_sponsorship_path(path_params.merge(previous_tda_course: true))
else
new_publish_provider_recruitment_cycle_courses_skilled_worker_visa_sponsorship_path(path_params.merge(previous_tda_course: true))
end
end

def sponsorship_path_without_previous_tda_course
if @course.student_visa?
new_publish_provider_recruitment_cycle_courses_student_visa_sponsorship_path(path_params)
else
new_publish_provider_recruitment_cycle_courses_skilled_worker_visa_sponsorship_path(path_params)
end
end
end
end
end
63 changes: 63 additions & 0 deletions app/helpers/publish/back_link_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

module Publish
module BackLinkHelper
def visa_path(course)
if previously_basic_details?
details_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
elsif previously_tda_course?
full_part_time_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code,
previous_tda_course: true
)
elsif course.provider.accredited_provider?
apprenticeship_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
else
funding_type_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
end
end

def study_mode_path(course)
if previously_tda_course?
funding_type_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code,
previous_tda_course: true
)
else

details_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)

end
end

private

def previously_tda_course?
params[:previous_tda_course] == 'true'
end

def previously_basic_details?
params[:back_to_basic_details].present?
end
end
end
32 changes: 29 additions & 3 deletions app/models/concerns/publish/course_basic_detail_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def path_params
end

def back_step
if go_to_confirmation_params
if previous_course_tda?
step_back_through_previously_defaulted_questions
elsif go_to_confirmation_params

{
modern_languages: :subjects,
can_sponsor_student_visa: (@course.is_uni_or_scitt? ? :apprenticeship : :funding_type),
Expand Down Expand Up @@ -197,7 +200,11 @@ def course_creation_path_for(page)
when :outcome
new_publish_provider_recruitment_cycle_courses_outcome_path(path_params)
when :full_or_part_time
new_publish_provider_recruitment_cycle_courses_study_mode_path(path_params)
if previous_course_tda?
new_publish_provider_recruitment_cycle_courses_study_mode_path(path_params.merge(previous_tda_course: true))
else
new_publish_provider_recruitment_cycle_courses_study_mode_path(path_params)
end
when :applications_open
new_publish_provider_recruitment_cycle_courses_applications_open_path(path_params)
when :accredited_provider
Expand All @@ -213,7 +220,11 @@ def course_creation_path_for(page)
when :subjects
new_publish_provider_recruitment_cycle_courses_subjects_path(path_params)
when :funding_type
new_publish_provider_recruitment_cycle_courses_funding_type_path(path_params)
if previous_course_tda?
new_publish_provider_recruitment_cycle_courses_funding_type_path(path_params.merge(previous_tda_course: true))
else
new_publish_provider_recruitment_cycle_courses_funding_type_path(path_params)
end
when :confirmation
confirmation_publish_provider_recruitment_cycle_courses_path(path_params)
end
Expand All @@ -222,5 +233,20 @@ def course_creation_path_for(page)
def go_to_confirmation_params
params[:goto_confirmation] || params.dig(:course, :goto_confirmation)
end

def previous_course_tda?
params[:previous_tda_course] == 'true'
end

def step_back_through_previously_defaulted_questions
case current_step
when :funding_type
:outcome
when :full_or_part_time
:funding_type
when :can_sponsor_student_visa, :can_sponsor_skilled_worker_visa
:full_or_part_time
end
end
end
end
6 changes: 5 additions & 1 deletion app/views/publish/courses/funding_type/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<% content_for :page_title, title_with_error_prefix("Funding type – #{course.name_and_code}", course.errors.any?) %>

<% content_for :before_content do %>
<%= govuk_back_link_to(details_publish_provider_recruitment_cycle_course_path(course.provider_code, course.recruitment_cycle_year, course.course_code)) %>
<% if params[:previous_tda_course] == 'true' %>
<%= govuk_back_link_to(outcome_publish_provider_recruitment_cycle_course_path(course.provider_code, course.recruitment_cycle_year, course.course_code, previous_tda_course: true)) %>
<% else %>
<%= govuk_back_link_to(details_publish_provider_recruitment_cycle_course_path(course.provider_code, course.recruitment_cycle_year, course.course_code)) %>
<% end %>
<% end %>

<%= render "publish/shared/errors" %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
<% content_for :page_title, title_with_error_prefix("#{t('page_titles.skilled_worker_visas.edit')} – #{course.name_and_code}", @visa_sponsorship_form.errors.any?) %>

<% content_for :before_content do %>
<% if params[:back_to_basic_details].present? %>
<%= govuk_back_link_to(
details_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
) %>
<% elsif @provider.accredited_provider? %>
<%= govuk_back_link_to(
apprenticeship_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
) %>
<% else %>
<%= govuk_back_link_to(
funding_type_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
) %>
<% end %>
<%= govuk_back_link_to(visa_path(course)) %>
<% end %>

<div class="govuk-grid-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@
</div>
<% end %>
</div>

<%= form.hidden_field :previous_tda_course, value: params[:previous_tda_course] %>
</fieldset>
<% end %>
26 changes: 1 addition & 25 deletions app/views/publish/courses/student_visa_sponsorship/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
<% content_for :page_title, title_with_error_prefix("#{t('page_titles.student_visas.edit')} – #{course.name_and_code}", @visa_sponsorship_form.errors.any?) %>

<% content_for :before_content do %>
<% if params[:back_to_basic_details].present? %>
<%= govuk_back_link_to(
details_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
) %>
<% elsif @provider.accredited_provider? %>
<%= govuk_back_link_to(
apprenticeship_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
) %>
<% else %>
<%= govuk_back_link_to(
funding_type_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
) %>
<% end %>
<%= govuk_back_link_to(visa_path(course)) %>
<% end %>

<div class="govuk-grid-row">
Expand Down
8 changes: 1 addition & 7 deletions app/views/publish/courses/study_mode/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
<% content_for :page_title, title_with_error_prefix("#{page_title} – #{course.name_and_code}", @course_study_mode_form.errors.any?) %>

<% content_for :before_content do %>
<%= govuk_back_link_to(
details_publish_provider_recruitment_cycle_course_path(
course.provider_code,
course.recruitment_cycle_year,
course.course_code
)
) %>
<%= govuk_back_link_to(study_mode_path(course)) %>
<% end %>

<div class="govuk-grid-row">
Expand Down
63 changes: 63 additions & 0 deletions spec/features/publish/courses/editing_course_outcome_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,21 @@
and_there_is_a_tda_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_i_choose_qts
and_the_back_link_points_to_the_outcome_page
and_i_choose_the_fee_paying
and_the_back_link_points_to_the_funding_type_page
and_i_choose_part_time
and_the_back_link_points_to_the_study_mode_page

and_i_click_back
then_i_am_on_the_study_mode_page

and_i_click_back
then_i_am_on_the_funding_type_page

when_i_update
and_i_update

and_i_choose_to_sponsor_a_student_visa
then_i_see_the_correct_attributes_in_the_database_for_fee_paying
end
Expand All @@ -64,8 +77,11 @@
and_there_is_a_tda_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_i_choose_qts
and_the_back_link_points_to_the_outcome_page
and_i_choose_salaried
and_the_back_link_points_to_the_funding_type_page
and_i_choose_part_time
and_the_back_link_points_to_the_study_mode_page
and_i_choose_to_sponsor_a_skilled_worker_visa
then_i_see_the_correct_attributes_in_the_database_for_salaried
end
Expand Down Expand Up @@ -233,5 +249,52 @@ def and_i_should_be_on_the_course_details_page
expect(page).to have_current_path(details_publish_provider_recruitment_cycle_course_path(provider_code: provider.provider_code, recruitment_cycle_year: provider.recruitment_cycle_year, code: course.course_code), ignore_query: true)
end

def and_the_back_link_points_to_the_outcome_page
expect(URI.parse(find_link('Back')[:href]).path).to eq(outcome_publish_provider_recruitment_cycle_course_path(
provider_code: provider.provider_code,
recruitment_cycle_year: 2025,
code: course.course_code
))
end

def and_the_back_link_points_to_the_funding_type_page
expect(URI.parse(find_link('Back')[:href]).path).to eq(funding_type_publish_provider_recruitment_cycle_course_path(
provider_code: provider.provider_code,
recruitment_cycle_year: 2025,
code: course.course_code
))
end

def and_the_back_link_points_to_the_study_mode_page
expect(URI.parse(find_link('Back')[:href]).path).to eq(full_part_time_publish_provider_recruitment_cycle_course_path(
provider_code: provider.provider_code,
recruitment_cycle_year: 2025,
code: course.course_code
))
end

def and_i_click_back
click_on 'Back'
end

def then_i_am_on_the_study_mode_page
expect(page).to have_current_path(full_part_time_publish_provider_recruitment_cycle_course_path(
provider_code: provider.provider_code,
recruitment_cycle_year: 2025,
code: course.course_code,
previous_tda_course: true
))
end

def then_i_am_on_the_funding_type_page
expect(page).to have_current_path(funding_type_publish_provider_recruitment_cycle_course_path(
provider_code: provider.provider_code,
recruitment_cycle_year: 2025,
code: course.course_code,
previous_tda_course: true
))
end

alias_method :and_i_choose_to_sponsor_a_skilled_worker_visa, :and_i_choose_to_sponsor_a_student_visa
alias_method :when_i_update, :and_i_update
end
Loading

0 comments on commit 42d4ead

Please sign in to comment.