diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 603de7e0e..a29bb8211 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,4 +1,8 @@ -<% title = "Your organisation (Users)" %> +<% if @searched.present? %> + <% search_title = " (search results for ‘#{@searched})’" %> +<% end %> +<% title = "Your organisation (Users)#{search_title}" %> + <% content_for :title, title %> <% content_for :tab_title do %> diff --git a/spec/controllers/modules/users_filter_spec.rb b/spec/controllers/modules/users_filter_spec.rb new file mode 100644 index 000000000..bd4a7d999 --- /dev/null +++ b/spec/controllers/modules/users_filter_spec.rb @@ -0,0 +1,30 @@ +require "rails_helper" + +RSpec.describe Modules::UsersFilter do + describe "filtered_users" do + before do + FactoryBot.create_list(:user, 5) + FactoryBot.create(:user, name: "Joe Blogg") + FactoryBot.create(:user, name: "Tom Blogg", active: false) + end + + subject(:instance) { Class.new.include(described_class).new } + let(:user_list) { User.all } + + context "when given a search term" do + let(:search_term) { "Blogg" } + + it "filters the collection on search term and active users" do + expect(instance.filtered_users(user_list, search_term).count).to eq(1) + end + end + + context "when not given a search term" do + let(:search_term) { nil } + + it "filters the collection on active users" do + expect(instance.filtered_users(user_list, search_term).count).to eq(6) + end + end + end +end