From 14caf3b25ca48d60d952daaf5582d9fd678d8bc8 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 2 Oct 2023 16:13:03 +0100 Subject: [PATCH] Moves helper into support folder Wraps SubscripionHelper module around definitions --- spec/support/subscription_helper.rb | 34 +++++++++++++++++++ spec/system/admin/subscriptions/crud_spec.rb | 3 +- spec/system/admin/subscriptions/helper.rb | 34 ------------------- .../admin/subscriptions/smoke_tests_spec.rb | 3 +- 4 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 spec/support/subscription_helper.rb delete mode 100644 spec/system/admin/subscriptions/helper.rb diff --git a/spec/support/subscription_helper.rb b/spec/support/subscription_helper.rb new file mode 100644 index 0000000000..234fdfcfe3 --- /dev/null +++ b/spec/support/subscription_helper.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module SubscriptionHelper + def fill_in_subscription_basic_details + select2_select customer.email, from: "customer_id" + select2_select schedule.name, from: "schedule_id" + select2_select payment_method.name, from: "payment_method_id" + select2_select shipping_method.name, from: "shipping_method_id" + + find_field("begins_at").click + choose_today_from_datepicker + end + + def expect_not_in_open_or_upcoming_order_cycle_warning(count) + expect(page).to have_content(variant_not_in_open_or_upcoming_order_cycle_warning, count:) + end + + def add_variant_to_subscription(variant, quantity) + row_count = all("#subscription-line-items .item").length + variant_name = if variant.full_name.present? + "#{variant.name} - #{variant.full_name}" + else + variant.name + end + select2_select variant.name, from: "add_variant_id", search: true, select_text: variant_name + fill_in "add_quantity", with: quantity + click_link "Add" + expect(page).to have_selector("#subscription-line-items .item", count: row_count + 1) + end + + def variant_not_in_open_or_upcoming_order_cycle_warning + 'There are no open or upcoming order cycles for this product.' + end +end diff --git a/spec/system/admin/subscriptions/crud_spec.rb b/spec/system/admin/subscriptions/crud_spec.rb index d374080397..274ecf823d 100644 --- a/spec/system/admin/subscriptions/crud_spec.rb +++ b/spec/system/admin/subscriptions/crud_spec.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require './spec/system/admin/subscriptions/helper' +require 'system_helper' describe 'Subscriptions' do include AdminHelper include AuthenticationHelper include WebHelper + include SubscriptionHelper context "as an enterprise user" do let!(:user) { create(:user) } diff --git a/spec/system/admin/subscriptions/helper.rb b/spec/system/admin/subscriptions/helper.rb deleted file mode 100644 index d3f12fdd89..0000000000 --- a/spec/system/admin/subscriptions/helper.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require 'system_helper' - -def fill_in_subscription_basic_details - select2_select customer.email, from: "customer_id" - select2_select schedule.name, from: "schedule_id" - select2_select payment_method.name, from: "payment_method_id" - select2_select shipping_method.name, from: "shipping_method_id" - - find_field("begins_at").click - choose_today_from_datepicker -end - -def expect_not_in_open_or_upcoming_order_cycle_warning(count) - expect(page).to have_content(variant_not_in_open_or_upcoming_order_cycle_warning, count:) -end - -def add_variant_to_subscription(variant, quantity) - row_count = all("#subscription-line-items .item").length - variant_name = if variant.full_name.present? - "#{variant.name} - #{variant.full_name}" - else - variant.name - end - select2_select variant.name, from: "add_variant_id", search: true, select_text: variant_name - fill_in "add_quantity", with: quantity - click_link "Add" - expect(page).to have_selector("#subscription-line-items .item", count: row_count + 1) -end - -def variant_not_in_open_or_upcoming_order_cycle_warning - 'There are no open or upcoming order cycles for this product.' -end diff --git a/spec/system/admin/subscriptions/smoke_tests_spec.rb b/spec/system/admin/subscriptions/smoke_tests_spec.rb index 3ca60487b9..cfd1e7a2a4 100644 --- a/spec/system/admin/subscriptions/smoke_tests_spec.rb +++ b/spec/system/admin/subscriptions/smoke_tests_spec.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require './spec/system/admin/subscriptions/helper' +require 'system_helper' describe 'Subscriptions' do include AdminHelper include AuthenticationHelper include WebHelper + include SubscriptionHelper context "as an enterprise user" do let!(:user) { create(:user) }