mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Tweaks for laura, reworking authentication workflow, tidying up checkout
This commit is contained in:
@@ -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]
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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-
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
= render partial: "checkout/payment", locals: {f: f}
|
||||
|
||||
%input.button.primary{type: :submit, value: "Place order now", "ng-show" => "checkout.$valid"}
|
||||
|
||||
@@ -16,4 +16,6 @@
|
||||
.small-3.columns
|
||||
= render partial: "checkout/summary"
|
||||
|
||||
= render partial: "shared/footer"
|
||||
|
||||
= render partial: "shared/footer"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
.columns.small-4
|
||||
%strong Shop for
|
||||
%p.trans-sentence
|
||||
{{ producer.taxons | printArray }}
|
||||
{{ producer.taxons | printArrayOfObjects }}
|
||||
.columns.small-8
|
||||
About Us
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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?"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
9
spec/support/request/checkout_workflow.rb
Normal file
9
spec/support/request/checkout_workflow.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user