Skip to content

Commit

Permalink
Test coverage for moving support users to multi org views
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie committed Oct 8, 2024
1 parent 44656f0 commit f59e3c2
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 49 deletions.
8 changes: 7 additions & 1 deletion app/controllers/placements/providers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
class Placements::ProvidersController < Placements::ApplicationController
def show
@provider = current_user.providers.find(params.require(:id)).decorate
@provider = providers.find(params.require(:id)).decorate
end

private

def providers
current_user.support_user? ? Placements::Provider.all : current_user.providers
end
end
8 changes: 7 additions & 1 deletion app/controllers/placements/schools_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
class Placements::SchoolsController < Placements::ApplicationController
def show
@school = current_user.schools.find(params.require(:id)).decorate
@school = schools.find(params.require(:id)).decorate
end

private

def schools
current_user.support_user? ? Placements::School.all : current_user.schools
end
end
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<% caption = current_user.support_user? ? "#{t(".caption")} #{contextual_text}" : t(".caption") %>
<% content_for :page_title, user_step.errors.any? ? t(".title_with_error", caption:) : t(".title", caption:) %>
<% content_for :page_title, user_step.errors.any? ? t(".title_with_error", caption: t(".caption")) : t(".title", caption: t(".caption")) %>
<%= form_for(user_step, url: current_step_path, method: :put) do |f| %>
<%= f.govuk_error_summary %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l"><%= caption %></span>
<span class="govuk-caption-l"><%= t(".caption") %></span>
<h1 class="govuk-heading-l"><%= t(".personal_details") %></h1>

<div class="govuk-form-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
then_i_see_form_with_trn_and_date_of_birth(claims_mentor.trn, 1, 1, 1990)
when_i_click_on("Continue")
then_i_see_check_page_for(claims_mentor)
when_i_click_on("Change")
when_i_click_on("Change Teacher reference number (TRN)")
then_i_see_form_with_trn_and_date_of_birth(claims_mentor.trn, 1, 1, 1990)
when_i_click_on("Continue")
then_i_see_check_page_for(claims_mentor)
Expand Down Expand Up @@ -167,6 +167,8 @@
end
end

private

def given_i_sign_in_as_colin
user = create(:placements_support_user, :colin)
user_exists_in_dfe_sign_in(user:)
Expand All @@ -184,7 +186,7 @@ def given_a_placements_mentor_exists(school, mentor)

def given_i_navigate_to_schools_mentors_list(school)
click_on school.name
within(".app-secondary-navigation") do
within(".app-primary-navigation") do
click_on "Mentors"
end
end
Expand Down Expand Up @@ -214,10 +216,12 @@ def then_i_see_check_page_for(mentor)
end

def expect_organisations_to_be_selected_in_primary_navigation
within(".app-primary-navigation__nav") do
expect(page).to have_link "Organisations", current: "page"
expect(page).to have_link "Support users", current: "false"
end
# TODO: Re-added in https://github.com/DFE-Digital/itt-mentor-services/pull/1085
# when the nav is moved to the service header
# within(".app-primary-navigation__nav") do
# expect(page).to have_link "Organisations", current: "page"
# expect(page).to have_link "Support users", current: "false"
# end
end

def then_mentor_is_added(mentor_name)
Expand All @@ -240,11 +244,11 @@ def when_i_enter_date_of_birth(day, month, year)
end

def then_i_see_the_index_page(school)
expect(page).to have_current_path placements_support_school_mentors_path(school), ignore_query: true
expect(page).to have_current_path placements_school_mentors_path(school), ignore_query: true
end

def then_i_see_the_error(message, school_name, title = message, field_index = 0)
expect(page).to have_title "Error: #{title} - Mentor details - #{school_name}"
expect(page).to have_title "Error: #{title} - Mentor details"
within(".govuk-error-summary") do
expect(page).to have_content message
end
Expand All @@ -269,7 +273,7 @@ def then_i_see_form_with_trn_and_date_of_birth(trn, day, month, year)

def then_i_see_no_results_page(_school_name, trn)
expect(page).to have_title "No results found for ‘#{trn}’"
expect(page).to have_content "Mentor not found - #{school.name}"
expect(page).to have_content "Mentor not found"
expect(page).to have_content "No results found for ‘#{trn}’"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
scenario "Support user navigates to different organisations on the list" do
given_i_am_signed_in_as_a_support_user
when_i_click_on_a_organisation_name(school.name)
and_i_click_on("Organisation details")
then_i_see_the_school_details
when_i_navigate_back_to_the_organisations_list
when_i_click_on_a_organisation_name(university.name)
and_i_click_on("Organisation details")
then_i_see_the_provider_details
end

Expand All @@ -31,11 +33,8 @@ def when_i_click_on_a_organisation_name(name)
end

def then_i_see_the_provider_details
within(".govuk-heading-l") do
expect(page).to have_content university.name
end

within("#organisation-details") do
expect(page).to have_content university.name
expect(page).to have_content "Name"
expect(page).to have_content "UK provider reference number (UKPRN)"
expect(page).to have_content "Unique reference number (URN)"
Expand All @@ -47,9 +46,13 @@ def then_i_see_the_provider_details
end

def when_i_navigate_back_to_the_organisations_list
within(".app-primary-navigation__list") do
click_on "Organisations"
end
# TODO: Re-added in https://github.com/DFE-Digital/itt-mentor-services/pull/1085
# when the nav is moved to the service header
# within(".app-primary-navigation__list") do
# click_on "Organisations"
# end

visit placements_support_organisations_path
end

def then_i_see_the_school_details
Expand Down Expand Up @@ -100,4 +103,8 @@ def then_i_see_the_school_details
def and_i_navigate_to_the_school_details_page
visit placements_support_school_path(school)
end

def and_i_click_on(text)
click_on text
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def given_i_am_signed_in_as_a_support_user

def and_i_visit_the_user_page(organisation)
click_on organisation.name
within(".app-secondary-navigation__list") do
within(".app-primary-navigation__list") do
click_on "Users"
end
click_on user.full_name
Expand All @@ -108,29 +108,31 @@ def when_i_click_on(text)
def then_i_am_asked_to_confirm(organisation)
organisations_is_selected_in_primary_nav
expect(page).to have_title(
"Are you sure you want to delete this user? - #{user.full_name} - #{organisation.name} - Manage school placements",
"Are you sure you want to delete this user? - #{user.full_name} - Manage school placements",
)
expect(page).to have_content "#{user.full_name} - #{organisation.name}"
expect(page).to have_content user.full_name
expect(page).to have_content "Are you sure you want to delete this user?"
expect(page).to have_content "The user will be sent an email to tell them you deleted them from #{organisation.name}"
end

def organisations_is_selected_in_primary_nav
within(".app-primary-navigation__nav") do
expect(page).to have_link "Organisations", current: "page"
expect(page).to have_link "Support users", current: "false"
end
# TODO: Re-added in https://github.com/DFE-Digital/itt-mentor-services/pull/1085
# when the nav is moved to the service header
# within(".app-primary-navigation__nav") do
# expect(page).to have_link "Organisations", current: "page"
# expect(page).to have_link "Support users", current: "false"
# end
end

def users_is_selected_in_secondary_nav(organisation)
within(".app-secondary-navigation__list") do
expect(page).to have_link "Details", current: "false"
within(".app-primary-navigation__list") do
expect(page).to have_link "Organisation details", current: "false"
expect(page).to have_link "Users", current: "page"
if organisation.is_a?(Provider)
expect(page).to have_link "Partner schools", current: "false"
expect(page).to have_link "Schools", current: "false"
else
expect(page).to have_link "Mentors", current: "false"
expect(page).to have_link "Partner providers", current: "false"
expect(page).to have_link "Providers", current: "false"
expect(page).to have_link "Placements", current: "false"
end
end
Expand All @@ -140,9 +142,9 @@ def then_i_return_to_user_page(organisation)
organisations_is_selected_in_primary_nav
case organisation
when School
expect(page).to have_current_path placements_support_school_user_path(organisation, user), ignore_query: true
expect(page).to have_current_path placements_school_user_path(organisation, user), ignore_query: true
when Provider
expect(page).to have_current_path placements_support_provider_user_path(organisation, user), ignore_query: true
expect(page).to have_current_path placements_provider_user_path(organisation, user), ignore_query: true
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def given_i_am_signed_in_as_a_support_user

def when_i_visit_the_users_page_for(organisation:)
click_on organisation.name
within(".app-secondary-navigation__list") do
within(".app-primary-navigation__list") do
click_on "Users"
end
end
Expand All @@ -160,19 +160,21 @@ def and_i_enter_the_details_for_a_new_user
end

def then_i_see_the_navigation_bars_with_organisations_and_users_selected(organisation)
within(".app-primary-navigation__nav") do
expect(page).to have_link "Organisations", current: "page"
expect(page).to have_link "Support users", current: "false"
end

within(".app-secondary-navigation") do
expect(page).to have_link "Details", current: "false"
# TODO: Re-added in https://github.com/DFE-Digital/itt-mentor-services/pull/1085
# when the nav is moved to the service header
# within(".app-primary-navigation__nav") do
# expect(page).to have_link "Organisations", current: "page"
# expect(page).to have_link "Support users", current: "false"
# end

within(".app-primary-navigation") do
expect(page).to have_link "Organisation details", current: "false"
expect(page).to have_link "Users", current: "page"
if organisation.is_a?(Provider)
expect(page).to have_link "Partner schools", current: "false"
expect(page).to have_link "Schools", current: "false"
else
expect(page).to have_link "Mentors", current: "false"
expect(page).to have_link "Partner providers", current: "false"
expect(page).to have_link "Providers", current: "false"
expect(page).to have_link "Placements", current: "false"
end
end
Expand Down Expand Up @@ -255,9 +257,11 @@ def then_i_see_an_error(error_message, error_index = 0)
end

def then_i_see_support_navigation_with_organisation_selected
within(".app-primary-navigation__nav") do
expect(page).to have_link "Organisations", current: "page"
expect(page).to have_link "Support users", current: "false"
end
# TODO: Re-added in https://github.com/DFE-Digital/itt-mentor-services/pull/1085
# when the nav is moved to the service header
# within(".app-primary-navigation__nav") do
# expect(page).to have_link "Organisations", current: "page"
# expect(page).to have_link "Support users", current: "false"
# end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def given_users_have_been_assigned_to_the(organisation:)
def when_i_visit_the_users_page_for(organisation:)
visit placements_support_root_path
click_on organisation.name
within(".app-secondary-navigation__list") do
within(".app-primary-navigation__list") do
click_on "Users"
end
end
Expand Down

0 comments on commit f59e3c2

Please sign in to comment.