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
86bad4a1
Commit
86bad4a1
authored
Jan 05, 2017
by
Saleem Latif
Committed by
Saleem Latif
Jan 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix JS test failure for basket page tests
parent
b6411709
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
21 deletions
+46
-21
ecommerce/static/js/pages/basket_page.js
+4
-1
ecommerce/static/js/test/specs/pages/basket_page_spec.js
+42
-20
No files found.
ecommerce/static/js/pages/basket_page.js
View file @
86bad4a1
...
@@ -102,7 +102,10 @@ define([
...
@@ -102,7 +102,10 @@ define([
cardInfoValidation
=
function
(
event
)
{
cardInfoValidation
=
function
(
event
)
{
var
cardType
,
var
cardType
,
currentMonth
=
new
Date
().
getMonth
(),
// We are adding 1 here because month in js style date-time starts with 0
// i.e. 0 for JAN, 1 for FEB etc. However, credit card expiry months start with 1
// i.e 1 for JAN, 2 for FEB etc.
currentMonth
=
new
Date
().
getMonth
()
+
1
,
currentYear
=
new
Date
().
getFullYear
(),
currentYear
=
new
Date
().
getFullYear
(),
cardNumber
=
$
(
'input[name=card_number]'
).
val
(),
cardNumber
=
$
(
'input[name=card_number]'
).
val
(),
cvnNumber
=
$
(
'input[name=card_cvn]'
).
val
(),
cvnNumber
=
$
(
'input[name=card_cvn]'
).
val
(),
...
...
ecommerce/static/js/test/specs/pages/basket_page_spec.js
View file @
86bad4a1
...
@@ -7,7 +7,8 @@ define([
...
@@ -7,7 +7,8 @@ define([
'models/tracking_model'
,
'models/tracking_model'
,
'models/user_model'
,
'models/user_model'
,
'views/analytics_view'
,
'views/analytics_view'
,
'js-cookie'
'js-cookie'
,
'moment'
],
],
function
(
$
,
function
(
$
,
_
,
_
,
...
@@ -17,7 +18,9 @@ define([
...
@@ -17,7 +18,9 @@ define([
TrackingModel
,
TrackingModel
,
UserModel
,
UserModel
,
AnalyticsView
,
AnalyticsView
,
Cookies
)
{
Cookies
,
moment
)
{
'use strict'
;
'use strict'
;
describe
(
'Basket Page'
,
function
()
{
describe
(
'Basket Page'
,
function
()
{
...
@@ -208,8 +211,21 @@ define([
...
@@ -208,8 +211,21 @@ define([
});
});
describe
(
'clientSideCheckoutValidation'
,
function
()
{
describe
(
'clientSideCheckoutValidation'
,
function
()
{
var
currentYear
=
2016
,
var
cc_expiry_months
=
{
lastMonth
=
11
;
JAN
:
'01'
,
FEB
:
'02'
,
MAR
:
'03'
,
APR
:
'04'
,
MAY
:
'05'
,
JUN
:
'06'
,
JUL
:
'07'
,
AUG
:
'08'
,
SEP
:
'09'
,
OCT
:
'10'
,
NOV
:
'11'
,
DEC
:
'12'
};
beforeEach
(
function
()
{
beforeEach
(
function
()
{
$
(
$
(
...
@@ -232,8 +248,6 @@ define([
...
@@ -232,8 +248,6 @@ define([
'<div><input name="card_cvn">'
+
'<div><input name="card_cvn">'
+
'<p class="help-block"></p></div>'
+
'<p class="help-block"></p></div>'
+
'<div><select name="card_expiry_month">'
+
'<div><select name="card_expiry_month">'
+
'<option value="01">01</option>'
+
'<option value="12">12</option>'
+
'<option value="99">99</option>'
+
'<option value="99">99</option>'
+
'</select>'
+
'</select>'
+
'<p class="help-block"></p></div>'
+
'<p class="help-block"></p></div>'
+
...
@@ -244,11 +258,10 @@ define([
...
@@ -244,11 +258,10 @@ define([
'<button id="payment-button">Pay</button>'
'<button id="payment-button">Pay</button>'
).
appendTo
(
'body'
);
).
appendTo
(
'body'
);
$
(
'select[name=card_expiry_year]'
).
append
(
'<option value="'
+
$
(
'select[name=card_expiry_month]'
).
append
(
currentYear
+
'">'
+
currentYear
+
'</option>'
_
.
reduce
(
_
.
toArray
(
cc_expiry_months
),
function
(
memo
,
value
){
);
return
memo
+
'<option value="'
+
value
+
'">'
+
value
+
'</option>'
;
$
(
'select[name=card_expiry_month]'
).
append
(
'<option value="'
+
},
''
)
lastMonth
+
'">'
+
lastMonth
+
'</option>'
);
);
$
(
'input[name=first_name]'
).
val
(
'Joey'
);
$
(
'input[name=first_name]'
).
val
(
'Joey'
);
...
@@ -257,10 +270,6 @@ define([
...
@@ -257,10 +270,6 @@ define([
$
(
'input[name=city]'
).
val
(
'New York City'
);
$
(
'input[name=city]'
).
val
(
'New York City'
);
$
(
'select[name=country]'
).
val
(
'US'
);
$
(
'select[name=country]'
).
val
(
'US'
);
// Freeze time to 12-2016.
spyOn
(
Date
.
prototype
,
'getFullYear'
).
and
.
returnValue
(
currentYear
);
spyOn
(
Date
.
prototype
,
'getMonth'
).
and
.
returnValue
(
lastMonth
+
1
);
BasketPage
.
onReady
();
BasketPage
.
onReady
();
});
});
...
@@ -325,7 +334,20 @@ define([
...
@@ -325,7 +334,20 @@ define([
describe
(
'cardInfoValidation'
,
function
()
{
describe
(
'cardInfoValidation'
,
function
()
{
var
validCardNumber
=
'378282246310005'
,
// AMEX (CVN length 4)
var
validCardNumber
=
'378282246310005'
,
// AMEX (CVN length 4)
validCvn
=
'1234'
,
validCvn
=
'1234'
,
enRouteCardNumber
=
'201401173701274'
;
// Unsupported type (Dec, 2016)
enRouteCardNumber
=
'201401173701274'
,
// Unsupported type (Dec, 2016)
today
=
moment
(),
cardExpirationMonth
=
'FEB'
,
// Card Expires in February
thisMonth
=
moment
().
month
(
'MAR'
).
month
();
// Let's say this month is March
beforeEach
(
function
()
{
$
(
'select[name=card_expiry_year]'
).
append
(
'<option value="'
+
today
.
year
()
+
'">'
+
today
.
year
()
+
'</option>'
);
// Freeze month to March.
// We are using moment here to get number of month instead of
// hard coding it, so that it conforms to js date time style.
spyOn
(
Date
.
prototype
,
'getMonth'
).
and
.
returnValue
(
thisMonth
);
});
it
(
'should validate card number'
,
function
()
{
it
(
'should validate card number'
,
function
()
{
$
(
'input[name=card_number]'
).
val
(
'123invalid456'
);
$
(
'input[name=card_number]'
).
val
(
'123invalid456'
);
...
@@ -382,7 +404,7 @@ define([
...
@@ -382,7 +404,7 @@ define([
$
(
'#payment-button'
).
click
();
$
(
'#payment-button'
).
click
();
expect
(
$
(
'select[name=card_expiry_year] ~ .help-block span'
).
text
()).
toEqual
(
'Invalid year'
);
expect
(
$
(
'select[name=card_expiry_year] ~ .help-block span'
).
text
()).
toEqual
(
'Invalid year'
);
$
(
'select[name=card_expiry_year]'
).
val
(
currentYear
);
$
(
'select[name=card_expiry_year]'
).
val
(
today
.
year
()
);
$
(
'#payment-button'
).
click
();
$
(
'#payment-button'
).
click
();
expect
(
$
(
'select[name=card_expiry_year] ~ .help-block'
).
has
(
'span'
).
length
).
toEqual
(
0
);
expect
(
$
(
'select[name=card_expiry_year] ~ .help-block'
).
has
(
'span'
).
length
).
toEqual
(
0
);
});
});
...
@@ -390,13 +412,13 @@ define([
...
@@ -390,13 +412,13 @@ define([
it
(
'should validate card expiration'
,
function
()
{
it
(
'should validate card expiration'
,
function
()
{
$
(
'input[name=card_number]'
).
val
(
validCardNumber
);
$
(
'input[name=card_number]'
).
val
(
validCardNumber
);
$
(
'input[name=card_cvn]'
).
val
(
validCvn
);
$
(
'input[name=card_cvn]'
).
val
(
validCvn
);
$
(
'select[name=card_expiry_month]'
).
val
(
lastMonth
);
$
(
'select[name=card_expiry_month]'
).
val
(
cc_expiry_months
[
cardExpirationMonth
]
);
$
(
'select[name=card_expiry_year]'
).
val
(
currentYear
);
$
(
'select[name=card_expiry_year]'
).
val
(
today
.
year
()
);
$
(
'#payment-button'
).
click
();
$
(
'#payment-button'
).
click
();
expect
(
$
(
'select[name=card_expiry_month] ~ .help-block span'
).
text
()).
toEqual
(
'Card expired'
);
expect
(
$
(
'select[name=card_expiry_month] ~ .help-block span'
).
text
()).
toEqual
(
'Card expired'
);
$
(
'select[name=card_expiry_month]'
).
val
(
'12'
);
$
(
'select[name=card_expiry_month]'
).
val
(
'12'
);
$
(
'select[name=card_expiry_year]'
).
val
(
currentYear
+
1
);
$
(
'select[name=card_expiry_year]'
).
val
(
today
.
year
()
);
$
(
'#payment-button'
).
click
();
$
(
'#payment-button'
).
click
();
expect
(
$
(
'select[name=card_expiry_month] ~ .help-block'
).
has
(
'span'
).
length
).
toEqual
(
0
);
expect
(
$
(
'select[name=card_expiry_month] ~ .help-block'
).
has
(
'span'
).
length
).
toEqual
(
0
);
});
});
...
...
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