diff --git a/app/views/case_logs/_log_list.html.erb b/app/views/case_logs/_log_list.html.erb index e728a5385..3cb30289f 100644 --- a/app/views/case_logs/_log_list.html.erb +++ b/app/views/case_logs/_log_list.html.erb @@ -15,6 +15,10 @@ Tenancy starts Log created Completed + <% if current_user.support? %> + Owning organisation + Managing organisation + <% end %> @@ -41,6 +45,14 @@ text: log.status.humanize ) %> + <% if current_user.support? %> + + <%= log.owning_organisation.name %> + + + <%= log.managing_organisation.name %> + + <% end %> <% end %> diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index 7adad985b..bbc97a5c6 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -159,106 +159,129 @@ RSpec.describe CaseLogsController, type: :request do context "when displaying a collection of logs" do let(:headers) { { "Accept" => "text/html" } } - before do - sign_in user - end + context "when the user is a customer support user" do + let(:user) { FactoryBot.create(:user, :support) } - context "when there are less than 20 logs" do before do - get "/logs", headers: headers, params: {} + allow(user).to receive(:need_two_factor_authentication?).and_return(false) + sign_in user end - it "shows a table of logs" do - expect(CGI.unescape_html(response.body)).to match(//) - expect(CGI.unescape_html(response.body)).to match(/logs/) - end - - it "only shows case logs for your organisation" do - expected_case_row_log = "#{case_log.id}" - unauthorized_case_row_log = "#{unauthorized_case_log.id}" - expect(CGI.unescape_html(response.body)).to include(expected_case_row_log) - expect(CGI.unescape_html(response.body)).not_to include(unauthorized_case_row_log) - end - - it "shows the formatted created at date for each log" do - formatted_date = case_log.created_at.to_formatted_s(:govuk_date) - expect(CGI.unescape_html(response.body)).to include(formatted_date) + it "does have organisation columns" do + get "/logs", headers: headers, params: {} + expect(CGI.unescape_html(response.body)).to match(/
Owning organisation<\/th>/) + expect(CGI.unescape_html(response.body)).to match(/Managing organisation<\/th>/) end + end - it "shows the log's status" do - expect(CGI.unescape_html(response.body)).to include(case_log.status.humanize) + context "when the user is not a customer support user" do + before do + sign_in user end - it "shows the total log count" do - expect(CGI.unescape_html(response.body)).to match("1 total logs") + it "does not have organisation columns" do + get "/logs", headers: headers, params: {} + expect(CGI.unescape_html(response.body)).not_to match(/Owning organisation<\/th>/) + expect(CGI.unescape_html(response.body)).not_to match(/Managing organisation<\/th>/) end - it "does not show the pagination links" do - expect(page).not_to have_link("Previous") - expect(page).not_to have_link("Next") - end + context "when there are less than 20 logs" do + before do + get "/logs", headers: headers, params: {} + end - it "does not show the pagination result line" do - expect(CGI.unescape_html(response.body)).not_to match("Showing 1 to 20 of 26 logs") - end + it "shows a table of logs" do + expect(CGI.unescape_html(response.body)).to match(//) + expect(CGI.unescape_html(response.body)).to match(/logs/) + end - it "does not have pagination in the title" do - expect(page).to have_title("Logs") - end + it "only shows case logs for your organisation" do + expected_case_row_log = "#{case_log.id}" + unauthorized_case_row_log = "#{unauthorized_case_log.id}" + expect(CGI.unescape_html(response.body)).to include(expected_case_row_log) + expect(CGI.unescape_html(response.body)).not_to include(unauthorized_case_row_log) + end - it "shows the download csv link" do - expect(page).to have_link("Download (CSV)", href: "/logs.csv") - end - end + it "shows the formatted created at date for each log" do + formatted_date = case_log.created_at.to_formatted_s(:govuk_date) + expect(CGI.unescape_html(response.body)).to include(formatted_date) + end - context "when there are more than 20 logs" do - before do - FactoryBot.create_list(:case_log, 25, owning_organisation: organisation, managing_organisation: organisation) - end + it "shows the log's status" do + expect(CGI.unescape_html(response.body)).to include(case_log.status.humanize) + end - context "when on the first page" do - before do - get "/logs", headers: headers, params: {} + it "shows the total log count" do + expect(CGI.unescape_html(response.body)).to match("1 total logs") end - it "has pagination links" do - expect(page).to have_content("Previous") + it "does not show the pagination links" do expect(page).not_to have_link("Previous") - expect(page).to have_content("Next") - expect(page).to have_link("Next") + expect(page).not_to have_link("Next") end - it "shows which logs are being shown on the current page" do - expect(CGI.unescape_html(response.body)).to match("Showing 1 to 20 of 26 logs") + it "does not show the pagination result line" do + expect(CGI.unescape_html(response.body)).not_to match("Showing 1 to 20 of 26 logs") end - it "has pagination in the title" do - expect(page).to have_title("Logs (page 1 of 2)") + it "does not have pagination in the title" do + expect(page).to have_title("Logs") + end + + it "shows the download csv link" do + expect(page).to have_link("Download (CSV)", href: "/logs.csv") end end - context "when on the second page" do + context "when there are more than 20 logs" do before do - get "/logs?page=2", headers: headers, params: {} + FactoryBot.create_list(:case_log, 25, owning_organisation: organisation, managing_organisation: organisation) end - it "shows the total log count" do - expect(CGI.unescape_html(response.body)).to match("26 total logs") - end + context "when on the first page" do + before do + get "/logs", headers: headers, params: {} + end - it "has pagination links" do - expect(page).to have_content("Previous") - expect(page).to have_link("Previous") - expect(page).to have_content("Next") - expect(page).not_to have_link("Next") - end + it "has pagination links" do + expect(page).to have_content("Previous") + expect(page).not_to have_link("Previous") + expect(page).to have_content("Next") + expect(page).to have_link("Next") + end - it "shows which logs are being shown on the current page" do - expect(CGI.unescape_html(response.body)).to match("Showing 21 to 26 of 26 logs") + it "shows which logs are being shown on the current page" do + expect(CGI.unescape_html(response.body)).to match("Showing 1 to 20 of 26 logs") + end + + it "has pagination in the title" do + expect(page).to have_title("Logs (page 1 of 2)") + end end - it "has pagination in the title" do - expect(page).to have_title("Logs (page 2 of 2)") + context "when on the second page" do + before do + get "/logs?page=2", headers: headers, params: {} + end + + it "shows the total log count" do + expect(CGI.unescape_html(response.body)).to match("26 total logs") + end + + it "has pagination links" do + expect(page).to have_content("Previous") + expect(page).to have_link("Previous") + expect(page).to have_content("Next") + expect(page).not_to have_link("Next") + end + + it "shows which logs are being shown on the current page" do + expect(CGI.unescape_html(response.body)).to match("Showing 21 to 26 of 26 logs") + end + + it "has pagination in the title" do + expect(page).to have_title("Logs (page 2 of 2)") + end end end end