From 43502e6a126cc48712ff3113fc4da885d5a0b620 Mon Sep 17 00:00:00 2001 From: JG Date: Tue, 7 Jun 2022 14:08:50 +0100 Subject: [PATCH] code for title format with sub nav for support user --- app/helpers/title_helper.rb | 14 ++++-- app/views/case_logs/index.html.erb | 2 +- app/views/organisations/index.html.erb | 2 +- app/views/organisations/show.html.erb | 1 + app/views/organisations/users.html.erb | 2 +- spec/helpers/title_helper_spec.rb | 65 ++++++++++++++++++++++---- 6 files changed, 71 insertions(+), 15 deletions(-) diff --git a/app/helpers/title_helper.rb b/app/helpers/title_helper.rb index aebb97ebf..d0b6aa407 100644 --- a/app/helpers/title_helper.rb +++ b/app/helpers/title_helper.rb @@ -3,11 +3,19 @@ module TitleHelper count > 1 ? item.pluralize : item end - def format_title(path, searched, page_title, current_user, item_label, count) + def format_title(path, searched, page_title, current_user, item_label, count, organisation_name) if searched.present? - title = "#{page_title} (#{count} #{item_label} matching ‘#{searched}’)" + actual_title = support_user_sab_nav?(current_user, organisation_name) ? "#{organisation_name}" : page_title + title = "#{actual_title} (#{count} #{item_label} matching ‘#{searched}’)" else - title = page_title + actual_title = support_user_sab_nav?(current_user, organisation_name) ? "#{organisation_name} (#{page_title})" : page_title + title = actual_title end end + + private + + def support_user_sab_nav? current_user, organisation_name + current_user.support? && organisation_name + end end diff --git a/app/views/case_logs/index.html.erb b/app/views/case_logs/index.html.erb index 6f60b5ad0..d3a706aa4 100644 --- a/app/views/case_logs/index.html.erb +++ b/app/views/case_logs/index.html.erb @@ -1,5 +1,5 @@ <% item_label = format_label(@pagy.count, "log") %> -<% title = format_title(request.path, @searched, "Logs", current_user, item_label, @pagy.count) %> +<% title = format_title(request.path, @searched, "Logs", current_user, item_label, @pagy.count, nil) %> <% content_for :title, title %> diff --git a/app/views/organisations/index.html.erb b/app/views/organisations/index.html.erb index 966272ed8..2e4d9f48a 100644 --- a/app/views/organisations/index.html.erb +++ b/app/views/organisations/index.html.erb @@ -1,5 +1,5 @@ <% item_label = format_label(@pagy.count, "organisation") %> -<% title = format_title(request.path, @searched, "Organisations", current_user, item_label, @pagy.count) %> +<% title = format_title(request.path, @searched, "Organisations", current_user, item_label, @pagy.count, nil) %> <% content_for :title, title %> diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index c148f08d4..9dd2089f1 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -1,4 +1,5 @@ <% title = current_user.support? ? "#{@organisation.name} (Organisation details)" : "Organisation details" %> +<% title = format_title(request.path, nil, "Organisation details", current_user, nil, nil, @organisation.name) %> <% content_for :title, title %>

diff --git a/app/views/organisations/users.html.erb b/app/views/organisations/users.html.erb index 37561f1a2..b8d46032a 100644 --- a/app/views/organisations/users.html.erb +++ b/app/views/organisations/users.html.erb @@ -1,5 +1,5 @@ <% item_label = format_label(@pagy.count, "user") %> -<% title = format_title(request.path, @searched, "Users", current_user, item_label, @pagy.count) %> +<% title = format_title(request.path, @searched, "Users", current_user, item_label, @pagy.count, @organisation.name) %> <% content_for :title, title %> diff --git a/spec/helpers/title_helper_spec.rb b/spec/helpers/title_helper_spec.rb index 1fcb322ec..da08309eb 100644 --- a/spec/helpers/title_helper_spec.rb +++ b/spec/helpers/title_helper_spec.rb @@ -19,6 +19,7 @@ RSpec.describe TitleHelper do let(:item_label) { "label" } let(:search_item) { nil } let(:count) { 1 } + let(:organisation_name) { nil } context "highest level links" do context "organisation path" do @@ -29,7 +30,7 @@ RSpec.describe TitleHelper do let(:expected_title) { page_title } it "returns expected title when no search" do - expect(format_title(path, nil, page_title, user, item_label, count)).to eq(expected_title) + expect(format_title(path, nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end @@ -38,7 +39,7 @@ RSpec.describe TitleHelper do let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" } it "returns expected title when search is present" do - expect(format_title(path, search_item, page_title, user, item_label, count)).to eq(expected_title) + expect(format_title(path, search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end end @@ -51,7 +52,7 @@ RSpec.describe TitleHelper do let(:expected_title) { page_title } it "returns expected title when no search" do - expect(format_title(path, nil, page_title, user, item_label, count)).to eq(expected_title) + expect(format_title(path, nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end @@ -60,7 +61,7 @@ RSpec.describe TitleHelper do let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" } it "returns expected title when search is present" do - expect(format_title(path, search_item, page_title, user, item_label, count)).to eq(expected_title) + expect(format_title(path, search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end end @@ -73,7 +74,7 @@ RSpec.describe TitleHelper do let(:expected_title) { page_title } it "returns expected title when no search" do - expect(format_title(path, nil, page_title, user, item_label, count)).to eq(expected_title) + expect(format_title(path, nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end @@ -82,7 +83,7 @@ RSpec.describe TitleHelper do let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" } it "returns expected title when search is present" do - expect(format_title(path, search_item, page_title, user, item_label, count)).to eq(expected_title) + expect(format_title(path, search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end end @@ -92,13 +93,13 @@ RSpec.describe TitleHelper do context "specific organisation logs path" do let(:path) { "organisations/1/logs" } let(:page_title) { "Logs" } - let(:organisation_name) { "Some Name" } + let(:organisation_name) { "Foo Bar" } context "search is missing" do let(:expected_title) { "#{organisation_name} (#{page_title})" } it "returns expected title when no search" do - expect(format_title(path, nil, page_title, user, item_label, count)).to eq(expected_title) + expect(format_title(path, nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end @@ -107,7 +108,53 @@ RSpec.describe TitleHelper do let(:expected_title) { "#{organisation_name} (#{count} #{item_label} matching ‘#{search_item}’)" } it "returns expected title when search is present" do - expect(format_title(path, search_item, page_title, user, item_label, count)).to eq(expected_title) + expect(format_title(path, search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) + end + end + end + + context "specific organisation users path" do + let(:path) { "organisations/1/users" } + let(:page_title) { "Users" } + let(:organisation_name) { "Foo Bar" } + + context "search is missing" do + let(:expected_title) { "#{organisation_name} (#{page_title})" } + + it "returns expected title when no search" do + expect(format_title(path, nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) + end + end + + context "search is present" do + let(:search_item) { "foobar" } + let(:expected_title) { "#{organisation_name} (#{count} #{item_label} matching ‘#{search_item}’)" } + + it "returns expected title when search is present" do + expect(format_title(path, search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) + end + end + end + + context "specific organisation details path" do + let(:path) { "organisations/1/details" } + let(:page_title) { "Organisation details" } + let(:organisation_name) { "Foo Bar" } + + context "search is missing" do + let(:expected_title) { "#{organisation_name} (#{page_title})" } + + it "returns expected title when no search" do + expect(format_title(path, nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) + end + end + + context "search is present" do + let(:search_item) { "foobar" } + let(:expected_title) { "#{organisation_name} (#{count} #{item_label} matching ‘#{search_item}’)" } + + it "returns expected title when search is present" do + expect(format_title(path, search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end end