mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #12353 from filipefurtad0/regression_spec_#12343_improvement
Improves regression spec after reviewer feedback
This commit is contained in:
@@ -574,16 +574,6 @@ describe '
|
||||
end
|
||||
|
||||
context "can bulk print invoices" do
|
||||
def extract_pdf_content
|
||||
# Extract last part of invoice URL
|
||||
link = page.find(class: "button", text: "VIEW FILE")
|
||||
filename = link[:href].match %r{/invoices/.*}
|
||||
|
||||
# Load invoice temp file directly instead of downloading
|
||||
reader = PDF::Reader.new("tmp/#{filename}.pdf")
|
||||
reader.pages.map(&:text)
|
||||
end
|
||||
|
||||
let(:order4_selector){ "#order_#{order4.id} input[name='bulk_ids[]']" }
|
||||
let(:order5_selector){ "#order_#{order5.id} input[name='bulk_ids[]']" }
|
||||
|
||||
@@ -662,36 +652,6 @@ 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
|
||||
|
||||
expect(
|
||||
invoice_content.join
|
||||
).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?)
|
||||
@@ -703,34 +663,7 @@ describe '
|
||||
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
|
||||
context "ascending" do
|
||||
let!(:surnames) {
|
||||
[order2.name.gsub(/.* /, ""), order3.name.gsub(/.* /, ""),
|
||||
order4.name.gsub(/.* /, ""), order5.name.gsub(/.* /, "")].sort
|
||||
}
|
||||
before do
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
context "one of the two orders is not invoiceable" do
|
||||
before do
|
||||
order4.cancel!
|
||||
@@ -741,6 +674,51 @@ describe '
|
||||
it_behaves_like "should ignore the non invoiceable order"
|
||||
end
|
||||
end
|
||||
|
||||
context "ordering by customer name" do
|
||||
context "ascending" do
|
||||
let!(:surnames) {
|
||||
[order2.name.gsub(/.* /, ""), order3.name.gsub(/.* /, ""),
|
||||
order4.name.gsub(/.* /, ""), order5.name.gsub(/.* /, "")].sort
|
||||
}
|
||||
it "orders by customer name ascending" do
|
||||
page.find('a', text: "NAME").click # orders alphabetically (asc)
|
||||
sleep(0.5) # waits for column sorting
|
||||
|
||||
page.find("#selectAll").click
|
||||
|
||||
print_all_invoices
|
||||
|
||||
invoice_content = extract_pdf_content
|
||||
|
||||
expect(
|
||||
invoice_content.join
|
||||
).to match(/#{surnames[0]}.*#{surnames[1]}.*#{surnames[2]}.*#{surnames[3]}/m)
|
||||
end
|
||||
end
|
||||
context "descending" do
|
||||
let!(:surnames) {
|
||||
[order2.name.gsub(/.* /, ""), order3.name.gsub(/.* /, ""),
|
||||
order4.name.gsub(/.* /, ""), order5.name.gsub(/.* /, "")].sort.reverse
|
||||
}
|
||||
it "order by customer name descending" do
|
||||
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
|
||||
|
||||
print_all_invoices
|
||||
|
||||
invoice_content = extract_pdf_content
|
||||
|
||||
expect(
|
||||
invoice_content.join
|
||||
).to match(/#{surnames[0]}.*#{surnames[1]}.*#{surnames[2]}.*#{surnames[3]}/m)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
context "ABN is required" do
|
||||
before do
|
||||
@@ -1153,4 +1131,30 @@ describe '
|
||||
expect(find("input.datepicker").value).to be_empty
|
||||
end
|
||||
end
|
||||
def extract_pdf_content
|
||||
# Extract last part of invoice URL
|
||||
link = page.find(class: "button", text: "VIEW FILE")
|
||||
filename = link[:href].match %r{/invoices/.*}
|
||||
|
||||
# Load invoice temp file directly instead of downloading
|
||||
reader = PDF::Reader.new("tmp/#{filename}.pdf")
|
||||
reader.pages.map(&:text)
|
||||
end
|
||||
|
||||
def print_all_invoices
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user