From 00f6d01738c9680ed24168412e1b760889f4cc0c Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 14 May 2024 11:06:25 +1000 Subject: [PATCH] Remove errored variants I found another case. --- app/views/admin/products_v3/_table.html.haml | 2 +- spec/system/admin/products_v3/products_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/views/admin/products_v3/_table.html.haml b/app/views/admin/products_v3/_table.html.haml index 20fd3311ef..27d5d7434f 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -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| diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 8665039568..757be44d02 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -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