From bb5452ad26a9d9791dc72ac13084e5c2b52f0047 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 10 May 2021 18:57:47 +0100 Subject: [PATCH 1/4] Adds verification of product import on products page --- spec/features/admin/product_import_spec.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spec/features/admin/product_import_spec.rb b/spec/features/admin/product_import_spec.rb index e1b93d1e69..30e67f07a5 100644 --- a/spec/features/admin/product_import_spec.rb +++ b/spec/features/admin/product_import_spec.rb @@ -33,7 +33,10 @@ feature "Product Import", js: true do let(:shipping_category_id_str) { Spree::ShippingCategory.all.first.id.to_s } describe "when importing products from uploaded file" do - before { login_as_admin } + before do + allow(Spree::Config).to receive(:available_units).and_return("g,lb,oz,kg,T,mL,L,kL") + login_as_admin + end after { File.delete('/tmp/test.csv') } it "validates entries and saves them if they are all valid and allows viewing new items in Bulk Products" do @@ -392,6 +395,14 @@ feature "Product Import", js: true do expect(page).to have_selector '.created-count', text: '2' expect(page).to have_no_selector '.updated-count' + + visit spree.admin_products_path + + within "#p_#{Spree::Product.find_by(name: 'Carrots').id}" do + expect(page).to have_input "product_name", with: "Carrots" + expect(page).to have_select "variant_unit_with_scale", selected: "Weight (lb)" + expect(page).to have_content "5" #on_hand + end end it "does not allow import for lines with unknown units" do From 8e24c655b041efd5f80d4953defa7646bb956d60 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 10 May 2021 19:01:41 +0100 Subject: [PATCH 2/4] Adds verification of inventory import on inventory page --- spec/features/admin/product_import_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/features/admin/product_import_spec.rb b/spec/features/admin/product_import_spec.rb index 30e67f07a5..78e1d8af27 100644 --- a/spec/features/admin/product_import_spec.rb +++ b/spec/features/admin/product_import_spec.rb @@ -325,6 +325,12 @@ feature "Product Import", js: true do save_data expect(page).to have_selector '.inv-created-count', text: '1' + + visit main_app.admin_inventory_path + + expect(page).to have_content "Beets" + expect(page).to have_select "variant-overrides-#{Spree::Product.find_by(name: 'Beets').variants.first.id}-on_demand", selected: "Yes" + expect(page).to have_input "variant-overrides-#{Spree::Product.find_by(name: 'Beets').variants.first.id}-price", with: "3.2" end it "handles on_demand and on_hand validations with inventory" do From 5475b79cde349e2bce1da90391bc35dd7e11d267 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 10 May 2021 19:07:05 +0100 Subject: [PATCH 3/4] Adds test-case on the product import unit Items --- spec/features/admin/product_import_spec.rb | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/spec/features/admin/product_import_spec.rb b/spec/features/admin/product_import_spec.rb index 78e1d8af27..63dbd0360e 100644 --- a/spec/features/admin/product_import_spec.rb +++ b/spec/features/admin/product_import_spec.rb @@ -411,6 +411,43 @@ feature "Product Import", js: true do end end + it "imports lines with item products" do + csv_data = CSV.generate do |csv| + csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "variant_unit_name", "shipping_category_id"] + csv << ["Cupcake", "User Enterprise", "Cake", "5", "2.2", "1", "", "Bunch", shipping_category_id_str] + end + File.write('/tmp/test.csv', csv_data) + + visit main_app.admin_product_import_path + + expect(page).to have_content "Select a spreadsheet to upload" + 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 '.create-count', text: "1" + expect(page).to have_no_selector '.update-count' + + save_data + + expect(page).to have_selector '.created-count', text: '1' + expect(page).to have_no_selector '.updated-count' + expect(page).to have_content "GO TO PRODUCTS PAGE" + expect(page).to have_content "UPLOAD ANOTHER FILE" + + visit spree.admin_products_path + + within "#p_#{Spree::Product.find_by(name: 'Cupcake').id}" do + expect(page).to have_input "product_name", with: "Cupcake" + expect(page).to have_select "variant_unit_with_scale", selected: "Items" + expect(page).to have_input "variant_unit_name", with: "Bunch" + expect(page).to have_content "5" #on_hand + end + end + it "does not allow import for lines with unknown units" do csv_data = CSV.generate do |csv| csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category_id"] From 0cd6c53e0d0199147f455156a0719de5d96cf56d Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 10 May 2021 19:12:41 +0100 Subject: [PATCH 4/4] Adds test-case on the inventory import for unit Items --- spec/features/admin/product_import_spec.rb | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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"]