diff --git a/app/models/bulk_upload_error.rb b/app/models/bulk_upload_error.rb index 0c298ddf8..b9ad3ddde 100644 --- a/app/models/bulk_upload_error.rb +++ b/app/models/bulk_upload_error.rb @@ -1,6 +1,7 @@ class BulkUploadError < ApplicationRecord belongs_to :bulk_upload + scope :order_by_row, -> { order(row: :asc) } scope :order_by_cell, -> { order(Arel.sql("LPAD(cell, 10, '0')")) } scope :order_by_col, -> { order(Arel.sql("LPAD(col, 10, '0')")) } end diff --git a/app/views/bulk_upload_lettings_results/show.html.erb b/app/views/bulk_upload_lettings_results/show.html.erb index dea114e63..63c7d3241 100644 --- a/app/views/bulk_upload_lettings_results/show.html.erb +++ b/app/views/bulk_upload_lettings_results/show.html.erb @@ -13,7 +13,7 @@
- <% @bulk_upload.bulk_upload_errors.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> + <% @bulk_upload.bulk_upload_errors.order_by_row.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> <%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: errors_for_row) %> <% end %>
diff --git a/app/views/bulk_upload_lettings_results/summary.html.erb b/app/views/bulk_upload_lettings_results/summary.html.erb index 51aa652f8..6f70f9800 100644 --- a/app/views/bulk_upload_lettings_results/summary.html.erb +++ b/app/views/bulk_upload_lettings_results/summary.html.erb @@ -20,7 +20,7 @@ <% end %> <% c.with_tab(label: "Full error report") do %> - <% @bulk_upload.bulk_upload_errors.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> + <% @bulk_upload.bulk_upload_errors.order_by_row.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> <%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: errors_for_row) %> <% end %> <% end %> diff --git a/app/views/bulk_upload_sales_results/show.html.erb b/app/views/bulk_upload_sales_results/show.html.erb index 161edb013..24f84ebf6 100644 --- a/app/views/bulk_upload_sales_results/show.html.erb +++ b/app/views/bulk_upload_sales_results/show.html.erb @@ -13,7 +13,7 @@
- <% @bulk_upload.bulk_upload_errors.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> + <% @bulk_upload.bulk_upload_errors.order_by_row.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> <%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: errors_for_row) %> <% end %>
diff --git a/app/views/bulk_upload_sales_results/summary.html.erb b/app/views/bulk_upload_sales_results/summary.html.erb index 2d02848c0..fc872cb31 100644 --- a/app/views/bulk_upload_sales_results/summary.html.erb +++ b/app/views/bulk_upload_sales_results/summary.html.erb @@ -20,7 +20,7 @@ <% end %> <% c.with_tab(label: "Full error report") do %> - <% @bulk_upload.bulk_upload_errors.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> + <% @bulk_upload.bulk_upload_errors.order_by_row.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %> <%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: errors_for_row) %> <% end %> <% end %> diff --git a/spec/views/bulk_upload_lettings_results/show.html.erb_spec.rb b/spec/views/bulk_upload_lettings_results/show.html.erb_spec.rb index 286e1e279..62da07d01 100644 --- a/spec/views/bulk_upload_lettings_results/show.html.erb_spec.rb +++ b/spec/views/bulk_upload_lettings_results/show.html.erb_spec.rb @@ -3,18 +3,37 @@ require "rails_helper" RSpec.describe "bulk_upload_lettings_results/show.html.erb" do let(:bulk_upload) { create(:bulk_upload, :lettings) } - before do - create(:bulk_upload_error, bulk_upload:, cell: "AA100", row: "100", col: "AA") - create(:bulk_upload_error, bulk_upload:, cell: "Z100", row: "100", col: "Z") + context "when mutiple rows in wrong order" do + before do + create(:bulk_upload_error, bulk_upload:, cell: "C14", row: "14", col: "C") + create(:bulk_upload_error, bulk_upload:, cell: "D10", row: "10", col: "D") + end + + it "renders errors order by row" do + assign(:bulk_upload, bulk_upload) + + render + + fragment = Capybara::Node::Simple.new(rendered) + + expect(fragment.find_css(".x-govuk-summary-card__title strong").map(&:inner_text)).to eql(["Row 10", "Row 14"]) + end end - it "renders errors ordered by cell" do - assign(:bulk_upload, bulk_upload) + context "when 1 row with 2 errors" do + before do + create(:bulk_upload_error, bulk_upload:, cell: "AA100", row: "100", col: "AA") + create(:bulk_upload_error, bulk_upload:, cell: "Z100", row: "100", col: "Z") + end + + it "renders errors ordered by cell" do + assign(:bulk_upload, bulk_upload) - render + render - fragment = Capybara::Node::Simple.new(rendered) + fragment = Capybara::Node::Simple.new(rendered) - expect(fragment.find_css("table tbody th").map(&:inner_text)).to eql(%w[Z100 AA100]) + expect(fragment.find_css("table tbody th").map(&:inner_text)).to eql(%w[Z100 AA100]) + end end end diff --git a/spec/views/bulk_upload_lettings_results/summary.html.erb_spec.rb b/spec/views/bulk_upload_lettings_results/summary.html.erb_spec.rb index 25499133d..242e58d4e 100644 --- a/spec/views/bulk_upload_lettings_results/summary.html.erb_spec.rb +++ b/spec/views/bulk_upload_lettings_results/summary.html.erb_spec.rb @@ -3,18 +3,37 @@ require "rails_helper" RSpec.describe "bulk_upload_lettings_results/summary.html.erb" do let(:bulk_upload) { create(:bulk_upload, :lettings) } - before do - create(:bulk_upload_error, bulk_upload:, cell: "AA100", row: "100", col: "AA") - create(:bulk_upload_error, bulk_upload:, cell: "Z100", row: "100", col: "Z") + context "when mutiple rows in wrong order" do + before do + create(:bulk_upload_error, bulk_upload:, cell: "C14", row: "14", col: "C") + create(:bulk_upload_error, bulk_upload:, cell: "D10", row: "10", col: "D") + end + + it "renders errors order by row" do + assign(:bulk_upload, bulk_upload) + + render + + fragment = Capybara::Node::Simple.new(rendered) + + expect(fragment.find_css(".x-govuk-summary-card__title strong").map(&:inner_text)).to eql(["Row 10", "Row 14"]) + end end - it "renders errors ordered by cell" do - assign(:bulk_upload, bulk_upload) + context "when 1 row with 2 errors" do + before do + create(:bulk_upload_error, bulk_upload:, cell: "AA100", row: "100", col: "AA") + create(:bulk_upload_error, bulk_upload:, cell: "Z100", row: "100", col: "Z") + end + + it "renders errors ordered by cell" do + assign(:bulk_upload, bulk_upload) - render + render - fragment = Capybara::Node::Simple.new(rendered) + fragment = Capybara::Node::Simple.new(rendered) - expect(fragment.find_css("table tbody th").map(&:inner_text)).to eql(%w[Z100 AA100]) + expect(fragment.find_css("table tbody th").map(&:inner_text)).to eql(%w[Z100 AA100]) + end end end diff --git a/spec/views/bulk_upload_sales_results/show.html.erb_spec.rb b/spec/views/bulk_upload_sales_results/show.html.erb_spec.rb new file mode 100644 index 000000000..b553d27ce --- /dev/null +++ b/spec/views/bulk_upload_sales_results/show.html.erb_spec.rb @@ -0,0 +1,39 @@ +require "rails_helper" + +RSpec.describe "bulk_upload_sales_results/show.html.erb" do + let(:bulk_upload) { create(:bulk_upload, :sales) } + + context "when mutiple rows in wrong order" do + before do + create(:bulk_upload_error, bulk_upload:, cell: "C14", row: "14", col: "C") + create(:bulk_upload_error, bulk_upload:, cell: "D10", row: "10", col: "D") + end + + it "renders errors order by row" do + assign(:bulk_upload, bulk_upload) + + render + + fragment = Capybara::Node::Simple.new(rendered) + + expect(fragment.find_css(".x-govuk-summary-card__title strong").map(&:inner_text)).to eql(["Row 10", "Row 14"]) + end + end + + context "when 1 row with 2 errors" do + before do + create(:bulk_upload_error, bulk_upload:, cell: "AA100", row: "100", col: "AA") + create(:bulk_upload_error, bulk_upload:, cell: "Z100", row: "100", col: "Z") + end + + it "renders errors ordered by cell" do + assign(:bulk_upload, bulk_upload) + + render + + fragment = Capybara::Node::Simple.new(rendered) + + expect(fragment.find_css("table tbody th").map(&:inner_text)).to eql(%w[Z100 AA100]) + end + end +end diff --git a/spec/views/bulk_upload_sales_results/summary.html.erb_spec.rb b/spec/views/bulk_upload_sales_results/summary.html.erb_spec.rb new file mode 100644 index 000000000..4ac2e3807 --- /dev/null +++ b/spec/views/bulk_upload_sales_results/summary.html.erb_spec.rb @@ -0,0 +1,39 @@ +require "rails_helper" + +RSpec.describe "bulk_upload_sales_results/summary.html.erb" do + let(:bulk_upload) { create(:bulk_upload, :sales) } + + context "when mutiple rows in wrong order" do + before do + create(:bulk_upload_error, bulk_upload:, cell: "C14", row: "14", col: "C") + create(:bulk_upload_error, bulk_upload:, cell: "D10", row: "10", col: "D") + end + + it "renders errors order by row" do + assign(:bulk_upload, bulk_upload) + + render + + fragment = Capybara::Node::Simple.new(rendered) + + expect(fragment.find_css(".x-govuk-summary-card__title strong").map(&:inner_text)).to eql(["Row 10", "Row 14"]) + end + end + + context "when 1 row with 2 errors" do + before do + create(:bulk_upload_error, bulk_upload:, cell: "AA100", row: "100", col: "AA") + create(:bulk_upload_error, bulk_upload:, cell: "Z100", row: "100", col: "Z") + end + + it "renders errors ordered by cell" do + assign(:bulk_upload, bulk_upload) + + render + + fragment = Capybara::Node::Simple.new(rendered) + + expect(fragment.find_css("table tbody th").map(&:inner_text)).to eql(%w[Z100 AA100]) + end + end +end