Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added specs for Settings tab sections (#12775)
Damian Legawiecc8a4b60a2fa1
diff --git a/.circleci/config.yml b/.circleci/config.ymlindex 40adc085fa..84d79b3894 100644--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -105,6 +105,7 @@ jobs:PROJECTS: apitest_admin_postgres:<<: *test+ parallelism: 2environment:<<: *environmentPROJECTS: admin@@ -134,6 +135,7 @@ jobs:PROJECTS: apitest_admin_mysql:<<: *test_mysql+ parallelism: 2environment:<<: *mysql_environmentPROJECTS: admindiff --git a/admin/spec/features/spree/admin/getting_started_spec.rb b/admin/spec/features/spree/admin/getting_started_spec.rbnew file mode 100644index 0000000000..9779d8a0dd--- /dev/null+++ b/admin/spec/features/spree/admin/getting_started_spec.rb@@ -0,0 +1,48 @@+require 'spec_helper'++RSpec.feature 'Getting Started' do+ stub_authorization!+ let(:store) { Spree::Store.default }+ let(:us_country) { Spree::Country.find_by(iso: 'US') }+ let!(:ny_state) { create(:state, name: 'New York', abbr: 'NY', country: us_country) }++ describe 'Getting started tasks', js: true do+ describe 'setup taxes collection' do+ context 'when there are no tax rates' do+ it 'asks to setup taxes' do+ visit spree.admin_getting_started_path+ click_on Spree.t('admin.store_setup_tasks.setup_taxes_collection')++ expect(page).to have_text Spree.t('admin.store_setup_tasks.taxes.copy', link: spree.admin_tax_rates_path)+ end+ end++ context 'tax rates are added' do+ before do+ create(:tax_rate)+ visit spree.admin_getting_started_path+ end++ it 'confirms the setup' do+ expect(page.find('span', text: Spree.t('admin.store_setup_tasks.setup_taxes_collection')).ancestor('a')).to have_css('i.bg-success')+ end+ end+ end++ describe 'set customer support email' do+ before do+ visit spree.admin_getting_started_path+ end++ scenario 'Retailer adds and updates the customer support email' do+ click_on 'Set customer support email'+ click_on 'Edit'++ fill_in 'Customer Support Email', with: '[email protected]'+ click_on 'Save'++ expect(page).to have_content("Store \"#{store.name}\" has been successfully updated!")+ end+ end+ end+enddiff --git a/admin/spec/features/spree/admin/api_keys_spec.rb b/admin/spec/features/spree/admin/settings/api_keys_spec.rbsimilarity index 100%rename from admin/spec/features/spree/admin/api_keys_spec.rbrename to admin/spec/features/spree/admin/settings/api_keys_spec.rbdiff --git a/admin/spec/features/spree/admin/settings/custom_domains_spec.rb b/admin/spec/features/spree/admin/settings/custom_domains_spec.rbnew file mode 100644index 0000000000..9b8b22d524--- /dev/null+++ b/admin/spec/features/spree/admin/settings/custom_domains_spec.rb@@ -0,0 +1,38 @@+require 'spec_helper'++describe 'Custom domains admin', type: :feature do+ stub_authorization!+ let(:store) { Spree::Store.default }++ context 'without custom domains' do+ it 'can change store code' do+ visit spree.admin_custom_domains_path++ fill_in 'store[code]', with: 'new-code'+ click_on 'Update'++ expect(page).to have_field('store[code]', with: 'new-code')+ expect(page.current_url).to include('new-code')+ end+ end++ context 'with custom domains' do+ let!(:custom_domain) { create(:custom_domain, store: store) }++ it 'cannot change store code' do+ visit spree.admin_custom_domains_path++ expect(page).to have_field('store[code]', with: store.code, disabled: true)+ end++ it 'can manage custom domains' do+ visit spree.admin_custom_domains_path++ expect(page).to have_link('New domain')++ within_row(1) do+ expect(page).to have_content(custom_domain.url)+ end+ end+ end+enddiff --git a/admin/spec/features/spree/admin/settings/shipping_categories_spec.rb b/admin/spec/features/spree/admin/settings/shipping_categories_spec.rbnew file mode 100644index 0000000000..2644b4e989--- /dev/null+++ b/admin/spec/features/spree/admin/settings/shipping_categories_spec.rb@@ -0,0 +1,67 @@+require 'spec_helper'++RSpec.feature 'Shipping categories' do+ stub_authorization!++ it 'can create new shipping category' do+ visit spree.admin_shipping_categories_path+ click_on 'New Shipping Category'++ fill_in 'Name', with: 'New Shipping Category'++ click_on 'Create'++ wait_for_turbo+ expect(page).to have_content 'Shipping Category "New Shipping Category" has been successfully created!'++ expect(Spree::ShippingCategory.count).to eq 1++ shipping_category = Spree::ShippingCategory.first++ expect(shipping_category.name).to eq 'New Shipping Category'+ end++ it 'can edit shipping category' do+ shipping_category = create(:shipping_category, name: 'Standard')++ visit spree.admin_shipping_categories_path+ click_on 'Edit'++ fill_in 'Name', with: 'Express'++ within('#page-header') { click_button 'Update' }++ wait_for_turbo+ expect(page).to have_content 'Shipping Category "Express" has been successfully updated!'++ shipping_category.reload+ expect(shipping_category.name).to eq 'Express'+ end++ it 'can delete shipping category', js: true do+ shipping_category = create(:shipping_category, name: 'Standard')++ visit spree.admin_shipping_categories_path+ click_on 'Edit'+ wait_for_turbo++ accept_confirm do+ click_on 'Delete'+ end++ wait_for_turbo+ expect(page).to have_content "Shipping Category \"#{shipping_category.name}\" has been successfully removed!"++ expect(Spree::ShippingCategory.count).to eq 0+ end++ it 'should list shipping categories' do+ create(:shipping_category, name: 'Standard')+ create(:shipping_category, name: 'Express')++ visit spree.admin_shipping_categories_path++ expect(page).to have_content 'Standard'+ expect(page).to have_content 'Express'+ end+enddiff --git a/admin/spec/features/spree/admin/settings/shipping_methods_spec.rb b/admin/spec/features/spree/admin/settings/shipping_methods_spec.rbnew file mode 100644index 0000000000..d36c991d7f--- /dev/null+++ b/admin/spec/features/spree/admin/settings/shipping_methods_spec.rb@@ -0,0 +1,90 @@+require 'spec_helper'++RSpec.feature 'Shipping methods', js: true do+ before do+ Spree::Seeds::Countries.call+ Spree::Seeds::Zones.call+ Spree::Seeds::ShippingCategories.call+ end++ stub_authorization!++ it 'allows Store Owner to create new shipping method' do+ visit spree.new_admin_shipping_method_path++ fill_in 'Name', with: 'New Shipping Method'+ select 'Flat rate', from: 'Calculator'++ expect(page).to have_content 'Flat rate'+ fill_in 'Amount', with: '10'++ fill_in 'Min', with: '2' # Minimum estimated delivery time+ fill_in 'Max', with: '5' # Maximum estimated delivery time++ uncheck 'Middle East', allow_label_click: true+ check 'Digital', allow_label_click: true++ click_on 'Create'++ expect(page).to have_content 'has been successfully created!'++ expect(Spree::ShippingMethod.count).to eq 1++ shipping_method = Spree::ShippingMethod.first++ expect(shipping_method.name).to eq 'New Shipping Method'+ expect(shipping_method.calculator.class).to eq Spree::Calculator::Shipping::FlatRate+ expect(shipping_method.calculator.preferred_amount).to eq 10+ expect(shipping_method.zones.pluck(:name)).not_to include 'Middle East'+ expect(shipping_method.shipping_categories.pluck(:name)).to include 'Digital'+ expect(shipping_method.estimated_transit_business_days_min).to eq 2+ expect(shipping_method.estimated_transit_business_days_max).to eq 5+ end++ it 'allows Store Owner to edit shipping method' do+ shipping_method = create(:shipping_method, name: 'Standard', display_on: 'both')++ visit spree.edit_admin_shipping_method_path(shipping_method)++ fill_in 'Name', with: 'Express'+ select 'Flat Percent', from: 'Calculator'++ expect(page).to have_content 'Flat Percent'+ fill_in 'Flat Percent', with: '5'++ fill_in 'Min', with: '3'+ fill_in 'Max', with: '6'++ uncheck 'Middle East', allow_label_click: true+ check 'Digital', allow_label_click: true++ within('#page-header') { click_button 'Update' }++ wait_for_turbo+ expect(page).to have_content 'has been successfully updated!'++ shipping_method.reload++ expect(shipping_method.name).to eq 'Express'+ expect(shipping_method.calculator.class).to eq Spree::Calculator::Shipping::FlatPercentItemTotal+ expect(shipping_method.calculator.preferred_flat_percent).to eq 5+ expect(shipping_method.zones.pluck(:name)).not_to include 'Middle East'+ expect(shipping_method.shipping_categories.pluck(:name)).to include 'Digital'+ expect(shipping_method.estimated_transit_business_days_min).to eq 3+ expect(shipping_method.estimated_transit_business_days_max).to eq 6+ end++ it 'allows Store Owner to delete shipping method' do+ shipping_method = create(:shipping_method)++ visit spree.edit_admin_shipping_method_path(shipping_method)++ accept_confirm do+ click_on 'Delete'+ end++ expect(page).to have_content "has been successfully removed!"++ expect(Spree::ShippingMethod.count).to eq 0+ end+enddiff --git a/admin/spec/features/spree/admin/settings/stock_locations_spec.rb b/admin/spec/features/spree/admin/settings/stock_locations_spec.rbnew file mode 100644index 0000000000..7011235125--- /dev/null+++ b/admin/spec/features/spree/admin/settings/stock_locations_spec.rb@@ -0,0 +1,51 @@+require 'spec_helper'++RSpec.feature 'Stock Locations', js: true do+ let!(:stock_location) { create(:stock_location) }++ stub_authorization!++ it 'renders a list of stock locations' do+ visit spree.admin_stock_locations_path+ expect(page).to have_content(stock_location.name)+ end++ it 'allows to create a new stock location' do+ visit spree.new_admin_stock_location_path+ fill_in 'stock_location_name', with: 'New Stock Location'+ fill_in 'Internal Name', with: 'New Stock Location Internal Name'++ fill_in 'Address', with: 'New Stock Location Street Address'+ fill_in 'Address (contd.)', with: 'New Stock Location Street Address (contd)'+ fill_in 'City', with: 'New Stock Location City'+ fill_in 'Zip Code', with: 'New Stock Location Zip Code'+ fill_in 'Phone', with: 'New Stock Location Phone'++ click_button 'Create'+ expect(page).to have_content('Location "New Stock Location" has been successfully created!')++ stock_location = Spree::StockLocation.last+ expect(stock_location.address1).to eq('New Stock Location Street Address')+ expect(stock_location.address2).to eq('New Stock Location Street Address (contd)')+ expect(stock_location.city).to eq('New Stock Location City')+ expect(stock_location.zipcode).to eq('New Stock Location Zip Code')+ expect(stock_location.phone).to eq('New Stock Location Phone')+ expect(stock_location.country).to eq(Spree::Country.find_by(iso: 'US'))+ end++ it 'allows to update an existing stock location' do+ visit spree.edit_admin_stock_location_path(stock_location)+ fill_in 'stock_location_name', with: ''+ fill_in 'stock_location_name', with: 'Updated Stock Location'+ within('#page-header') { click_button 'Update' }+ expect(page).to have_content("Location \"Updated Stock Location\" has been successfully updated")+ end++ it 'allows to delete a stock location' do+ visit spree.edit_admin_stock_location_path(stock_location)+ accept_confirm do+ click_on 'Delete'+ end+ expect(page).to have_content("Location \"#{stock_location.name}\" has been successfully removed!")+ end+enddiff --git a/admin/spec/features/spree/admin/settings/store_spec.rb b/admin/spec/features/spree/admin/settings/store_spec.rbnew file mode 100644index 0000000000..d35b299b14--- /dev/null+++ b/admin/spec/features/spree/admin/settings/store_spec.rb@@ -0,0 +1,70 @@+require 'spec_helper'++describe 'Store admin', type: :feature, js: true do+ stub_authorization!++ let(:store) { Spree::Store.default }+ let!(:admin_user) { create(:admin_user) }+ let!(:zone) { create(:zone, name: 'EU_VAT') }++ before do+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:try_spree_current_user).and_return(admin_user)+ end++ describe 'creating another store' do+ it 'creates another store' do+ visit spree.admin_root_path+ find('#store-menu .dropdown:last-child button').click+ click_on 'New Store'+ fill_in 'store_name', with: 'New Store Name'+ click_button 'Create'+ # Wait for the redirect to complete+ expect(page).to have_content('New Store Name')+ end+ end++ describe 'updating store' do+ it 'updates store' do+ visit spree.edit_admin_store_path(section: 'general-settings')+ page.fill_in 'store_name', with: '', wait: 5+ page.fill_in 'store_name', with: 'New Store Name', wait: 5+ click_button 'Update'++ expect(page).to have_content('successfully updated')++ # tom_select 'EUR', from: 'Currency'+ # click_button 'Update'++ wait_for_turbo++ expect(page).to have_content('successfully updated')++ # expect(store.reload.default_currency).to eq 'EUR'+ expect(store.reload.name).to eq 'New Store Name'+ # expect(store.checkout_zone).to eq zone+ # expect(store.url).to eq 'www.my-store.com/shop'+ end++ it 'have unit system and weightage unit' do+ visit spree.edit_admin_store_path(section: 'general-settings')++ expect(page).to have_select(+ 'store_preferred_unit_system',+ selected: 'Imperial system'+ )++ expect(page).to have_select(+ 'store_preferred_weight_unit',+ selected: ['Pound (lb)']+ )++ select 'Imperial system', from: 'store_preferred_unit_system'+ click_button 'Update'++ expect(page).to have_content('successfully updated')++ store.reload+ expect(store.preferred_weight_unit).to eq 'lb'+ end+ end+enddiff --git a/admin/spec/features/spree/admin/settings/tax_categories_spec.rb b/admin/spec/features/spree/admin/settings/tax_categories_spec.rbnew file mode 100644index 0000000000..ea80f05942--- /dev/null+++ b/admin/spec/features/spree/admin/settings/tax_categories_spec.rb@@ -0,0 +1,75 @@+require 'spec_helper'++RSpec.feature 'Tax categories' do+ stub_authorization!++ it 'allows to create new tax category' do+ visit spree.admin_tax_categories_path+ click_on 'New Tax Category'++ fill_in 'Name', with: 'New Tax Category'+ fill_in 'Description', with: 'New Tax Category Description'+ fill_in 'Tax Code', with: 'NEW_TAX_CATEGORY'+ check 'Is default', allow_label_click: true++ click_on 'Create'++ wait_for_turbo+ expect(page).to have_content 'Tax Category "New Tax Category" has been successfully created!'++ expect(Spree::TaxCategory.count).to eq 1++ tax_category = Spree::TaxCategory.first++ expect(tax_category.name).to eq 'New Tax Category'+ expect(tax_category.description).to eq 'New Tax Category Description'+ expect(tax_category.tax_code).to eq 'NEW_TAX_CATEGORY'+ expect(tax_category.is_default).to eq true+ end++ it 'allows to edit tax category' do+ tax_category = create(+ :tax_category,+ name: 'Standard',+ description: 'Standard Tax Category',+ tax_code: 'STANDARD_TAX_CATEGORY',+ is_default: true+ )++ visit spree.admin_tax_categories_path+ click_on 'Edit'++ fill_in 'Name', with: 'Non-Taxable'+ fill_in 'Description', with: 'Non-Taxable Tax Category'+ fill_in 'Tax Code', with: 'NON_TAXABLE_TAX_CATEGORY'+ uncheck 'Is default', allow_label_click: true++ within('#page-header') { click_button 'Update' }++ wait_for_turbo+ expect(page).to have_content 'Tax Category "Non-Taxable" has been successfully updated!'++ tax_category.reload++ expect(tax_category.name).to eq 'Non-Taxable'+ expect(tax_category.description).to eq 'Non-Taxable Tax Category'+ expect(tax_category.tax_code).to eq 'NON_TAXABLE_TAX_CATEGORY'+ expect(tax_category.is_default).to eq false+ end++ it 'allows to delete tax category', js: true do+ create(:tax_category)++ visit spree.admin_tax_categories_path+ click_on 'Edit'+ wait_for_turbo++ accept_confirm do+ click_on 'Delete'+ end++ wait_for_turbo++ expect(Spree::TaxCategory.count).to eq 0+ end+enddiff --git a/admin/spec/features/spree/admin/settings/tax_rates_spec.rb b/admin/spec/features/spree/admin/settings/tax_rates_spec.rbnew file mode 100644index 0000000000..c532319b95--- /dev/null+++ b/admin/spec/features/spree/admin/settings/tax_rates_spec.rb@@ -0,0 +1,95 @@+require 'spec_helper'++RSpec.feature 'Tax rates', js: true do+ stub_authorization!++ before do+ Spree::Seeds::Countries.call+ Spree::Seeds::Zones.call+ create(:tax_category, name: 'Default', is_default: true)+ create(:default_tax_calculator)+ end++ it 'allows Store Owner to create new tax rate' do+ visit spree.admin_tax_rates_path+ click_on 'New Tax Rate'++ fill_in 'Name', with: 'New Tax Rate'+ fill_in 'Rate', with: 0.10+ check 'Included in Price', allow_label_click: true+ check 'Show rate in label', allow_label_click: true+ select 'Default', from: 'Tax Category'+ select 'EU_VAT', from: 'Zone'+ select 'Default Tax', from: 'Calculator'++ click_on 'Create'++ wait_for_turbo+ expect(page).to have_content 'Tax Rate "New Tax Rate" has been successfully created!'++ expect(Spree::TaxRate.count).to eq 1++ tax_rate = Spree::TaxRate.first++ expect(tax_rate.name).to eq 'New Tax Rate'+ expect(tax_rate.amount).to eq 0.10+ expect(tax_rate.included_in_price).to eq true+ expect(tax_rate.show_rate_in_label).to eq true+ expect(tax_rate.tax_category.name).to eq 'Default'+ expect(tax_rate.zone.name).to eq 'EU_VAT'+ expect(tax_rate.calculator.class).to eq Spree::Calculator::DefaultTax+ end++ it 'allows Store Owner to edit tax rate' do+ tax_rate = create(+ :tax_rate,+ name: 'Standard',+ amount: 0.10,+ included_in_price: true,+ show_rate_in_label: true,+ tax_category: create(:tax_category, name: 'Standard'),+ zone: Spree::Zone.find_by(name: 'EU_VAT')+ )++ visit spree.admin_tax_rates_path+ click_on 'Edit'++ fill_in 'Name', with: 'Updated Tax Rate'+ fill_in 'Rate', with: 0.20+ uncheck 'Included in Price', allow_label_click: true+ uncheck 'Show rate in label', allow_label_click: true+ select 'Default', from: 'Tax Category'+ select 'Asia', from: 'Zone'+ select 'Default Tax', from: 'Calculator'++ within('#page-header') { click_button 'Update' }++ wait_for_turbo++ expect(page).to have_content 'Tax Rate "Updated Tax Rate" has been successfully updated!'++ expect(tax_rate.reload.name).to eq 'Updated Tax Rate'+ expect(tax_rate.amount).to eq 0.20+ expect(tax_rate.included_in_price).to eq false+ expect(tax_rate.show_rate_in_label).to eq false+ expect(tax_rate.tax_category.name).to eq 'Default'+ expect(tax_rate.zone.reload.name).to eq 'Asia'+ expect(tax_rate.calculator.class).to eq Spree::Calculator::DefaultTax+ end++ it 'allows Store Owner to delete tax rate' do+ tax_rate = create(:tax_rate)++ visit spree.admin_tax_rates_path+ click_on 'Edit'+ wait_for_turbo++ accept_confirm do+ click_on 'Delete'+ end++ wait_for_turbo++ expect(Spree::TaxRate.count).to eq 0+ end+end