Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.8 KiB

CLDC-2290 implement delete multiple logs story (#1657) * add a button to the logs list to delete multiple logs style and position of button helpers for displaying the button conditionally depending on user role and what filters and search are active * correct indentation from 4 spaces to 2 in view file * test appearance of delete logs button on index page for lettings logs * write a happy path feature test for the entire journey * create basic tests for the view component for listing logs to delete * create request tests for the GET delete-logs path * create request tests for the GET delete-logs-confirmation path * create request tests for the DELETE delete-logs path * comprehensive reworking after code review ensure that we are not passing lists of ids through params in the query string, risking overflowing the maximum URL length, adjust tests accordingly, do not attempt to reuse the same table for sales and lettings * alter config to allow creating controllers from the command line with associated spec files that matches how we test * extract controller methods and associated tests to do with the delete logs feature into their own controller, amend routes accordingly * implement same work for sales as for lettings * implement the story for lettings and sales logs under the organisation tab routing and controller methods testing for deleting sales logs, lettings or sales logs for an organisation move storage of relevant routes inside the form object as a comprehensive view model * merge the delete pages for lettings logs and sales logs, add to the tests for the lettings page to test sales specific content * minor refactor to delete logs controller: ensure session filters are only fetched from teh session when needed and extract discard logs method to private method * extract tables for lettings and sales to own partials * refactor delete logs controller after tech review improve the private method that builds the form object so that it has the flexibility to do so for all controller methods ensure that the search term is passed to the delete logs controller when navigating through the organisations tab ensure that noly logs for that organisation are displayed when navigating to delete logs through the organisations tab * remove unnecessary untested arguments * test new helper methods * implement dirty fiddle to get the checkboxes smaller and also not misaligned * ensure delete logs button is always visible on log lists when in the organisations tab * minor linting corrections * revert change, causing errors and outside the scope of this ticket * simplify tests for whether delete logs button appears on index page * replicate request specs from lettings for sales and organisations controllers * minor refactor of lettings log feature spec setup, replicate happy path for sales * minor refactors after rebasing onto Nat's work * temp * write tests for the delete logs form object * lint: add new line at end of file * respond to PO feedback the log id in the delte logs table should be a link to the log the delete logs button should be visible when the user is in a bulk upload journey updated associated tests
2 years ago
require "rails_helper"
RSpec.describe "logs/delete_logs.html.erb" do
let(:user) { create(:user, :support, name: "Dirk Gently") }
let(:lettings_log_1) { create(:lettings_log, tenancycode: "Holistic", propcode: "Detective Agency", created_by: user) }
let(:lettings_logs) { [lettings_log_1] }
let(:paths) do
{
delete_confirmation_path: delete_logs_confirmation_lettings_logs_path,
back_to_logs_path: lettings_logs_path(search: "search_term"),
delete_path: delete_logs_lettings_logs_path,
}
end
let(:delete_logs_form) { Forms::DeleteLogsForm.new(log_type: :lettings, current_user: user, **paths) }
before do
sign_in user
allow(FilterManager).to receive(:filter_logs).and_return lettings_logs
assign(:delete_logs_form, delete_logs_form)
end
it "has the correct h1 content" do
render
fragment = Capybara::Node::Simple.new(rendered)
h1 = fragment.find("h1")
expect(h1.text).to include "Review the logs you want to delete"
end
context "when there is one log to delete" do
it "shows the informative text in the singular" do
render
fragment = Capybara::Node::Simple.new(rendered)
info_text = fragment.first("p").text
expect(info_text).to eq "You've selected 1 log to delete"
end
end
context "when there is more than one log to delete" do
let(:lettings_log_2) { create(:lettings_log, tenancycode: "01-354", propcode: "9112") }
before do
lettings_logs << lettings_log_2
allow(FilterManager).to receive(:filter_logs).and_return lettings_logs
delete_logs_form = Forms::DeleteLogsForm.new(log_type: :lettings, current_user: user, **paths)
assign(:delete_logs_form, delete_logs_form)
end
it "shows the informative text in the plural" do
render
fragment = Capybara::Node::Simple.new(rendered)
info_text = fragment.first("p").text
expect(info_text).to eq "You've selected #{lettings_logs.count} logs to delete"
end
end
context "when the table contains lettings logs" do
it "shows the correct headers in the table" do
render
fragment = Capybara::Node::Simple.new(rendered)
headers = fragment.find_all("table thead tr th").map(&:text)
expect(headers).to eq ["Log ID", "Tenancy code", "Property reference", "Status", "Delete?"]
end
it "shows the correct information in each row" do
render
fragment = Capybara::Node::Simple.new(rendered)
row_data = fragment.find_all("table tbody tr td").map(&:text)[0...-1].map(&:strip)
expect(row_data).to eq [lettings_log_1.id.to_s, lettings_log_1.tenancycode, lettings_log_1.propcode, lettings_log_1.status.humanize.capitalize]
end
it "links to the relevant log on each row" do
render
fragment = Capybara::Node::Simple.new(rendered)
first_cell = fragment.first("table tbody tr td")
expect(first_cell).to have_link lettings_log_1.id.to_s, href: lettings_log_path(lettings_log_1)
end
end
context "when the table contains sales logs" do
let(:sales_log) { create(:sales_log, purchid: "Interconnectedness", saledate: Time.zone.today, created_by: user) }
let(:sales_logs) { [sales_log] }
let(:delete_logs_form_sales) { Forms::DeleteLogsForm.new(log_type: :sales, current_user: user, **paths) }
before do
sign_in user
allow(FilterManager).to receive(:filter_logs).and_return sales_logs
assign(:delete_logs_form, delete_logs_form_sales)
end
it "shows the correct headers in the table" do
render
fragment = Capybara::Node::Simple.new(rendered)
headers = fragment.find_all("table thead tr th").map(&:text)
expect(headers).to eq ["Log ID", "Purchaser code", "Sale completion date", "Status", "Delete?"]
end
it "shows the correct information in each row" do
render
fragment = Capybara::Node::Simple.new(rendered)
row_data = fragment.find_all("table tbody tr td").map(&:text)[0...-1].map(&:strip)
expect(row_data).to eq [sales_log.id.to_s, sales_log.purchid, sales_log.saledate.to_formatted_s(:govuk_date), sales_log.status.humanize.capitalize]
end
it "links to the relevant log on each row" do
render
fragment = Capybara::Node::Simple.new(rendered)
first_cell = fragment.first("table tbody tr td")
expect(first_cell).to have_link sales_log.id.to_s, href: sales_log_path(sales_log)
end
end
it "shows a checkbox with the correct hidden label in the final cell of each row" do
render
fragment = Capybara::Node::Simple.new(rendered)
final_cell = fragment.find_all("table tbody tr td")[-1]
expect(final_cell.find("input")[:type]).to eq "checkbox"
checkbox_label = final_cell.find("label span")
expect(checkbox_label.text).to eq lettings_log_1.id.to_s
expect(checkbox_label[:class]).to include "govuk-visually-hidden"
end
end