From 289414a504ed4f08fa69726143b739e7fb9fa476 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 16 Jan 2024 18:46:16 +0000 Subject: [PATCH] Adds tests around product creation Introduces a tom-select helper file --- spec/base_spec_helper.rb | 1 + spec/support/tom_select_helper.rb | 13 ++++++++ .../system/admin/products_v3/products_spec.rb | 30 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 spec/support/tom_select_helper.rb diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 1b156768fb..a5d04a5ce3 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -287,6 +287,7 @@ RSpec.configure do |config| config.include OpenFoodNetwork::PerformanceHelper config.include ActiveJob::TestHelper config.include ReportsHelper + config.include TomSelectHelper config.include ViewComponent::TestHelpers, type: :component diff --git a/spec/support/tom_select_helper.rb b/spec/support/tom_select_helper.rb new file mode 100644 index 0000000000..31d2a32ef5 --- /dev/null +++ b/spec/support/tom_select_helper.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module TomSelectHelper + def select_tom_select(value, from:) + container = find(:id, from) + + within(container) do + find('.ts-control').send_keys(value) + end + + all('.ts-dropdown .ts-dropdown-content .option', text: /#{Regexp.quote(value)}/i)[0].click + end +end diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 00941f4d11..be38466788 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -1581,6 +1581,36 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi end end + describe "creating a new product" do + let!(:stock_location) { create(:stock_location, backorderable_default: false) } + let!(:supplier) { create(:supplier_enterprise) } + let!(:distributor) { create(:distributor_enterprise) } + let!(:shipping_category) { create(:shipping_category) } + let!(:taxon) { create(:taxon) } + + before do + login_as_admin + visit spree.admin_products_path + end + + it "creating a new product" do + find("a", text: "New Product").click + expect(page).to have_content "New Product" + fill_in 'product_name', with: 'Big Bag Of Apples' + select_tom_select supplier.name, from: 'product_supplier_field' + select_tom_select 'Weight (g)', from: 'product_variant_unit_field' + fill_in 'product_unit_value', with: '100' + fill_in 'product_price', with: '10.00' + # TODO dropdowns below are still using select2: + select taxon.name, from: 'product_primary_taxon_id' # ...instead of tom-select + select shipping_category.name, from: 'product_shipping_category_id' # ...instead of tom-select + click_button 'Create' + expect(URI.parse(current_url).path).to eq spree.admin_products_path + expect(flash_message).to eq 'Product "Big Bag Of Apples" has been successfully created!' + expect(page).to have_field "_products_0_name", with: 'Big Bag Of Apples' + end + end + def create_products(amount) amount.times do |i| create(:simple_product, name: "product #{i}", supplier: producer)