Commit a9367db8 by jaebradley Committed by Jae Bradley

trailing spaces in price regex

parent c58582c1
...@@ -269,9 +269,9 @@ define([ ...@@ -269,9 +269,9 @@ define([
}, },
generateLocalPriceText: function(usdPriceText) { generateLocalPriceText: function(usdPriceText) {
// Assumes price value is prefixed by $ or USD with optional sign // Assumes price value is prefixed by $ or USD with optional sign followed by optional string
var localPriceText = usdPriceText, var localPriceText = usdPriceText,
prefixMatch = localPriceText.match(/(\$|USD).*/), prefixMatch = localPriceText.match(/(\$|USD)?(([1-9][0-9]{0,2}(,[0-9]{3})*)|[0-9]+)?\.[0-9]{1,2}/),
entireMatch, entireMatch,
groupMatch, groupMatch,
startIndex, startIndex,
...@@ -281,7 +281,8 @@ define([ ...@@ -281,7 +281,8 @@ define([
entireMatch = prefixMatch[0]; entireMatch = prefixMatch[0];
groupMatch = prefixMatch[1]; groupMatch = prefixMatch[1];
startIndex = prefixMatch.index; startIndex = prefixMatch.index;
priceValue = localPriceText.substring(startIndex + groupMatch.length); priceValue = localPriceText
.substring(startIndex + groupMatch.length, startIndex + entireMatch.length);
localPriceText = localPriceText localPriceText = localPriceText
.replace(entireMatch, BasketPage.formatToLocalPrice(groupMatch, priceValue)); .replace(entireMatch, BasketPage.formatToLocalPrice(groupMatch, priceValue));
......
...@@ -636,8 +636,14 @@ define([ ...@@ -636,8 +636,14 @@ define([
it('should replace commaseparated values', function() { it('should replace commaseparated values', function() {
spyOn(BasketPage, 'formatToLocalPrice').and.returnValue('foo'); spyOn(BasketPage, 'formatToLocalPrice').and.returnValue('foo');
expect('-foo').toEqual(BasketPage.generateLocalPriceText('-$1,234')); expect('-foo').toEqual(BasketPage.generateLocalPriceText('-$1,234.56'));
expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('$', '1,234'); expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('$', '1,234.56');
});
it('should only replace currency value', function() {
spyOn(BasketPage, 'formatToLocalPrice').and.returnValue('foo');
expect('baz -foo bar').toEqual(BasketPage.generateLocalPriceText('baz -$1,234.56 bar'));
expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('$', '1,234.56');
}); });
it('should not replace text without USD values', function() { it('should not replace text without USD values', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment