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
Add test for creating promotion with specific start and end time.
Matthew Kennedyb94749d92106
diff --git a/backend/spec/features/admin/orders/listing_spec.rb b/backend/spec/features/admin/orders/listing_spec.rbindex 7446c0f61d..761af59c5b 100644--- a/backend/spec/features/admin/orders/listing_spec.rb+++ b/backend/spec/features/admin/orders/listing_spec.rb@@ -249,7 +249,8 @@ describe 'Orders Listing', type: :feature dofill_in 'q_bill_address_lastname_start', with: 'Smith'select2 'spree', from: 'Channel'- # Can not test these in the filter dropdown.+ # Can not test these in the filter dropdown+ # With current implementation of flatpickr test support.#fill_in_date_picker('q_created_at_gt', with: '2018-01-01')#fill_in_date_picker('q_created_at_lt', with: '2018-01-01')enddiff --git a/backend/spec/features/admin/promotions/promotion_spec.rb b/backend/spec/features/admin/promotions/promotion_spec.rbnew file mode 100644index 0000000000..31191975a2--- /dev/null+++ b/backend/spec/features/admin/promotions/promotion_spec.rb@@ -0,0 +1,33 @@+require 'spec_helper'++describe 'Create New Promotion', type: :feature, js: true do+ stub_authorization!++ context 'coupon promotions' do+ before do+ visit spree.new_admin_promotion_path+ end++ it 'Checkbox generates random promotion code' do+ fill_in 'Name', with: 'Promotion 1'+ check 'Generate coupon code'++ click_button 'Create'++ promotion = Spree::Promotion.find_by(name: 'Promotion 1')+ expect(page).to have_field(id: 'promotion_code', with: promotion.code)+ end++ it 'Allows you to set a promotion with start and end time' do+ fill_in 'Name', with: 'Promotion 2'+ fill_in 'Code', with: 'Random 2323'+ fill_in_date_time_picker('promotion_starts_at', with: '2012-01-24-16-45')+ fill_in_date_time_picker('promotion_expires_at', with: '2012-01-25-22-10')++ click_button 'Create'++ expect(page).to have_field(id: 'promotion_starts_at', type: :hidden, with: '2012-01-24 16:45')+ expect(page).to have_field(id: 'promotion_expires_at', type: :hidden, with: '2012-01-25 22:10')+ end+ end+enddiff --git a/core/lib/spree/testing_support/flatpickr_capybara.rb b/core/lib/spree/testing_support/flatpickr_capybara.rbindex a198dad3d5..e9900e019b 100644--- a/core/lib/spree/testing_support/flatpickr_capybara.rb+++ b/core/lib/spree/testing_support/flatpickr_capybara.rb@@ -7,12 +7,30 @@ enddef fill_in_date_picker(label_text, with:)within_open_flatpickr(label_text) dowithin_flatpickr_months do+ fill_in_flatpickr_year(with.split('-')[0])+select_flatpickr_month(with.split('-')[1])+ click_on_flatpickr_day(with.split('-')[2])+ end+ end+end++def fill_in_date_time_picker(label_text, with:)+ within_open_flatpickr(label_text) do+ within_flatpickr_months dofill_in_flatpickr_year(with.split('-')[0])+ select_flatpickr_month(with.split('-')[1])+click_on_flatpickr_day(with.split('-')[2])end++ within_flatpickr_time do+ select_flatpickr_hour(with.split('-')[3])++ select_flatpickr_min(with.split('-')[4])+ endendend@@ -37,6 +55,10 @@ def within_flatpickr_monthswithin find('.flatpickr-months .flatpickr-month .flatpickr-current-month') { yield }end+def within_flatpickr_time+ within find('.flatpickr-time') { yield }+end+def select_flatpickr_month(month)find("select.flatpickr-monthDropdown-months > option:nth-child(#{month.to_i})").select_optionend@@ -61,3 +83,11 @@ def fill_in_date_with_js(label_text, with:)page.execute_script(script)end++def select_flatpickr_hour(hour)+ find('input.flatpickr-hour').set(hour)+end++def select_flatpickr_min(min)+ find('input.flatpickr-minute').set(min)+end