|
|
@ -159,106 +159,129 @@ RSpec.describe CaseLogsController, type: :request do |
|
|
|
context "when displaying a collection of logs" do |
|
|
|
context "when displaying a collection of logs" do |
|
|
|
let(:headers) { { "Accept" => "text/html" } } |
|
|
|
let(:headers) { { "Accept" => "text/html" } } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
context "when the user is a customer support user" do |
|
|
|
sign_in user |
|
|
|
let(:user) { FactoryBot.create(:user, :support) } |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when there are less than 20 logs" do |
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
get "/logs", headers: headers, params: {} |
|
|
|
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
|
|
|
|
|
|
|
sign_in user |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "shows a table of logs" do |
|
|
|
it "does have organisation columns" do |
|
|
|
expect(CGI.unescape_html(response.body)).to match(/<table class="govuk-table">/) |
|
|
|
get "/logs", headers: headers, params: {} |
|
|
|
expect(CGI.unescape_html(response.body)).to match(/logs/) |
|
|
|
expect(CGI.unescape_html(response.body)).to match(/<th class="govuk-table__header" scope="col">Owning organisation<\/th>/) |
|
|
|
end |
|
|
|
expect(CGI.unescape_html(response.body)).to match(/<th class="govuk-table__header" scope="col">Managing organisation<\/th>/) |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "shows the log's status" do |
|
|
|
context "when the user is not a customer support user" do |
|
|
|
expect(CGI.unescape_html(response.body)).to include(case_log.status.humanize) |
|
|
|
before do |
|
|
|
|
|
|
|
sign_in user |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "shows the total log count" do |
|
|
|
it "does not have organisation columns" do |
|
|
|
expect(CGI.unescape_html(response.body)).to match("<strong>1</strong> total logs") |
|
|
|
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 |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does not show the pagination links" do |
|
|
|
context "when there are less than 20 logs" do |
|
|
|
expect(page).not_to have_link("Previous") |
|
|
|
before do |
|
|
|
expect(page).not_to have_link("Next") |
|
|
|
get "/logs", headers: headers, params: {} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does not show the pagination result line" do |
|
|
|
it "shows a table of logs" do |
|
|
|
expect(CGI.unescape_html(response.body)).not_to match("Showing <b>1</b> to <b>20</b> of <b>26</b> logs") |
|
|
|
expect(CGI.unescape_html(response.body)).to match(/<table class="govuk-table">/) |
|
|
|
end |
|
|
|
expect(CGI.unescape_html(response.body)).to match(/logs/) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does not have pagination in the title" do |
|
|
|
it "only shows case logs for your organisation" do |
|
|
|
expect(page).to have_title("Logs") |
|
|
|
expected_case_row_log = "<a class=\"govuk-link\" href=\"/logs/#{case_log.id}\">#{case_log.id}</a>" |
|
|
|
end |
|
|
|
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 |
|
|
|
it "shows the formatted created at date for each log" do |
|
|
|
expect(page).to have_link("Download (CSV)", href: "/logs.csv") |
|
|
|
formatted_date = case_log.created_at.to_formatted_s(:govuk_date) |
|
|
|
end |
|
|
|
expect(CGI.unescape_html(response.body)).to include(formatted_date) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when there are more than 20 logs" do |
|
|
|
it "shows the log's status" do |
|
|
|
before do |
|
|
|
expect(CGI.unescape_html(response.body)).to include(case_log.status.humanize) |
|
|
|
FactoryBot.create_list(:case_log, 25, owning_organisation: organisation, managing_organisation: organisation) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when on the first page" do |
|
|
|
it "shows the total log count" do |
|
|
|
before do |
|
|
|
expect(CGI.unescape_html(response.body)).to match("<strong>1</strong> total logs") |
|
|
|
get "/logs", headers: headers, params: {} |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "has pagination links" do |
|
|
|
it "does not show the pagination links" do |
|
|
|
expect(page).to have_content("Previous") |
|
|
|
|
|
|
|
expect(page).not_to have_link("Previous") |
|
|
|
expect(page).not_to have_link("Previous") |
|
|
|
expect(page).to have_content("Next") |
|
|
|
expect(page).not_to have_link("Next") |
|
|
|
expect(page).to have_link("Next") |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "shows which logs are being shown on the current page" do |
|
|
|
it "does not show the pagination result line" do |
|
|
|
expect(CGI.unescape_html(response.body)).to match("Showing <b>1</b> to <b>20</b> of <b>26</b> logs") |
|
|
|
expect(CGI.unescape_html(response.body)).not_to match("Showing <b>1</b> to <b>20</b> of <b>26</b> logs") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "has pagination in the title" do |
|
|
|
it "does not have pagination in the title" do |
|
|
|
expect(page).to have_title("Logs (page 1 of 2)") |
|
|
|
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 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when on the second page" do |
|
|
|
context "when there are more than 20 logs" do |
|
|
|
before do |
|
|
|
before do |
|
|
|
get "/logs?page=2", headers: headers, params: {} |
|
|
|
FactoryBot.create_list(:case_log, 25, owning_organisation: organisation, managing_organisation: organisation) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "shows the total log count" do |
|
|
|
context "when on the first page" do |
|
|
|
expect(CGI.unescape_html(response.body)).to match("<strong>26</strong> total logs") |
|
|
|
before do |
|
|
|
end |
|
|
|
get "/logs", headers: headers, params: {} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "has pagination links" do |
|
|
|
it "has pagination links" do |
|
|
|
expect(page).to have_content("Previous") |
|
|
|
expect(page).to have_content("Previous") |
|
|
|
expect(page).to have_link("Previous") |
|
|
|
expect(page).not_to have_link("Previous") |
|
|
|
expect(page).to have_content("Next") |
|
|
|
expect(page).to have_content("Next") |
|
|
|
expect(page).not_to have_link("Next") |
|
|
|
expect(page).to have_link("Next") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "shows which logs are being shown on the current page" do |
|
|
|
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") |
|
|
|
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 |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "has pagination in the title" do |
|
|
|
context "when on the second page" do |
|
|
|
expect(page).to have_title("Logs (page 2 of 2)") |
|
|
|
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 |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|