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
d01a8139
Commit
d01a8139
authored
Oct 27, 2017
by
jaebradley
Committed by
Jae Bradley
Oct 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parse price and update multiplication
parent
a9367db8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
7 deletions
+20
-7
ecommerce/static/js/pages/basket_page.js
+5
-2
ecommerce/static/js/test/specs/pages/basket_page_spec.js
+15
-5
No files found.
ecommerce/static/js/pages/basket_page.js
View file @
d01a8139
...
@@ -257,11 +257,14 @@ define([
...
@@ -257,11 +257,14 @@ define([
},
},
formatToLocalPrice
:
function
(
prefix
,
priceInUsd
)
{
formatToLocalPrice
:
function
(
prefix
,
priceInUsd
)
{
var
countryData
=
Cookies
.
getJSON
(
'edx-price-l10n'
);
var
countryData
=
Cookies
.
getJSON
(
'edx-price-l10n'
),
parsedPriceInUsd
;
// 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
).
toLocaleString
()
+
' '
// assumes all formatted prices have a comma every three places
parsedPriceInUsd
=
parseFloat
(
priceInUsd
.
replace
(
','
,
''
));
return
countryData
.
symbol
+
Math
.
round
(
parsedPriceInUsd
*
countryData
.
rate
).
toLocaleString
()
+
' '
+
countryData
.
code
+
' *'
;
+
countryData
.
code
+
' *'
;
}
else
{
}
else
{
return
prefix
+
priceInUsd
;
return
prefix
+
priceInUsd
;
...
...
ecommerce/static/js/test/specs/pages/basket_page_spec.js
View file @
d01a8139
...
@@ -587,9 +587,9 @@ define([
...
@@ -587,9 +587,9 @@ define([
describe
(
'formatToLocalPrice'
,
function
()
{
describe
(
'formatToLocalPrice'
,
function
()
{
var
EDX_PRICE_LOCATION_COOKIE_NAME
=
'edx-price-l10n'
,
var
EDX_PRICE_LOCATION_COOKIE_NAME
=
'edx-price-l10n'
,
USD_VALUE
=
100.25
,
USD_VALUE
=
'1,234.56'
,
ANOTHER_USD_VALUE
=
'123.45'
,
PREFIX
=
'PREFIX'
,
PREFIX
=
'PREFIX'
,
EXPECTED_USD_PRICE
=
'100.25'
,
COOKIE_VALUES
=
{
countryCode
:
'FOO'
,
rate
:
2
,
code
:
'BAR'
,
symbol
:
'BAZ'
};
COOKIE_VALUES
=
{
countryCode
:
'FOO'
,
rate
:
2
,
code
:
'BAR'
,
symbol
:
'BAZ'
};
beforeEach
(
function
()
{
beforeEach
(
function
()
{
...
@@ -601,17 +601,27 @@ define([
...
@@ -601,17 +601,27 @@ define([
});
});
it
(
'should return prefixed price when cookie does not exist'
,
function
()
{
it
(
'should return prefixed price when cookie does not exist'
,
function
()
{
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
PREFIX
+
EXPECTED_USD_PRIC
E
);
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
PREFIX
+
USD_VALU
E
);
});
});
it
(
'should return prefixed price when country code is USA'
,
function
()
{
it
(
'should return prefixed price when country code is USA'
,
function
()
{
Cookies
.
set
(
EDX_PRICE_LOCATION_COOKIE_NAME
,
{
countryCode
:
'USA'
});
Cookies
.
set
(
EDX_PRICE_LOCATION_COOKIE_NAME
,
{
countryCode
:
'USA'
});
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
PREFIX
+
EXPECTED_USD_PRICE
);
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
PREFIX
+
USD_VALUE
);
});
it
(
'should return prefixed price when country code is USA'
,
function
()
{
Cookies
.
set
(
EDX_PRICE_LOCATION_COOKIE_NAME
,
{
countryCode
:
'USA'
});
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
PREFIX
+
USD_VALUE
);
});
});
it
(
'should return formatted local price value when non-US cookie exists'
,
function
()
{
it
(
'should return formatted local price value when non-US cookie exists'
,
function
()
{
Cookies
.
set
(
EDX_PRICE_LOCATION_COOKIE_NAME
,
COOKIE_VALUES
);
Cookies
.
set
(
EDX_PRICE_LOCATION_COOKIE_NAME
,
COOKIE_VALUES
);
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
'BAZ201 BAR *'
);
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
'BAZ2,469 BAR *'
);
});
it
(
'should return non-comma separated local price value when non-US cookie exists'
,
function
()
{
Cookies
.
set
(
EDX_PRICE_LOCATION_COOKIE_NAME
,
COOKIE_VALUES
);
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
ANOTHER_USD_VALUE
)).
toEqual
(
'BAZ247 BAR *'
);
});
});
});
});
...
...
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