Adding product property filter to shop page

This commit is contained in:
Rob Harrington
2015-03-06 11:22:52 +11:00
parent 55b8918ea1
commit 06f10398da
12 changed files with 105 additions and 50 deletions

View File

@@ -4,19 +4,23 @@ describe 'ProductsCtrl', ->
event = null
Products = null
Cart = {}
Taxons = null
beforeEach ->
module('Darkswarm')
Products =
Products =
all: ->
update: ->
products: ["testy mctest"]
loading: false
OrderCycle =
order_cycle: {}
inject ($controller) ->
scope = {}
ctrl = $controller 'ProductsCtrl', {$scope: scope, Products: Products, OrderCycle: OrderCycle, Cart: Cart}
Taxons:
taxons: []
inject ($rootScope, $controller) ->
scope = $rootScope
ctrl = $controller 'ProductsCtrl', {$scope: scope, Products: Products, OrderCycle: OrderCycle, Cart: Cart, Taxons: Taxons}
it 'fetches products from Products', ->
expect(scope.Products.products).toEqual ['testy mctest']

View File

@@ -4,13 +4,15 @@ describe 'Products service', ->
Enterprises = null
Variants = null
Cart = null
CurrentHubMock = {}
CurrentHubMock = {}
currentOrder = null
product = null
productWithImage = null
properties = null
taxons = null
beforeEach ->
product =
product =
test: "cats"
supplier:
id: 9
@@ -27,16 +29,23 @@ describe 'Products service', ->
]
currentOrder =
line_items: []
properties =
{ id: 1, name: "some property" }
taxons =
{ id: 2, name: "some taxon" }
module 'Darkswarm'
module ($provide)->
$provide.value "CurrentHub", CurrentHubMock
$provide.value "currentOrder", currentOrder
$provide.value "CurrentHub", CurrentHubMock
$provide.value "currentOrder", currentOrder
$provide.value "taxons", taxons
$provide.value "properties", properties
null
inject ($injector, _$httpBackend_)->
Products = $injector.get("Products")
Enterprises = $injector.get("Enterprises")
Properties = $injector.get("Properties")
Variants = $injector.get("Variants")
Cart = $injector.get("Cart")
$httpBackend = _$httpBackend_
@@ -44,20 +53,32 @@ describe 'Products service', ->
it "Fetches products from the backend on init", ->
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].test).toEqual "cats"
expect(Products.products[0].test).toEqual "cats"
it "dereferences suppliers", ->
Enterprises.enterprises_by_id =
Enterprises.enterprises_by_id =
{id: 9, name: "test"}
$httpBackend.expectGET("/shop/products").respond([{supplier : {id: 9}, master: {}}])
$httpBackend.flush()
expect(Products.products[0].supplier).toBe Enterprises.enterprises_by_id["9"]
it "dereferences taxons", ->
product.taxons = [2]
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].taxons[1]).toBe taxons[0]
it "dereferences properties", ->
product.properties = [1]
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].properties[1]).toBe properties[0]
it "registers variants with Variants service", ->
product.variants = [{id: 1}]
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].variants[0]).toBe Variants.variants[1]
expect(Products.products[0].variants[0]).toBe Variants.variants[1]
it "registers variants with the Cart", ->
product.variants = [{id: 8}]

View File

@@ -0,0 +1,16 @@
describe "Properties service", ->
Properties = null
properties = [
{id: 1, name: "Property1"}
{id: 2, name: "Property2"}
]
beforeEach ->
module('Darkswarm')
angular.module('Darkswarm').value 'properties', properties
inject ($injector)->
Properties = $injector.get("Properties")
it "caches properties in an id-referenced hash", ->
expect(Properties.properties_by_id[1]).toBe properties[0]