UnitsCtrl can interpret unit_value_with_description without a separating space

This commit is contained in:
Rob Harrington
2015-04-24 12:15:35 +10:00
parent 05c350b5ff
commit ed7b763ecf
2 changed files with 13 additions and 1 deletions

View File

@@ -25,7 +25,7 @@ angular.module("admin.products")
$scope.processUnitValueWithDescription = ->
if $scope.product.master.hasOwnProperty("unit_value_with_description")
match = $scope.product.master.unit_value_with_description.match(/^([\d\.]+(?= |$)|)( |)(.*)$/)
match = $scope.product.master.unit_value_with_description.match(/^([\d\.]+(?= *|$)|)( *)(.*)$/)
if match
$scope.product.master.unit_value = parseFloat(match[1])
$scope.product.master.unit_value = null if isNaN($scope.product.master.unit_value)

View File

@@ -53,3 +53,15 @@ describe "unitsCtrl", ->
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"