Browse Source

CLDC-2639 Display correct back to logs button (#2721)

* Display correct back to logs button

* Add bulk_upload_filter_applied for sales

* Update view tests
pull/2713/head^2
kosiakkatrina 2 months ago committed by GitHub
parent
commit
be52a7b7b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/controllers/lettings_logs_controller.rb
  2. 2
      app/controllers/sales_logs_controller.rb
  3. 8
      app/helpers/log_actions_helper.rb
  4. 4
      app/services/storage/local_disk_service.rb
  5. 2
      app/views/logs/edit.html.erb
  6. 25
      spec/requests/lettings_logs_controller_spec.rb
  7. 26
      spec/views/logs/edit.html.erb_spec.rb

2
app/controllers/lettings_logs_controller.rb

@ -65,7 +65,7 @@ class LettingsLogsController < LogsController
elsif @log.collection_closed_for_editing?
redirect_to review_lettings_log_path(@log)
else
render("logs/edit", locals: { current_user: })
render("logs/edit", locals: { current_user:, bulk_upload_filter_applied: session_filters["bulk_upload_id"].present? })
end
end

2
app/controllers/sales_logs_controller.rb

@ -39,7 +39,7 @@ class SalesLogsController < LogsController
if @log.collection_closed_for_editing?
redirect_to review_sales_log_path(@log, sales_log: true)
else
render "logs/edit", locals: { current_user: }
render "logs/edit", locals: { current_user:, bulk_upload_filter_applied: session_filters["bulk_upload_id"].present? }
end
end

8
app/helpers/log_actions_helper.rb

@ -2,8 +2,8 @@ module LogActionsHelper
include GovukLinkHelper
include GovukVisuallyHiddenHelper
def edit_actions_for_log(log)
back = back_button_for(log)
def edit_actions_for_log(log, bulk_upload_filter_applied)
back = back_button_for(log, bulk_upload_filter_applied)
delete = delete_button_for_log(log)
return if back.nil? && delete.nil?
@ -15,9 +15,9 @@ module LogActionsHelper
private
def back_button_for(log)
def back_button_for(log, bulk_upload_filter_applied)
if log.completed?
if log.creation_method_bulk_upload? && log.bulk_upload.present?
if log.creation_method_bulk_upload? && log.bulk_upload.present? && bulk_upload_filter_applied
if log.lettings?
govuk_button_link_to "Back to uploaded logs", resume_bulk_upload_lettings_result_path(log.bulk_upload)
else

4
app/services/storage/local_disk_service.rb

@ -19,7 +19,9 @@ module Storage
File.open(path, "r")
end
def write_file(filename, data, _content_type: nil)
# rubocop:disable Lint/UnusedMethodArgument
def write_file(filename, data, content_type: nil)
# rubocop:enable Lint/UnusedMethodArgument
path = Rails.root.join("tmp/storage", filename)
FileUtils.mkdir_p(path.dirname)

2
app/views/logs/edit.html.erb

@ -38,6 +38,6 @@
<%= render "tasklist" %>
<%= edit_actions_for_log(@log) %>
<%= edit_actions_for_log(@log, bulk_upload_filter_applied) %>
</div>
</div>

25
spec/requests/lettings_logs_controller_spec.rb

@ -1158,6 +1158,31 @@ RSpec.describe LettingsLogsController, type: :request do
expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{lettings_log.id}/review")
end
end
context "with bulk_upload_id filter" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:) }
let(:lettings_log) { create(:lettings_log, :completed, age1: nil, bulk_upload:, assigned_to: user, creation_method: "bulk upload") }
before do
lettings_log.status = "completed"
lettings_log.skip_update_status = true
lettings_log.save!(validate: false)
end
context "with bulk_upload_id filter in session" do
it "displays back to uploaded logs link" do
get "/lettings-logs/#{lettings_log.id}?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).to have_link("Back to uploaded logs")
end
end
context "without bulk_upload_id filter in session" do
it "does not display back to uploaded logs link" do
get "/lettings-logs/#{lettings_log.id}"
expect(page).not_to have_link("Back to uploaded logs")
end
end
end
end
context "with lettings logs from a closed collection period before the previous collection" do

26
spec/views/logs/edit.html.erb_spec.rb

@ -1,11 +1,13 @@
require "rails_helper"
RSpec.describe "logs/edit.html.erb" do
let(:current_user) { create(:user, :support) }
before do
Timecop.freeze(Time.zone.local(2024, 3, 1))
Singleton.__init__(FormHandler)
assign(:log, log)
sign_in create(:user, :support)
sign_in current_user
end
after do
@ -17,7 +19,7 @@ RSpec.describe "logs/edit.html.erb" do
let(:log) { create(:lettings_log, :in_progress) }
it "there is no link back to log type root" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: false }
fragment = Capybara::Node::Simple.new(rendered)
@ -25,7 +27,7 @@ RSpec.describe "logs/edit.html.erb" do
end
it "has link 'Delete log'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: false }
fragment = Capybara::Node::Simple.new(rendered)
@ -38,7 +40,7 @@ RSpec.describe "logs/edit.html.erb" do
let(:log) { create(:lettings_log, :completed) }
it "has link 'Back to lettings logs'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: false }
fragment = Capybara::Node::Simple.new(rendered)
@ -46,7 +48,7 @@ RSpec.describe "logs/edit.html.erb" do
end
it "has link 'Delete log'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: false }
fragment = Capybara::Node::Simple.new(rendered)
@ -58,7 +60,7 @@ RSpec.describe "logs/edit.html.erb" do
let(:log) { create(:sales_log, :completed) }
it "has link 'Back to sales logs'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: false }
fragment = Capybara::Node::Simple.new(rendered)
@ -66,7 +68,7 @@ RSpec.describe "logs/edit.html.erb" do
end
it "has link 'Delete log'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: false }
fragment = Capybara::Node::Simple.new(rendered)
@ -79,7 +81,7 @@ RSpec.describe "logs/edit.html.erb" do
let(:log) { create(:lettings_log, :completed, bulk_upload:, creation_method: "bulk upload") }
it "has link 'Back to uploaded logs'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: true }
fragment = Capybara::Node::Simple.new(rendered)
@ -87,7 +89,7 @@ RSpec.describe "logs/edit.html.erb" do
end
it "has link 'Delete log'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: true }
fragment = Capybara::Node::Simple.new(rendered)
@ -99,7 +101,7 @@ RSpec.describe "logs/edit.html.erb" do
let(:log) { create(:lettings_log, :completed, bulk_upload: nil, creation_method: "bulk upload") }
it "does not have link 'Back to uploaded logs'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: false }
fragment = Capybara::Node::Simple.new(rendered)
@ -112,7 +114,7 @@ RSpec.describe "logs/edit.html.erb" do
let(:log) { create(:sales_log, :completed, bulk_upload:, creation_method: "bulk upload") }
it "has link 'Back to uploaded logs'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: true }
fragment = Capybara::Node::Simple.new(rendered)
@ -120,7 +122,7 @@ RSpec.describe "logs/edit.html.erb" do
end
it "has link 'Delete log'" do
render
render template: "logs/edit", locals: { current_user:, bulk_upload_filter_applied: true }
fragment = Capybara::Node::Simple.new(rendered)

Loading…
Cancel
Save