mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Reworking the JS specs
This commit is contained in:
@@ -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