mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Fix product system spec
The pending spec are to be fix after a rebase, master currently as some changes which will make this easier
This commit is contained in:
@@ -41,64 +41,64 @@ describe "unitsCtrl", ->
|
||||
|
||||
describe "interpretting unit_value_with_description", ->
|
||||
beforeEach ->
|
||||
scope.product.master = {}
|
||||
scope.product = {}
|
||||
|
||||
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.product.unit_value_with_description = "12 boxes"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 12
|
||||
expect(scope.product.master.unit_description).toEqual "boxes"
|
||||
expect(scope.product.unit_value).toEqual 12
|
||||
expect(scope.product.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.product.unit_value_with_description = "12345"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 12345
|
||||
expect(scope.product.master.unit_description).toEqual ''
|
||||
expect(scope.product.unit_value).toEqual 12345
|
||||
expect(scope.product.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.product.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"
|
||||
expect(scope.product.unit_value).toEqual null
|
||||
expect(scope.product.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.product.unit_value_with_description = "12boxes"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 12
|
||||
expect(scope.product.master.unit_description).toEqual "boxes"
|
||||
expect(scope.product.unit_value).toEqual 12
|
||||
expect(scope.product.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.product.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"
|
||||
expect(scope.product.unit_value).toEqual 123
|
||||
expect(scope.product.unit_description).toEqual "54 boxes"
|
||||
|
||||
it "handle final point as decimal separator", ->
|
||||
scope.product.master.unit_value_with_description = "22.22"
|
||||
scope.product.unit_value_with_description = "22.22"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 22.22
|
||||
expect(scope.product.master.unit_description).toEqual ""
|
||||
expect(scope.product.unit_value).toEqual 22.22
|
||||
expect(scope.product.unit_description).toEqual ""
|
||||
|
||||
it "handle comma as decimal separator", ->
|
||||
scope.product.master.unit_value_with_description = "22,22"
|
||||
scope.product.unit_value_with_description = "22,22"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 22.22
|
||||
expect(scope.product.master.unit_description).toEqual ""
|
||||
|
||||
expect(scope.product.unit_value).toEqual 22.22
|
||||
expect(scope.product.unit_description).toEqual ""
|
||||
|
||||
it "handle comma as decimal separator with description", ->
|
||||
scope.product.master.unit_value_with_description = "22,22 things"
|
||||
scope.product.unit_value_with_description = "22,22 things"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 22.22
|
||||
expect(scope.product.master.unit_description).toEqual "things"
|
||||
expect(scope.product.unit_value).toEqual 22.22
|
||||
expect(scope.product.unit_description).toEqual "things"
|
||||
|
||||
it "handles nice rounded division", ->
|
||||
# this is a bit absurd, but it assure use that bigDecimal is called
|
||||
window.bigDecimal.multiply.and.returnValue 0.7
|
||||
scope.product.master.unit_value_with_description = "700"
|
||||
scope.product.unit_value_with_description = "700"
|
||||
scope.product.variant_unit_scale = 0.001
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 0.7
|
||||
expect(scope.product.unit_value).toEqual 0.7
|
||||
|
||||
Reference in New Issue
Block a user