From bdc42deeb63e489e63f631daaecd0a1d872b69fe Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 12 Jul 2024 18:32:29 +0100 Subject: [PATCH 1/7] Sets import column test as pending As of now, it is not clear whether we wish to re-implement this feature on BUU --- spec/system/admin/product_import_spec.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index c0929e5ef2..37b3de2004 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -187,6 +187,8 @@ RSpec.describe "Product Import" do end it "records a timestamp on import that can be viewed and filtered under Bulk Edit Products" do + pending "This feature was removed, see: + https://github.com/openfoodfoundation/openfoodnetwork/issues/10694#issuecomment-1578097339" csv_data = <<~CSV name, producer, category, on_hand, price, units, unit_type, shipping_category_id Carrots, User Enterprise, Vegetables, 5, 3.20, 500, g, #{shipping_category_id_str} @@ -209,15 +211,18 @@ RSpec.describe "Product Import" do potatoes = Spree::Product.find_by(name: 'Potatoes') expect(potatoes.variants.first.import_date).to be_within(1.minute).of Time.zone.now - puts "TODO: migrate to v3" - Flipper.disable(:admin_style_v3) # disabling BUU for legacy products page click_link 'Go To Products Page' - wait_until { page.find("#p_#{carrots.id}").present? } + # displays product list + expect(page).to have_field("_products_2_name", with: carrots.name.to_s) + expect(page).to have_field("_products_5_name", with: potatoes.name.to_s) - expect(page).to have_field "product_name", with: carrots.name - expect(page).to have_field "product_name", with: potatoes.name - toggle_columns "Import" + click_button "Save changes" + + ofn_drop_down("Columns").click + within ofn_drop_down("Columns") do + check "Import" + end within "tr#p_#{carrots.id} td.import_date" do expect(page).to have_content Time.zone.now.year From 91daec4806ff8e5e819951ef06e824b68189ba52 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 12 Jul 2024 19:59:01 +0100 Subject: [PATCH 2/7] Removes TODO, preparing spec for admin_style_3 (1) Removes TODO, preparing spec for admin_style_3 (2) Uses xpath to point to on hand field --- spec/system/admin/product_import_spec.rb | 32 ++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index 37b3de2004..e916a56a74 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -680,14 +680,20 @@ RSpec.describe "Product Import" do expect(page).to have_selector '.created-count', text: '2' expect(page).not_to have_selector '.updated-count' - puts "TODO: migrate to v3" - Flipper.disable(:admin_style_v3) # disabling BUU for legacy products page + default_variant_selector = "tr:has(input[aria-label=Name][value='Carrots'])" + 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 + carrots = Spree::Product.find_by(name: 'Carrots') + + within "#product_#{carrots.id}" do + expect(page).to have_input("[products][2][variants_attributes][0][display_name]", + text: "Carrots") + expect(page).to have_input("[products][2][variants_attributes][][0][unit_to_display]", + text: "1 lb") + within(:xpath, '//*[@id="products-form"]/table/tbody[3]/tr[2]/td[7]') do + expect(page).to have_content("5") + end end end @@ -721,15 +727,15 @@ RSpec.describe "Product Import" do expect(page).to have_content "Go To Products Page" expect(page).to have_content "Upload Another File" - puts "TODO: migrate to v3" - Flipper.disable(:admin_style_v3) # disabling BUU for legacy products page 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 + expect(page).to have_input("[products][2][variants_attributes][0][display_name]", + text: "Cupcake") + expect(page).to have_select "_products_2_variant_unit_with_scale", selected: "Items" + expect(page).to have_input("[products][2][variant_unit_name]", + text: "Bunch") + within(:xpath, '//*[@id="products-form"]/table/tbody[3]/tr[2]/td[7]') do + expect(page).to have_content("5") end end From e1976c6cc2b974df89f873056e6ea9c71598bdae Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 12 Jul 2024 20:10:00 +0100 Subject: [PATCH 3/7] Brings back xpath selector Fixes xpath --- spec/system/admin/products_v3/index_spec.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/products_v3/index_spec.rb b/spec/system/admin/products_v3/index_spec.rb index 264bdad71c..261ee39693 100644 --- a/spec/system/admin/products_v3/index_spec.rb +++ b/spec/system/admin/products_v3/index_spec.rb @@ -76,10 +76,15 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi 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 + within(:xpath, '//*[@id="products-form"]/table/tbody[1]/tr[2]/td[7]') do + expect(page).to have_content "On demand" + end + within(:xpath, '//*[@id="products-form"]/table/tbody[2]/tr[2]/td[7]') do + expect(page).to have_content "16" # displays the stock for variant_2 + end + within(:xpath, '//*[@id="products-form"]/table/tbody[2]/tr[3]/td[7]') do + expect(page).to have_content "4" # displays the stock for variant_3 + end end end From 46696dfa172aa9ba7917b018f4c4550e7b02ea3b Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 15 Jul 2024 11:46:52 +0100 Subject: [PATCH 4/7] Removes references to enabling admin_style_v3 features Reverts removal from bulk_product_spec.rb --- spec/base_spec_helper.rb | 3 - spec/system/admin/products_spec.rb | 55 ------------------- spec/system/admin/products_v3/actions_spec.rb | 2 +- spec/system/admin/products_v3/create_spec.rb | 2 +- spec/system/admin/products_v3/index_spec.rb | 2 +- spec/system/admin/products_v3/update_spec.rb | 2 +- .../admin/subscriptions/smoke_tests_spec.rb | 2 +- 7 files changed, 5 insertions(+), 63 deletions(-) diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 02007105ec..f9bfa1e57c 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -148,9 +148,6 @@ RSpec.configure do |config| config.before(:each) do Flipper.features.each(&:remove) OpenFoodNetwork::FeatureToggle.setup! - - # activate feature toggle admin_style_v3 to use new admin interface and run the build - Flipper.enable(:admin_style_v3) end config.before(:each, :feature) do |example| diff --git a/spec/system/admin/products_spec.rb b/spec/system/admin/products_spec.rb index ea5a3c2d5f..abe75464db 100644 --- a/spec/system/admin/products_spec.rb +++ b/spec/system/admin/products_spec.rb @@ -250,61 +250,6 @@ RSpec.describe ' end end - describe "legacy products page (TODO: migrate/combine specs with v3 specs)" do - before { Flipper.disable(:admin_style_v3) } - - describe "deleting" do - let!(:product1) { - create(:simple_product, name: 'a product to keep', supplier_id: supplier.id) - } - - context 'a simple product' do - let!(:product2) { - create(:simple_product, name: 'a product to delete', supplier_id: supplier.id) - } - - before do - login_as_admin - visit spree.admin_products_path - - within "#p_#{product2.id}" do - accept_alert { page.find("[data-powertip=Remove]").click } - end - visit current_path - end - - it 'removes it from the product list' do - expect(page).not_to have_selector "#p_#{product2.id}" - expect(page).to have_selector "#p_#{product1.id}" - end - end - end - - describe 'cloning' do - let!(:product1) { - create(:simple_product, name: 'a weight product', supplier_id: supplier.id, - variant_unit: "weight") - } - - context 'products' do - before do - login_as_admin - visit spree.admin_products_path - end - - it 'creates a copy of the product' do - within "#p_#{product1.id}" do - page.find("[data-powertip=Clone]").click - end - visit current_path - within "#p_#{product1.id + 1}" do - expect(page).to have_input "product_name", with: 'COPY OF a weight product' - end - end - end - end - end - context "as an enterprise user" do let!(:tax_category) { create(:tax_category) } let(:filter) { { producerFilter: 2 } } diff --git a/spec/system/admin/products_v3/actions_spec.rb b/spec/system/admin/products_v3/actions_spec.rb index a02b56fab3..12c021b0a6 100644 --- a/spec/system/admin/products_v3/actions_spec.rb +++ b/spec/system/admin/products_v3/actions_spec.rb @@ -2,7 +2,7 @@ require "system_helper" -RSpec.describe 'As an enterprise user, I can manage my products', feature: :admin_style_v3 do +RSpec.describe 'As an enterprise user, I can manage my products' do include AdminHelper include WebHelper include AuthenticationHelper diff --git a/spec/system/admin/products_v3/create_spec.rb b/spec/system/admin/products_v3/create_spec.rb index 2a007a8f43..b92fada37d 100644 --- a/spec/system/admin/products_v3/create_spec.rb +++ b/spec/system/admin/products_v3/create_spec.rb @@ -2,7 +2,7 @@ require "system_helper" -RSpec.describe 'As an enterprise user, I can manage my products', feature: :admin_style_v3 do +RSpec.describe 'As an enterprise user, I can manage my products' do include AuthenticationHelper include WebHelper diff --git a/spec/system/admin/products_v3/index_spec.rb b/spec/system/admin/products_v3/index_spec.rb index 261ee39693..da9593ec9c 100644 --- a/spec/system/admin/products_v3/index_spec.rb +++ b/spec/system/admin/products_v3/index_spec.rb @@ -2,7 +2,7 @@ require "system_helper" -RSpec.describe 'As an enterprise user, I can manage my products', feature: :admin_style_v3 do +RSpec.describe 'As an enterprise user, I can manage my products' do include AdminHelper include WebHelper include AuthenticationHelper diff --git a/spec/system/admin/products_v3/update_spec.rb b/spec/system/admin/products_v3/update_spec.rb index 9495838ff3..ea0bfcb6bf 100644 --- a/spec/system/admin/products_v3/update_spec.rb +++ b/spec/system/admin/products_v3/update_spec.rb @@ -2,7 +2,7 @@ require "system_helper" -RSpec.describe 'As an enterprise user, I can update my products', feature: :admin_style_v3 do +RSpec.describe 'As an enterprise user, I can update my products' do include AdminHelper include WebHelper include AuthenticationHelper diff --git a/spec/system/admin/subscriptions/smoke_tests_spec.rb b/spec/system/admin/subscriptions/smoke_tests_spec.rb index 6dd8a2862c..19f224f41d 100644 --- a/spec/system/admin/subscriptions/smoke_tests_spec.rb +++ b/spec/system/admin/subscriptions/smoke_tests_spec.rb @@ -2,7 +2,7 @@ require 'system_helper' -RSpec.describe 'Subscriptions', feature: :admin_style_v3 do +RSpec.describe 'Subscriptions' do include AdminHelper include AuthenticationHelper include WebHelper From 24defac470c80ae2dcf9bf89acc75e5efa6e8017 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 15 Jul 2024 15:52:42 +0100 Subject: [PATCH 5/7] Adds a migration to enable the feature by default --- .../20240715103415_enable_admin_style_v3_by_default.rb | 5 +++++ db/schema.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20240715103415_enable_admin_style_v3_by_default.rb diff --git a/db/migrate/20240715103415_enable_admin_style_v3_by_default.rb b/db/migrate/20240715103415_enable_admin_style_v3_by_default.rb new file mode 100644 index 0000000000..279073bf6e --- /dev/null +++ b/db/migrate/20240715103415_enable_admin_style_v3_by_default.rb @@ -0,0 +1,5 @@ +class EnableAdminStyleV3ByDefault < ActiveRecord::Migration[7.0] + def up + Flipper.enable(:admin_style_v3) + end +end diff --git a/db/schema.rb b/db/schema.rb index 9b49e0676c..5108150214 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_07_10_013128) do +ActiveRecord::Schema[7.0].define(version: 2024_07_15_103415) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" From e0d7252fe3bf4eceb9335a67748f9e3cc08d19b7 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 16 Jul 2024 10:45:16 +0100 Subject: [PATCH 6/7] Adds condition for dev environment only We don't want to enable this in production just yet --- db/migrate/20240715103415_enable_admin_style_v3_by_default.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/migrate/20240715103415_enable_admin_style_v3_by_default.rb b/db/migrate/20240715103415_enable_admin_style_v3_by_default.rb index 279073bf6e..29099bcb0f 100644 --- a/db/migrate/20240715103415_enable_admin_style_v3_by_default.rb +++ b/db/migrate/20240715103415_enable_admin_style_v3_by_default.rb @@ -1,5 +1,7 @@ class EnableAdminStyleV3ByDefault < ActiveRecord::Migration[7.0] def up - Flipper.enable(:admin_style_v3) + if Rails.env.development? + Flipper.enable(:admin_style_v3) + end end end From 0123d6fb2e45f8070126946aacebbb0ae6e1b6a9 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 16 Jul 2024 10:53:57 +0100 Subject: [PATCH 7/7] Copies admin_style_v3 feature into ACTIVE_BY_DEFAULT section This should have an effect on test environment --- lib/open_food_network/feature_toggle.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb index 6ee7a1fe5e..aedef176fb 100644 --- a/lib/open_food_network/feature_toggle.rb +++ b/lib/open_food_network/feature_toggle.rb @@ -50,6 +50,9 @@ module OpenFoodNetwork ACTIVE_BY_DEFAULT = { # Copy features here that were activated in a migration so that new # instances, development and test environments have the feature active. + "admin_style_v3" => <<~DESC, + Test the work-in-progress design updates. + DESC }.freeze def self.setup!