Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
a099ff86
Commit
a099ff86
authored
Oct 15, 2015
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move edx.utils.validate.
The test was not running where it lived before.
parent
6fb89fee
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
158 additions
and
156 deletions
+158
-156
common/static/common/js/spec/utils/edx.utils.validate_spec.js
+153
-151
common/static/common/js/utils/edx.utils.validate.js
+0
-0
common/static/js/spec/main_requirejs.js
+2
-1
common/static/js_test.yml
+0
-1
lms/static/js/spec/main.js
+1
-1
lms/static/js/student_account/views/FormView.js
+1
-1
lms/static/js_test.yml
+1
-1
No files found.
common/static/
js/spec
/edx.utils.validate_spec.js
→
common/static/
common/js/spec/utils
/edx.utils.validate_spec.js
View file @
a099ff86
;(
function
(
define
)
{
'use strict'
;
define
([
'jquery'
,
'js/utils/edx.utils.validate'
],
function
(
$
)
{
var
fixture
=
null
,
field
=
null
,
result
=
null
,
MIN_LENGTH
=
2
,
MAX_LENGTH
=
20
,
VALID_STRING
=
'xsy_is_awesome'
,
SHORT_STRING
=
'x'
,
LONG_STRING
=
'xsy_is_way_too_awesome'
,
EMAIL_ERROR_FRAGMENT
=
'formatted'
,
MIN_ERROR_FRAGMENT
=
'least'
,
MAX_ERROR_FRAGMENT
=
'up to'
,
REQUIRED_ERROR_FRAGMENT
=
'Please enter your'
,
CUSTOM_MESSAGE
=
'custom message'
;
var
createFixture
=
function
(
type
,
name
,
required
,
minlength
,
maxlength
,
value
)
{
setFixtures
(
'<input id="field" type='
+
type
+
'>'
);
field
=
$
(
'#field'
);
field
.
prop
(
'required'
,
required
);
field
.
attr
({
name
:
name
,
minlength
:
minlength
,
maxlength
:
maxlength
,
value
:
value
define
([
'jquery'
,
'common/js/utils/edx.utils.validate'
],
function
(
$
,
EdxUtilsValidate
)
{
describe
(
"EdxUtilsValidate"
,
function
()
{
var
fixture
=
null
,
field
=
null
,
result
=
null
,
MIN_LENGTH
=
2
,
MAX_LENGTH
=
20
,
VALID_STRING
=
'xsy_is_awesome'
,
SHORT_STRING
=
'x'
,
LONG_STRING
=
'xsy_is_way_too_awesome'
,
EMAIL_ERROR_FRAGMENT
=
'formatted'
,
MIN_ERROR_FRAGMENT
=
'least'
,
MAX_ERROR_FRAGMENT
=
'up to'
,
REQUIRED_ERROR_FRAGMENT
=
'Please enter your'
,
CUSTOM_MESSAGE
=
'custom message'
;
var
createFixture
=
function
(
type
,
name
,
required
,
minlength
,
maxlength
,
value
)
{
setFixtures
(
'<input id="field" type='
+
type
+
'>'
);
field
=
$
(
'#field'
);
field
.
prop
(
'required'
,
required
);
field
.
attr
({
name
:
name
,
minlength
:
minlength
,
maxlength
:
maxlength
,
value
:
value
});
};
var
expectValid
=
function
()
{
result
=
EdxUtilsValidate
.
validate
(
field
);
expect
(
result
.
isValid
).
toBe
(
true
);
};
var
expectInvalid
=
function
(
errorFragment
)
{
result
=
EdxUtilsValidate
.
validate
(
field
);
expect
(
result
.
isValid
).
toBe
(
false
);
expect
(
result
.
message
).
toMatch
(
errorFragment
);
};
it
(
'succeeds if an optional field is left blank'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
''
);
expectValid
();
});
};
var
expectValid
=
function
()
{
result
=
edx
.
utils
.
validate
(
field
);
expect
(
result
.
isValid
).
toBe
(
true
);
};
var
expectInvalid
=
function
(
errorFragment
)
{
result
=
edx
.
utils
.
validate
(
field
);
expect
(
result
.
isValid
).
toBe
(
false
);
expect
(
result
.
message
).
toMatch
(
errorFragment
);
};
it
(
'succeeds if an optional field is left blank'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
''
);
expectValid
();
});
it
(
'succeeds if a required field is provided a valid value'
,
function
()
{
createFixture
(
'text'
,
'username'
,
true
,
MIN_LENGTH
,
MAX_LENGTH
,
VALID_STRING
);
expectValid
();
});
it
(
'succeeds if a required field is provided a valid value'
,
function
()
{
createFixture
(
'text'
,
'username'
,
true
,
MIN_LENGTH
,
MAX_LENGTH
,
VALID_STRING
);
expectValid
();
});
it
(
'fails if a required field is left blank'
,
function
()
{
createFixture
(
'text'
,
'username'
,
true
,
MIN_LENGTH
,
MAX_LENGTH
,
''
);
expectInvalid
(
REQUIRED_ERROR_FRAGMENT
);
});
it
(
'fails if a required field is left blank'
,
function
()
{
createFixture
(
'text'
,
'username'
,
true
,
MIN_LENGTH
,
MAX_LENGTH
,
''
);
expectInvalid
(
REQUIRED_ERROR_FRAGMENT
);
});
it
(
'fails if a field is provided a value below its minimum character limit'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
SHORT_STRING
);
it
(
'fails if a field is provided a value below its minimum character limit'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
SHORT_STRING
);
// Verify optional field behavior
expectInvalid
(
MIN_ERROR_FRAGMENT
);
// Verify optional field behavior
expectInvalid
(
MIN_ERROR_FRAGMENT
);
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectInvalid
(
MIN_ERROR_FRAGMENT
);
});
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectInvalid
(
MIN_ERROR_FRAGMENT
);
});
it
(
'succeeds if a field with no minimum character limit is provided a value below its maximum character limit'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
null
,
MAX_LENGTH
,
SHORT_STRING
);
it
(
'succeeds if a field with no minimum character limit is provided a value below its maximum character limit'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
null
,
MAX_LENGTH
,
SHORT_STRING
);
// Verify optional field behavior
expectValid
();
// Verify optional field behavior
expectValid
();
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectValid
();
});
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectValid
();
});
it
(
'fails if a required field with no minimum character limit is left blank'
,
function
()
{
createFixture
(
'text'
,
'username'
,
true
,
null
,
MAX_LENGTH
,
''
);
expectInvalid
(
REQUIRED_ERROR_FRAGMENT
);
});
it
(
'fails if a required field with no minimum character limit is left blank'
,
function
()
{
createFixture
(
'text'
,
'username'
,
true
,
null
,
MAX_LENGTH
,
''
);
expectInvalid
(
REQUIRED_ERROR_FRAGMENT
);
});
it
(
'fails if a field is provided a value above its maximum character limit'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
LONG_STRING
);
it
(
'fails if a field is provided a value above its maximum character limit'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
LONG_STRING
);
// Verify optional field behavior
expectInvalid
(
MAX_ERROR_FRAGMENT
);
// Verify optional field behavior
expectInvalid
(
MAX_ERROR_FRAGMENT
);
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectInvalid
(
MAX_ERROR_FRAGMENT
);
});
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectInvalid
(
MAX_ERROR_FRAGMENT
);
});
it
(
'succeeds if a field with no maximum character limit is provided a value above its minimum character limit'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
MIN_LENGTH
,
null
,
LONG_STRING
);
it
(
'succeeds if a field with no maximum character limit is provided a value above its minimum character limit'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
MIN_LENGTH
,
null
,
LONG_STRING
);
// Verify optional field behavior
expectValid
();
// Verify optional field behavior
expectValid
();
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectValid
();
});
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectValid
();
});
it
(
'succeeds if a field with no character limits is provided a value'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
null
,
null
,
VALID_STRING
);
it
(
'succeeds if a field with no character limits is provided a value'
,
function
()
{
createFixture
(
'text'
,
'username'
,
false
,
null
,
null
,
VALID_STRING
);
// Verify optional field behavior
expectValid
();
// Verify optional field behavior
expectValid
();
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectValid
();
});
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectValid
();
});
it
(
'fails if an email field is provided an invalid address'
,
function
()
{
createFixture
(
'email'
,
'email'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
'localpart'
);
it
(
'fails if an email field is provided an invalid address'
,
function
()
{
createFixture
(
'email'
,
'email'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
'localpart'
);
// Verify optional field behavior
expectInvalid
(
EMAIL_ERROR_FRAGMENT
);
// Verify optional field behavior
expectInvalid
(
EMAIL_ERROR_FRAGMENT
);
// Verify required field behavior
field
.
prop
(
'required'
,
false
);
expectInvalid
(
EMAIL_ERROR_FRAGMENT
);
});
// Verify required field behavior
field
.
prop
(
'required'
,
false
);
expectInvalid
(
EMAIL_ERROR_FRAGMENT
);
});
it
(
'succeeds if an email field is provided a valid address'
,
function
()
{
createFixture
(
'email'
,
'email'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
'localpart@label.tld'
);
it
(
'succeeds if an email field is provided a valid address'
,
function
()
{
createFixture
(
'email'
,
'email'
,
false
,
MIN_LENGTH
,
MAX_LENGTH
,
'localpart@label.tld'
);
// Verify optional field behavior
expectValid
();
// Verify optional field behavior
expectValid
();
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectValid
();
});
// Verify required field behavior
field
.
prop
(
'required'
,
true
);
expectValid
();
});
it
(
'succeeds if a checkbox is optional, or required and checked, but fails if a required checkbox is unchecked'
,
function
()
{
createFixture
(
'checkbox'
,
'checkbox'
,
false
,
null
,
null
,
'value'
);
it
(
'succeeds if a checkbox is optional, or required and checked, but fails if a required checkbox is unchecked'
,
function
()
{
createFixture
(
'checkbox'
,
'checkbox'
,
false
,
null
,
null
,
'value'
);
// Optional, unchecked
expectValid
();
// Optional, unchecked
expectValid
();
// Optional, checked
field
.
prop
(
'checked'
,
true
);
expectValid
();
// Optional, checked
field
.
prop
(
'checked'
,
true
);
expectValid
();
// Required, checked
field
.
prop
(
'required'
,
true
);
expectValid
();
// Required, checked
field
.
prop
(
'required'
,
true
);
expectValid
();
// Required, unchecked
field
.
prop
(
'checked'
,
false
);
expectInvalid
(
REQUIRED_ERROR_FRAGMENT
);
});
// Required, unchecked
field
.
prop
(
'checked'
,
false
);
expectInvalid
(
REQUIRED_ERROR_FRAGMENT
);
});
it
(
'succeeds if a select is optional, or required and default is selected, but fails if a required select has the default option selected'
,
function
()
{
var
select
=
[
'<select id="dropdown" name="country">'
,
'<option value="" data-isdefault="true">Please select a country</option>'
,
'<option value="BE">Belgium</option>'
,
'<option value="DE">Germany</option>'
,
'</select>'
].
join
(
''
);
it
(
'succeeds if a select is optional, or required and default is selected, but fails if a required select has the default option selected'
,
function
()
{
var
select
=
[
'<select id="dropdown" name="country">'
,
'<option value="" data-isdefault="true">Please select a country</option>'
,
'<option value="BE">Belgium</option>'
,
'<option value="DE">Germany</option>'
,
'</select>'
].
join
(
''
);
setFixtures
(
select
);
setFixtures
(
select
);
field
=
$
(
'#dropdown'
);
field
=
$
(
'#dropdown'
);
// Optional
expectValid
();
// Optional
expectValid
();
// Required, default text selected
field
.
attr
(
'required'
,
true
);
expectInvalid
(
REQUIRED_ERROR_FRAGMENT
);
// Required, default text selected
field
.
attr
(
'required'
,
true
);
expectInvalid
(
REQUIRED_ERROR_FRAGMENT
);
// Required, country selected
field
.
val
(
'BE'
);
expectValid
();
});
// Required, country selected
field
.
val
(
'BE'
);
expectValid
();
});
it
(
'returns a custom error message if an invalid field has one attached'
,
function
()
{
// Create a blank required field
createFixture
(
'text'
,
'username'
,
true
,
MIN_LENGTH
,
MAX_LENGTH
,
''
);
it
(
'returns a custom error message if an invalid field has one attached'
,
function
()
{
// Create a blank required field
createFixture
(
'text'
,
'username'
,
true
,
MIN_LENGTH
,
MAX_LENGTH
,
''
);
// Attach a custom error message to the field
field
.
data
(
'errormsg-required'
,
CUSTOM_MESSAGE
);
// Attach a custom error message to the field
field
.
data
(
'errormsg-required'
,
CUSTOM_MESSAGE
);
expectInvalid
(
CUSTOM_MESSAGE
);
expectInvalid
(
CUSTOM_MESSAGE
);
});
});
});
}).
call
(
this
,
define
||
RequireJS
.
define
);
common/static/js/utils/edx.utils.validate.js
→
common/static/
common/
js/utils/edx.utils.validate.js
View file @
a099ff86
File moved
common/static/js/spec/main_requirejs.js
View file @
a099ff86
...
...
@@ -162,7 +162,8 @@
'common-requirejs/include/common/js/spec/components/paging_header_spec.js'
,
'common-requirejs/include/common/js/spec/components/paging_footer_spec.js'
,
'common-requirejs/include/common/js/spec/components/search_field_spec.js'
,
'common-requirejs/include/common/js/spec/components/view_utils_spec.js'
'common-requirejs/include/common/js/spec/components/view_utils_spec.js'
,
'common-requirejs/include/common/js/spec/utils/edx.utils.validate_spec.js'
]);
}).
call
(
this
,
requirejs
,
define
);
common/static/js_test.yml
View file @
a099ff86
...
...
@@ -48,7 +48,6 @@ src_paths:
-
js/xblock
-
coffee/src
-
js/src
-
js/utils
-
js/capa/src
# Paths to spec (test) JavaScript files
...
...
lms/static/js/spec/main.js
View file @
a099ff86
...
...
@@ -89,7 +89,7 @@
'annotator_1.2.9'
:
'xmodule_js/common_static/js/vendor/edxnotes/annotator-full.min'
,
// Common edx utils
'
js/utils/edx.utils.validate'
:
'xmodule_js/common_static
/js/utils/edx.utils.validate'
'
common/js/utils/edx.utils.validate'
:
'xmodule_js/common_static/common
/js/utils/edx.utils.validate'
},
shim
:
{
'gettext'
:
{
...
...
lms/static/js/student_account/views/FormView.js
View file @
a099ff86
...
...
@@ -4,7 +4,7 @@
'jquery'
,
'underscore'
,
'backbone'
,
'js/utils/edx.utils.validate'
'
common/
js/utils/edx.utils.validate'
],
function
(
$
,
_
,
Backbone
,
EdxUtilsValidate
)
{
...
...
lms/static/js_test.yml
View file @
a099ff86
...
...
@@ -64,7 +64,7 @@ lib_paths:
-
xmodule_js/common_static/js/vendor/date.js
-
xmodule_js/common_static/js/vendor/moment.min.js
-
xmodule_js/common_static/js/vendor/moment-with-locales.min.js
-
xmodule_js/common_static/js/utils/edx.utils.validate.js
-
xmodule_js/common_static/
common/
js/utils/edx.utils.validate.js
# Paths to source JavaScript files
src_paths
:
...
...
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