From 0bf7e53ce4fad7d639cc948163b6ab23705954bc Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Sat, 6 May 2023 13:37:46 -0300 Subject: [PATCH 01/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Isolate when no field is filled on first screen. --- spec/system/admin/subscriptions_spec.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 070ff32316..4c995a93e2 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -196,7 +196,7 @@ describe 'Subscriptions' do end end - context 'creating a new subscription' do + context 'when creating a new subscription' do let(:address) { create(:address) } let!(:customer_user) { create(:user) } let!(:credit_card1) { @@ -238,6 +238,20 @@ describe 'Subscriptions' do click_button "Continue" end + context 'and no field is filled' do + it 'counts a can not be blank content once' do + 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' + + click_button('Next') + + expect(page).to have_content 'can\'t be blank', count: 1 + expect(page).to have_content 'Oops! Please fill in all of the required fields...' + end + end + it "passes the smoke test" do select2_select customer.email, from: 'customer_id' select2_select schedule.name, from: 'schedule_id' From 47b0d626e2557cdf3f67782fa6b0e8d94781a2d1 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 10 May 2023 22:03:24 -0300 Subject: [PATCH 02/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Isolate when no field is filled on first screen describe it better as per reviewer suggestion. --- spec/system/admin/subscriptions_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 4c995a93e2..874b713320 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -238,7 +238,7 @@ describe 'Subscriptions' do click_button "Continue" end - context 'and no field is filled' do + context 'and date field is not filled' do it 'counts a can not be blank content once' do select2_select customer.email, from: 'customer_id' select2_select schedule.name, from: 'schedule_id' From 77857a01687258017a243961d4f66aa8e8a01be0 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 10 May 2023 22:04:26 -0300 Subject: [PATCH 03/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context when date field is filled. It goes to the next page with preloaded data. --- spec/system/admin/subscriptions_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 874b713320..7429b8119f 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -252,6 +252,25 @@ describe 'Subscriptions' do end end + context 'and date field is filled' do + it 'goes to the next page' do + 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 + click_button('Next') + + expect(page).to have_content 'BILLING ADDRESS' + # Customer bill address has been pre-loaded + expect(page).to have_input "bill_address_firstname", with: address.firstname + expect(page).to have_input "bill_address_lastname", with: address.lastname + expect(page).to have_input "bill_address_address1", with: address.address1 + end + end + it "passes the smoke test" do select2_select customer.email, from: 'customer_id' select2_select schedule.name, from: 'schedule_id' From 384ad1ba1279ca5fffb4ab21c4d7d46ae24a7b1c Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 10 May 2023 22:18:36 -0300 Subject: [PATCH 04/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Group context for first page scenarios. Extract common customer actions to its before do block. --- spec/system/admin/subscriptions_spec.rb | 42 ++++++++++++------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 7429b8119f..dc47ae97c5 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -238,36 +238,34 @@ describe 'Subscriptions' do click_button "Continue" end - context 'and date field is not filled' do - it 'counts a can not be blank content once' do + context 'on first page' do + before do 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' - - click_button('Next') - - expect(page).to have_content 'can\'t be blank', count: 1 - expect(page).to have_content 'Oops! Please fill in all of the required fields...' end - end - context 'and date field is filled' do - it 'goes to the next page' do - 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' + context 'and date field is not filled' do + it 'counts a can not be blank content once' do + click_button('Next') - find_field('begins_at').click - choose_today_from_datepicker - click_button('Next') + expect(page).to have_content 'can\'t be blank', count: 1 + expect(page).to have_content 'Oops! Please fill in all of the required fields...' + end + end - expect(page).to have_content 'BILLING ADDRESS' - # Customer bill address has been pre-loaded - expect(page).to have_input "bill_address_firstname", with: address.firstname - expect(page).to have_input "bill_address_lastname", with: address.lastname - expect(page).to have_input "bill_address_address1", with: address.address1 + context 'and date field is filled' do + it 'goes to the next page and preload customer bill address' do + find_field('begins_at').click + choose_today_from_datepicker + click_button('Next') + + expect(page).to have_content 'BILLING ADDRESS' + expect(page).to have_input "bill_address_firstname", with: address.firstname + expect(page).to have_input "bill_address_lastname", with: address.lastname + expect(page).to have_input "bill_address_address1", with: address.address1 + end end end From 573ab1beb02aa32ee0142250841ebae09716afb9 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Thu, 11 May 2023 20:21:44 -0300 Subject: [PATCH 05/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context on second page when clearing some elements of the bill address. --- spec/system/admin/subscriptions_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index dc47ae97c5..41d564045c 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -269,6 +269,27 @@ describe 'Subscriptions' do end end + context 'on second page' do + it 'counts 6 can not be blank messages' do + 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 + click_button('Next') + # Clear some elements of bill address + fill_in "bill_address_firstname", with: '' + fill_in "bill_address_lastname", with: '' + fill_in "bill_address_address1", with: '' + fill_in "bill_address_city", with: '' + fill_in "bill_address_zipcode", with: '' + fill_in "bill_address_phone", with: '' + click_button('Next') + expect(page).to have_content 'can\'t be blank', count: 6 + end + end + it "passes the smoke test" do select2_select customer.email, from: 'customer_id' select2_select schedule.name, from: 'schedule_id' From 79ff13e8ba866ce651ae29d16f212ecdc1cfd185 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Thu, 11 May 2023 20:31:43 -0300 Subject: [PATCH 06/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Move on second page to a before action and clearing some elements of bill address to a before action. Let the unit test with the action isolated. --- spec/system/admin/subscriptions_spec.rb | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 41d564045c..40ab1c3b20 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -270,7 +270,7 @@ describe 'Subscriptions' do end context 'on second page' do - it 'counts 6 can not be blank messages' do + before do select2_select customer.email, from: 'customer_id' select2_select schedule.name, from: 'schedule_id' select2_select payment_method.name, from: 'payment_method_id' @@ -278,15 +278,23 @@ describe 'Subscriptions' do find_field('begins_at').click choose_today_from_datepicker click_button('Next') - # Clear some elements of bill address - fill_in "bill_address_firstname", with: '' - fill_in "bill_address_lastname", with: '' - fill_in "bill_address_address1", with: '' - fill_in "bill_address_city", with: '' - fill_in "bill_address_zipcode", with: '' - fill_in "bill_address_phone", with: '' - click_button('Next') - expect(page).to have_content 'can\'t be blank', count: 6 + end + + context 'when clearing some elements of bill address' do + before do + # Clear some elements of bill address + fill_in "bill_address_firstname", with: '' + fill_in "bill_address_lastname", with: '' + fill_in "bill_address_address1", with: '' + fill_in "bill_address_city", with: '' + fill_in "bill_address_zipcode", with: '' + fill_in "bill_address_phone", with: '' + end + + it 'counts 6 can not be blank messages' do + click_button('Next') + expect(page).to have_content 'can\'t be blank', count: 6 + end end end From 39a76861f30f838a0354a745d83a5d142c0cfecb Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Thu, 11 May 2023 20:41:52 -0300 Subject: [PATCH 07/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context when resetting the billing address after clearing the bill address. --- spec/system/admin/subscriptions_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 40ab1c3b20..7062618f89 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -295,6 +295,25 @@ describe 'Subscriptions' do click_button('Next') expect(page).to have_content 'can\'t be blank', count: 6 end + + context 're-setting the billing address' do + it 'has input with ship address values' do + fill_in "bill_address_firstname", with: 'Freda' + fill_in "bill_address_lastname", with: 'Figapple' + fill_in "bill_address_address1", with: '7 Tempany Lane' + fill_in "bill_address_city", with: 'Natte Yallock' + fill_in "bill_address_zipcode", with: '3465' + fill_in "bill_address_phone", with: '0400 123 456' + select2_select "Australia", from: "bill_address_country_id" + select2_select "Victoria", from: "bill_address_state_id" + + # Use copy button to fill in ship address + click_link "Copy" + expect(page).to have_input "ship_address_firstname", with: 'Freda' + expect(page).to have_input "ship_address_lastname", with: 'Figapple' + expect(page).to have_input "ship_address_address1", with: '7 Tempany Lane' + end + end end end From aa16110e9ae32e72fb94eed3ad5dbd3a5f95d605 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Thu, 11 May 2023 20:48:16 -0300 Subject: [PATCH 08/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context when resetting the billing address after clearing the bill address. MOve scenario to its before do block. --- spec/system/admin/subscriptions_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 7062618f89..3d02afc40d 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -296,8 +296,8 @@ describe 'Subscriptions' do expect(page).to have_content 'can\'t be blank', count: 6 end - context 're-setting the billing address' do - it 'has input with ship address values' do + context 'and re-setting the billing address' do + before do fill_in "bill_address_firstname", with: 'Freda' fill_in "bill_address_lastname", with: 'Figapple' fill_in "bill_address_address1", with: '7 Tempany Lane' @@ -306,7 +306,9 @@ describe 'Subscriptions' do fill_in "bill_address_phone", with: '0400 123 456' select2_select "Australia", from: "bill_address_country_id" select2_select "Victoria", from: "bill_address_state_id" + end + it 'has input with ship address values' do # Use copy button to fill in ship address click_link "Copy" expect(page).to have_input "ship_address_firstname", with: 'Freda' From 7efc68281e5fc237256b2106ee309777c3e26730 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Thu, 11 May 2023 20:55:48 -0300 Subject: [PATCH 09/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context when using copy button to fill in ship address. --- spec/system/admin/subscriptions_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 3d02afc40d..3ff5441654 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -308,13 +308,16 @@ describe 'Subscriptions' do select2_select "Victoria", from: "bill_address_state_id" end - it 'has input with ship address values' do - # Use copy button to fill in ship address - click_link "Copy" - expect(page).to have_input "ship_address_firstname", with: 'Freda' - expect(page).to have_input "ship_address_lastname", with: 'Figapple' - expect(page).to have_input "ship_address_address1", with: '7 Tempany Lane' + context 'and using copy button to fill in ship address' do + before { click_link "Copy" } + + it 'has input with ship address values' do + expect(page).to have_input "ship_address_firstname", with: 'Freda' + expect(page).to have_input "ship_address_lastname", with: 'Figapple' + expect(page).to have_input "ship_address_address1", with: '7 Tempany Lane' + end end + end end end From 35ce46381169d0fc0f503529239169dbd064081d Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Thu, 11 May 2023 21:03:46 -0300 Subject: [PATCH 10/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context on third page. --- spec/system/admin/subscriptions_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 3ff5441654..f9dfd55ffd 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -322,6 +322,23 @@ describe 'Subscriptions' do end end + context 'on third page' do + before do + 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 + click_button('Next') + click_button('Next') + end + + it 'has content NAME OR SKU' do + expect(page).to have_content 'NAME OR SKU' + end + end + it "passes the smoke test" do select2_select customer.email, from: 'customer_id' select2_select schedule.name, from: 'schedule_id' From f05e2618be0760df25c23bea2cb0aecf1fdb17e1 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Thu, 11 May 2023 21:07:33 -0300 Subject: [PATCH 11/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context on third page and click next button without adding at least one product. --- spec/system/admin/subscriptions_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index f9dfd55ffd..e84151ef66 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -337,6 +337,14 @@ describe 'Subscriptions' do it 'has content NAME OR SKU' do expect(page).to have_content 'NAME OR SKU' end + + context 'and click next button without adding at least one product' do + before { click_button('Next') } + + it 'has content Please add at least one product' do + expect(page).to have_content 'Please add at least one product' + end + end end it "passes the smoke test" do From b0623ab4de435d6c1a7a6eae077f7b28dea1f9e7 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Thu, 11 May 2023 21:14:50 -0300 Subject: [PATCH 12/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context on third page and adding a product. --- spec/system/admin/subscriptions_spec.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index e84151ef66..dd342bf6d3 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -317,7 +317,6 @@ describe 'Subscriptions' do expect(page).to have_input "ship_address_address1", with: '7 Tempany Lane' end end - end end end @@ -345,6 +344,20 @@ describe 'Subscriptions' do expect(page).to have_content 'Please add at least one product' end end + + context 'and adding a product' do + before { add_variant_to_subscription test_variant, 2 } + + it 'has description, price estimates, quantity and total' do + within 'table#subscription-line-items tr.item', match: :first do + expect(page).to have_selector '.description', + text: "#{test_product.name} - #{test_variant.full_name}" + expect(page).to have_selector 'td.price', text: "$13.75" + expect(page).to have_input 'quantity', with: "2" + expect(page).to have_selector 'td.total', text: "$27.50" + end + end + end end it "passes the smoke test" do From 5776bdb31c61277936c3cc54be314a6734ac7c70 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Fri, 12 May 2023 22:03:29 -0300 Subject: [PATCH 13/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context on third page and adding a product AND deleting the existing product. --- spec/system/admin/subscriptions_spec.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index dd342bf6d3..35c90296bf 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -345,7 +345,7 @@ describe 'Subscriptions' do end end - context 'and adding a product' do + context 'with a product' do before { add_variant_to_subscription test_variant, 2 } it 'has description, price estimates, quantity and total' do @@ -357,6 +357,23 @@ describe 'Subscriptions' do expect(page).to have_selector 'td.total', text: "$27.50" end end + + context 'and deleting the existing product' do + before do + within 'table#subscription-line-items tr.item', match: :first do + find("a.delete-item").click + end + end + + it 'has content Please add at least one product and subscription does not change' do + click_button('Next') + + expect{ + click_button('Create Subscription') + expect(page).to have_content 'Please add at least one product' + }.to_not change(Subscription, :count) + end + end end end From 5a5aa4c0673ac1740a9d3162b2dbd3074b515408 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Fri, 12 May 2023 22:19:34 -0300 Subject: [PATCH 14/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context on third page and adding a product AND deleting the existing product AND adding a new product. --- spec/system/admin/subscriptions_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 35c90296bf..24f15dbdd5 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -373,6 +373,24 @@ describe 'Subscriptions' do expect(page).to have_content 'Please add at least one product' }.to_not change(Subscription, :count) end + + context 'and adding a new product' do + before do + click_button('Next') + click_button('edit-products') + add_variant_to_subscription shop_variant, 3 + end + + it 'has selectors for description, price, quantity and total' do + within 'table#subscription-line-items tr.item', match: :first do + expect(page).to have_selector '.description', + text: "#{shop_product.name} - #{shop_variant.full_name}" + expect(page).to have_selector 'td.price', text: "$7.75" + expect(page).to have_input 'quantity', with: "3" + expect(page).to have_selector 'td.total', text: "$23.25" + end + end + end end end end From c63a8d12f78798b507e1dfe05fb571477eeae69d Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Fri, 12 May 2023 22:30:07 -0300 Subject: [PATCH 15/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context on third page and adding a product AND deleting the existing product AND adding a new product and click next button. --- spec/system/admin/subscriptions_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 24f15dbdd5..65807162ad 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -390,6 +390,17 @@ describe 'Subscriptions' do expect(page).to have_selector 'td.total', text: "$23.25" end end + + context 'and click next button' do + before { click_button('Next') } + + it 'has current path as admin_subscriptions_path and counts by one subscription' do + expect{ + click_button('Create Subscription') + expect(page).to have_current_path admin_subscriptions_path + }.to change(Subscription, :count).by(1) + end + end end end end From 8c709e13e05f6fd37444fbc332d4f1c66f5c12f8 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Fri, 12 May 2023 22:39:46 -0300 Subject: [PATCH 16/25] lint(spec/system/admin/subscriptions_spec.rb): issue #7483 Solve line too lng offense. --- spec/system/admin/subscriptions_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 65807162ad..55c5ada90c 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -382,9 +382,11 @@ describe 'Subscriptions' do end it 'has selectors for description, price, quantity and total' do + description = "#{shop_product.name} - #{shop_variant.full_name}" + within 'table#subscription-line-items tr.item', match: :first do expect(page).to have_selector '.description', - text: "#{shop_product.name} - #{shop_variant.full_name}" + text: description expect(page).to have_selector 'td.price', text: "$7.75" expect(page).to have_input 'quantity', with: "3" expect(page).to have_selector 'td.total', text: "$23.25" From f0da85d723fe21a46598cc73d920c724210a9bfb Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 17 May 2023 21:42:29 -0300 Subject: [PATCH 17/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context when click Create Subscription button on third page after click next button previously on second page. --- spec/system/admin/subscriptions_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 55c5ada90c..c90567c6dd 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -402,6 +402,15 @@ describe 'Subscriptions' do expect(page).to have_current_path admin_subscriptions_path }.to change(Subscription, :count).by(1) end + + context 'and click Create Subscription button' do + it 'has selector td.items.panel-toggle' do + click_button('Create Subscription') + + select2_select shop.name, from: "shop_id" + expect(page).to have_selector "td.items.panel-toggle" + end + end end end end From 03aade4072575eca3a668c8485593c85ff81acb1 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 17 May 2023 21:48:25 -0300 Subject: [PATCH 18/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Add context when click Create Subscription button on third page after click next button previously on second page. It has selector for price, input for quantity and selector for total price. --- spec/system/admin/subscriptions_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index c90567c6dd..3b4181c1e6 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -410,6 +410,20 @@ describe 'Subscriptions' do select2_select shop.name, from: "shop_id" expect(page).to have_selector "td.items.panel-toggle" end + + it 'has selector for price, input for quantity and selector for total price' do + click_button('Create Subscription') + select2_select shop.name, from: "shop_id" + first("td.items.panel-toggle").click + + within 'table#subscription-line-items tr.item', match: :first do + expect(page).to have_selector '.description', + text: "#{shop_product.name} - #{shop_variant.full_name}" + expect(page).to have_selector 'td.price', text: "$7.75" + expect(page).to have_input 'quantity', with: "3" + expect(page).to have_selector 'td.total', text: "$23.25" + end + end end end end From 49ceec8b8e0068ef5a108e427f3f0c10458eb30e Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 17 May 2023 21:53:42 -0300 Subject: [PATCH 19/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 share common before action Create subscription between samples. --- spec/system/admin/subscriptions_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 3b4181c1e6..6fa90d888e 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -404,16 +404,16 @@ describe 'Subscriptions' do end context 'and click Create Subscription button' do - it 'has selector td.items.panel-toggle' do + before do click_button('Create Subscription') - select2_select shop.name, from: "shop_id" + end + + it 'has selector td.items.panel-toggle' do expect(page).to have_selector "td.items.panel-toggle" end it 'has selector for price, input for quantity and selector for total price' do - click_button('Create Subscription') - select2_select shop.name, from: "shop_id" first("td.items.panel-toggle").click within 'table#subscription-line-items tr.item', match: :first do From 4df550fcf17d0daff6b8ab3b4f4c06805dcef923 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 17 May 2023 22:24:37 -0300 Subject: [PATCH 20/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 add unit test to check basic Subscription properties when click create subscription without changing shipping address. --- spec/system/admin/subscriptions_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 6fa90d888e..cc112cb6d9 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -424,6 +424,16 @@ describe 'Subscriptions' do expect(page).to have_selector 'td.total', text: "$23.25" end end + + it 'sets basic properties of subscription' do + subscription = Subscription.last + expect(subscription.customer).to eq customer + expect(subscription.schedule).to eq schedule + expect(subscription.payment_method).to eq payment_method + expect(subscription.shipping_method).to eq shipping_method + expect(subscription.bill_address.firstname).to eq 'John' + expect(subscription.ship_address.firstname).to eq 'John' + end end end end From 105d695f18835cc1d1c39cc00ce334fa33bcb998 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 17 May 2023 22:30:58 -0300 Subject: [PATCH 21/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 add unit test to check creation of standing line items when click create subscription without changing shipping address. --- spec/system/admin/subscriptions_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index cc112cb6d9..d18ec8217a 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -434,6 +434,15 @@ describe 'Subscriptions' do expect(subscription.bill_address.firstname).to eq 'John' expect(subscription.ship_address.firstname).to eq 'John' end + + it 'creates standing line items' do + subscription = Subscription.last + subscription_line_item = subscription.subscription_line_items.first + + expect(subscription.subscription_line_items.count).to eq 1 + expect(subscription_line_item.variant).to eq shop_variant + expect(subscription_line_item.quantity).to eq 3 + end end end end From bd05f40b171d2bb28eb60064f42d945e029706ac Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 17 May 2023 22:43:22 -0300 Subject: [PATCH 22/25] lint(spec/system/admin/subscriptions_spec.rb): issue #7483 Solve line too long offense and separate variables from expectations. --- spec/system/admin/subscriptions_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index d18ec8217a..f2d5e6b8fe 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -414,11 +414,12 @@ describe 'Subscriptions' do end it 'has selector for price, input for quantity and selector for total price' do + description = "#{shop_product.name} - #{shop_variant.full_name}" first("td.items.panel-toggle").click within 'table#subscription-line-items tr.item', match: :first do expect(page).to have_selector '.description', - text: "#{shop_product.name} - #{shop_variant.full_name}" + text: description expect(page).to have_selector 'td.price', text: "$7.75" expect(page).to have_input 'quantity', with: "3" expect(page).to have_selector 'td.total', text: "$23.25" @@ -427,6 +428,7 @@ describe 'Subscriptions' do it 'sets basic properties of subscription' do subscription = Subscription.last + expect(subscription.customer).to eq customer expect(subscription.schedule).to eq schedule expect(subscription.payment_method).to eq payment_method From 1e1d4b07d122a84d17df65417908a77473e24b7d Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Wed, 17 May 2023 22:53:28 -0300 Subject: [PATCH 23/25] refactor(spec/system/admin/subscriptions_spec.rb): issue #7483 Remove the old chained smoke test. --- spec/system/admin/subscriptions_spec.rb | 122 ------------------------ 1 file changed, 122 deletions(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index f2d5e6b8fe..69a8cb6933 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -451,128 +451,6 @@ describe 'Subscriptions' do end end end - - it "passes the smoke test" do - 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' - - # No date, so error returned - click_button('Next') - expect(page).to have_content 'can\'t be blank', count: 1 - expect(page).to have_content 'Oops! Please fill in all of the required fields...' - find_field('begins_at').click - choose_today_from_datepicker - - click_button('Next') - expect(page).to have_content 'BILLING ADDRESS' - # Customer bill address has been pre-loaded - expect(page).to have_input "bill_address_firstname", with: address.firstname - expect(page).to have_input "bill_address_lastname", with: address.lastname - expect(page).to have_input "bill_address_address1", with: address.address1 - - # Clear some elements of bill address - fill_in "bill_address_firstname", with: '' - fill_in "bill_address_lastname", with: '' - fill_in "bill_address_address1", with: '' - fill_in "bill_address_city", with: '' - fill_in "bill_address_zipcode", with: '' - fill_in "bill_address_phone", with: '' - click_button('Next') - expect(page).to have_content 'can\'t be blank', count: 6 - - # Re-setting the billing address - fill_in "bill_address_firstname", with: 'Freda' - fill_in "bill_address_lastname", with: 'Figapple' - fill_in "bill_address_address1", with: '7 Tempany Lane' - fill_in "bill_address_city", with: 'Natte Yallock' - fill_in "bill_address_zipcode", with: '3465' - fill_in "bill_address_phone", with: '0400 123 456' - select2_select "Australia", from: "bill_address_country_id" - select2_select "Victoria", from: "bill_address_state_id" - - # Use copy button to fill in ship address - click_link "Copy" - expect(page).to have_input "ship_address_firstname", with: 'Freda' - expect(page).to have_input "ship_address_lastname", with: 'Figapple' - expect(page).to have_input "ship_address_address1", with: '7 Tempany Lane' - - click_button('Next') - expect(page).to have_content 'NAME OR SKU' - click_button('Next') - expect(page).to have_content 'Please add at least one product' - - # Adding a product and getting a price estimate - add_variant_to_subscription test_variant, 2 - within 'table#subscription-line-items tr.item', match: :first do - expect(page).to have_selector '.description', - text: "#{test_product.name} - #{test_variant.full_name}" - expect(page).to have_selector 'td.price', text: "$13.75" - expect(page).to have_input 'quantity', with: "2" - expect(page).to have_selector 'td.total', text: "$27.50" - end - - # Deleting the existing product - within 'table#subscription-line-items tr.item', match: :first do - find("a.delete-item").click - end - - click_button('Next') - - # Attempting to submit without a product - expect{ - click_button('Create Subscription') - expect(page).to have_content 'Please add at least one product' - }.to_not change(Subscription, :count) - - click_button('edit-products') - - # Adding a new product - add_variant_to_subscription shop_variant, 3 - within 'table#subscription-line-items tr.item', match: :first do - expect(page).to have_selector '.description', - text: "#{shop_product.name} - #{shop_variant.full_name}" - expect(page).to have_selector 'td.price', text: "$7.75" - expect(page).to have_input 'quantity', with: "3" - expect(page).to have_selector 'td.total', text: "$23.25" - end - - click_button('Next') - - expect{ - click_button('Create Subscription') - expect(page).to have_current_path admin_subscriptions_path - }.to change(Subscription, :count).by(1) - - select2_select shop.name, from: "shop_id" - expect(page).to have_selector "td.items.panel-toggle" - first("td.items.panel-toggle").click - - # Prices are shown in the index - within 'table#subscription-line-items tr.item', match: :first do - expect(page).to have_selector '.description', - text: "#{shop_product.name} - #{shop_variant.full_name}" - expect(page).to have_selector 'td.price', text: "$7.75" - expect(page).to have_input 'quantity', with: "3" - expect(page).to have_selector 'td.total', text: "$23.25" - end - - # Basic properties of subscription are set - subscription = Subscription.last - expect(subscription.customer).to eq customer - expect(subscription.schedule).to eq schedule - expect(subscription.payment_method).to eq payment_method - expect(subscription.shipping_method).to eq shipping_method - expect(subscription.bill_address.firstname).to eq 'Freda' - expect(subscription.ship_address.firstname).to eq 'Freda' - - # Standing Line Items are created - expect(subscription.subscription_line_items.count).to eq 1 - subscription_line_item = subscription.subscription_line_items.first - expect(subscription_line_item.variant).to eq shop_variant - expect(subscription_line_item.quantity).to eq 3 - end end context 'editing an existing subscription' do From c9ab092f7c12cb3ea50041fe36df31db6373b247 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Fri, 19 May 2023 19:14:55 -0300 Subject: [PATCH 24/25] chore(spec/system/admin/subscriptions_spec.rb): issue #7483 Add back comment explaining bill address has been pre-loaded. --- spec/system/admin/subscriptions_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 69a8cb6933..3b158f9bf8 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -262,6 +262,7 @@ describe 'Subscriptions' do click_button('Next') expect(page).to have_content 'BILLING ADDRESS' + # Customer bill address has been pre-loaded expect(page).to have_input "bill_address_firstname", with: address.firstname expect(page).to have_input "bill_address_lastname", with: address.lastname expect(page).to have_input "bill_address_address1", with: address.address1 From 3a35f128012381434f7365ba73011c629fc6d640 Mon Sep 17 00:00:00 2001 From: paulo-felipe Date: Fri, 19 May 2023 19:33:05 -0300 Subject: [PATCH 25/25] chore(spec/system/admin/subscriptions_spec.rb): issue #7483 Group together sample tests to avoid rebuilding browser state. --- spec/system/admin/subscriptions_spec.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/spec/system/admin/subscriptions_spec.rb b/spec/system/admin/subscriptions_spec.rb index 3b158f9bf8..204dd50241 100644 --- a/spec/system/admin/subscriptions_spec.rb +++ b/spec/system/admin/subscriptions_spec.rb @@ -416,6 +416,9 @@ describe 'Subscriptions' do it 'has selector for price, input for quantity and selector for total price' do description = "#{shop_product.name} - #{shop_variant.full_name}" + subscription = Subscription.last + subscription_line_item = subscription.subscription_line_items.first + first("td.items.panel-toggle").click within 'table#subscription-line-items tr.item', match: :first do @@ -425,10 +428,6 @@ describe 'Subscriptions' do expect(page).to have_input 'quantity', with: "3" expect(page).to have_selector 'td.total', text: "$23.25" end - end - - it 'sets basic properties of subscription' do - subscription = Subscription.last expect(subscription.customer).to eq customer expect(subscription.schedule).to eq schedule @@ -436,12 +435,6 @@ describe 'Subscriptions' do expect(subscription.shipping_method).to eq shipping_method expect(subscription.bill_address.firstname).to eq 'John' expect(subscription.ship_address.firstname).to eq 'John' - end - - it 'creates standing line items' do - subscription = Subscription.last - subscription_line_item = subscription.subscription_line_items.first - expect(subscription.subscription_line_items.count).to eq 1 expect(subscription_line_item.variant).to eq shop_variant expect(subscription_line_item.quantity).to eq 3