From 2a2d05ad391b5745ac835985e1728cf8ec928c9f Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 19 Jun 2019 15:03:36 +0100 Subject: [PATCH 1/2] First view spec in OFN testing the print invoice button display in the orders list page --- .../admin/orders/index.html.haml_spec.rb | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 spec/views/spree/admin/orders/index.html.haml_spec.rb diff --git a/spec/views/spree/admin/orders/index.html.haml_spec.rb b/spec/views/spree/admin/orders/index.html.haml_spec.rb new file mode 100644 index 0000000000..7b72128dd0 --- /dev/null +++ b/spec/views/spree/admin/orders/index.html.haml_spec.rb @@ -0,0 +1,33 @@ +require "spec_helper" + +describe "spree/admin/orders/index.html.haml" do + include AuthenticationWorkflow + + around do |example| + original_config = Spree::Config[:enable_invoices?] + example.run + Spree::Config[:enable_invoices?] = original_config + end + + before do + allow(view).to receive_messages spree_current_user: create_enterprise_user + end + + describe "print invoices button" do + it "displays button when invoices are enabled" do + Spree::Config[:enable_invoices?] = true + + render + + expect(rendered).to have_content("Print Invoices") + end + + it "does not display button when invoices are disabled" do + Spree::Config[:enable_invoices?] = false + + render + + expect(rendered).to_not have_content("Print Invoices") + end + end +end From a6655623d0ee8fd763dbd5c6b0f93fd79f3384c7 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Mon, 1 Jul 2019 21:39:07 +0100 Subject: [PATCH 2/2] New admin orders edit view spec and workaround (current_ability) to make view specs work --- .../spree/admin/orders/edit.html.haml_spec.rb | 38 +++++++++++++++++++ .../admin/orders/index.html.haml_spec.rb | 6 +++ 2 files changed, 44 insertions(+) create mode 100644 spec/views/spree/admin/orders/edit.html.haml_spec.rb diff --git a/spec/views/spree/admin/orders/edit.html.haml_spec.rb b/spec/views/spree/admin/orders/edit.html.haml_spec.rb new file mode 100644 index 0000000000..b33cd187ef --- /dev/null +++ b/spec/views/spree/admin/orders/edit.html.haml_spec.rb @@ -0,0 +1,38 @@ +require "spec_helper" + +describe "spree/admin/orders/edit.html.haml" do + include AuthenticationWorkflow + helper Spree::BaseHelper # required to make pretty_time work + + around do |example| + original_config = Spree::Config[:enable_invoices?] + example.run + Spree::Config[:enable_invoices?] = original_config + end + + before do + controller.singleton_class.class_eval do + def current_ability + Spree::Ability.new(Spree.user_class.new) + end + end + + allow(view).to receive_messages spree_current_user: create_enterprise_user + + order = create(:completed_order_with_fees) + order.distributor = create(:distributor_enterprise) + assign(:order, order) + assign(:shops, [order.distributor]) + assign(:order_cycles, []) + end + + describe "order values" do + it "displays order shipping costs, transaction fee and order total" do + render + + expect(rendered).to have_content("Shipping: UPS Ground $6.00") + expect(rendered).to have_content("Transaction fee: $10.00") + expect(rendered).to have_content("Order Total $36.00") + end + end +end diff --git a/spec/views/spree/admin/orders/index.html.haml_spec.rb b/spec/views/spree/admin/orders/index.html.haml_spec.rb index 7b72128dd0..8cbbfeb90a 100644 --- a/spec/views/spree/admin/orders/index.html.haml_spec.rb +++ b/spec/views/spree/admin/orders/index.html.haml_spec.rb @@ -10,6 +10,12 @@ describe "spree/admin/orders/index.html.haml" do end before do + controller.singleton_class.class_eval do + def current_ability + Spree::Ability.new(Spree.user_class.new) + end + end + allow(view).to receive_messages spree_current_user: create_enterprise_user end