From 35dfdc8bdc362a3040a4ebe84bc9862a552b1ba2 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 19 Jul 2023 20:04:10 +0100 Subject: [PATCH 1/2] Adds coverage on Invoice tab which should be visible as a function of the order state Corrects cancelled case --- spec/system/admin/order_spec.rb | 90 +++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index 526a3429ac..cec4aac267 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -1004,4 +1004,94 @@ describe ' end end end + + describe "Legal Invoices" do + before do + Flipper.enable(:invoices) + login_as user + end + + describe "for order states" do + context "complete" do + let!(:order1) { + create(:order_with_totals_and_distribution, user: user, distributor:, + order_cycle: order_cycle, state: 'complete', + payment_state: 'balance_due') + } + before do + visit spree.edit_admin_order_path(order1) + end + + it "displays the invoice tab" do + expect(page).to have_content "Complete".upcase + expect(page).to have_content "Invoices".upcase + end + end + + context "resumed" do + let!(:order2) { + create(:order_with_totals_and_distribution, user: user, distributor:, + order_cycle: order_cycle, state: 'resumed', + payment_state: 'balance_due') + } + before do + visit spree.edit_admin_order_path(order2) + end + + it "displays the invoice tab" do + expect(page).to have_content "Resumed".upcase + expect(page).to have_content "Invoices".upcase + end + end + + context "canceled" do + let!(:order3) { + create(:order_with_totals_and_distribution, user: user, distributor:, + order_cycle: order_cycle, state: 'canceled', + payment_state: 'balance_due') + } + before do + visit spree.edit_admin_order_path(order3) + end + + it "displays the invoice tab" do + expect(page).to have_content "Cancelled".upcase + expect(page).to have_content "Invoices".upcase + end + end + + context "cart" do + let!(:order_empty) { + create(:order_with_line_items, user: user, distributor:, order_cycle: order_cycle, + line_items_count: 0) + } + before do + visit spree.edit_admin_order_path(order_empty) + end + + it "displays the invoice tab" do + pending "issue #11240" + expect(page).to have_content "Cart".upcase + expect(page).not_to have_content "Invoices".upcase + end + end + + context "payment" do + let!(:order4) do + create(:order_ready_for_payment, user: user, distributor: distributor, + order_cycle: order_cycle, + payment_state: 'balance_due') + end + before do + visit spree.edit_admin_order_path(order4) + end + + it "displays the invoice tab" do + pending "issue #11240" + expect(page).to have_content "Payment".upcase + expect(page).not_to have_content "Invoices".upcase + end + end + end + end end From 98f29dcd9bf0b08d60ad62548e601cf268cc1023 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 27 Jul 2023 17:27:41 +0100 Subject: [PATCH 2/2] Adds coverage on invoices section/table --- spec/system/admin/order_spec.rb | 66 ++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index cec4aac267..37b0043c00 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -1016,15 +1016,69 @@ describe ' let!(:order1) { create(:order_with_totals_and_distribution, user: user, distributor:, order_cycle: order_cycle, state: 'complete', - payment_state: 'balance_due') + payment_state: 'balance_due', + customer_id: customer.id) } - before do - visit spree.edit_admin_order_path(order1) + + context "editing the order" do + before do + visit spree.edit_admin_order_path(order1) + end + + it "displays the invoice tab" do + expect(page).to have_content "Complete".upcase + expect(page).to have_content "Invoices".upcase + end end - it "displays the invoice tab" do - expect(page).to have_content "Complete".upcase - expect(page).to have_content "Invoices".upcase + context "visiting the invoices tab" do + let!(:table_header) { + [ + "Date/Time", + "Invoice Number", + "Amount", + "Status", + "File", + ].join(" ").upcase + } + + let(:table_contents) { + [ + Invoice.first.created_at.strftime('%B %d, %Y 12:00 AM').to_s, + "1", + "0.0", + "Active", + "Download" + ].join(" ") + } + let(:download_href) { + "#{spree.print_admin_order_path(order1)}?invoice_id=#{Invoice.last.id}" + } + + before do + visit spree.admin_order_invoices_path(order1) + end + + it "displays the invoices table" do + # with no invoices, only the table header is displayed + expect(page).to have_css "table.index" + expect(page).to have_content "#{customer.first_name} #{customer.last_name} -" + expect(page.find("table").text).to have_content(table_header) + + # the New invoice button should be visible + expect(page).to have_link "New Invoice" + click_link 'New Invoice' + + # and disappear after clicking + expect(page).to have_no_link "New Invoice" + + # creating an invoice, displays a second row + expect(page.find("table").text).to have_content(table_contents) + + # with a valid invoice download link + expect(page).to have_link("Download", + href: download_href) + end end end