From f618ef1201881bafb026327d569640c0aefafaf6 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 5 Apr 2024 14:46:52 +0100 Subject: [PATCH 1/2] Adds regression spec for S2 bug #12340 --- spec/system/admin/orders_spec.rb | 47 +++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 9bcda2b2ee..bc6ed4df7a 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -445,7 +445,7 @@ describe ' within "tr#order_#{order3.id}" do expect(page).to have_content "Note" find(".icon-warning-sign").hover - expect(page).to have_content /#{order3.special_instructions}/i + expect(page).to have_content(/#{order3.special_instructions}/i) end end end @@ -662,17 +662,58 @@ describe ' end end + shared_examples "prints invoices accordering to column ordering" do + it "bulk prints invoices in pdf format" do + page.find("span.icon-reorder", text: "ACTIONS").click + within ".ofn-drop-down .menu" do + expect { + page.find("span", text: "Print Invoices").click # Prints invoices in bulk + }.to enqueue_job(BulkInvoiceJob).exactly(:once) + end + + expect(page).to have_content "Compiling Invoices" + expect(page).to have_content "Please wait until the PDF is ready " \ + "before closing this modal." + + perform_enqueued_jobs(only: BulkInvoiceJob) + + expect(page).to have_content "Bulk Invoice created" + + within ".modal-content" do + expect(page).to have_link(class: "button", text: "VIEW FILE", + href: /invoices/) + + invoice_content = extract_pdf_content + + surnames = [order2.name.gsub(/.* /, ""), order3.name.gsub(/.* /, ""), + order4.name.gsub(/.* /, ""), order5.name.gsub(/.* /, "")].sort + expect( + invoice_content + ).to match(/#{surnames[0]}.*#{surnames[1]}.*#{surnames[2]}.*#{surnames[3]}/m) + end + end + end + context "ABN is not required" do before do allow(Spree::Config).to receive(:enterprise_number_required_on_invoices?) .and_return false end + it_behaves_like "can bulk print invoices from 2 orders" context "with legal invoices feature", feature: :invoices do it_behaves_like "can bulk print invoices from 2 orders" end - + context "ordering by customer name" do + before do + pending("#12340") + page.find('a', text: "NAME").click # orders alphabetically (asc) + sleep(1) # waits for column sorting + page.find('#selectAll').click + end + it_behaves_like "prints invoices accordering to column ordering" + end context "one of the two orders is not invoiceable" do before do order4.cancel! @@ -684,7 +725,6 @@ describe ' end end end - context "ABN is required" do before do allow(Spree::Config).to receive(:enterprise_number_required_on_invoices?) @@ -747,7 +787,6 @@ describe ' end end end - it "can bulk cancel 2 orders" do page.find("#listing_orders tbody tr:nth-child(1) input[name='bulk_ids[]']").click page.find("#listing_orders tbody tr:nth-child(2) input[name='bulk_ids[]']").click From 8ad4f885a04297818ae8f290b4d3bb7e21cec09f Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 7 Apr 2024 17:15:12 +0100 Subject: [PATCH 2/2] Adds shared example for descending name ordering --- spec/system/admin/orders_spec.rb | 35 ++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index bc6ed4df7a..2a70eef01c 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -685,8 +685,6 @@ describe ' invoice_content = extract_pdf_content - surnames = [order2.name.gsub(/.* /, ""), order3.name.gsub(/.* /, ""), - order4.name.gsub(/.* /, ""), order5.name.gsub(/.* /, "")].sort expect( invoice_content ).to match(/#{surnames[0]}.*#{surnames[1]}.*#{surnames[2]}.*#{surnames[3]}/m) @@ -706,13 +704,34 @@ describe ' it_behaves_like "can bulk print invoices from 2 orders" end context "ordering by customer name" do - before do - pending("#12340") - page.find('a', text: "NAME").click # orders alphabetically (asc) - sleep(1) # waits for column sorting - page.find('#selectAll').click + context "ascending" do + let!(:surnames) { + [order2.name.gsub(/.* /, ""), order3.name.gsub(/.* /, ""), + order4.name.gsub(/.* /, ""), order5.name.gsub(/.* /, "")].sort + } + before do + pending("#12340") + page.find('a', text: "NAME").click # orders alphabetically (asc) + sleep(0.5) # waits for column sorting + page.find('#selectAll').click + end + it_behaves_like "prints invoices accordering to column ordering" + end + context "descending" do + let!(:surnames) { + [order2.name.gsub(/.* /, ""), order3.name.gsub(/.* /, ""), + order4.name.gsub(/.* /, ""), order5.name.gsub(/.* /, "")].sort.reverse + } + before do + pending("#12340") + page.find('a', text: "NAME").click # orders alphabetically (asc) + sleep(0.5) # waits for column sorting + page.find('a', text: "NAME").click # orders alphabetically (desc) + sleep(0.5) # waits for column sorting + page.find('#selectAll').click + end + it_behaves_like "prints invoices accordering to column ordering" end - it_behaves_like "prints invoices accordering to column ordering" end context "one of the two orders is not invoiceable" do before do