From f25617dde77f74599717ea58c562ccf803da659c Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 9 May 2014 15:41:18 +1000 Subject: [PATCH] Tweaks for laura, reworking authentication workflow, tidying up checkout --- .../checkout/billing_controller.js.coffee | 4 +++ .../checkout/details_controller.js.coffee | 9 ++++++ .../darkswarm/filters/print_array.js.coffee | 9 +++++- .../darkswarm/services/order.js.coffee | 4 +-- app/views/checkout/_authentication.html.haml | 2 +- app/views/checkout/_billing.html.haml | 4 +-- app/views/checkout/_details.html.haml | 5 +--- app/views/checkout/_form.html.haml | 9 ++++-- app/views/checkout/edit.html.haml | 4 ++- app/views/home/_fat.html.haml | 2 +- app/views/producers/_fat.html.haml | 2 +- .../admin/bulk_order_management_spec.rb | 10 +------ .../consumer/shopping/checkout_auth_spec.rb | 14 +++++---- .../consumer/shopping/checkout_spec.rb | 4 ++- .../darkswarm/services/order_spec.js.coffee | 29 ++++++++++--------- .../request/authentication_workflow.rb | 4 +-- spec/support/request/checkout_workflow.rb | 9 ++++++ 17 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 spec/support/request/checkout_workflow.rb diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee index 33b9ed9184..4dc4d8f88c 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee @@ -3,4 +3,8 @@ Darkswarm.controller "BillingCtrl", ($scope) -> $scope.name = "billing" $scope.nextPanel = "shipping" + $scope.summary = -> + [$scope.order.bill_address.address1, + $scope.order.bill_address.city, + $scope.order.bill_address.zipcode] diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee index dbf273e9e8..c9d559a0d0 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee @@ -3,6 +3,15 @@ Darkswarm.controller "DetailsCtrl", ($scope) -> $scope.name = "details" $scope.nextPanel = "billing" + $scope.summary = -> + [$scope.fullName(), + $scope.order.email, + $scope.order.bill_address.phone] + + $scope.fullName = -> + [$scope.order.bill_address.firstname ? null, + $scope.order.bill_address.lastname ? null].join(" ").trim() + #$scope.$watch -> #$scope.detailsValid() diff --git a/app/assets/javascripts/darkswarm/filters/print_array.js.coffee b/app/assets/javascripts/darkswarm/filters/print_array.js.coffee index 344eeac144..3ff940ded2 100644 --- a/app/assets/javascripts/darkswarm/filters/print_array.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/print_array.js.coffee @@ -1,6 +1,13 @@ -Darkswarm.filter "printArray", -> +Darkswarm.filter "printArrayOfObjects", -> (array, attr = 'name')-> array ?= [] array.map (a)-> a[attr].toLowerCase() .join(", ") + +Darkswarm.filter "printArray", -> + (array)-> + array ?= [] + output = (item for item in array when item).join ", " + output + diff --git a/app/assets/javascripts/darkswarm/services/order.js.coffee b/app/assets/javascripts/darkswarm/services/order.js.coffee index 63ea6ee6c7..2357fd42da 100644 --- a/app/assets/javascripts/darkswarm/services/order.js.coffee +++ b/app/assets/javascripts/darkswarm/services/order.js.coffee @@ -4,8 +4,6 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http, CheckoutFormState, constructor: -> @order = order - # Default to first shipping method if none selected - @order.shipping_method_id ||= parseInt(Object.keys(@order.shipping_methods)[0]) submit: -> $http.put('/checkout', {order: @preprocess()}).success (data, status)=> @@ -35,7 +33,7 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http, CheckoutFormState, munged_order shippingMethod: -> - @order.shipping_methods[@order.shipping_method_id] + @order.shipping_methods[@order.shipping_method_id] if @order.shipping_method_id requireShipAddress: -> @shippingMethod()?.require_ship_address diff --git a/app/views/checkout/_authentication.html.haml b/app/views/checkout/_authentication.html.haml index e89e6d87ac..723028df3a 100644 --- a/app/views/checkout/_authentication.html.haml +++ b/app/views/checkout/_authentication.html.haml @@ -3,7 +3,7 @@ .small-12.columns.text-center{"ng-controller" => "AuthenticationCtrl"} %h3.pad-top Ok, ready to checkout? .row - .small-5.columns.text-center.pad-top + .small-5.columns.text-center.pad-top{"ng-controller" => "AuthenticationCtrl"} %button.primary.expand{"ng-click" => "open()"} Log in .small-2.columns.text-center %p.pad-top -OR- diff --git a/app/views/checkout/_billing.html.haml b/app/views/checkout/_billing.html.haml index 97f55655a2..dc48eadbe2 100644 --- a/app/views/checkout/_billing.html.haml +++ b/app/views/checkout/_billing.html.haml @@ -16,9 +16,7 @@ .small-11.columns %em %small - {{ order.bill_address.address1 }}, - {{ order.bill_address.city }} - {{ order.bill_address.zipcode }} + {{ summary() | printArray }} .small-1.columns.right %span.accordion-up.right %i.fi-arrow-up diff --git a/app/views/checkout/_details.html.haml b/app/views/checkout/_details.html.haml index 9785b159b0..76c5c32398 100644 --- a/app/views/checkout/_details.html.haml +++ b/app/views/checkout/_details.html.haml @@ -16,10 +16,7 @@ .small-11.columns %em %small - {{ order.bill_address.firstname }} - {{ order.bill_address.lastname }}, - {{ order.email }}, - {{ order.bill_address.phone }} + {{ summary() | printArray }} .small-1.columns.right %span.accordion-up.right %i.fi-arrow-up diff --git a/app/views/checkout/_form.html.haml b/app/views/checkout/_form.html.haml index d2e65d6cb4..74673342df 100644 --- a/app/views/checkout/_form.html.haml +++ b/app/views/checkout/_form.html.haml @@ -11,8 +11,13 @@ -#{{ Order.order == order }} .small-12.columns - %h3.text-center.pad-top Checkout from !hub_name! + %h3.text-center.pad-top + Checkout from + = current_distributor.name + = render partial: "checkout/details", locals: {f: f} = render partial: "checkout/billing", locals: {f: f} = render partial: "checkout/shipping", locals: {f: f} - = render partial: "checkout/payment", locals: {f: f} \ No newline at end of file + = render partial: "checkout/payment", locals: {f: f} + + %input.button.primary{type: :submit, value: "Place order now", "ng-show" => "checkout.$valid"} diff --git a/app/views/checkout/edit.html.haml b/app/views/checkout/edit.html.haml index ab263e614c..ee5fdb7b52 100644 --- a/app/views/checkout/edit.html.haml +++ b/app/views/checkout/edit.html.haml @@ -16,4 +16,6 @@ .small-3.columns = render partial: "checkout/summary" -= render partial: "shared/footer" \ No newline at end of file + += render partial: "shared/footer" + diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml index 7a0af31130..86ef92cfdd 100644 --- a/app/views/home/_fat.html.haml +++ b/app/views/home/_fat.html.haml @@ -2,7 +2,7 @@ .columns.small-4 %strong Shop for %p.trans-sentence - {{ hub.taxons | printArray }} + {{ hub.taxons | printArrayOfObjects }} .columns.small-4 %strong Delivery options %ol diff --git a/app/views/producers/_fat.html.haml b/app/views/producers/_fat.html.haml index d0108680ce..ba1c8889b3 100644 --- a/app/views/producers/_fat.html.haml +++ b/app/views/producers/_fat.html.haml @@ -2,7 +2,7 @@ .columns.small-4 %strong Shop for %p.trans-sentence - {{ producer.taxons | printArray }} + {{ producer.taxons | printArrayOfObjects }} .columns.small-8 About Us diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb index 44e8d58a59..79981bbd16 100644 --- a/spec/features/admin/bulk_order_management_spec.rb +++ b/spec/features/admin/bulk_order_management_spec.rb @@ -7,13 +7,12 @@ feature %q{ include AuthenticationWorkflow include AuthorizationHelpers include WebHelper - + after { Warden.test_reset! } stub_authorization! context "listing orders" do before :each do admin_user = quick_login_as_admin - Spree::Admin::OrdersController.any_instance.stub(:spree_current_user).and_return admin_user end it "displays a Bulk Management Tab under the Orders item" do @@ -102,10 +101,7 @@ feature %q{ context "altering line item properties" do before :each do - #login_to_admin_section - #quick_login_as_admin admin_user = quick_login_as_admin - Spree::Admin::OrdersController.any_instance.stub(:spree_current_user).and_return admin_user end context "tracking changes" do @@ -153,10 +149,7 @@ feature %q{ context "using page controls" do before :each do - #login_to_admin_section - #quick_login_as_admin admin_user = quick_login_as_admin - Spree::Admin::OrdersController.any_instance.stub(:spree_current_user).and_return admin_user end let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) } @@ -590,7 +583,6 @@ feature %q{ @enterprise_user.enterprise_roles.build(enterprise: s1).save @enterprise_user.enterprise_roles.build(enterprise: d1).save - Spree::Admin::OrdersController.any_instance.stub(:spree_current_user).and_return @enterprise_user quick_login_as @enterprise_user end diff --git a/spec/features/consumer/shopping/checkout_auth_spec.rb b/spec/features/consumer/shopping/checkout_auth_spec.rb index b9589f75fd..09dd93e6c9 100644 --- a/spec/features/consumer/shopping/checkout_auth_spec.rb +++ b/spec/features/consumer/shopping/checkout_auth_spec.rb @@ -4,6 +4,7 @@ feature "As a consumer I want to check out my cart", js: true do include AuthenticationWorkflow include WebHelper include ShopWorkflow + include CheckoutWorkflow include UIComponentHelper let(:distributor) { create(:distributor_enterprise) } @@ -12,6 +13,7 @@ feature "As a consumer I want to check out my cart", js: true do let(:product) { create(:simple_product, supplier: supplier) } let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) } let(:user) { create_enterprise_user } + after { Warden.test_reset! } before do set_order order @@ -22,24 +24,24 @@ feature "As a consumer I want to check out my cart", js: true do quick_login_as user visit checkout_path within "section[role='main']" do - page.should_not have_content "Login" - page.should have_content "Customer Details" + page.should_not have_content "Log in" + page.should have_checkout_details end end it "renders the login buttons when logged out" do visit checkout_path within "section[role='main']" do - page.should have_content "Login" - click_button "Login" + page.should have_content "Log in" + click_button "Log in" end - page.should have_content "Remember Me" + page.should have_login_modal end it "allows user to checkout as guest" do visit checkout_path click_button "Checkout as guest" - page.should have_content "Customer Details" + page.should have_checkout_details end end diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index adb6071784..13291dc4ca 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' feature "As a consumer I want to check out my cart", js: true do include AuthenticationWorkflow include ShopWorkflow + include CheckoutWorkflow include WebHelper include UIComponentHelper @@ -45,7 +46,8 @@ feature "As a consumer I want to check out my cart", js: true do context "When shipping method requires an address" do before do toggle_accordion "Shipping" - find(:radio_button, sm1.name, {}).trigger "click" + #find(:radio_button, sm1.name, {}).trigger "click" + choose sm1.name end it "shows ship address forms when 'same as billing address' is unchecked" do uncheck "Shipping address same as billing address?" diff --git a/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee index fa06ead17f..0462e92952 100644 --- a/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/order_spec.js.coffee @@ -34,23 +34,24 @@ describe 'Order service', -> CheckoutFormState = $injector.get("CheckoutFormState") spyOn(Navigation, "go") # Stubbing out writes to window.location - it "defaults the shipping method to the first", -> - expect(Order.order.shipping_method_id).toEqual 7 - expect(Order.shippingMethod()).toEqual { require_ship_address : true, price : 0 } + it "defaults to no shipping method", -> + expect(Order.order.shipping_method_id).toEqual null + expect(Order.shippingMethod()).toEqual undefined - # This is now handled via localStorage defaults - xit "defaults to 'same as billing' for address", -> - expect(Order.order.ship_address_same_as_billing).toEqual true - it 'Tracks whether a ship address is required', -> - expect(Order.requireShipAddress()).toEqual true - Order.order.shipping_method_id = 25 - expect(Order.requireShipAddress()).toEqual false + describe "with shipping method", -> + beforeEach -> + Order.order.shipping_method_id = 7 - it 'Gets the current shipping price', -> - expect(Order.shippingPrice()).toEqual 0.0 - Order.order.shipping_method_id = 25 - expect(Order.shippingPrice()).toEqual 13 + it 'Tracks whether a ship address is required', -> + expect(Order.requireShipAddress()).toEqual true + Order.order.shipping_method_id = 25 + expect(Order.requireShipAddress()).toEqual false + + it 'Gets the current shipping price', -> + expect(Order.shippingPrice()).toEqual 0.0 + Order.order.shipping_method_id = 25 + expect(Order.shippingPrice()).toEqual 13 it 'Gets the current payment method', -> expect(Order.paymentMethod()).toEqual null diff --git a/spec/support/request/authentication_workflow.rb b/spec/support/request/authentication_workflow.rb index da02535646..e26932bfef 100644 --- a/spec/support/request/authentication_workflow.rb +++ b/spec/support/request/authentication_workflow.rb @@ -1,7 +1,7 @@ module AuthenticationWorkflow + include Warden::Test::Helpers def quick_login_as(user) - ApplicationController.any_instance.stub(:spree_current_user).and_return user - ApplicationController.any_instance.stub(:current_api_user).and_return user + login_as user end def quick_login_as_admin diff --git a/spec/support/request/checkout_workflow.rb b/spec/support/request/checkout_workflow.rb new file mode 100644 index 0000000000..3cb5d1e22e --- /dev/null +++ b/spec/support/request/checkout_workflow.rb @@ -0,0 +1,9 @@ +module CheckoutWorkflow + def have_checkout_details + have_content "Customer details" + end + + def toggle_accordion(name) + find("dd a", text: name).trigger "click" + end +end