Remove errored variants

I found another case.
This commit is contained in:
David Cook
2024-05-14 11:06:25 +10:00
parent da77994a89
commit 00f6d01738
2 changed files with 17 additions and 1 deletions

View File

@@ -71,7 +71,7 @@
- product.variants.each_with_index do |variant, variant_index|
= form.fields_for("products][#{product_index}][variants_attributes][", variant, index: variant_index) do |variant_form|
%tr.condensed{ 'data-controller': "variant" }
%tr.condensed{ 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': variant.new_record? ? "true" : false }
= render partial: 'variant_row', locals: { variant:, f: variant_form, category_options:, tax_category_options: }
= form.fields_for("products][#{product_index}][variants_attributes][NEW_RECORD", product.variants.build) do |new_variant_form|

View File

@@ -735,6 +735,22 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi
expect(new_variant.price).to eq 10.25
expect(new_variant.unit_value).to eq 200
end
it "removes unsaved record" do
click_button "Save changes"
expect(page).to have_text("1 product could not be saved.")
within row_containing_name("N" * 256) do
page.find(".vertical-ellipsis-menu").click
page.find('a', text: 'Remove').click
end
# Now that invalid variant is removed, we can proceed to save
click_button "Save changes"
expect(page).not_to have_text("1 product could not be saved.")
expect(page).not_to have_css('form.disabled-section#filters')
end
end
end