Fix Bulk Edit product part 2

Note, the empty entry for unit scale need a css fix , currently showing
at half height
This commit is contained in:
Gaetan Craig-Riou
2024-07-12 14:54:12 +10:00
parent e8234ee4a0
commit 768825d689
4 changed files with 32 additions and 34 deletions

View File

@@ -12,10 +12,9 @@
= f.hidden_field :variant_unit_scale
= f.select :variant_unit_with_scale,
options_for_select(WeightsAndMeasures.variant_unit_options, variant.variant_unit_with_scale),
{},
class: "fullwidth no-input",
'aria-label': t('admin.products_page.columns.unit_scale'),
data: { "controller": "tom-select", "tom-select-options-value": '{ "plugins": [] }', action: "change->toggle-control#displayIfMatch"}
{ include_blank: true },
{ class: "fullwidth no-input", 'aria-label': t('admin.products_page.columns.unit_scale'), data: { "controller": "tom-select", "tom-select-options-value": '{ "plugins": [] }', action: "change->toggle-control#displayIfMatch" } }
= error_message_on variant, :variant_unit, 'data-toggle-control-target': 'control'
.field
= f.text_field :variant_unit_name, 'aria-label': t('items'), 'data-toggle-control-target': 'control', style: (variant.variant_unit == "items" ? "" : "display: none")
= error_message_on variant, :variant_unit_name, 'data-toggle-control-target': 'control'

View File

@@ -111,13 +111,10 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
let!(:variant_a1) {
product_a.variants.first.tap{ |v|
v.update! display_name: "Medium box", sku: "APL-01", price: 5.25, on_hand: 5,
on_demand: false
}
}
let!(:product_a) {
create(:simple_product, name: "Apples", sku: "APL-00",
variant_unit: "weight", variant_unit_scale: 1) # Grams
on_demand: false, variant_unit: "weight", variant_unit_scale: 1
} # Grams
}
let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-00") }
context "when they are under 11" do
before do
@@ -299,7 +296,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
it "shows error message when cloning invalid record" do
# Existing product is invalid:
product_a.update_columns(variant_unit: nil)
product_a.update_columns(name: nil)
click_product_clone "Apples"

View File

@@ -38,7 +38,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
end
describe "creating new variants" do
let!(:product) { create(:product, variant_unit: 'weight', variant_unit_scale: 1000) }
let!(:product) { create(:product) }
before { visit_products_page_as_admin }
@@ -80,6 +80,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
within page.all("tr.condensed")[1] do # selects second variant row
find('input[id$="_sku"]').fill_in with: "345"
find('input[id$="_display_name"]').fill_in with: "Small bag"
tomselect_select "Weight (g)", from: "Unit scale"
find('button[id$="unit_to_display"]').click # opens the unit value pop out
find('input[id$="_unit_value_with_description"]').fill_in with: "0.002"
find('input[id$="_display_as"]').fill_in with: "2 grams"
@@ -111,6 +112,8 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
new_variant = Spree::Variant.where(deleted_at: nil).last
expect(new_variant.sku).to eq "345"
expect(new_variant.display_name).to eq "Small bag"
expect(new_variant.variant_unit).to eq "weight"
expect(new_variant.variant_unit_scale).to eq 1 # g
expect(new_variant.unit_value).to eq 2.0
expect(new_variant.display_as).to eq "2 grams"
expect(new_variant.unit_presentation).to eq "2 grams"

View File

@@ -25,22 +25,20 @@ RSpec.describe 'As an enterprise user, I can update my products' do
let!(:variant_a1) {
product_a.variants.first.tap{ |v|
v.update! display_name: "Medium box", sku: "APL-01", price: 5.25, on_hand: 5,
on_demand: false
}
on_demand: false, variant_unit: "weight", variant_unit_scale: 1
} # Grams
}
let!(:product_a) {
create(:simple_product, name: "Apples", sku: "APL-00",
variant_unit: "weight", variant_unit_scale: 1) # Grams
create(:simple_product, name: "Apples", sku: "APL-00" )
}
let(:variant_b1) {
product_b.variants.first.tap{ |v|
v.update! display_name: "Medium box", sku: "TMT-01", price: 5, on_hand: 5,
on_demand: false
}
on_demand: false, variant_unit: "weight", variant_unit_scale: 1
} # Grams
}
let(:product_b) {
create(:simple_product, name: "Tomatoes", sku: "TMT-01",
variant_unit: "weight", variant_unit_scale: 1) # Grams
create(:simple_product, name: "Tomatoes", sku: "TMT-01")
}
before do
visit admin_products_url
@@ -50,11 +48,16 @@ RSpec.describe 'As an enterprise user, I can update my products' do
within row_containing_name("Apples") 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"
click_on "Unit" # activate popout
end
# Unit popout
click_on "Unit" # activate 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
@@ -85,13 +88,13 @@ RSpec.describe 'As an enterprise user, I can update my products' do
variant_a1.reload
}.to change { product_a.name }.to("Pommes")
.and change{ product_a.sku }.to("POM-00")
.and change{ product_a.variant_unit }.to("volume")
.and change{ product_a.variant_unit_scale }.to(0.001)
.and change{ variant_a1.display_name }.to("Large box")
.and change{ variant_a1.sku }.to("POM-01")
.and change{ variant_a1.unit_value }.to(0.5001) # volumes are stored in litres
.and change{ variant_a1.price }.to(10.25)
.and change{ variant_a1.on_hand }.to(6)
.and change{ variant_a1.variant_unit }.to("volume")
.and change{ variant_a1.variant_unit_scale }.to(0.001)
within row_containing_name("Pommes") do
expect(page).to have_field "Name", with: "Pommes"
@@ -130,11 +133,7 @@ RSpec.describe 'As an enterprise user, I can update my products' do
it "saves unit values using the new scale" do
within row_containing_name("Medium box") do
expect(page).to have_button "Unit", text: "1g"
end
within row_containing_name("Apples") do
tomselect_select "Weight (kg)", from: "Unit scale"
end
within row_containing_name("Medium box") do
# New scale is visible immediately
expect(page).to have_button "Unit", text: "1kg"
end
@@ -142,10 +141,10 @@ RSpec.describe 'As an enterprise user, I can update my products' do
click_button "Save changes"
expect(page).to have_content "Changes saved"
product_a.reload
expect(product_a.variant_unit).to eq "weight"
expect(product_a.variant_unit_scale).to eq 1000 # kg
expect(variant_a1.reload.unit_value).to eq 1000 # 1kg
variant_a1.reload
expect(variant_a1.variant_unit).to eq "weight"
expect(variant_a1.variant_unit_scale).to eq 1000 # kg
expect(variant_a1.unit_value).to eq 1000 # 1kg
within row_containing_name("Medium box") do
expect(page).to have_button "Unit", text: "1kg"
@@ -153,7 +152,7 @@ RSpec.describe 'As an enterprise user, I can update my products' do
end
it "saves a custom item unit name" do
within row_containing_name("Apples") do
within row_containing_name("Medium box") do
tomselect_select "Items", from: "Unit scale"
fill_in "Items", with: "box"
end
@@ -163,8 +162,8 @@ RSpec.describe 'As an enterprise user, I can update my products' do
expect(page).to have_content "Changes saved"
product_a.reload
}.to change{ product_a.variant_unit }.to("items")
.and change{ product_a.variant_unit_name }.to("box")
}.to change{ variant_a1.variant_unit }.to("items")
.and change{ variant_a1.variant_unit_name }.to("box")
within row_containing_name("Apples") do
pending "#12005"