Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ecommerce
Commits
970182b7
Commit
970182b7
authored
Oct 02, 2017
by
jaebradley
Committed by
Jae Bradley
Oct 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LEARNER-2413 Implement local currency conversion
parent
9dde4916
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
1 deletions
+150
-1
.gitignore
+1
-0
ecommerce/static/js/pages/basket_page.js
+0
-0
ecommerce/static/js/test/fixtures/basket.html
+26
-0
ecommerce/static/js/test/specs/pages/basket_page_spec.js
+119
-1
ecommerce/static/sass/partials/views/_basket.scss
+4
-0
No files found.
.gitignore
View file @
970182b7
...
@@ -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/
...
...
ecommerce/static/js/pages/basket_page.js
View file @
970182b7
This diff is collapsed.
Click to expand it.
ecommerce/static/js/test/fixtures/basket.html
View file @
970182b7
<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"
>
...
...
ecommerce/static/js/test/specs/pages/basket_page_spec.js
View file @
970182b7
...
@@ -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
());
});
});
});
});
}
}
);
);
ecommerce/static/sass/partials/views/_basket.scss
View file @
970182b7
...
@@ -598,6 +598,10 @@
...
@@ -598,6 +598,10 @@
#order-details
{
#order-details
{
margin
:
50px
0
;
margin
:
50px
0
;
}
}
.price-disclaimer
{
font-style
:
italic
;
}
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment