From 0d254a8ba4e087a0c1515790dc79f2c79a690e1b Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 2 Jul 2024 16:54:34 +1000 Subject: [PATCH] Move listing block to index file also --- spec/system/admin/products_v3/index_spec.rb | 86 +++++++++++++++++++ .../system/admin/products_v3/products_spec.rb | 86 ------------------- 2 files changed, 86 insertions(+), 86 deletions(-) diff --git a/spec/system/admin/products_v3/index_spec.rb b/spec/system/admin/products_v3/index_spec.rb index b4c6575b71..23b678138e 100644 --- a/spec/system/admin/products_v3/index_spec.rb +++ b/spec/system/admin/products_v3/index_spec.rb @@ -19,6 +19,92 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi let(:categories_search_selector) { 'input[placeholder="Search for categories"]' } let(:tax_categories_search_selector) { 'input[placeholder="Search for tax categories"]' } + describe "listing" do + let!(:p1) { create(:product) } + let!(:p2) { create(:product) } + + before do + visit admin_products_url + end + + it "displays a list of products" do + within ".products" do + # displays table header + expect(page).to have_selector "th", text: "Name" + expect(page).to have_selector "th", text: "SKU" + expect(page).to have_selector "th", text: "Unit scale" + expect(page).to have_selector "th", text: "Unit" + expect(page).to have_selector "th", text: "Price" + expect(page).to have_selector "th", text: "On Hand" + expect(page).to have_selector "th", text: "Producer" + expect(page).to have_selector "th", text: "Category" + expect(page).to have_selector "th", text: "Tax Category" + expect(page).to have_selector "th", text: "Inherits Properties?" + expect(page).to have_selector "th", text: "Actions" + + # displays product list + expect(page).to have_field("_products_0_name", with: p1.name.to_s) + expect(page).to have_field("_products_1_name", with: p2.name.to_s) + end + end + + it "displays a select box for suppliers, with the appropriate supplier selected" do + pending( "[BUU] Change producer, unit type, category and tax category #11060" ) + s1 = FactoryBot.create(:supplier_enterprise) + s2 = FactoryBot.create(:supplier_enterprise) + s3 = FactoryBot.create(:supplier_enterprise) + p1 = FactoryBot.create(:product, supplier: s2) + p2 = FactoryBot.create(:product, supplier: s3) + + visit spree.admin_products_path + + expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name], + selected: s2.name + expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name], + selected: s3.name + end + + context "with several variants" do + let!(:variant1) { p1.variants.first } + let!(:variant2) { p2.variants.first } + let!(:variant3) { create(:variant, product: p2, on_demand: false, on_hand: 4) } + + before do + variant1.update!(on_hand: 0, on_demand: true) + variant2.update!(on_hand: 16, on_demand: false) + visit spree.admin_products_path + end + + it "displays an on hand count in a span for each product" do + expect(page).to have_content "On demand" + expect(page).not_to have_content "20" # does not display the total stock + expect(page).to have_content "16" # displays the stock for variant_2 + expect(page).to have_content "4" # displays the stock for variant_3 + end + end + + it "displays a select box for the unit of measure for the product's variants" do + pending( "[BUU] Change producer, unit type and tax category #11060" ) + p = FactoryBot.create(:product, variant_unit: 'weight', variant_unit_scale: 1, + variant_unit_name: '') + + visit spree.admin_products_path + + expect(page).to have_select "variant_unit_with_scale", selected: "Weight (g)" + end + + it "displays a text field for the item name when unit is set to 'Items'" do + pending( "[BUU] Change producer, unit type and tax category #11060" ) + p = FactoryBot.create(:product, variant_unit: 'items', variant_unit_scale: nil, + variant_unit_name: 'packet') + + visit spree.admin_products_path + + expect(page).to have_select "variant_unit_with_scale", selected: "Items" + expect(page).to have_field "variant_unit_name", with: "packet" + end + end + describe "sorting" do let!(:product_b) { create(:simple_product, name: "Bananas") } let!(:product_a) { create(:simple_product, name: "Apples") } diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 5c11f9c265..ca829c2b33 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -73,92 +73,6 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi end end - describe "listing" do - let!(:p1) { create(:product) } - let!(:p2) { create(:product) } - - before do - visit admin_products_url - end - - it "displays a list of products" do - within ".products" do - # displays table header - expect(page).to have_selector "th", text: "Name" - expect(page).to have_selector "th", text: "SKU" - expect(page).to have_selector "th", text: "Unit scale" - expect(page).to have_selector "th", text: "Unit" - expect(page).to have_selector "th", text: "Price" - expect(page).to have_selector "th", text: "On Hand" - expect(page).to have_selector "th", text: "Producer" - expect(page).to have_selector "th", text: "Category" - expect(page).to have_selector "th", text: "Tax Category" - expect(page).to have_selector "th", text: "Inherits Properties?" - expect(page).to have_selector "th", text: "Actions" - - # displays product list - expect(page).to have_field("_products_0_name", with: p1.name.to_s) - expect(page).to have_field("_products_1_name", with: p2.name.to_s) - end - end - - it "displays a select box for suppliers, with the appropriate supplier selected" do - pending( "[BUU] Change producer, unit type, category and tax category #11060" ) - s1 = FactoryBot.create(:supplier_enterprise) - s2 = FactoryBot.create(:supplier_enterprise) - s3 = FactoryBot.create(:supplier_enterprise) - p1 = FactoryBot.create(:product, supplier: s2) - p2 = FactoryBot.create(:product, supplier: s3) - - visit spree.admin_products_path - - expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name], - selected: s2.name - expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name], - selected: s3.name - end - - context "with several variants" do - let!(:variant1) { p1.variants.first } - let!(:variant2) { p2.variants.first } - let!(:variant3) { create(:variant, product: p2, on_demand: false, on_hand: 4) } - - before do - variant1.update!(on_hand: 0, on_demand: true) - variant2.update!(on_hand: 16, on_demand: false) - visit spree.admin_products_path - end - - it "displays an on hand count in a span for each product" do - expect(page).to have_content "On demand" - expect(page).not_to have_content "20" # does not display the total stock - expect(page).to have_content "16" # displays the stock for variant_2 - expect(page).to have_content "4" # displays the stock for variant_3 - end - end - - it "displays a select box for the unit of measure for the product's variants" do - pending( "[BUU] Change producer, unit type and tax category #11060" ) - p = FactoryBot.create(:product, variant_unit: 'weight', variant_unit_scale: 1, - variant_unit_name: '') - - visit spree.admin_products_path - - expect(page).to have_select "variant_unit_with_scale", selected: "Weight (g)" - end - - it "displays a text field for the item name when unit is set to 'Items'" do - pending( "[BUU] Change producer, unit type and tax category #11060" ) - p = FactoryBot.create(:product, variant_unit: 'items', variant_unit_scale: nil, - variant_unit_name: 'packet') - - visit spree.admin_products_path - - expect(page).to have_select "variant_unit_with_scale", selected: "Items" - expect(page).to have_field "variant_unit_name", with: "packet" - end - end - describe "columns" describe "Changing producers, category and tax category" do