Commit 970182b7 by jaebradley Committed by Jae Bradley

LEARNER-2413 Implement local currency conversion

parent 9dde4916
...@@ -32,6 +32,7 @@ node_modules/ ...@@ -32,6 +32,7 @@ node_modules/
ecommerce/static/bower_components/ ecommerce/static/bower_components/
ecommerce/static/build/ ecommerce/static/build/
npm-debug.log npm-debug.log
package-lock.json
# Unit test / coverage reports # Unit test / coverage reports
coverage/ coverage/
......
<div id="line-price" class="amount row">
<span class="price">$123.45</span>
</div>
<div id="line-discount" class="amount row">
<span class="price">$56.78</span>
</div>
<div id="basket-total" class="row">
<span class="price">$9.10</span>
</div>
<div id="voucher-1" class="amount row">
<span class="voucher">$123.45</span>
</div>
<div id="voucher-2" class="amount row">
<span class="voucher">$56.78</span>
</div>
<div id="voucher-3" class="row">
<span class="voucher">$9.10</span>
</div>
<div aria-labelledby="order-details-region"></div>
<div class="spinner"> <div class="spinner">
<input class="quantity" id="id_form-0-quantity" min="1" max="10" name="form-0-quantity" type="number" value="1"> <input class="quantity" id="id_form-0-quantity" min="1" max="10" name="form-0-quantity" type="number" value="1">
......
...@@ -492,7 +492,7 @@ define([ ...@@ -492,7 +492,7 @@ define([
$errorMessagesDiv = $('#messages'); $errorMessagesDiv = $('#messages');
BasketPage.onFail(); BasketPage.onFail();
expect($errorMessagesDiv.text()).toEqual( expect($errorMessagesDiv.text()).toEqual(
'Problem occurred during checkout. Please contact support' 'Problem occurred during checkout. Please contact support.'
); );
}); });
}); });
...@@ -554,6 +554,124 @@ define([ ...@@ -554,6 +554,124 @@ define([
expect(window.analytics.page).toHaveBeenCalled(); expect(window.analytics.page).toHaveBeenCalled();
}); });
}); });
describe('formatToLocalPrice', function() {
var EDX_PRICE_LOCATION_COOKIE_NAME = 'edx-price-l10n',
USD_VALUE = 100.25,
EXPECTED_USD_PRICE = '$100.25',
COOKIE_VALUES = {countryCode: 'FOO', rate: 2, code: 'BAR', symbol: 'BAZ'};
beforeEach(function() {
Cookies.remove(EDX_PRICE_LOCATION_COOKIE_NAME);
});
afterAll(function() {
Cookies.remove(EDX_PRICE_LOCATION_COOKIE_NAME);
});
it('should return USD price when cookie does not exist', function() {
expect(BasketPage.formatToLocalPrice(USD_VALUE)).toEqual(EXPECTED_USD_PRICE);
});
it('should return USD price when country code is USA', function() {
Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, {countryCode: 'USA'});
expect(BasketPage.formatToLocalPrice(USD_VALUE)).toEqual(EXPECTED_USD_PRICE);
});
it('should return formatted USD when non-US cookie exists', function() {
Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, COOKIE_VALUES);
expect(BasketPage.formatToLocalPrice(USD_VALUE)).toEqual('BAZ201 BAR *');
});
});
describe('generateLocalPriceText', function() {
it('should replace USD values', function() {
spyOn(BasketPage, 'formatToLocalPrice').and.returnValue('foo');
expect('Replace foo and foo with foo')
.toEqual(BasketPage.generateLocalPriceText('Replace $12.34 and $56.78 with foo'));
expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('12.34');
expect(BasketPage.formatToLocalPrice).toHaveBeenCalledWith('56.78');
});
});
describe('translateElementToLocalPrices', function() {
it('should replace price when local price text does not match price text', function() {
var $element = $('<div />');
spyOn(BasketPage, 'generateLocalPriceText').and.callFake(function(priceText) {
return 'localprice' + priceText;
});
spyOn($element, 'text').and.returnValue('foobar');
BasketPage.translateElementToLocalPrices($element);
expect($element.text.calls.count()).toEqual(2);
expect($element.text).toHaveBeenCalledWith('localpricefoobar');
});
it('should replace not replace price when local price text matches', function() {
var $element = $('<div />'),
priceText = 'someprice';
spyOn(BasketPage, 'generateLocalPriceText').and.returnValue(priceText);
spyOn($element, 'text').and.returnValue(priceText);
BasketPage.translateElementToLocalPrices($element);
expect($element.text.calls.count()).toEqual(1);
expect($element.text).not.toHaveBeenCalledWith(priceText);
});
});
describe('translateToLocalPrices', function() {
it('should replace prices', function() {
spyOn(BasketPage, 'translateElementToLocalPrices');
BasketPage.translateToLocalPrices();
// 3 .price elements + 3 .voucher elements
expect(BasketPage.translateElementToLocalPrices.calls.count()).toEqual(6);
// check to make sure the method was called
$('.price').each(function() {
expect(BasketPage.translateElementToLocalPrices).toHaveBeenCalledWith($(this));
});
$('.voucher').each(function() {
expect(BasketPage.translateElementToLocalPrices).toHaveBeenCalledWith($(this));
});
});
});
describe('addPriceDisclaimer', function() {
var EDX_PRICE_LOCATION_COOKIE_NAME = 'edx-price-l10n';
var COOKIE_VALUES = {countryCode: 'FOO', rate: 2, code: 'BAR', symbol: 'BAZ'};
beforeEach(function() {
Cookies.remove(EDX_PRICE_LOCATION_COOKIE_NAME);
});
afterAll(function() {
Cookies.remove(EDX_PRICE_LOCATION_COOKIE_NAME);
});
it('should not add disclaimer when cookie does not exist', function() {
BasketPage.addPriceDisclaimer();
expect(0).toEqual($('.price-disclaimer').length);
});
it('should return USD price when country code is USA', function() {
Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, {countryCode: 'USA'});
BasketPage.addPriceDisclaimer();
expect($('.price-disclaimer').length).toEqual(0);
});
it('should return formatted USD when non-US cookie exists', function() {
Cookies.set(EDX_PRICE_LOCATION_COOKIE_NAME, COOKIE_VALUES);
BasketPage.addPriceDisclaimer();
// eslint-disable-next-line max-len
expect('* This total contains an approximate conversion. You will be charged $9.10 USD.')
.toEqual($('.price-disclaimer').text());
});
});
}); });
} }
); );
...@@ -598,6 +598,10 @@ ...@@ -598,6 +598,10 @@
#order-details { #order-details {
margin: 50px 0; margin: 50px 0;
} }
.price-disclaimer {
font-style: italic;
}
} }
} }
} }
......
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