diff --git a/spec/features/admin/product_import_spec.rb b/spec/features/admin/product_import_spec.rb index 63dbd0360e..378b8dc015 100644 --- a/spec/features/admin/product_import_spec.rb +++ b/spec/features/admin/product_import_spec.rb @@ -333,6 +333,34 @@ feature "Product Import", js: true do expect(page).to have_input "variant-overrides-#{Spree::Product.find_by(name: 'Beets').variants.first.id}-price", with: "3.2" end + it "handles the Items unit for inventory import" do + + product = create(:simple_product, supplier: enterprise, on_hand: nil, name: 'Aubergine', unit_value: '1', variant_unit_scale: nil, variant_unit: "items", variant_unit_name: "Bag") + csv_data = CSV.generate do |csv| + csv << ["name", "distributor", "producer", "category", "on_hand", "price", "unit_type", "units", "on_demand", "variant_unit_name"] + csv << ["Aubergine", "Another Enterprise", "User Enterprise", "Vegetables", "", "3.3", "kg", "1", "true", "Bag"] + end + + File.write('/tmp/test.csv', csv_data) + visit main_app.admin_product_import_path + select2_select I18n.t('admin.product_import.index.inventories'), from: "settings_import_into" + attach_file 'file', '/tmp/test.csv' + click_button 'Upload' + proceed_to_validation + expect(page).to have_selector '.item-count', text: "1" + expect(page).to have_no_selector '.invalid-count' + expect(page).to have_selector '.inv-create-count', text: '1' + save_data + + expect(page).to have_selector '.inv-created-count', text: '1' + + visit main_app.admin_inventory_path + + expect(page).to have_content "Aubergine" + expect(page).to have_select "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-on_demand", selected: "Yes" + expect(page).to have_input "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-price", with: "3.3" + end + it "handles on_demand and on_hand validations with inventory" do csv_data = CSV.generate do |csv| csv << ["name", "distributor", "producer", "category", "on_hand", "price", "units", "on_demand"]