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.

90 lines
2.5 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 Forms::DeleteLogsForm do
let(:delete_logs_form) { described_class.new(attributes) }
let(:attributes) do
{
log_type:,
search_term:,
current_user:,
log_filters:,
selected_ids:,
delete_confirmation_path:,
back_to_logs_path:,
delete_path:,
}
end
let(:log_type) { :lettings }
let(:search_term) { "meaning" }
let(:current_user) { create(:user) }
let(:log_filters) do
{
"years" => [""],
"status" => ["", "completed"],
"user" => "you",
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
}
end
let(:selected_ids) { [visible_logs.first.id] }
let(:delete_confirmation_path) { "/lettings-logs/delete-logs-confirmation" }
let(:back_to_logs_path) { "/lettings-logs?search=meaning" }
let(:delete_path) { "/lettings-logs/delete-logs" }
let(:visible_logs) { create_list(:lettings_log, 3, created_by: current_user) }
before do
allow(FilterManager).to receive(:filter_logs).and_return visible_logs
end
it "exposes the log type" do
expect(delete_logs_form.log_type).to be log_type
end
it "exposes the search term" do
expect(delete_logs_form.search_term).to be search_term
end
it "exposes the paths" do
expect(delete_logs_form.delete_confirmation_path).to be delete_confirmation_path
expect(delete_logs_form.back_to_logs_path).to be back_to_logs_path
expect(delete_logs_form.delete_path).to be delete_path
end
it "exposes the logs returned by the filter manager" do
expect(delete_logs_form.logs).to be visible_logs
end
it "exposes the selected ids" do
expect(delete_logs_form.selected_ids).to be selected_ids
end
context "when selected ids are not provided to the initializer" do
let(:selected_ids) { nil }
it "sets the selected ids to be all logs" do
expect(delete_logs_form.selected_ids).to match_array visible_logs.map(&:id)
end
end
it "calls the filter manager with the correct arguments" do
create(:lettings_log)
expect(FilterManager).to receive(:filter_logs) { |arg1, arg2, arg3, arg4, arg5|
expect(arg1).to contain_exactly(*visible_logs)
expect(arg2).to eq search_term
expect(arg3).to eq log_filters
expect(arg4).to be nil
expect(arg5).to be current_user
}.and_return visible_logs
delete_logs_form
end
it "exposes the number of logs" do
expect(delete_logs_form.log_count).to be visible_logs.count
end
it "provides the name of the table partial relevant to the log type" do
expect(delete_logs_form.table_partial_name).to eq "logs/delete_logs_table_lettings"
end
end