Merge pull request #10275 from filipefurtad0/update_orders_spec

Updates system spec for orders page
This commit is contained in:
Filipe
2023-01-23 16:00:38 +00:00
committed by GitHub
3 changed files with 228 additions and 56 deletions

View File

@@ -3574,6 +3574,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
server_error: "Server error"
shipping_method_names:
UPS Ground: "UPS Ground"
pick_up: "Pick-up at the farm"
delivery: "Signed, sealed, delivered"
start_date: "Start date"
successfully_removed: "Successfully Removed"
taxonomy_edit: "Taxonomy edit"

View File

@@ -61,5 +61,7 @@ FactoryBot.define do
factory :distributor_enterprise_with_tax, parent: :distributor_enterprise do
charges_sales_tax { true }
allow_order_changes { true }
abn { "222333444" }
acn { "555666777" }
end
end

View File

@@ -9,12 +9,26 @@ describe '
include AuthenticationHelper
include WebHelper
let(:user) { create(:user) }
let(:owner) { create(:user) }
let(:owner2) { create(:user) }
let(:customer) { create(:user) }
let(:customer2) { create(:user) }
let(:customer3) { create(:user) }
let(:customer4) { create(:user) }
let(:customer5) { create(:user) }
let(:billing_address) { create(:address, :randomized) }
let(:billing_address2) { create(:address, :randomized) }
let(:billing_address3) { create(:address, :randomized) }
let(:billing_address4) { create(:address, :randomized) }
let(:billing_address5) { create(:address, :randomized) }
let(:product) { create(:simple_product) }
let(:distributor) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) }
let(:distributor2) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) }
let(:distributor3) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) }
let(:distributor4) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) }
let(:distributor) { create(:distributor_enterprise, owner: owner, with_payment_and_shipping: true, charges_sales_tax: true) }
let(:distributor2) { create(:distributor_enterprise_with_tax, owner: owner) }
let(:distributor3) { create(:distributor_enterprise, owner: owner, with_payment_and_shipping: true, charges_sales_tax: true) }
let(:distributor4) { create(:distributor_enterprise, owner: owner, with_payment_and_shipping: true, charges_sales_tax: true) }
let(:distributor5) { create(:distributor_enterprise, owner: owner2, charges_sales_tax: true) }
let!(:shipping_method) { create(:shipping_method_with, :pickup, name: "pick_up", distributors: [distributor, distributor2, distributor3]) }
let!(:shipping_method2) { create(:shipping_method_with, :pickup, name: "delivery", distributors: [distributor4, distributor5]) }
let(:order_cycle) do
create(:simple_order_cycle, name: 'One', distributors: [distributor, distributor2, distributor3, distributor4],
variants: [product.variants.first])
@@ -22,9 +36,10 @@ describe '
context "with a complete order" do
let(:order) do
create(:order_with_totals_and_distribution, user: user, distributor: distributor,
create(:order_with_totals_and_distribution, user: customer, distributor: distributor,
order_cycle: order_cycle,
state: 'complete', payment_state: 'balance_due')
state: 'complete', payment_state: 'balance_due',
bill_address_id: billing_address.id)
end
let!(:order_cycle2) {
@@ -36,69 +51,165 @@ describe '
let!(:order_cycle4) {
create(:simple_order_cycle, name: 'Four', orders_close_at: 4.weeks.from_now)
}
let!(:order_cycle5) do
create(:simple_order_cycle, name: 'Five', coordinator: distributor5, distributors: [distributor5],
variants: [product.variants.first])
end
let!(:order2) {
create(:order_with_credit_payment, user: user, distributor: distributor2,
order_cycle: order_cycle2, completed_at: 2.days.ago)
create(:order_ready_to_ship, user: customer2, distributor: distributor2,
order_cycle: order_cycle2, completed_at: 2.days.ago,
bill_address_id: billing_address2.id)
}
let!(:order3) {
create(:order_with_credit_payment, user: user, distributor: distributor3,
order_cycle: order_cycle3)
create(:order_with_credit_payment, user: customer3, distributor: distributor3,
order_cycle: order_cycle3,
bill_address_id: billing_address3.id)
}
let!(:order4) {
create(:order_with_credit_payment, user: user, distributor: distributor4,
order_cycle: order_cycle4)
create(:order_with_credit_payment, user: customer4, distributor: distributor4,
order_cycle: order_cycle4,
bill_address_id: billing_address4.id)
}
let!(:order5) {
create(:order_ready_to_ship, user: customer5, distributor: distributor5,
order_cycle: order_cycle5,)
}
it "order cycles appear in descending order by close date on orders page" do
login_as_admin_and_visit 'admin/orders'
context "logging as superadmin and visiting the orders page" do
before do
order2.select_shipping_method(shipping_method.id)
order4.select_shipping_method(shipping_method2.id)
login_as_admin_and_visit spree.admin_orders_path
end
open_select2('#s2id_q_order_cycle_id_in')
it "order cycles appear in descending order by close date on orders page" do
open_select2('#s2id_q_order_cycle_id_in')
expect(find('#q_order_cycle_id_in',
visible: :all)[:innerHTML]).to have_content(/.*Four.*Three.*Two/m)
end
expect(find('#q_order_cycle_id_in',
visible: :all)[:innerHTML]).to have_content(/.*Four.*Three.*Two.*Five/m)
end
it "filter by multiple order cycles" do
login_as_admin_and_visit 'admin/orders'
it "filter by multiple order cycles" do
select2_select 'Two', from: 'q_order_cycle_id_in'
select2_select 'Three', from: 'q_order_cycle_id_in'
select2_select 'Two', from: 'q_order_cycle_id_in'
select2_select 'Three', from: 'q_order_cycle_id_in'
page.find('.filter-actions .button.icon-search').click
page.find('.filter-actions .button.icon-search').click
# Order 2 and 3 should show, but not 4
expect(page).to have_content order2.number
expect(page).to have_content order3.number
expect(page).to_not have_content order4.number
end
# Order 2 and 3 should show, but not 4
expect(page).to have_content order2.number
expect(page).to have_content order3.number
expect(page).to_not have_content order4.number
end
it "filter by distributors" do
select2_select distributor2.name.to_s, from: 'q_distributor_id_in'
select2_select distributor4.name.to_s, from: 'q_distributor_id_in'
it "filter by distributors" do
login_as_admin_and_visit 'admin/orders'
page.find('.filter-actions .button.icon-search').click
select2_select distributor2.name.to_s, from: 'q_distributor_id_in'
select2_select distributor4.name.to_s, from: 'q_distributor_id_in'
# Order 2 and 4 should show, but not 3
expect(page).to have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to have_content order4.number
end
page.find('.filter-actions .button.icon-search').click
it "filter by complete date" do
find("input.datepicker").click
select_dates_from_daterangepicker(order3.completed_at.yesterday, order4.completed_at.tomorrow)
# Order 2 and 4 should show, but not 3
expect(page).to have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to have_content order4.number
end
page.find('.filter-actions .button.icon-search').click
it "filter by complete date" do
login_as_admin_and_visit 'admin/orders'
# Order 3 and 4 should show, but not 2
expect(page).to_not have_content order2.number
expect(page).to have_content order3.number
expect(page).to have_content order4.number
end
find("input.datepicker").click
select_dates_from_daterangepicker(order3.completed_at.yesterday, order4.completed_at.tomorrow)
it "filter by email" do
fill_in "Email", with: customer3.email
page.find('.filter-actions .button.icon-search').click
page.find('.filter-actions .button.icon-search').click
# Order 3 and 4 should show, but not 2
expect(page).to_not have_content order2.number
expect(page).to have_content order3.number
expect(page).to have_content order4.number
# Order 3 should show, but not 2 and 4
expect(page).to_not have_content order2.number
expect(page).to have_content order3.number
expect(page).to_not have_content order4.number
end
it "filter by customer first and last names" do
# NOTE: this field refers to the name given in billing addresses and not to customer name
# filtering by first name
fill_in "First name begins with", with: billing_address2.firstname
page.find('.filter-actions .button.icon-search').click
# Order 3 should show, but not 2 and 4
expect(page).to have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to_not have_content order4.number
find("a#clear_filters_button").click
# filtering by last name
fill_in "Last name begins with", with: billing_address4.lastname
page.find('.filter-actions .button.icon-search').click
# Order 4 should show, but not 2 and 3
expect(page).to_not have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to have_content order4.number
end
it "filter by shipping methods" do
select2_select "Pick-up at the farm", from: 'q_shipping_method_id'
page.find('.filter-actions .button.icon-search').click
# Order 2 should show, but not 3 and 5
expect(page).to have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to_not have_content order4.number
find("a#clear_filters_button").click
select2_select "Signed, sealed, delivered", from: 'q_shipping_method_id'
page.find('.filter-actions .button.icon-search').click
# Order 4 should show, but not 2 and 3
expect(page).to_not have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to have_content order4.number
end
it "filter by invoice number" do
fill_in "Invoice number:", with: order2.number
page.find('.filter-actions .button.icon-search').click
# Order 2 should show, but not 3 and 4
expect(page).to have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to_not have_content order4.number
end
it "filter by order state" do
order.update(state: "payment")
uncheck 'Only show complete orders'
page.find('.filter-actions .button.icon-search').click
expect(page).to have_content order.number
expect(page).to have_content order2.number
expect(page).to have_content order3.number
expect(page).to have_content order4.number
expect(page).to have_content order5.number
select2_select "payment", from: 'q_state_eq'
page.find('.filter-actions .button.icon-search').click
# Order 2 should show, but not 3 and 4
expect(page).to have_content order.number
expect(page).to_not have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to_not have_content order4.number
expect(page).to_not have_content order5.number
end
end
context "select/unselect all orders" do
@@ -146,20 +257,77 @@ describe '
expect(page).to have_content "Confirmation emails sent for 2 orders."
end
it "can bulk print invoices from 2 orders" do
login_as_admin_and_visit spree.admin_orders_path
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
page.find("#listing_orders tbody tr:nth-child(2) input[name='order_ids[]']").click
page.find("span.icon-reorder", text: "ACTIONS").click
within ".ofn-drop-down-with-prepend .menu" do
page.find("span", text: "Print Invoices").click
end
expect(page).to have_content "Compiling Invoices"
expect(page).to have_content "Please wait until the PDF is ready before closing this modal."
# an error 422 is generated in the console
end
it "can bulk cancel 2 orders" do
login_as_admin_and_visit spree.admin_orders_path
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
page.find("#listing_orders tbody tr:nth-child(2) input[name='order_ids[]']").click
page.find("span.icon-reorder", text: "ACTIONS").click
within ".ofn-drop-down-with-prepend .menu" do
page.find("span", text: "Cancel Orders").click
end
expect(page).to have_content "Are you sure you want to proceed?"
expect(page).to have_content "This will cancel the current order."
within "#custom-confirm.modal" do
expect {
find_button("Cancel").click # Cancels the cancel action
}.to_not enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice)
end
page.find("span.icon-reorder", text: "ACTIONS").click
within ".ofn-drop-down-with-prepend .menu" do
page.find("span", text: "Cancel Orders").click
end
within "#custom-confirm.modal" do
expect {
find_button("OK").click # Confirms the cancel action
}.to_not enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice)
end
expect(page).to have_content("CANCELLED", count: 2)
end
context "for a hub manager" do
before do
login_to_admin_as user
login_to_admin_as owner2
visit spree.admin_orders_path
end
it "cannnot send emails to orders if permission have been revoked in the meantime" do
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
it "displays the orders for the respective distributor" do
expect(page).to have_content order5.number # displays the only order for distributor5
expect(page).not_to have_content order.number
expect(page).not_to have_content order2.number
expect(page).not_to have_content order3.number
expect(page).not_to have_content order4.number
end
it "cannot send emails to orders if permission have been revoked in the meantime" do
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
# Find the clicked order
order = Spree::Order.find_by(id: page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").value)
# Revoke permission for the current user on that specific order by changing its owners
order.update_attribute(:created_by, create(:user))
order.update_attribute(:distributor, create(:distributor_enterprise))
order.update_attribute(:distributor, distributor)
order.update_attribute(:order_cycle, order_cycle)
page.find("span.icon-reorder", text: "ACTIONS").click
within ".ofn-drop-down-with-prepend .menu" do
@@ -237,7 +405,7 @@ describe '
:order_with_line_items,
distributor: distributor,
order_cycle: order_cycle,
user: user,
user: customer,
state: 'complete',
payment_state: 'balance_due',
completed_at: 1.day.ago,
@@ -248,7 +416,7 @@ describe '
:order_with_line_items,
distributor: distributor,
order_cycle: order_cycle,
user: user,
user: customer,
state: 'complete',
payment_state: 'balance_due',
completed_at: 1.day.ago,
@@ -272,7 +440,7 @@ describe '
end
end
context "save the filter params", js: true do
context "save the filter params" do
let!(:shipping_method) { create(:shipping_method, name: "UPS Ground") }
let!(:user) { create(:user, email: 'an@email.com') }
let!(:order) do