Skip to content

Commit

Permalink
Merge branch 'strip-dollar-sign' into ep-upgrade-stage
Browse files Browse the repository at this point in the history
  • Loading branch information
wrandall22 committed Oct 25, 2023
2 parents bb6392c + 13c2e86 commit 4ea6dd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,10 @@ class ProductConfigFormController {
}

transformAmountIfNecessary (amount) {
let transformedAmount = amount
if (!angular.isNumber(amount)) {
transformedAmount = amount.replace('$', '')
transformedAmount = parseFloat(transformedAmount)
if (isNaN(transformedAmount)) {
return amount
}
return amount.replace('$', '')
}
return transformedAmount
return amount
}

displayId () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,13 @@ describe('product config form component', function () {
it('should transform the amount', () => {
$ctrl.itemConfig.AMOUNT = '$85'
$ctrl.itemConfigForm.$dirty = true
const overrideArgs = isEdit
? ['uri', 'items/crugive/<some id>', { AMOUNT: '85' }]
: ['items/crugive/<some id>', { AMOUNT: '85' }, undefined]
$ctrl.saveGiftToCart()

expect($ctrl.submittingGift).toEqual(false)
expect($ctrl.cartService[operation]).toHaveBeenCalledWith(...operationArgs)
expect($ctrl.cartService[operation]).toHaveBeenCalledWith(...overrideArgs)
expect($ctrl.$scope.$emit).toHaveBeenCalledWith(cartEvent)
expect($ctrl.onStateChange).toHaveBeenCalledWith({ state: 'submitted' })
expect($ctrl.errorAlreadyInCart).toEqual(false)
Expand Down Expand Up @@ -779,17 +782,22 @@ describe('product config form component', function () {
describe('transformAmountIfNecessary', () => {
it('should not change the int amount', () => {
const amount = '5'
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(5)
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(amount)
})

it('should not change the float amount', () => {
const amount = '5.12'
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(5.12)
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(amount)
})

it('should remove the $', () => {
const amount = '$50'
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(50)
expect($ctrl.transformAmountIfNecessary(amount)).toEqual('50')
})

it('should not strip other characters', () => {
const amount = '23,00'
expect($ctrl.transformAmountIfNecessary(amount)).toEqual(amount)
})

it('should pass through the original amount', () => {
Expand Down

0 comments on commit 4ea6dd5

Please sign in to comment.