From 6dd4bb3e3bfa7cd062ee2fa8a0a83f1e9e649ea1 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 9 Jul 2024 16:51:24 +0100 Subject: [PATCH 1/7] Removes test case around shipped product This is already covered on the v3 version of the spec, under ./spec/system/admin/products_v3/products_spec.rb:452 --- spec/system/admin/products_spec.rb | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/spec/system/admin/products_spec.rb b/spec/system/admin/products_spec.rb index 5a74e7972a..ea5a3c2d5f 100644 --- a/spec/system/admin/products_spec.rb +++ b/spec/system/admin/products_spec.rb @@ -278,35 +278,6 @@ RSpec.describe ' expect(page).to have_selector "#p_#{product1.id}" end end - - context 'a shipped product' do - let!(:order) { create(:shipped_order, line_items_count: 1) } - let!(:line_item) { order.reload.line_items.first } - - context "a deleted line item from a shipped order" do - before do - login_as_admin - visit spree.admin_products_path - - within "#p_#{order.variants.first.product_id}" do - accept_alert { page.find("[data-powertip=Remove]").click } - end - end - - it 'removes it from the product list' do - visit spree.admin_products_path - - expect(page).to have_selector "#p_#{product1.id}" - expect(page).not_to have_selector "#p_#{order.variants.first.product_id}" - end - - it 'keeps the line item on the order (admin)' do - visit spree.edit_admin_order_path(order) - - expect(page).to have_content(line_item.product.name.to_s) - end - end - end end describe 'cloning' do From dfcd9391d9afdb75a47effad431f31d68fdc14a0 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 9 Jul 2024 17:29:32 +0100 Subject: [PATCH 2/7] Prepares smoke_tests_spec for admin_style_v3 Enables admin_style_v3 for smoke_tests_spec --- .../admin/subscriptions/smoke_tests_spec.rb | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/spec/system/admin/subscriptions/smoke_tests_spec.rb b/spec/system/admin/subscriptions/smoke_tests_spec.rb index 33f9b7c31e..72bb8b77ab 100644 --- a/spec/system/admin/subscriptions/smoke_tests_spec.rb +++ b/spec/system/admin/subscriptions/smoke_tests_spec.rb @@ -2,7 +2,7 @@ require 'system_helper' -RSpec.describe 'Subscriptions' do +RSpec.describe 'Subscriptions', feature: :admin_style_v3 do include AdminHelper include AuthenticationHelper include WebHelper @@ -242,15 +242,21 @@ RSpec.describe 'Subscriptions' do expect(page).to have_selector "#subscription-line-items .item", count: 4 # Delete an existing product - puts "TODO: migrate to v3" # but first we need to make the actions menu more accessible. - Flipper.disable(:admin_style_v3) # disabling BUU for legacy products page - login_as_admin - visit spree.admin_products_path - within "#p_#{shop_product2.id}" do - accept_alert { page.find("[data-powertip=Remove]").click } + visit admin_products_url + + product_selector = row_containing_name(shop_product2.name) + delete_option_selector = "a[data-controller='modal-link'].delete" + delete_button_selector = "input[type=button][value='Delete product']" + modal_selector = "div[data-modal-target=modal]" + + within product_selector do + page.find(".vertical-ellipsis-menu").click + page.find(delete_option_selector).click + end + within modal_selector do + page.find(delete_button_selector).click end - Flipper.enable(:admin_style_v3) # re-enabling it for the rest of the spec visit edit_admin_subscription_path(subscription) # Remove deleted shop_variant from the subscription From 7f6780b5e9841de0483d949ebb68b18efd774ae8 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 10 Jul 2024 12:59:44 +0100 Subject: [PATCH 3/7] Simplifies specs, by replacing selector declaration with click_button --- spec/system/admin/products_v3/actions_spec.rb | 21 +++++++------------ .../admin/subscriptions/smoke_tests_spec.rb | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/spec/system/admin/products_v3/actions_spec.rb b/spec/system/admin/products_v3/actions_spec.rb index e462a39e01..a02b56fab3 100644 --- a/spec/system/admin/products_v3/actions_spec.rb +++ b/spec/system/admin/products_v3/actions_spec.rb @@ -351,9 +351,8 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi page.find(".vertical-ellipsis-menu").click page.find(delete_option_selector).click end - keep_button_selector = "input[type=button][value='Keep product']" within modal_selector do - page.find(keep_button_selector).click + click_button "Keep product" end expect(page).not_to have_selector(modal_selector) @@ -364,9 +363,8 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi page.find(".vertical-ellipsis-menu").click page.find(delete_option_selector).click end - keep_button_selector = "input[type=button][value='Keep variant']" within modal_selector do - page.find(keep_button_selector).click + click_button "Keep variant" end expect(page).not_to have_selector(modal_selector) @@ -385,9 +383,8 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi page.find(delete_option_selector).click end - delete_button_selector = "input[type=button][value='Delete variant']" within modal_selector do - page.find(delete_button_selector).click + click_button "Delete variant" end expect(page).not_to have_selector(modal_selector) @@ -402,9 +399,8 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi page.find(".vertical-ellipsis-menu").click page.find(delete_option_selector).click end - delete_button_selector = "input[type=button][value='Delete product']" within modal_selector do - page.find(delete_button_selector).click + click_button "Delete product" end expect(page).not_to have_selector(modal_selector) expect(page).not_to have_selector(product_selector) @@ -424,9 +420,8 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi page.find(delete_option_selector).click end - delete_button_selector = "input[type=button][value='Delete variant']" within modal_selector do - page.find(delete_button_selector).click + click_button "Delete variant" end within error_flash_message_selector do @@ -439,9 +434,8 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi page.find(".vertical-ellipsis-menu").click page.find(delete_option_selector).click end - delete_button_selector = "input[type=button][value='Delete product']" within modal_selector do - page.find(delete_button_selector).click + click_button "Delete product" end within error_flash_message_selector do expect(page).to have_content("Unable to delete the product") @@ -464,9 +458,8 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi page.find(delete_option_selector).click end - delete_button_selector = "input[type=button][value='Delete variant']" within modal_selector do - page.find(delete_button_selector).click + click_button "Delete variant" end end diff --git a/spec/system/admin/subscriptions/smoke_tests_spec.rb b/spec/system/admin/subscriptions/smoke_tests_spec.rb index 72bb8b77ab..6dd8a2862c 100644 --- a/spec/system/admin/subscriptions/smoke_tests_spec.rb +++ b/spec/system/admin/subscriptions/smoke_tests_spec.rb @@ -254,7 +254,7 @@ RSpec.describe 'Subscriptions', feature: :admin_style_v3 do page.find(delete_option_selector).click end within modal_selector do - page.find(delete_button_selector).click + click_button "Delete product" end visit edit_admin_subscription_path(subscription) From 7d1cb0c957906873c382e1623cfdcaf3a2559f6c Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 10 Jul 2024 13:43:20 +0100 Subject: [PATCH 4/7] Sets up enterprise with payment and shipping methods So that the warning does not need to be dismissed - which is not what we wish to test here --- .../order_cycles/complex_editing_multiple_updation_spec.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/order_cycles/complex_editing_multiple_updation_spec.rb b/spec/system/admin/order_cycles/complex_editing_multiple_updation_spec.rb index cbb4ed897f..66ce80f988 100644 --- a/spec/system/admin/order_cycles/complex_editing_multiple_updation_spec.rb +++ b/spec/system/admin/order_cycles/complex_editing_multiple_updation_spec.rb @@ -9,8 +9,10 @@ RSpec.describe ' include AuthenticationHelper include WebHelper + let(:distributor_enterprise) { create(:distributor_enterprise, with_payment_and_shipping: true) } + let(:oc) { create(:order_cycle, distributors: [distributor_enterprise]) } + it "Alerts for unsaved changes on general settings (/edit) page" do - oc = create(:order_cycle) login_as_admin visit edit_admin_order_cycle_path(oc) @@ -35,9 +37,6 @@ RSpec.describe ' click_link 'Orders' end - # Click dismiss on distributor warning - click_button 'Dismiss' - # Click cancel with unsaved changes dismiss_confirm "" do click_button 'Cancel' From f7c47fecc448f82616bc79fb66237285a4d7e6b5 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 10 Jul 2024 14:13:10 +0100 Subject: [PATCH 5/7] Removes the need for using overlapping_elements_helper Improves the specs so we don't need to recurr to overlapping elements clicks, and removes the respective helper --- spec/support/overlapping_elements_helper.rb | 11 -------- spec/system/admin/enterprise_roles_spec.rb | 2 +- .../order_cycles/complex_editing_spec.rb | 4 +-- spec/system/admin/order_cycles/list_spec.rb | 28 +++++++++++++------ spec/system/admin/order_cycles/simple_spec.rb | 4 +-- spec/system/admin/order_spec.rb | 14 +++++----- 6 files changed, 30 insertions(+), 33 deletions(-) delete mode 100644 spec/support/overlapping_elements_helper.rb diff --git a/spec/support/overlapping_elements_helper.rb b/spec/support/overlapping_elements_helper.rb deleted file mode 100644 index 4a2ff2ab43..0000000000 --- a/spec/support/overlapping_elements_helper.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -def dismiss_warning - # Click dismiss on distributor warning - click_button 'Dismiss' -end - -def trigger_click(id, text) - # replace node buy the elements node, for example - page.find(id, text).trigger("click") -end diff --git a/spec/system/admin/enterprise_roles_spec.rb b/spec/system/admin/enterprise_roles_spec.rb index 4d4742bf9d..43b08b17f6 100644 --- a/spec/system/admin/enterprise_roles_spec.rb +++ b/spec/system/admin/enterprise_roles_spec.rb @@ -182,7 +182,7 @@ create(:enterprise) def navigate_to_enterprise_users scroll_to(:bottom) within ".side_menu" do - trigger_click(:link, "Users") + click_link "Users" end end diff --git a/spec/system/admin/order_cycles/complex_editing_spec.rb b/spec/system/admin/order_cycles/complex_editing_spec.rb index e8e097d75d..19b22ca465 100644 --- a/spec/system/admin/order_cycles/complex_editing_spec.rb +++ b/spec/system/admin/order_cycles/complex_editing_spec.rb @@ -32,7 +32,7 @@ RSpec.describe ' .to eq(oc.orders_close_at.strftime("%Y-%m-%d %H:%M")) expect(page).to have_content "Coordinator #{oc.coordinator.name}" - trigger_click(:button, 'Next') + click_button "Next" # And I should see the suppliers expect(page).to have_selector 'td.supplier_name', text: oc.suppliers.first.name @@ -76,7 +76,7 @@ RSpec.describe ' selected: supplier.enterprise_fees.first.name ) - trigger_click(:button, 'Next') + click_button "Next" # And I should see the distributors expect(page).to have_selector 'td.distributor_name', text: oc.distributors.first.name diff --git a/spec/system/admin/order_cycles/list_spec.rb b/spec/system/admin/order_cycles/list_spec.rb index ea71316afb..9fba7e4ac1 100644 --- a/spec/system/admin/order_cycles/list_spec.rb +++ b/spec/system/admin/order_cycles/list_spec.rb @@ -10,24 +10,32 @@ RSpec.describe ' include AuthenticationHelper include WebHelper + let(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) } + it "listing and filtering order cycles" do # Given some order cycles (created in an arbitrary order) oc4 = create(:simple_order_cycle, name: 'oc4', orders_open_at: 2.days.from_now, - orders_close_at: 1.month.from_now) - oc2 = create(:simple_order_cycle, name: 'oc2', orders_close_at: 1.month.from_now) + orders_close_at: 1.month.from_now, distributors: [hub]) + oc2 = create(:simple_order_cycle, name: 'oc2', + orders_close_at: 1.month.from_now, distributors: [hub]) oc6 = create(:simple_order_cycle, name: 'oc6', - orders_open_at: 1.month.ago, orders_close_at: 3.weeks.ago) + orders_open_at: 1.month.ago, orders_close_at: 3.weeks.ago, + distributors: [hub]) oc3 = create(:simple_order_cycle, name: 'oc3', orders_open_at: 1.day.from_now, - orders_close_at: 1.month.from_now) + orders_close_at: 1.month.from_now, + distributors: [hub]) oc5 = create(:simple_order_cycle, name: 'oc5', - orders_open_at: 1.month.ago, orders_close_at: 2.weeks.ago) - oc1 = create(:order_cycle, name: 'oc1') + orders_open_at: 1.month.ago, orders_close_at: 2.weeks.ago, + distributors: [hub]) + oc1 = create(:order_cycle, name: 'oc1', distributors: [hub]) oc0 = create(:simple_order_cycle, name: 'oc0', - orders_open_at: nil, orders_close_at: nil) + orders_open_at: nil, orders_close_at: nil, + distributors: [hub]) oc7 = create(:simple_order_cycle, name: 'oc7', - orders_open_at: 2.months.ago, orders_close_at: 5.weeks.ago) + orders_open_at: 2.months.ago, orders_close_at: 5.weeks.ago, + distributors: [hub]) schedule1 = create(:schedule, name: 'Schedule1', order_cycles: [oc1, oc3]) create(:proxy_order, subscription: create(:subscription, schedule: schedule1), order_cycle: oc1) @@ -73,7 +81,9 @@ RSpec.describe ' # I can load more order_cycles expect(page).not_to have_selector "#listing_order_cycles tr.order-cycle-#{oc7.id}" - trigger_click(:button, "Show 30 more days") + # binding.pry + # trigger_click(:button, "Show 30 more days") + click_button "Show 30 more days" expect(page).to have_selector "#listing_order_cycles tr.order-cycle-#{oc7.id}" diff --git a/spec/system/admin/order_cycles/simple_spec.rb b/spec/system/admin/order_cycles/simple_spec.rb index 74f077de9b..841b4688a1 100644 --- a/spec/system/admin/order_cycles/simple_spec.rb +++ b/spec/system/admin/order_cycles/simple_spec.rb @@ -516,9 +516,7 @@ RSpec.describe ' "table.exchanges tr.distributor-#{distributor_managed.id} td.tags" ) - # When I save, any exchanges that I can't manage remain - # overlapping warning, we need to use 'node.trigger("click")' - page.find(:button, "Save").trigger("click") + click_button "Save" expect(page).to have_content "Your order cycle has been updated." oc.reload diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index bf77b56de6..90c5028f39 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -129,7 +129,7 @@ RSpec.describe ' check 'order_use_billing' - trigger_click(:button, 'Update') + click_button "Update" expect(page).to have_content 'Customer Details updated' @@ -156,7 +156,7 @@ RSpec.describe ' expect(page).to have_field 'order_email', with: customer3.email expect do - trigger_click(:button, 'Update') + click_button "Update" expect(page).to have_content 'Customer Details updated' end.to change { order.reload.customer }.from(customer2).to(customer3) end @@ -292,7 +292,7 @@ RSpec.describe ' login_as_admin visit spree.edit_admin_order_path(order) - dismiss_warning + click_button 'Dismiss' expect(page).to have_select2 "order_distributor_id", with_options: [d.name] select2_select d.name, from: 'order_distributor_id' @@ -778,7 +778,7 @@ RSpec.describe ' visit spree.edit_admin_order_path(order) expect(page).not_to have_content different_shipping_method_for_distributor1.name - dismiss_warning + click_button 'Dismiss' find('.edit-method').click @@ -1088,7 +1088,7 @@ RSpec.describe ' end # updates the order and verifies the warning disappears - trigger_click(:button, 'Update And Recalculate Fees') + click_button "Update And Recalculate Fees" expect(page).not_to have_content "Out of Stock" end end @@ -1099,7 +1099,7 @@ RSpec.describe ' expect(page).to have_selector 'h1', text: 'Customer Details' click_link "Order Details" - dismiss_warning + click_button 'Dismiss' expect(page).to have_content 'Add Product' select2_select product.name, from: 'add_variant_id', search: true @@ -1111,7 +1111,7 @@ RSpec.describe ' expect(page).to have_select2 'order_distributor_id', with_options: [distributor1.name] expect(page).not_to have_select2 'order_distributor_id', with_options: [distributor2.name] - dismiss_warning + click_button 'Dismiss' expect(page).to have_select2 'order_order_cycle_id', with_options: ["#{order_cycle1.name} (open)"] From 5e933af0797842f49ea2f749e085331410af4067 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 10 Jul 2024 17:05:37 +0100 Subject: [PATCH 6/7] Prepares spec for admin_style_v3 - replaces TODO (1) --- spec/system/admin/product_import_spec.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index 85555f96bb..c0929e5ef2 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -97,16 +97,12 @@ RSpec.describe "Product Import" do expect(potatoes.variants.first.price).to eq 6.50 expect(potatoes.variants.first.import_date).to be_within(1.minute).of Time.zone.now - wait_until { page.find("a.button.view").present? } - - puts "TODO: migrate to v3" - Flipper.disable(:admin_style_v3) # disabling BUU for legacy products page click_link 'Go To Products Page' - expect(page).to have_content 'Bulk Edit Products' - wait_until { page.find("#p_#{potatoes.id}").present? } - expect(page).to have_field "product_name", with: carrots.name - expect(page).to have_field "product_name", with: potatoes.name + + # 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) end it "displays info about invalid entries but no save button if all items are invalid" do From c86f7f9d501ec537e3546c10343060d2aeac6f1c Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 11 Jul 2024 10:52:20 +1000 Subject: [PATCH 7/7] Remove comments --- spec/system/admin/order_cycles/list_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/system/admin/order_cycles/list_spec.rb b/spec/system/admin/order_cycles/list_spec.rb index 9fba7e4ac1..eddb8a6d6c 100644 --- a/spec/system/admin/order_cycles/list_spec.rb +++ b/spec/system/admin/order_cycles/list_spec.rb @@ -81,8 +81,6 @@ RSpec.describe ' # I can load more order_cycles expect(page).not_to have_selector "#listing_order_cycles tr.order-cycle-#{oc7.id}" - # binding.pry - # trigger_click(:button, "Show 30 more days") click_button "Show 30 more days" expect(page).to have_selector "#listing_order_cycles tr.order-cycle-#{oc7.id}"