From f4464e5b53f70b56c0b887a5ba33c23f7612f228 Mon Sep 17 00:00:00 2001 From: JG Date: Fri, 10 Jun 2022 10:28:14 +0100 Subject: [PATCH] navs helper done --- app/helpers/navigation_items_helper.rb | 3 +- spec/helpers/navigation_items_helper_spec.rb | 29 +++++ .../requests/organisations_controller_spec.rb | 121 +++++++++++++----- 3 files changed, 120 insertions(+), 33 deletions(-) diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index 6c56db96c..c0b55c674 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -28,6 +28,7 @@ module NavigationItemsHelper def secondary_items(path, current_organisation_id) [ NavigationItem.new("Logs", "/organisations/#{current_organisation_id}/logs", subnav_logs_path?(path)), + NavigationItem.new("Supported housing", "/organisations/#{current_organisation_id}/supported-housing", subnav_supported_housing_path?(path)), NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)), NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)), ] @@ -48,7 +49,7 @@ private end def organisations_current?(path) - path == "/organisations" || subnav_users_path?(path) || subnav_logs_path?(path) || subnav_details_path?(path) + path == "/organisations" || subnav_users_path?(path) || subnav_logs_path?(path) || subnav_details_path?(path) || subnav_supported_housing_path?(path) end def subnav_supported_housing_path?(path) diff --git a/spec/helpers/navigation_items_helper_spec.rb b/spec/helpers/navigation_items_helper_spec.rb index 0d138fe9b..92135841a 100644 --- a/spec/helpers/navigation_items_helper_spec.rb +++ b/spec/helpers/navigation_items_helper_spec.rb @@ -147,6 +147,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_secondary_navigation_items) do [ NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", true), + NavigationItemsHelper::NavigationItem.new("Supported housing", "/organisations/#{current_user.organisation.id}/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), ] @@ -172,6 +173,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_secondary_navigation_items) do [ NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", false), + NavigationItemsHelper::NavigationItem.new("Supported housing", "/organisations/#{current_user.organisation.id}/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), ] @@ -183,6 +185,32 @@ RSpec.describe NavigationItemsHelper do end end + context "when the user is on organisation schemes page" do + let(:required_sub_path) { "supported-housing" } + let(:expected_navigation_items) do + [ + NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), + NavigationItemsHelper::NavigationItem.new("Users", "/users", false), + NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), + NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + ] + end + + let(:expected_secondary_navigation_items) do + [ + NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", false), + NavigationItemsHelper::NavigationItem.new("Supported housing", "/organisations/#{current_user.organisation.id}/supported-housing", true), + NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users",false), + NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), + ] + end + + it "returns navigation items with the schemes item set as current" do + expect(primary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user)).to eq(expected_navigation_items) + expect(secondary_items("/organisations/#{current_user.organisation.id}/#{required_sub_path}", current_user.organisation.id)).to eq(expected_secondary_navigation_items) + end + end + context "when the user is on organisation details page" do let(:required_sub_path) { "details" } let(:expected_navigation_items) do @@ -197,6 +225,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_secondary_navigation_items) do [ NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", false), + NavigationItemsHelper::NavigationItem.new("Supported housing", "/organisations/#{current_user.organisation.id}/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", true), ] diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 9dfdaaac7..3638cd30d 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -35,56 +35,113 @@ RSpec.describe OrganisationsController, type: :request do context "when user is signed in" do describe "#schemes" do - let(:user) { FactoryBot.create(:user, :data_coordinator) } - let!(:schemes) { FactoryBot.create_list(:scheme, 5) } - let!(:same_org_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } + context "support user" do + let(:user) { FactoryBot.create(:user, :support) } + let!(:schemes) { FactoryBot.create_list(:scheme, 5) } + let!(:same_org_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } - before do - sign_in user - get "/organisations/#{organisation.id}/supported-housing", headers:, params: {} - end + before do + sign_in user + get "/organisations/#{organisation.id}/supported-housing", headers:, params: {} + end - it "has page heading" do - expect(page).to have_content("Supported housing services") - end + it "has page heading" do + expect(page).to have_content("Supported housing services") + end - it "shows a search bar" do - expect(page).to have_field("search", type: "search") - end + it "shows a search bar" do + expect(page).to have_field("search", type: "search") + end - it "has hidden accebility field with description" do - expected_field = "

Supported housing services

" - expect(CGI.unescape_html(response.body)).to include(expected_field) - end + it "has hidden accebility field with description" do + expected_field = "

Supported housing services

" + expect(CGI.unescape_html(response.body)).to include(expected_field) + end + + it "shows only schemes belonging to the same organisation" do + expect(page).to have_content(same_org_scheme.code) + schemes.each do |scheme| + expect(page).not_to have_content(scheme.code) + end + end + + context "when searching" do + let!(:searched_scheme) { FactoryBot.create(:scheme, code: "CODE321", organisation: user.organisation) } + let(:search_param) { "CODE321" } + + before do + get "/organisations/#{organisation.id}/supported-housing?search=#{search_param}" + end + + it "returns matching results" do + expect(page).to have_content(searched_scheme.code) + schemes.each do |scheme| + expect(page).not_to have_content(scheme.code) + end + end + + it "updates the table caption" do + expect(page).to have_content("1 scheme found matching ‘#{search_param}’") + end - it "shows only schemes belonging to the same organisation" do - expect(page).to have_content(same_org_scheme.code) - schemes.each do |scheme| - expect(page).not_to have_content(scheme.code) + it "has search in the title" do + expect(page).to have_title("Supported housing services (1 scheme matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") + end end end - context "when searching" do - let!(:searched_scheme) { FactoryBot.create(:scheme, code: "CODE321", organisation: user.organisation) } - let(:search_param) { "CODE321" } + context "data coordinator user" do + let(:user) { FactoryBot.create(:user, :data_coordinator) } + let!(:schemes) { FactoryBot.create_list(:scheme, 5) } + let!(:same_org_scheme) { FactoryBot.create(:scheme, organisation: user.organisation) } before do - get "/organisations/#{organisation.id}/supported-housing?search=#{search_param}" + sign_in user + get "/organisations/#{organisation.id}/supported-housing", headers:, params: {} + end + + it "has page heading" do + expect(page).to have_content("Supported housing services") + end + + it "shows a search bar" do + expect(page).to have_field("search", type: "search") end - it "returns matching results" do - expect(page).to have_content(searched_scheme.code) + it "has hidden accebility field with description" do + expected_field = "

Supported housing services

" + expect(CGI.unescape_html(response.body)).to include(expected_field) + end + + it "shows only schemes belonging to the same organisation" do + expect(page).to have_content(same_org_scheme.code) schemes.each do |scheme| expect(page).not_to have_content(scheme.code) end end - it "updates the table caption" do - expect(page).to have_content("1 scheme found matching ‘#{search_param}’") - end + context "when searching" do + let!(:searched_scheme) { FactoryBot.create(:scheme, code: "CODE321", organisation: user.organisation) } + let(:search_param) { "CODE321" } + + before do + get "/organisations/#{organisation.id}/supported-housing?search=#{search_param}" + end - it "has search in the title" do - expect(page).to have_title("Supported housing services (1 scheme matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") + it "returns matching results" do + expect(page).to have_content(searched_scheme.code) + schemes.each do |scheme| + expect(page).not_to have_content(scheme.code) + end + end + + it "updates the table caption" do + expect(page).to have_content("1 scheme found matching ‘#{search_param}’") + end + + it "has search in the title" do + expect(page).to have_title("Supported housing services (1 scheme matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") + end end end end