From 3185033dea30ba3fd3effb857b73ee02675947ea Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 17 Aug 2021 15:33:49 +0200 Subject: [PATCH 1/6] Generate `id` and `for` on label and input when using rails helper --- config/application.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/application.rb b/config/application.rb index 3273f812d1..c82fc95267 100644 --- a/config/application.rb +++ b/config/application.rb @@ -231,5 +231,7 @@ module Openfoodnetwork config.generators.template_engine = :haml config.autoloader = :zeitwerk + + config.action_view.form_with_generates_ids = true end end From 04ba5708754f0d7c34346ceb114fb4a003bee8b0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 17 Aug 2021 15:51:42 +0200 Subject: [PATCH 2/6] Add split checkout system test --- .../split_checkout/split_checkout_spec.rb | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 spec/system/split_checkout/split_checkout_spec.rb diff --git a/spec/system/split_checkout/split_checkout_spec.rb b/spec/system/split_checkout/split_checkout_spec.rb new file mode 100644 index 0000000000..1b341c6d5e --- /dev/null +++ b/spec/system/split_checkout/split_checkout_spec.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +require "system_helper" + +describe "As a consumer, I want to checkout my order", js: true do + include ShopWorkflow + + let!(:zone) { create(:zone_with_member) } + let(:supplier) { create(:supplier_enterprise) } + let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true) } + let(:product) { + create(:taxed_product, supplier: supplier, price: 10, zone: zone, tax_rate_amount: 0.1) + } + let(:variant) { product.variants.first } + let!(:order_cycle) { + create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], + coordinator: create(:distributor_enterprise), variants: [variant]) + } + let(:order) { + create(:order, order_cycle: order_cycle, distributor: distributor, bill_address_id: nil, + ship_address_id: nil) + } + + let(:fee_tax_rate) { create(:tax_rate, amount: 0.10, zone: zone, included_in_price: true) } + let(:fee_tax_category) { create(:tax_category, tax_rates: [fee_tax_rate]) } + let(:enterprise_fee) { create(:enterprise_fee, amount: 1.23, tax_category: fee_tax_category) } + + let(:free_shipping) { + create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow", + calculator: Calculator::FlatRate.new(preferred_amount: 0.00)) + } + let(:shipping_tax_rate) { create(:tax_rate, amount: 0.25, zone: zone, included_in_price: true) } + let(:shipping_tax_category) { create(:tax_category, tax_rates: [shipping_tax_rate]) } + let(:shipping_with_fee) { + create(:shipping_method, require_ship_address: false, tax_category: shipping_tax_category, + name: "Donkeys", description: "blue", + calculator: Calculator::FlatRate.new(preferred_amount: 4.56)) + } + let(:tagged_shipping) { + create(:shipping_method, require_ship_address: false, name: "Local", tag_list: "local") + } + let!(:paypal) do + Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test', + distributor_ids: [distributor.id]).tap do |pm| + pm.preferred_login = 'devnull-facilitator_api1.rohanmitchell.com' + pm.preferred_password = '1406163716' + pm.preferred_signature = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AaTntNJ-AjvUJkWf4dgJIvcLsf1V' + end + end + + before do + allow(Flipper).to receive(:enabled?).with(:split_checkout, anything).and_return(true) + add_enterprise_fee enterprise_fee + set_order order + add_product_to_cart order, product + + distributor.shipping_methods << free_shipping + distributor.shipping_methods << shipping_with_fee + distributor.shipping_methods << tagged_shipping + end + + context "guest checkout" do + before do + visit checkout_path + end + + it "should display the split checkout page" do + expect(page).to have_content distributor.name + expect(page).to have_current_path("/checkout/details") + expect(page).to have_content("1 - Your details") + expect(page).to have_selector("div.checkout-tab.selected", text: "1 - Your details") + expect(page).to have_content("2 - Payment method") + expect(page).to have_content("3 - Order summary") + end + + it "should display error when fields are empty" do + click_button "Next - Payment method" + expect(page).to have_content("Saving failed, please update the highlighted fields") + expect(page).to have_css 'span.field_with_errors label', count: 6 + expect(page).to have_css 'span.field_with_errors input', count: 6 + expect(page).to have_css 'span.formError', count: 6 + end + + it "should validate once each needed field is filled" do + fill_in "First Name", with: "Jane" + fill_in "Last Name", with: "Doe" + fill_in "Phone number", with: "07987654321" + fill_in "Address (Street + House Number)", with: "Flat 1 Elm apartments" + fill_in "City", with: "London" + fill_in "Postcode", with: "SW1A 1AA" + choose free_shipping.name + click_button "Next - Payment method" + expect(page).to have_current_path("/checkout/payment") + end + end +end From 1089ded2a26ef7b66fa985b9e5fe52d52dd0fadf Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Nov 2021 17:46:44 +0000 Subject: [PATCH 3/6] Move spec under /consumer --- spec/system/{split_checkout => consumer}/split_checkout_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/system/{split_checkout => consumer}/split_checkout_spec.rb (100%) diff --git a/spec/system/split_checkout/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb similarity index 100% rename from spec/system/split_checkout/split_checkout_spec.rb rename to spec/system/consumer/split_checkout_spec.rb From ac317bc3cebd2f3ef3975f783a678ae07e114187 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Nov 2021 17:47:31 +0000 Subject: [PATCH 4/6] Fix Flipper stubs --- spec/system/consumer/split_checkout_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 1b341c6d5e..fb3df41274 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -49,7 +49,9 @@ describe "As a consumer, I want to checkout my order", js: true do end before do + allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) allow(Flipper).to receive(:enabled?).with(:split_checkout, anything).and_return(true) + add_enterprise_fee enterprise_fee set_order order add_product_to_cart order, product From f3dc1c80cf93cd17b100041c3523c30d1c4e6334 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Nov 2021 17:47:59 +0000 Subject: [PATCH 5/6] Update error field counts --- spec/system/consumer/split_checkout_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index fb3df41274..e152e04334 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -78,9 +78,9 @@ describe "As a consumer, I want to checkout my order", js: true do it "should display error when fields are empty" do click_button "Next - Payment method" expect(page).to have_content("Saving failed, please update the highlighted fields") - expect(page).to have_css 'span.field_with_errors label', count: 6 - expect(page).to have_css 'span.field_with_errors input', count: 6 - expect(page).to have_css 'span.formError', count: 6 + expect(page).to have_css 'span.field_with_errors label', count: 4 + expect(page).to have_css 'span.field_with_errors input', count: 4 + expect(page).to have_css 'span.formError', count: 5 end it "should validate once each needed field is filled" do From 8d5dbb1f47ec12f7d3f3e9b5d3bb52ba3d72424d Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Nov 2021 17:50:07 +0000 Subject: [PATCH 6/6] Remove/simplify setup objects and improve old shipping method names --- spec/system/consumer/split_checkout_spec.rb | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index e152e04334..986e95dc4b 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -26,27 +26,17 @@ describe "As a consumer, I want to checkout my order", js: true do let(:enterprise_fee) { create(:enterprise_fee, amount: 1.23, tax_category: fee_tax_category) } let(:free_shipping) { - create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow", + create(:shipping_method, require_ship_address: true, name: "Free Shipping", description: "yellow", calculator: Calculator::FlatRate.new(preferred_amount: 0.00)) } let(:shipping_tax_rate) { create(:tax_rate, amount: 0.25, zone: zone, included_in_price: true) } let(:shipping_tax_category) { create(:tax_category, tax_rates: [shipping_tax_rate]) } let(:shipping_with_fee) { create(:shipping_method, require_ship_address: false, tax_category: shipping_tax_category, - name: "Donkeys", description: "blue", + name: "Shipping with Fee", description: "blue", calculator: Calculator::FlatRate.new(preferred_amount: 4.56)) } - let(:tagged_shipping) { - create(:shipping_method, require_ship_address: false, name: "Local", tag_list: "local") - } - let!(:paypal) do - Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test', - distributor_ids: [distributor.id]).tap do |pm| - pm.preferred_login = 'devnull-facilitator_api1.rohanmitchell.com' - pm.preferred_password = '1406163716' - pm.preferred_signature = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AaTntNJ-AjvUJkWf4dgJIvcLsf1V' - end - end + let!(:payment_method) { create(:payment_method, distributors: [distributor]) } before do allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) @@ -58,7 +48,6 @@ describe "As a consumer, I want to checkout my order", js: true do distributor.shipping_methods << free_shipping distributor.shipping_methods << shipping_with_fee - distributor.shipping_methods << tagged_shipping end context "guest checkout" do @@ -91,6 +80,7 @@ describe "As a consumer, I want to checkout my order", js: true do fill_in "City", with: "London" fill_in "Postcode", with: "SW1A 1AA" choose free_shipping.name + click_button "Next - Payment method" expect(page).to have_current_path("/checkout/payment") end