Browse Source

ensure errors are sorted by row

pull/1633/head
Phil Lee 3 years ago
parent
commit
ac6393361a
  1. 1
      app/models/bulk_upload_error.rb
  2. 2
      app/views/bulk_upload_lettings_results/show.html.erb
  3. 2
      app/views/bulk_upload_lettings_results/summary.html.erb
  4. 2
      app/views/bulk_upload_sales_results/show.html.erb
  5. 2
      app/views/bulk_upload_sales_results/summary.html.erb
  6. 35
      spec/views/bulk_upload_lettings_results/show.html.erb_spec.rb
  7. 35
      spec/views/bulk_upload_lettings_results/summary.html.erb_spec.rb
  8. 39
      spec/views/bulk_upload_sales_results/show.html.erb_spec.rb
  9. 39
      spec/views/bulk_upload_sales_results/summary.html.erb_spec.rb

1
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

2
app/views/bulk_upload_lettings_results/show.html.erb

@ -13,7 +13,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<% @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 %>
</div>

2
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 %>

2
app/views/bulk_upload_sales_results/show.html.erb

@ -13,7 +13,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<% @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 %>
</div>

2
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 %>

35
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

35
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

39
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

39
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
Loading…
Cancel
Save