Merge pull request #12668 from filipefurtad0/prepare_import_spec_for_admin_style_3

Prepare product_import_spec.rb for BUU as default
This commit is contained in:
Rachel Arnould
2024-07-18 16:33:56 +02:00
committed by GitHub
11 changed files with 55 additions and 87 deletions

View File

@@ -0,0 +1,7 @@
class EnableAdminStyleV3ByDefault < ActiveRecord::Migration[7.0]
def up
if Rails.env.development?
Flipper.enable(:admin_style_v3)
end
end
end

View File

@@ -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"

View File

@@ -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!

View File

@@ -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|

View File

@@ -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
@@ -675,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
@@ -716,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

View File

@@ -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 } }

View File

@@ -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

View File

@@ -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

View File

@@ -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 @@ 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

View File

@@ -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

View File

@@ -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