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
7a6e2cef
Commit
7a6e2cef
authored
Oct 26, 2017
by
jaebradley
Committed by
Jae Bradley
Oct 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
default to local price prefix
parent
30f3cb03
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
19 deletions
+17
-19
ecommerce/static/js/pages/basket_page.js
+3
-3
ecommerce/static/js/test/specs/pages/basket_page_spec.js
+14
-16
No files found.
ecommerce/static/js/pages/basket_page.js
View file @
7a6e2cef
...
...
@@ -256,7 +256,7 @@ define([
}
},
formatToLocalPrice
:
function
(
priceInUsd
)
{
formatToLocalPrice
:
function
(
pr
efix
,
pr
iceInUsd
)
{
var
countryData
=
Cookies
.
getJSON
(
'edx-price-l10n'
);
// Default to USD when the exchange rate cookie doesn't exist
...
...
@@ -264,7 +264,7 @@ define([
return
countryData
.
symbol
+
Math
.
round
(
priceInUsd
*
countryData
.
rate
)
+
' '
+
countryData
.
code
+
' *'
;
}
else
{
return
'$'
+
priceInUsd
;
return
prefix
+
priceInUsd
;
}
},
...
...
@@ -285,7 +285,7 @@ define([
if
(
$
.
isNumeric
(
priceValue
))
{
localPriceText
=
localPriceText
.
replace
(
entireMatch
,
BasketPage
.
formatToLocalPrice
(
priceValue
));
.
replace
(
entireMatch
,
BasketPage
.
formatToLocalPrice
(
groupMatch
,
priceValue
));
}
}
...
...
ecommerce/static/js/test/specs/pages/basket_page_spec.js
View file @
7a6e2cef
...
...
@@ -588,7 +588,8 @@ define([
describe
(
'formatToLocalPrice'
,
function
()
{
var
EDX_PRICE_LOCATION_COOKIE_NAME
=
'edx-price-l10n'
,
USD_VALUE
=
100.25
,
EXPECTED_USD_PRICE
=
'$100.25'
,
PREFIX
=
'PREFIX'
,
EXPECTED_USD_PRICE
=
'100.25'
,
COOKIE_VALUES
=
{
countryCode
:
'FOO'
,
rate
:
2
,
code
:
'BAR'
,
symbol
:
'BAZ'
};
beforeEach
(
function
()
{
...
...
@@ -599,41 +600,38 @@ define([
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
prefixed
price when cookie does not exist'
,
function
()
{
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
PREFIX
+
EXPECTED_USD_PRICE
);
});
it
(
'should return
USD
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'
});
expect
(
BasketPage
.
formatToLocalPrice
(
USD_VALUE
)).
toEqual
(
EXPECTED_USD_PRICE
);
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
PREFIX
+
EXPECTED_USD_PRICE
);
});
it
(
'should return formatted
USD
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
);
expect
(
BasketPage
.
formatToLocalPrice
(
USD_VALUE
)).
toEqual
(
'BAZ201 BAR *'
);
expect
(
BasketPage
.
formatToLocalPrice
(
PREFIX
,
USD_VALUE
)).
toEqual
(
'BAZ201 BAR *'
);
});
});
describe
(
'generateLocalPriceText'
,
function
()
{
it
(
'should replace USD values'
,
function
()
{
spyOn
(
BasketPage
,
'formatToLocalPrice'
).
and
.
returnValue
(
'foo'
);
expect
(
'foo'
)
.
toEqual
(
BasketPage
.
generateLocalPriceText
(
'USD12.34'
));
expect
(
BasketPage
.
formatToLocalPrice
).
toHaveBeenCalledWith
(
'12.34'
);
expect
(
'foo'
).
toEqual
(
BasketPage
.
generateLocalPriceText
(
'USD12.34'
));
expect
(
BasketPage
.
formatToLocalPrice
).
toHaveBeenCalledWith
(
'USD'
,
'12.34'
);
});
it
(
'should replace $ values'
,
function
()
{
spyOn
(
BasketPage
,
'formatToLocalPrice'
).
and
.
returnValue
(
'foo'
);
expect
(
'foo'
)
.
toEqual
(
BasketPage
.
generateLocalPriceText
(
'$12.34'
));
expect
(
BasketPage
.
formatToLocalPrice
).
toHaveBeenCalledWith
(
'12.34'
);
expect
(
'foo'
).
toEqual
(
BasketPage
.
generateLocalPriceText
(
'$12.34'
));
expect
(
BasketPage
.
formatToLocalPrice
).
toHaveBeenCalledWith
(
'$'
,
'12.34'
);
});
it
(
'should replace negative values'
,
function
()
{
spyOn
(
BasketPage
,
'formatToLocalPrice'
).
and
.
returnValue
(
'foo'
);
expect
(
'-foo'
)
.
toEqual
(
BasketPage
.
generateLocalPriceText
(
'-$12.34'
));
expect
(
BasketPage
.
formatToLocalPrice
).
toHaveBeenCalledWith
(
'12.34'
);
expect
(
'-foo'
).
toEqual
(
BasketPage
.
generateLocalPriceText
(
'-$12.34'
));
expect
(
BasketPage
.
formatToLocalPrice
).
toHaveBeenCalledWith
(
'$'
,
'12.34'
);
});
it
(
'should not replace text without USD values'
,
function
()
{
...
...
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