Commit 30f3cb03 by jaebradley Committed by Jae Bradley

wrap disclaimer text

actually wrap in gettext
parent 0006cad8
...@@ -242,14 +242,16 @@ define([ ...@@ -242,14 +242,16 @@ define([
addPriceDisclaimer: function() { addPriceDisclaimer: function() {
var price = $('#basket-total').find('> .price').text(), var price = $('#basket-total').find('> .price').text(),
countryData = Cookies.getJSON('edx-price-l10n'); countryData = Cookies.getJSON('edx-price-l10n'),
disclaimerPrefix;
// when the price value has a USD prefix, replace it with a $ // when the price value has a USD prefix, replace it with a $
price = price.replace('USD', '$'); price = price.replace('USD', '$');
disclaimerPrefix = '* This total contains an approximate conversion. You will be charged ';
if (BasketPage.isValidLocalCurrencyCookie(countryData) && countryData.countryCode !== 'USA') { if (BasketPage.isValidLocalCurrencyCookie(countryData) && countryData.countryCode !== 'USA') {
$('<span>').attr('class', 'price-disclaimer') $('<span>').attr('class', 'price-disclaimer')
.text('* This total contains an approximate conversion. You will be charged ' + price + ' USD.') .text(gettext(disclaimerPrefix) + price + ' USD.')
.appendTo('div[aria-labelledby="order-details-region"]'); .appendTo('div[aria-labelledby="order-details-region"]');
} }
}, },
...@@ -267,16 +269,27 @@ define([ ...@@ -267,16 +269,27 @@ define([
}, },
generateLocalPriceText: function(usdPriceText) { generateLocalPriceText: function(usdPriceText) {
var localPriceText = usdPriceText;
// Assumes price value is in USDab.cd or $ab.cd format with optional sign // Assumes price value is in USDab.cd or $ab.cd format with optional sign
localPriceText = localPriceText.replace(/\$|USD/, ''); var localPriceText = usdPriceText,
prefixMatch = localPriceText.match(/(\$|USD)[0-9]+\.[0-9]+/),
if ($.isNumeric(localPriceText)) { entireMatch,
return BasketPage.formatToLocalPrice(localPriceText); groupMatch,
startIndex,
priceValue;
if (prefixMatch) {
entireMatch = prefixMatch[0];
groupMatch = prefixMatch[1];
startIndex = prefixMatch.index;
priceValue = localPriceText.substring(startIndex + groupMatch.length);
if ($.isNumeric(priceValue)) {
localPriceText = localPriceText
.replace(entireMatch, BasketPage.formatToLocalPrice(priceValue));
}
} }
return usdPriceText; return localPriceText;
}, },
replaceElementText: function(element, text) { replaceElementText: function(element, text) {
......
...@@ -631,9 +631,9 @@ define([ ...@@ -631,9 +631,9 @@ define([
it('should replace negative values', function() { it('should replace negative values', function() {
spyOn(BasketPage, 'formatToLocalPrice').and.returnValue('foo'); spyOn(BasketPage, 'formatToLocalPrice').and.returnValue('foo');
expect('foo') expect('-foo')
.toEqual(BasketPage.generateLocalPriceText('-$12.34')); .toEqual(BasketPage.generateLocalPriceText('-$12.34'));
expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('-12.34'); expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('12.34');
}); });
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