mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Merge branch 'master' into customers
Conflicts: app/assets/javascripts/admin/bulk_order_management.js.coffee app/assets/javascripts/admin/bulk_product_update.js.coffee app/assets/javascripts/admin/directives/line_item_upd_attr.js.coffee app/views/spree/admin/orders/bulk_management.html.haml db/schema.rb spec/javascripts/unit/bulk_order_management_spec.js.coffee
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
describe "unitsCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
product = null
|
||||
|
||||
beforeEach ->
|
||||
module('admin.products')
|
||||
inject ($rootScope, $controller, VariantUnitManager) ->
|
||||
scope = $rootScope
|
||||
ctrl = $controller 'unitsCtrl', {$scope: scope, VariantUnitManager: VariantUnitManager}
|
||||
|
||||
describe "interpretting variant_unit_with_scale", ->
|
||||
it "splits string with one underscore and stores the two parts", ->
|
||||
scope.product.variant_unit_with_scale = "weight_1000"
|
||||
scope.processVariantUnitWithScale()
|
||||
expect(scope.product.variant_unit).toEqual "weight"
|
||||
expect(scope.product.variant_unit_scale).toEqual 1000
|
||||
|
||||
it "interprets strings with no underscore as variant_unit", ->
|
||||
scope.product.variant_unit_with_scale = "items"
|
||||
scope.processVariantUnitWithScale()
|
||||
expect(scope.product.variant_unit).toEqual "items"
|
||||
expect(scope.product.variant_unit_scale).toEqual null
|
||||
|
||||
it "sets variant_unit and variant_unit_scale to null", ->
|
||||
scope.product.variant_unit_with_scale = null
|
||||
scope.processVariantUnitWithScale()
|
||||
expect(scope.product.variant_unit).toEqual null
|
||||
expect(scope.product.variant_unit_scale).toEqual null
|
||||
|
||||
describe "interpretting unit_value_with_description", ->
|
||||
beforeEach ->
|
||||
scope.product.master = {}
|
||||
|
||||
describe "when a variant_unit_scale is present", ->
|
||||
beforeEach ->
|
||||
scope.product.variant_unit_scale = 1
|
||||
|
||||
it "splits by whitespace in to unit_value and unit_description", ->
|
||||
scope.product.master.unit_value_with_description = "12 boxes"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 12
|
||||
expect(scope.product.master.unit_description).toEqual "boxes"
|
||||
|
||||
it "uses whole string as unit_value when only numerical characters are present", ->
|
||||
scope.product.master.unit_value_with_description = "12345"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 12345
|
||||
expect(scope.product.master.unit_description).toEqual ''
|
||||
|
||||
it "uses whole string as description when string does not start with a number", ->
|
||||
scope.product.master.unit_value_with_description = "boxes 12"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual null
|
||||
expect(scope.product.master.unit_description).toEqual "boxes 12"
|
||||
|
||||
it "does not require whitespace to split unit value and description", ->
|
||||
scope.product.master.unit_value_with_description = "12boxes"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 12
|
||||
expect(scope.product.master.unit_description).toEqual "boxes"
|
||||
|
||||
it "once a whitespace occurs, all subsequent numerical characters are counted as description", ->
|
||||
scope.product.master.unit_value_with_description = "123 54 boxes"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 123
|
||||
expect(scope.product.master.unit_description).toEqual "54 boxes"
|
||||
@@ -61,14 +61,14 @@ describe "BulkProducts service", ->
|
||||
clonedProduct =
|
||||
id: 17
|
||||
|
||||
spyOn(BulkProducts, "addProducts")
|
||||
spyOn(BulkProducts, "insertProductAfter")
|
||||
BulkProducts.products = [originalProduct]
|
||||
$httpBackend.expectGET("/admin/products/oranges/clone.json").respond 200,
|
||||
product: clonedProduct
|
||||
$httpBackend.expectGET("/api/products/17?template=bulk_show").respond 200, clonedProduct
|
||||
BulkProducts.cloneProduct BulkProducts.products[0]
|
||||
$httpBackend.flush()
|
||||
expect(BulkProducts.addProducts).toHaveBeenCalledWith [clonedProduct]
|
||||
expect(BulkProducts.insertProductAfter).toHaveBeenCalledWith originalProduct, clonedProduct
|
||||
|
||||
|
||||
describe "preparing products", ->
|
||||
|
||||
Reference in New Issue
Block a user