From 0695b434a2e81a1b8a8b1cd5d701de0cb4b53e49 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 19 Aug 2024 14:12:08 +1000 Subject: [PATCH] Fix rebase issue --- app/helpers/admin/products_helper.rb | 4 +-- .../admin/products_v3/_variant_row.html.haml | 2 +- spec/helpers/admin/products_helper_spec.rb | 7 +++-- spec/system/admin/products_v3/update_spec.rb | 31 +++++++++---------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/helpers/admin/products_helper.rb b/app/helpers/admin/products_helper.rb index b67aa57540..ea18887e04 100644 --- a/app/helpers/admin/products_helper.rb +++ b/app/helpers/admin/products_helper.rb @@ -18,9 +18,9 @@ module Admin end def unit_value_with_description(variant) - return "" if variant.unit_value.nil? + return variant.unit_description.to_s if variant.unit_value.nil? - scaled_unit_value = variant.unit_value / (variant.product.variant_unit_scale || 1) + scaled_unit_value = variant.unit_value / (variant.variant_unit_scale || 1) precised_unit_value = number_with_precision( scaled_unit_value, precision: nil, diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index 2d3fd67896..fa423bbce7 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -27,7 +27,7 @@ = f.hidden_field :unit_value = f.hidden_field :unit_description = f.text_field :unit_value_with_description, - value: unit_value_with_description(variant), 'aria-label': t('admin.products_page.columns.unit_value') + value: unit_value_with_description(variant), 'aria-label': t('admin.products_page.columns.unit_value'), required: true .field = f.label :display_as, t('admin.products_page.columns.display_as') = f.text_field :display_as, placeholder: VariantUnits::OptionValueNamer.new(variant).name diff --git a/spec/helpers/admin/products_helper_spec.rb b/spec/helpers/admin/products_helper_spec.rb index cdd4df9e2a..cfd04180d9 100644 --- a/spec/helpers/admin/products_helper_spec.rb +++ b/spec/helpers/admin/products_helper_spec.rb @@ -4,8 +4,9 @@ require "spec_helper" RSpec.describe Admin::ProductsHelper do describe '#unit_value_with_description' do - let(:product) { create(:product, variant_unit_scale: 1000.0) } - let(:variant) { create(:variant, product:, unit_value: 2000.0, unit_description: 'kg') } + let(:variant) { + create(:variant, variant_unit_scale: 1000.0, unit_value: 2000.0, unit_description: 'kg') + } context 'when unit_value and unit_description are present' do it 'returns the scaled unit value with the description' do @@ -30,7 +31,7 @@ RSpec.describe Admin::ProductsHelper do end context 'when variant_unit_scale is nil' do - before { product.update_column(:variant_unit_scale, nil) } + before { variant.update_column(:variant_unit_scale, nil) } it 'uses default scale of 1 and returns the unscaled unit value with the description' do expect(helper.unit_value_with_description(variant)).to eq('2000 kg') diff --git a/spec/system/admin/products_v3/update_spec.rb b/spec/system/admin/products_v3/update_spec.rb index 2d6bd09acc..9fa093311a 100644 --- a/spec/system/admin/products_v3/update_spec.rb +++ b/spec/system/admin/products_v3/update_spec.rb @@ -49,35 +49,34 @@ RSpec.describe 'As an enterprise user, I can update my products' do fill_in "Name", with: "Pommes" fill_in "SKU", with: "POM-00" end + within row_containing_name("Medium box") do fill_in "Name", with: "Large box" fill_in "SKU", with: "POM-01" tomselect_select "Volume (mL)", from: "Unit scale" + + # Unit popout click_on "Unit" # activate popout - end + # have to use below method to trigger the +change+ event, + # +fill_in "Unit value", with: ""+ does not trigger +change+ event + find_field('Unit value').send_keys(:control, 'a', :backspace) # empty the field + # In CI we get "Please fill out this field." and locally we get + # "Please fill in this field." + expect_browser_validation('input[aria-label="Unit value"]', + /Please fill (in|out) this field./) - # Unit popout - # have to use below method to trigger the +change+ event, - # +fill_in "Unit value", with: ""+ does not trigger +change+ event - find_field('Unit value').send_keys(:control, 'a', :backspace) # empty the field - click_button "Save changes" # attempt to save and should fail with below error - expect(page).to have_content "must be greater than 0" - click_on "Unit" # activate popout - fill_in "Unit value", with: "500.1" - - within row_containing_name("Medium box") do - fill_in "Name", with: "Large box" - fill_in "SKU", with: "POM-01" + fill_in "Unit value", with: "500.1" fill_in "Price", with: "10.25" + # Stock popout click_on "On Hand" # activate popout + fill_in "On Hand", with: "-1" end - # Stock popout - fill_in "On Hand", with: "-1" click_button "Save changes" # attempt to save or close the popout expect(page).to have_field "On Hand", with: "-1" # popout is still open + fill_in "On Hand", with: "6" expect { @@ -553,8 +552,6 @@ RSpec.describe 'As an enterprise user, I can update my products' do expect(page).to have_content "is too long" expect(page.find('.col-producer')).to have_content('must exist') expect(page.find('.col-category')).to have_content('must exist') - expect(page.find_button("Unit")).to have_text "" # have_button selector don't work here - expect(page).to have_content "can't be blank" expect(page).to have_field "Price", with: "10.25" # other updated value is retained end