From bc87c98e92069f6dfe4ce6482494cc14990331fe Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 9 Oct 2024 13:02:39 +1100 Subject: [PATCH 1/4] Add some specs for the producer dropdowns --- spec/system/admin/products_v3/index_spec.rb | 58 ++++++++++++++------ spec/system/admin/products_v3/update_spec.rb | 10 ++++ 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/spec/system/admin/products_v3/index_spec.rb b/spec/system/admin/products_v3/index_spec.rb index 15990c3460..fb88e8a631 100644 --- a/spec/system/admin/products_v3/index_spec.rb +++ b/spec/system/admin/products_v3/index_spec.rb @@ -47,22 +47,6 @@ RSpec.describe 'As an enterprise user, I can manage my products' do 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_id: s2.id) - p2 = FactoryBot.create(:product, supplier_id: s3.id) - - 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!(:variant2a) { p2.variants.first } @@ -91,6 +75,38 @@ RSpec.describe 'As an enterprise user, I can manage my products' do expect(page).to have_content "4" end end + + describe "Producer column" do + it "when I have one enterprise" do + visit spree.admin_products_path + + expect(page).to_not have_select "Producer" + end + + context "when I have multiple enterprises" do + let(:user) { create(:user, enterprises: [producer2, producer1]) } + let(:producer1) { create(:supplier_enterprise, name: "Producer A") } + let(:producer2) { create(:supplier_enterprise, name: "Producer B") } + + it "displays a select box for suppliers, with the appropriate supplier selected" do + producer3 = create(:supplier_enterprise, name: "Producer C") + variant1.update!(supplier: producer1) + variant2a.update!(supplier: producer2) + + visit spree.admin_products_path + + within row_containing_name "Variant1" do + expect(page).to have_select "Producer", with_options: ["Producer A", "Producer B"], + selected: "Producer A" + end + + within row_containing_name "Variant2a" do + expect(page).to have_select "Producer", with_options: ["Producer A", "Producer B"], + selected: "Producer B" + end + end + end + end end it "displays a select box for the unit of measure for the product's variants" do @@ -296,7 +312,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do end end - context "product has producer" do + context "User has multiple producers" do before { create_products 1 } # create a product with a different supplier @@ -334,6 +350,14 @@ RSpec.describe 'As an enterprise user, I can manage my products' do end end + context "User has single producer" do + it "producer filter does not show" do + visit admin_products_url + + expect(page).to_not have_select "Producers" + end + end + context "product has category" do before { create_products 1 } diff --git a/spec/system/admin/products_v3/update_spec.rb b/spec/system/admin/products_v3/update_spec.rb index 57245ecb6b..ead7feadd3 100644 --- a/spec/system/admin/products_v3/update_spec.rb +++ b/spec/system/admin/products_v3/update_spec.rb @@ -220,6 +220,8 @@ RSpec.describe 'As an enterprise user, I can update my products' do end end + # it "can select only the producers that I manage" + it "discards changes and reloads latest data" do within row_containing_name("Apples") do fill_in "Name", with: "Pommes" @@ -439,6 +441,14 @@ RSpec.describe 'As an enterprise user, I can update my products' do expect(page).not_to have_css('form.disabled-section#filters') end + describe "producer" do + # it "can select only the producers that I manage" + + context " when I manage only one producer" do + # it "producer select doesn't show, and is saved correctly" + end + end + context "With 2 products" do before do variant_b1 From ac5fa21ff2d9fc9dc702125075997b47d66f5bab Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 15 Oct 2024 10:33:20 +1100 Subject: [PATCH 2/4] Clean up --- spec/system/admin/products_v3/index_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/admin/products_v3/index_spec.rb b/spec/system/admin/products_v3/index_spec.rb index fb88e8a631..bc721730eb 100644 --- a/spec/system/admin/products_v3/index_spec.rb +++ b/spec/system/admin/products_v3/index_spec.rb @@ -89,7 +89,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do let(:producer2) { create(:supplier_enterprise, name: "Producer B") } it "displays a select box for suppliers, with the appropriate supplier selected" do - producer3 = create(:supplier_enterprise, name: "Producer C") + create(:supplier_enterprise, name: "Producer C") variant1.update!(supplier: producer1) variant2a.update!(supplier: producer2) From cc9b764f0f3a9db1c23e26703478957a4defd955 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 15 Oct 2024 10:37:20 +1100 Subject: [PATCH 3/4] Fix rubocop --- spec/system/admin/products_v3/index_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/system/admin/products_v3/index_spec.rb b/spec/system/admin/products_v3/index_spec.rb index bc721730eb..d88bc2451e 100644 --- a/spec/system/admin/products_v3/index_spec.rb +++ b/spec/system/admin/products_v3/index_spec.rb @@ -80,7 +80,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do it "when I have one enterprise" do visit spree.admin_products_path - expect(page).to_not have_select "Producer" + expect(page).not_to have_select "Producer" end context "when I have multiple enterprises" do @@ -89,7 +89,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do let(:producer2) { create(:supplier_enterprise, name: "Producer B") } it "displays a select box for suppliers, with the appropriate supplier selected" do - create(:supplier_enterprise, name: "Producer C") + create(:supplier_enterprise, name: "Producer C") variant1.update!(supplier: producer1) variant2a.update!(supplier: producer2) @@ -354,7 +354,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do it "producer filter does not show" do visit admin_products_url - expect(page).to_not have_select "Producers" + expect(page).not_to have_select "Producers" end end From d5b24089477d746a30fa6fd8fab6ea8f428d542c Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 16 Oct 2024 09:51:04 +1100 Subject: [PATCH 4/4] Reveal un-implemented tests --- spec/system/admin/products_v3/update_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/system/admin/products_v3/update_spec.rb b/spec/system/admin/products_v3/update_spec.rb index ead7feadd3..01af461c89 100644 --- a/spec/system/admin/products_v3/update_spec.rb +++ b/spec/system/admin/products_v3/update_spec.rb @@ -441,11 +441,11 @@ RSpec.describe 'As an enterprise user, I can update my products' do expect(page).not_to have_css('form.disabled-section#filters') end - describe "producer" do - # it "can select only the producers that I manage" + xdescribe "producer" do + it "can select only the producers that I manage" context " when I manage only one producer" do - # it "producer select doesn't show, and is saved correctly" + it "producer select doesn't show, and is saved correctly" end end