Ensure pagination is retained when saving or discarding

But we have more work to do.
This commit is contained in:
David Cook
2024-04-03 16:56:29 +11:00
committed by Filipe
parent 2c71f7f1ed
commit 0fc3d39106
3 changed files with 39 additions and 5 deletions

View File

@@ -26,8 +26,8 @@ module Admin
end
end
def index_url
"/admin/products" # todo: fix routing so this can be automatically generated
def index_url(params)
"/admin/products?#{params.to_query}" # todo: fix routing so this can be automaticly generated
end
private
@@ -43,8 +43,8 @@ module Admin
def init_pagination_params
# prority is given to element dataset (if present) over url params
@page = params[:_page] || 1
@per_page = params[:_per_page] || 15
@page = params[:_page].presence || 1
@per_page = params[:_per_page].presence || 15
end
def producers

View File

@@ -4,6 +4,10 @@
'bulk-form-error-value': defined?(@error_counts),
} } do |form|
= render(partial: "admin/shared/flashes", locals: { flashes: }) if defined? flashes
= hidden_field_tag :_page, @page
= hidden_field_tag :_per_page, @per_page
%table.products
%colgroup
%col{ width:"56" }= # Img (size + padding)
@@ -35,7 +39,6 @@
-# Y products could not be saved correctly. Please review errors and try again
= t('.error_summary.invalid', count: @error_counts[:invalid])
.form-buttons
%a.button.reset.medium{ href: admin_products_path(page: @page, per_page: @per_page) }
= t('.reset')
= form.submit t('.save'), class: "medium"

View File

@@ -608,6 +608,37 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do
expect(page).to have_content "Please review the errors and try again"
end
end
context "pagination" do
let!(:product_a) { create(:simple_product, name: "zucchini") } # appears on p2
it "retains selected page after saving" do
create_products 15 # in addition to product_a
visit admin_products_url
within ".pagination" do
click_link "2"
end
within row_containing_name("zucchini") do
fill_in "Name", with: "zucchinis"
end
expect {
click_button "Save changes"
expect(page).to have_content "Changes saved"
product_a.reload
}.to change { product_a.name }.to("zucchinis")
pending "awaiting pagination to be loaded without SR"
expect(page).to have_content "Showing 16 to 16" # todo: remove unnecessary duplication
expect_page_to_be 2
expect_per_page_to_be 15
expect_products_count_to_be 1
expect(page).to have_css row_containing_name("zucchinis")
end
end
end
describe "edit image" do