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
98835f06
Commit
98835f06
authored
Oct 26, 2017
by
jaebradley
Committed by
Jae Bradley
Oct 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle comma formatting
parent
1ea7f0cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
7 deletions
+11
-7
ecommerce/static/js/pages/basket_page.js
+5
-7
ecommerce/static/js/test/specs/pages/basket_page_spec.js
+6
-0
No files found.
ecommerce/static/js/pages/basket_page.js
View file @
98835f06
...
@@ -261,7 +261,7 @@ define([
...
@@ -261,7 +261,7 @@ define([
// 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
)
+
' '
return
countryData
.
symbol
+
Math
.
round
(
priceInUsd
*
countryData
.
rate
)
.
toLocaleString
()
+
' '
+
countryData
.
code
+
' *'
;
+
countryData
.
code
+
' *'
;
}
else
{
}
else
{
return
prefix
+
priceInUsd
;
return
prefix
+
priceInUsd
;
...
@@ -269,9 +269,9 @@ define([
...
@@ -269,9 +269,9 @@ define([
},
},
generateLocalPriceText
:
function
(
usdPriceText
)
{
generateLocalPriceText
:
function
(
usdPriceText
)
{
// Assumes price value is
in USDab.cd or $ab.cd format
with optional sign
// Assumes price value is
prefixed by $ or USD
with optional sign
var
localPriceText
=
usdPriceText
,
var
localPriceText
=
usdPriceText
,
prefixMatch
=
localPriceText
.
match
(
/
(\$
|USD
)
[
0-9
]
+
\.[
0-9
]
+
/
),
prefixMatch
=
localPriceText
.
match
(
/
(\$
|USD
)
.*
/
),
entireMatch
,
entireMatch
,
groupMatch
,
groupMatch
,
startIndex
,
startIndex
,
...
@@ -283,10 +283,8 @@ define([
...
@@ -283,10 +283,8 @@ define([
startIndex
=
prefixMatch
.
index
;
startIndex
=
prefixMatch
.
index
;
priceValue
=
localPriceText
.
substring
(
startIndex
+
groupMatch
.
length
);
priceValue
=
localPriceText
.
substring
(
startIndex
+
groupMatch
.
length
);
if
(
$
.
isNumeric
(
priceValue
))
{
localPriceText
=
localPriceText
localPriceText
=
localPriceText
.
replace
(
entireMatch
,
BasketPage
.
formatToLocalPrice
(
groupMatch
,
priceValue
));
.
replace
(
entireMatch
,
BasketPage
.
formatToLocalPrice
(
groupMatch
,
priceValue
));
}
}
}
return
localPriceText
;
return
localPriceText
;
...
...
ecommerce/static/js/test/specs/pages/basket_page_spec.js
View file @
98835f06
...
@@ -634,6 +634,12 @@ define([
...
@@ -634,6 +634,12 @@ define([
expect
(
BasketPage
.
formatToLocalPrice
).
toHaveBeenCalledWith
(
'$'
,
'12.34'
);
expect
(
BasketPage
.
formatToLocalPrice
).
toHaveBeenCalledWith
(
'$'
,
'12.34'
);
});
});
it
(
'should replace commaseparated values'
,
function
()
{
spyOn
(
BasketPage
,
'formatToLocalPrice'
).
and
.
returnValue
(
'foo'
);
expect
(
'-foo'
).
toEqual
(
BasketPage
.
generateLocalPriceText
(
'-$1,234'
));
expect
(
BasketPage
.
formatToLocalPrice
).
toHaveBeenCalledWith
(
'$'
,
'1,234'
);
});
it
(
'should not replace text without USD values'
,
function
()
{
it
(
'should not replace text without USD values'
,
function
()
{
var
messageWithoutUSDValue
=
'This caused a bug'
;
var
messageWithoutUSDValue
=
'This caused a bug'
;
spyOn
(
BasketPage
,
'formatToLocalPrice'
);
spyOn
(
BasketPage
,
'formatToLocalPrice'
);
...
...
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