diff --git a/app/views/case_logs/index.html.erb b/app/views/case_logs/index.html.erb
index 6a374d993..6f60b5ad0 100644
--- a/app/views/case_logs/index.html.erb
+++ b/app/views/case_logs/index.html.erb
@@ -1,9 +1,5 @@
<% item_label = format_label(@pagy.count, "log") %>
-<% if @searched.present? %>
- <% title = "#{current_user.support? ? 'Logs' : current_user.organisation.name} (#{@pagy.count} #{item_label} matching ‘#{@searched}’)" %>
-<% else %>
- <% title = "Logs" %>
-<% end %>
+<% title = format_title(request.path, @searched, "Logs", current_user, item_label, @pagy.count) %>
<% content_for :title, title %>
diff --git a/app/views/organisations/users.html.erb b/app/views/organisations/users.html.erb
index 595cc23de..37561f1a2 100644
--- a/app/views/organisations/users.html.erb
+++ b/app/views/organisations/users.html.erb
@@ -1,9 +1,5 @@
<% item_label = format_label(@pagy.count, "user") %>
-<% if @searched.present? %>
- <% title = "#{@organisation.name} (#{@pagy.count} #{item_label} matching ‘#{@searched}’" %>
-<% else %>
- <% title = "#{@organisation.name} (Users)" %>
-<% end %>
+<% title = format_title(request.path, @searched, "Users", current_user, item_label, @pagy.count) %>
<% content_for :title, title %>
diff --git a/spec/helpers/item_label_helper_spec.rb b/spec/helpers/item_label_helper_spec.rb
index e4f0e210b..aad52a549 100644
--- a/spec/helpers/item_label_helper_spec.rb
+++ b/spec/helpers/item_label_helper_spec.rb
@@ -15,26 +15,74 @@ RSpec.describe ItemLabelHelper do
describe "#format_title" do
context "coordinator user" do
let(:user) { FactoryBot.create(:user, :support) }
- let(:path) { "/organisations" }
let(:page_title) { "Title" }
let(:item_label) { "label" }
let(:search_item) { nil }
let(:count) { 1 }
- context "search is missing" do
- let(:expected_title) { page_title }
+ context "organisation path" do
+ let(:path) { "/organisations" }
+ let(:page_title) { "Organisations" }
- it "returns expected title when no search" do
- expect(format_title(path, nil, page_title, user, item_label, count)).to eq(expected_title)
+ context "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)).to eq(expected_title)
+ end
+ end
+
+ context "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)).to eq(expected_title)
+ end
+ end
+ end
+
+ context "users path" do
+ let(:path) { "/users" }
+ let(:page_title) { "Users" }
+
+ context "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)).to eq(expected_title)
+ end
+ end
+
+ context "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)).to eq(expected_title)
+ end
end
end
- context "search is present" do
- let(:search_item) { "foobar" }
- let(:expected_title) { "#{page_title} (#{count} #{item_label} matching ‘#{search_item}’)" }
+ context "logs path" do
+ let(:path) { "/logs" }
+ let(:page_title) { "Logs" }
+
+ context "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)).to eq(expected_title)
+ end
+ end
+
+ context "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)).to eq(expected_title)
+ 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)
+ end
end
end
end