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 00000000000..29099bcb0f6 --- /dev/null +++ b/db/migrate/20240715103415_enable_admin_style_v3_by_default.rb @@ -0,0 +1,7 @@ +class EnableAdminStyleV3ByDefault < ActiveRecord::Migration[7.0] + def up + if Rails.env.development? + Flipper.enable(:admin_style_v3) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9b49e0676c5..51081502142 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" diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb index 6ee7a1fe5eb..aedef176fb9 100644 --- a/lib/open_food_network/feature_toggle.rb +++ b/lib/open_food_network/feature_toggle.rb @@ -50,6 +50,9 @@ module FeatureToggle 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! diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 02007105eca..f9bfa1e57c1 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -148,9 +148,6 @@ 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/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index c0929e5ef28..e916a56a74f 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -187,6 +187,8 @@ 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 @@ 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 @@ -675,14 +680,20 @@ 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 @@ -716,15 +727,15 @@ 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 diff --git a/spec/system/admin/products_spec.rb b/spec/system/admin/products_spec.rb index ea5a3c2d5f8..abe75464db2 100644 --- a/spec/system/admin/products_spec.rb +++ b/spec/system/admin/products_spec.rb @@ -250,61 +250,6 @@ 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 a02b56fab31..12c021b0a6f 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 2a007a8f439..b92fada37d5 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 264bdad71ca..da9593ec9ca 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 @@ -76,10 +76,15 @@ 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 diff --git a/spec/system/admin/products_v3/update_spec.rb b/spec/system/admin/products_v3/update_spec.rb index 9495838ff3a..ea0bfcb6bfb 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 6dd8a2862ce..19f224f41df 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