Browse Source

Support user can see additional organisation columns on logs page

pull/454/head
baarkerlounger 3 years ago
parent
commit
453d126bdf
  1. 12
      app/views/case_logs/_log_list.html.erb
  2. 159
      spec/requests/case_logs_controller_spec.rb

12
app/views/case_logs/_log_list.html.erb

@ -15,6 +15,10 @@
<th class="govuk-table__header" scope="col">Tenancy starts</th>
<th class="govuk-table__header" scope="col">Log created</th>
<th class="govuk-table__header" scope="col">Completed</th>
<% if current_user.support? %>
<th class="govuk-table__header" scope="col">Owning organisation</th>
<th class="govuk-table__header" scope="col">Managing organisation</th>
<% end %>
</tr>
</thead>
<tbody class="govuk-table__body">
@ -41,6 +45,14 @@
text: log.status.humanize
) %>
</td>
<% if current_user.support? %>
<td class="govuk-table__cell">
<%= log.owning_organisation.name %>
</td>
<td class="govuk-table__cell">
<%= log.managing_organisation.name %>
</td>
<% end %>
</tr>
<% end %>
</tbody>

159
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(/<table class="govuk-table">/)
expect(CGI.unescape_html(response.body)).to match(/logs/)
end
it "only shows case logs for your organisation" do
expected_case_row_log = "<a class=\"govuk-link\" href=\"/logs/#{case_log.id}\">#{case_log.id}</a>"
unauthorized_case_row_log = "<a class=\"govuk-link\" href=\"/logs/#{unauthorized_case_log.id}\">#{unauthorized_case_log.id}</a>"
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(/<th class="govuk-table__header" scope="col">Owning organisation<\/th>/)
expect(CGI.unescape_html(response.body)).to match(/<th class="govuk-table__header" scope="col">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("<strong>1</strong> total logs")
it "does not have organisation columns" do
get "/logs", headers: headers, params: {}
expect(CGI.unescape_html(response.body)).not_to match(/<th class="govuk-table__header" scope="col">Owning organisation<\/th>/)
expect(CGI.unescape_html(response.body)).not_to match(/<th class="govuk-table__header" scope="col">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 <b>1</b> to <b>20</b> of <b>26</b> logs")
end
it "shows a table of logs" do
expect(CGI.unescape_html(response.body)).to match(/<table class="govuk-table">/)
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 = "<a class=\"govuk-link\" href=\"/logs/#{case_log.id}\">#{case_log.id}</a>"
unauthorized_case_row_log = "<a class=\"govuk-link\" href=\"/logs/#{unauthorized_case_log.id}\">#{unauthorized_case_log.id}</a>"
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("<strong>1</strong> 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 <b>1</b> to <b>20</b> of <b>26</b> logs")
it "does not show the pagination result line" do
expect(CGI.unescape_html(response.body)).not_to match("Showing <b>1</b> to <b>20</b> of <b>26</b> 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("<strong>26</strong> 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 <b>21</b> to <b>26</b> of <b>26</b> logs")
it "shows which logs are being shown on the current page" do
expect(CGI.unescape_html(response.body)).to match("Showing <b>1</b> to <b>20</b> of <b>26</b> 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("<strong>26</strong> 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 <b>21</b> to <b>26</b> of <b>26</b> logs")
end
it "has pagination in the title" do
expect(page).to have_title("Logs (page 2 of 2)")
end
end
end
end

Loading…
Cancel
Save