Add pagination in Angular and views

This commit is contained in:
Matt-Yorkley
2019-10-02 01:52:36 +01:00
parent 01d1e8243c
commit fe0de98821
6 changed files with 84 additions and 59 deletions

View File

@@ -27,13 +27,6 @@ describe 'ProductsCtrl', ->
it 'fetches products from Products', ->
expect(scope.Products.products).toEqual ['testy mctest']
it "increments the limit up to the number of products", ->
scope.limit = 0
scope.incrementLimit()
expect(scope.limit).toEqual 10
scope.incrementLimit()
expect(scope.limit).toEqual 10
it "blocks keypresses on code 13", ->
event =
keyCode: 13

View File

@@ -1,6 +1,7 @@
describe 'Products service', ->
$httpBackend = null
Products = null
OrderCycle = {}
Shopfront = null
Variants = null
Cart = null
@@ -38,6 +39,9 @@ describe 'Products service', ->
producers:
id: 9,
name: "Test"
OrderCycle =
order_cycle:
order_cycle_id: 1
module 'Darkswarm'
module ($provide)->
@@ -46,6 +50,7 @@ describe 'Products service', ->
$provide.value "taxons", taxons
$provide.value "properties", properties
$provide.value "Geo", Geo
$provide.value "OrderCycle", OrderCycle
null
inject ($injector, _$httpBackend_)->
@@ -57,60 +62,60 @@ describe 'Products service', ->
$httpBackend = _$httpBackend_
it "Fetches products from the backend on init", ->
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].test).toEqual "cats"
it "dereferences suppliers", ->
Shopfront.producers_by_id =
{id: 9, name: "test"}
$httpBackend.expectGET("/shop/products").respond([{supplier : {id: 9}, master: {}}])
$httpBackend.expectGET("/api/order_cycles/1/products").respond([{supplier : {id: 9}, master: {}}])
$httpBackend.flush()
expect(Products.products[0].supplier).toBe Shopfront.producers_by_id["9"]
it "dereferences taxons", ->
product.taxons = [2]
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].taxons[1]).toBe taxons[0]
it "dereferences properties", ->
product.properties_with_values = [1]
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.expectGET("/api/order_cycles/1/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.expectGET("/api/order_cycles/1/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].variants[0]).toBe Variants.variants[1]
it "stores variant names", ->
product.variants = [{id: 1, name_to_display: "one"}, {id: 2, name_to_display: "two"}]
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].variant_names).toEqual "one two "
it "sets primaryImageOrMissing when no images are provided", ->
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].primaryImage).toBeUndefined()
expect(Products.products[0].primaryImageOrMissing).toEqual "/assets/noimage/small.png"
it "sets largeImage", ->
$httpBackend.expectGET("/shop/products").respond([productWithImage])
$httpBackend.expectGET("/api/order_cycles/1/products").respond([productWithImage])
$httpBackend.flush()
expect(Products.products[0].largeImage).toEqual("foo.png")
describe "determining the price to display for a product", ->
it "displays the product price when the product does not have variants", ->
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].price).toEqual 11.00
it "displays the minimum variant price when the product has variants", ->
product.variants = [{price: 22}, {price: 33}]
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.expectGET("/api/order_cycles/1/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].price).toEqual 22