mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Reworking the JS specs
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
Darkswarm.controller "ProductNodeCtrl", ($scope) ->
|
||||
|
||||
$scope.price = ->
|
||||
if $scope.product.variants.length > 0
|
||||
prices = (v.price for v in $scope.product.variants)
|
||||
|
||||
@@ -12,5 +12,3 @@ Darkswarm.controller "ProductsCtrl", ($scope, $rootScope, Product, OrderCycle) -
|
||||
code = e.keyCode || e.which
|
||||
if code == 13
|
||||
e.preventDefault()
|
||||
|
||||
$scope.productPrice = (product) ->
|
||||
|
||||
@@ -2,6 +2,9 @@ Darkswarm.factory 'Product', ($resource) ->
|
||||
new class Product
|
||||
constructor: ->
|
||||
@update()
|
||||
|
||||
# TODO: don't need to scope this into object
|
||||
# Already on object as far as controller scope is concerned
|
||||
data:
|
||||
products: null
|
||||
loading: true
|
||||
|
||||
@@ -19,14 +19,3 @@ describe "HubNodeCtrl", ->
|
||||
expect(scope.current()).toEqual false
|
||||
scope.hub = {id: 99}
|
||||
expect(scope.current()).toEqual true
|
||||
|
||||
it "knows whether selecting this hub will empty the cart", ->
|
||||
CurrentHub.id = undefined
|
||||
expect(scope.emptiesCart()).toEqual false
|
||||
|
||||
CurrentHub.id = 99
|
||||
scope.hub.id = 99
|
||||
expect(scope.emptiesCart()).toEqual false
|
||||
|
||||
scope.hub.id = 1
|
||||
expect(scope.emptiesCart()).toEqual true
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
describe "ProductNodeCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
product =
|
||||
id: 99
|
||||
price: 10.00
|
||||
variants: []
|
||||
|
||||
beforeEach ->
|
||||
module('Darkswarm')
|
||||
inject ($controller) ->
|
||||
scope =
|
||||
product: product
|
||||
ctrl = $controller 'ProductNodeCtrl', {$scope: scope}
|
||||
|
||||
describe "determining the price to display for a product", ->
|
||||
it "displays the product price when the product does not have variants", ->
|
||||
expect(scope.price()).toEqual 10.00
|
||||
|
||||
it "displays the minimum variant price when the product has variants", ->
|
||||
scope.product =
|
||||
price: 11
|
||||
variants: [{price: 22}, {price: 33}]
|
||||
expect(scope.price()).toEqual 22
|
||||
@@ -1,47 +1,21 @@
|
||||
describe 'All controllers', ->
|
||||
describe 'ProductsCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
Product = null
|
||||
describe 'ProductsCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
Product = null
|
||||
|
||||
beforeEach ->
|
||||
module('Darkswarm')
|
||||
Product =
|
||||
all: ->
|
||||
update: ->
|
||||
data: "testy mctest"
|
||||
OrderCycle =
|
||||
order_cycle: {}
|
||||
|
||||
inject ($controller) ->
|
||||
scope = {}
|
||||
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product: Product, OrderCycle: OrderCycle}
|
||||
|
||||
it 'fetches products from Product', ->
|
||||
expect(scope.data).toEqual 'testy mctest'
|
||||
|
||||
describe "determining the price to display for a product", ->
|
||||
it "displays the product price when the product does not have variants", ->
|
||||
product = {variants: [], price: 12.34}
|
||||
expect(scope.productPrice(product)).toEqual 12.34
|
||||
|
||||
it "displays the minimum variant price when the product has variants", ->
|
||||
product =
|
||||
price: 11
|
||||
variants: [{price: 22}, {price: 33}]
|
||||
expect(scope.productPrice(product)).toEqual 22
|
||||
|
||||
describe 'OrderCycleCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
product_ctrl = null
|
||||
OrderCycle = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
beforeEach ->
|
||||
module('Darkswarm')
|
||||
Product =
|
||||
all: ->
|
||||
update: ->
|
||||
data: "testy mctest"
|
||||
OrderCycle =
|
||||
order_cycle: {}
|
||||
|
||||
inject ($controller) ->
|
||||
scope = {}
|
||||
inject ($controller) ->
|
||||
scope = {}
|
||||
ctrl = $controller 'OrderCycleCtrl', {$scope: scope}
|
||||
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product: Product, OrderCycle: OrderCycle}
|
||||
|
||||
it 'fetches products from Product', ->
|
||||
expect(scope.data).toEqual 'testy mctest'
|
||||
|
||||
@@ -26,8 +26,10 @@ describe 'Order service', ->
|
||||
}
|
||||
angular.module('Darkswarm').value('order', orderData)
|
||||
module 'Darkswarm'
|
||||
|
||||
inject ($injector, _$httpBackend_)->
|
||||
$httpBackend = _$httpBackend_
|
||||
$httpBackend.expectGET("/shop/products").respond 200, []
|
||||
Order = $injector.get("Order")
|
||||
Navigation = $injector.get("Navigation")
|
||||
flash = $injector.get("flash")
|
||||
|
||||
@@ -10,5 +10,5 @@ describe 'Product service', ->
|
||||
|
||||
it "Fetches products from the backend on init", ->
|
||||
$httpBackend.expectGET("/shop/products").respond([{test : "cats"}])
|
||||
products = Product.all()
|
||||
$httpBackend.flush()
|
||||
expect(Product.data.products[0].test).toEqual "cats"
|
||||
Reference in New Issue
Block a user