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
641c1a6f
Commit
641c1a6f
authored
Jan 12, 2017
by
Vedran Karacic
Committed by
Vedran Karačić
Jan 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make state field required for CA and US.
parent
c9f1d6d0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
49 deletions
+37
-49
ecommerce/static/js/pages/basket_page.js
+8
-0
ecommerce/static/js/test/specs/pages/basket_page_spec.js
+29
-49
No files found.
ecommerce/static/js/pages/basket_page.js
View file @
641c1a6f
...
...
@@ -89,6 +89,10 @@ define([
'select[name=country]'
];
if
([
'US'
,
'CA'
].
indexOf
(
$
(
'select[name=country]'
).
val
())
>
-
1
)
{
requiredFields
.
push
(
'select[name=state]'
);
}
_
.
each
(
requiredFields
,
function
(
field
)
{
if
(
$
(
field
).
val
()
===
''
)
{
event
.
preventDefault
();
...
...
@@ -261,11 +265,15 @@ define([
'<select name="state" class="select form-control" id="id_state"'
+
'aria-required="true" required></select>'
);
$
(
'#id_state'
).
append
(
$
(
'<option>'
,
{
value
:
''
,
text
:
'<Choose state/province>'
}));
$
(
'#div_id_state'
).
find
(
'label'
).
text
(
'State/Province (required)'
);
_
.
each
(
states
[
country
],
function
(
value
,
key
)
{
$
(
'#id_state'
).
append
(
$
(
'<option>'
,
{
value
:
value
,
text
:
key
}));
});
}
else
{
$
(
inputDiv
).
empty
();
$
(
'#div_id_state'
).
find
(
'label'
).
text
(
'State/Province'
);
// In order to change the maxlength attribute, the same needs to be changed in the Django form.
$
(
inputDiv
).
append
(
'<input class="textinput textInput form-control" id="id_state"'
+
...
...
ecommerce/static/js/test/specs/pages/basket_page_spec.js
View file @
641c1a6f
...
...
@@ -122,8 +122,8 @@ define([
'<option value="CA">Canada</option>'
+
'<option value="HR">Croatia</option>'
+
'</select></div><p class="help-block"></p></div>'
+
'<div class="form-item"><div id="div_id_state"><
div class="controls"
>'
+
'<
input name="state"
></div></div>'
+
'<div class="form-item"><div id="div_id_state"><
label>State/Province</label
>'
+
'<
div class="controls"><input name="state"></div
></div></div>'
+
'</fieldset>'
).
appendTo
(
'body'
);
BasketPage
.
onReady
();
...
...
@@ -136,6 +136,7 @@ define([
$
(
'select[name=country]'
).
val
(
'CA'
).
trigger
(
'change'
);
expect
(
$
(
'#id_state'
).
prop
(
'tagName'
)).
toEqual
(
'SELECT'
);
expect
(
$
(
'#div_id_state'
).
find
(
'label'
).
text
()).
toEqual
(
'State/Province (required)'
);
});
it
(
'should disable payment button before making ajax call'
,
function
()
{
...
...
@@ -242,6 +243,9 @@ define([
'<option value=""><Choose country></option>'
+
'<option value="US">United States</option>'
+
'</select></div><p class="help-block"></p></div>'
+
'<div class="form-item"><div><select name="state">'
+
'<option value=""><Choose state></option>'
+
'</select></div><p class="help-block"></p></div>'
+
'</fieldset>'
+
'<div><input name="card_number">'
+
'<p class="help-block"></p></div>'
+
...
...
@@ -274,61 +278,37 @@ define([
});
describe
(
'cardHolderInformationValidation'
,
function
()
{
it
(
'should validate first name'
,
function
()
{
$
(
'input[name=first_name]'
).
val
(
''
);
$
(
'#payment-button'
).
click
();
expect
(
$
(
'input[name=first_name]'
).
parentsUntil
(
'form-item'
).
find
(
'~.help-block span'
).
text
()
).
toEqual
(
'This field is required'
);
it
(
'should validate required fields'
,
function
()
{
var
requiredFields
=
[
'input[name=first_name]'
,
'input[name=last_name]'
,
'input[name=address_line1]'
,
'input[name=city]'
,
'select[name=country]'
];
_
.
each
(
requiredFields
,
function
(
field
)
{
$
(
field
).
val
(
''
);
$
(
'#payment-button'
).
click
();
expect
(
$
(
field
).
parentsUntil
(
'form-item'
).
find
(
'~.help-block span'
).
text
()
).
toEqual
(
'This field is required'
);
});
});
it
(
'should validate last name'
,
function
()
{
$
(
'input[name=last_name]'
).
val
(
''
);
it
(
'should validate state field'
,
function
()
{
$
(
'select[name=country]'
).
val
(
'US'
).
trigger
(
'change'
);
$
(
'select[name=state]'
).
val
(
''
);
$
(
'#payment-button'
).
click
();
expect
(
$
(
'
input[name=last_nam
e]'
).
parentsUntil
(
$
(
'
select[name=stat
e]'
).
parentsUntil
(
'form-item'
).
find
(
'~.help-block span'
).
text
()
).
toEqual
(
'This field is required'
);
});
it
(
'should validate address'
,
function
()
{
$
(
'input[name=address_line1]'
).
val
(
''
);
$
(
'#payment-button'
).
click
();
expect
(
$
(
'input[name=address_line1]'
).
parentsUntil
(
'form-item'
).
find
(
'~.help-block span'
).
text
()
).
toEqual
(
'This field is required'
);
});
it
(
'should validate city'
,
function
()
{
$
(
'input[name=city]'
).
val
(
''
);
$
(
'#payment-button'
).
click
();
expect
(
$
(
'input[name=city]'
).
parentsUntil
(
'form-item'
).
find
(
'~.help-block span'
).
text
()
).
toEqual
(
'This field is required'
);
});
it
(
'should validate country'
,
function
()
{
$
(
'select[name=country]'
).
val
(
''
);
$
(
'#payment-button'
).
click
();
expect
(
$
(
'select[name=country]'
).
parentsUntil
(
'form-item'
).
find
(
'~.help-block span'
).
text
()
).
toEqual
(
'This field is required'
);
});
});
describe
(
'cardInfoValidation'
,
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