mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Cart item total reflects total number of items in the cart
This commit is contained in:
@@ -43,6 +43,11 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http)->
|
||||
@line_items.filter (li)->
|
||||
li.quantity > 0
|
||||
|
||||
total_item_count: =>
|
||||
@line_items_present().reduce (sum,li) ->
|
||||
sum = sum + li.quantity
|
||||
, 0
|
||||
|
||||
empty: =>
|
||||
@line_items_present().length == 0
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
%span.nav-branded
|
||||
%i.ofn-i_027-shopping-cart
|
||||
%span
|
||||
{{ Cart.line_items_present().length }}
|
||||
{{ Cart.total_item_count() }}
|
||||
items
|
||||
|
||||
.joyride-tip-guide{"ng-class" => "{ in: open }", "ng-show" => "open"}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
describe 'Cart service', ->
|
||||
Cart = null
|
||||
Variants = null
|
||||
variant = {id: 1}
|
||||
order = {
|
||||
line_items: [
|
||||
variant: variant
|
||||
]
|
||||
}
|
||||
variant = null
|
||||
order = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
variant = {id: 1}
|
||||
order = {
|
||||
line_items: [
|
||||
variant: variant
|
||||
]
|
||||
}
|
||||
angular.module('Darkswarm').value('currentOrder', order)
|
||||
inject ($injector)->
|
||||
Variants = $injector.get("Variants")
|
||||
@@ -23,10 +25,15 @@ describe 'Cart service', ->
|
||||
|
||||
it "creates and backreferences new line items if necessary", ->
|
||||
Cart.register_variant(v2 = {id: 2})
|
||||
expect(Cart.line_items[1].variant).toBe v2
|
||||
expect(Cart.line_items[1].variant.line_item).toBe Cart.line_items[1]
|
||||
expect(Cart.line_items[1].variant).toBe v2
|
||||
expect(Cart.line_items[1].variant.line_item).toBe Cart.line_items[1]
|
||||
|
||||
it "returns a list of items actually in the cart", ->
|
||||
expect(Cart.line_items_present()).toEqual []
|
||||
order.line_items[0].quantity = 1
|
||||
expect(Cart.line_items_present().length).toEqual 1
|
||||
expect(Cart.line_items_present().length).toEqual
|
||||
|
||||
it "sums the quantity of each line item for cart total", ->
|
||||
expect(Cart.line_items_present()).toEqual []
|
||||
order.line_items[0].quantity = 2
|
||||
expect(Cart.total_item_count()).toEqual 2
|
||||
|
||||
Reference in New Issue
Block a user