diff --git a/app/helpers/title_helper.rb b/app/helpers/title_helper.rb index 1ca137c31..7c4187e2b 100644 --- a/app/helpers/title_helper.rb +++ b/app/helpers/title_helper.rb @@ -3,9 +3,9 @@ module TitleHelper count > 1 ? item.pluralize : item end - def format_title(_path, searched, page_title, current_user, item_label, count, organisation_name) + def format_title(searched, page_title, current_user, item_label, count, organisation_name) if searched.present? - actual_title = support_user_sab_nav?(current_user, organisation_name) ? organisation_name.to_s : page_title + actual_title = support_user_sab_nav?(current_user, organisation_name) ? organisation_name : page_title "#{actual_title} (#{count} #{item_label} matching ‘#{searched}’)" else support_user_sab_nav?(current_user, organisation_name) ? "#{organisation_name} (#{page_title})" : page_title diff --git a/app/views/case_logs/index.html.erb b/app/views/case_logs/index.html.erb index d3a706aa4..82fd29188 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, nil) %> +<% title = format_title(@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 2e4d9f48a..0455c23ad 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, nil) %> +<% title = format_title(@searched, "Organisations", current_user, item_label, @pagy.count, nil) %> <% content_for :title, title %> diff --git a/app/views/organisations/logs.html.erb b/app/views/organisations/logs.html.erb index 659f9b121..37877c9f8 100644 --- a/app/views/organisations/logs.html.erb +++ b/app/views/organisations/logs.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, @organisation.name) %> +<% title = format_title(@searched, "Logs", current_user, item_label, @pagy.count, @organisation.name) %> <% content_for :title, title %> diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index 11f572895..d85fc1e80 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -1,5 +1,5 @@ <% title = current_user.support? ? "#{@organisation.name} (Organisation details)" : "Organisation details" %> -<% title = format_title(request.path, nil, current_user.support? ? "Organisation details" : "About your organisation", current_user, nil, nil, @organisation.name) %> +<% title = format_title(nil, current_user.support? ? "Organisation details" : "About your organisation", 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 b8d46032a..0158778e2 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, @organisation.name) %> +<% title = format_title(@searched, "Users", current_user, item_label, @pagy.count, @organisation.name) %> <% content_for :title, title %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index a9b6cf67d..b9c76e8e5 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.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, nil) %> +<% title = format_title(@searched, "Users", current_user, item_label, @pagy.count, nil) %> <% content_for :title, title %> diff --git a/spec/helpers/title_helper_spec.rb b/spec/helpers/title_helper_spec.rb index 44ee8b4df..ccc3be1b8 100644 --- a/spec/helpers/title_helper_spec.rb +++ b/spec/helpers/title_helper_spec.rb @@ -20,38 +20,18 @@ RSpec.describe TitleHelper do let(:count) { 1 } let(:organisation_name) { nil } - context "when coordinator user" do - let(:user) { FactoryBot.create(:user, :data_coordinator) } + context "when provider user" do + let(:user) { FactoryBot.create(:user) } - context "when specific organisation details path" do - let(:path) { "organisations/1/details" } - let(:page_title) { "Organisation details" } + context "when any specific path" do + let(:page_title) { "Users" } let(:organisation_name) { nil } context "when search is missing" 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, organisation_name)).to eq(expected_title) - end - end - end - end - - context "when support user" do - let(:user) { FactoryBot.create(:user, :support) } - - context "when highest level links" do - context "when organisation path" do - let(:path) { "/organisations" } - let(:page_title) { "Organisations" } - - context "when search is missing" 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, organisation_name)).to eq(expected_title) - end + expect(format_title(nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end context "when search is present" do @@ -59,43 +39,25 @@ 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, organisation_name)).to eq(expected_title) + expect(format_title(search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end end + end + end - context "when users path" do - let(:path) { "/users" } - let(:page_title) { "Users" } - - context "when search is missing" 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, organisation_name)).to eq(expected_title) - end - end - - context "when search is present" do - let(:search_item) { "foobar" } - 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, organisation_name)).to eq(expected_title) - end - end - end + context "when coordinator user" do + let(:user) { FactoryBot.create(:user, :data_coordinator) } - context "when logs path" do - let(:path) { "/logs" } - let(:page_title) { "Logs" } + context "when any specific path" do + let(:page_title) { "Users" } + let(:organisation_name) { nil } - context "when search is missing" do - let(:expected_title) { page_title } + context "when search is missing" 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, organisation_name)).to eq(expected_title) - end + it "returns expected title when no search" do + expect(format_title(nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end context "when search is present" do @@ -103,79 +65,55 @@ 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, organisation_name)).to eq(expected_title) + expect(format_title(search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end end end + end - context "when sub nav links" do - context "when specific organisation logs path" do - let(:path) { "organisations/1/logs" } - let(:page_title) { "Logs" } - let(:organisation_name) { "Foo Bar" } - - context "when search is missing" do - let(:expected_title) { "#{organisation_name} (#{page_title})" } + context "when support user" do + let(:user) { FactoryBot.create(:user, :support) } - 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 "when no organisation is specified" do + let(:page_title) { "Organisations" } - context "when search is present" do - let(:search_item) { "foobar" } - let(:expected_title) { "#{organisation_name} (#{count} #{item_label} matching ‘#{search_item}’)" } + context "when search is missing" do + let(:expected_title) { page_title } - 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 + it "returns expected title when no search" do + expect(format_title(nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end - context "when specific organisation users path" do - let(:path) { "organisations/1/users" } - let(:page_title) { "Users" } - let(:organisation_name) { "Foo Bar" } + context "when search is present" do + let(:search_item) { "foobar" } + let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" } - context "when 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 "when 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 + it "returns expected title when search is present" do + expect(format_title(search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end + end - context "when specific organisation details path" do - let(:path) { "organisations/1/details" } - let(:page_title) { "Organisation details" } - let(:organisation_name) { "Foo Bar" } + context "when organisation is specified" do + let(:page_title) { "Organisations" } + let(:organisation_name) { "Some Name" } - context "when search is missing" do - let(:expected_title) { "#{organisation_name} (#{page_title})" } + context "when 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 + it "returns expected title when no search" do + expect(format_title(nil, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end + end - context "when search is present" do - let(:search_item) { "foobar" } - let(:expected_title) { "#{organisation_name} (#{count} #{item_label} matching ‘#{search_item}’)" } + context "when 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 + it "returns expected title when search is present" do + expect(format_title(search_item, page_title, user, item_label, count, organisation_name)).to eq(expected_title) end end end