Commit 98835f06 by jaebradley Committed by Jae Bradley

handle comma formatting

parent 1ea7f0cb
...@@ -261,7 +261,7 @@ define([ ...@@ -261,7 +261,7 @@ define([
// Default to USD when the exchange rate cookie doesn't exist // Default to USD when the exchange rate cookie doesn't exist
if (BasketPage.isValidLocalCurrencyCookie(countryData) && countryData.countryCode !== 'USA') { if (BasketPage.isValidLocalCurrencyCookie(countryData) && countryData.countryCode !== 'USA') {
return countryData.symbol + Math.round(priceInUsd * countryData.rate) + ' ' return countryData.symbol + Math.round(priceInUsd * countryData.rate).toLocaleString() + ' '
+ countryData.code + ' *'; + countryData.code + ' *';
} else { } else {
return prefix + priceInUsd; return prefix + priceInUsd;
...@@ -269,9 +269,9 @@ define([ ...@@ -269,9 +269,9 @@ define([
}, },
generateLocalPriceText: function(usdPriceText) { generateLocalPriceText: function(usdPriceText) {
// Assumes price value is in USDab.cd or $ab.cd format with optional sign // Assumes price value is prefixed by $ or USD with optional sign
var localPriceText = usdPriceText, var localPriceText = usdPriceText,
prefixMatch = localPriceText.match(/(\$|USD)[0-9]+\.[0-9]+/), prefixMatch = localPriceText.match(/(\$|USD).*/),
entireMatch, entireMatch,
groupMatch, groupMatch,
startIndex, startIndex,
...@@ -283,10 +283,8 @@ define([ ...@@ -283,10 +283,8 @@ define([
startIndex = prefixMatch.index; startIndex = prefixMatch.index;
priceValue = localPriceText.substring(startIndex + groupMatch.length); priceValue = localPriceText.substring(startIndex + groupMatch.length);
if ($.isNumeric(priceValue)) { localPriceText = localPriceText
localPriceText = localPriceText .replace(entireMatch, BasketPage.formatToLocalPrice(groupMatch, priceValue));
.replace(entireMatch, BasketPage.formatToLocalPrice(groupMatch, priceValue));
}
} }
return localPriceText; return localPriceText;
......
...@@ -634,6 +634,12 @@ define([ ...@@ -634,6 +634,12 @@ define([
expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('$', '12.34'); expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('$', '12.34');
}); });
it('should replace commaseparated values', function() {
spyOn(BasketPage, 'formatToLocalPrice').and.returnValue('foo');
expect('-foo').toEqual(BasketPage.generateLocalPriceText('-$1,234'));
expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('$', '1,234');
});
it('should not replace text without USD values', function() { it('should not replace text without USD values', function() {
var messageWithoutUSDValue = 'This caused a bug'; var messageWithoutUSDValue = 'This caused a bug';
spyOn(BasketPage, 'formatToLocalPrice'); spyOn(BasketPage, 'formatToLocalPrice');
......
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