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
6e01ce50
Commit
6e01ce50
authored
Dec 11, 2013
by
polesye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests.
parent
4e10c729
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
506 additions
and
6 deletions
+506
-6
cms/static/coffee/spec/main.coffee
+4
-0
cms/static/js_test.yml
+1
-0
cms/static/js_test_squire.yml
+1
-0
common/lib/xmodule/xmodule/js/js_test.yml
+1
-0
common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee
+108
-1
common/lib/xmodule/xmodule/js/spec/helper.coffee
+2
-0
common/lib/xmodule/xmodule/js/src/capa/display.coffee
+5
-5
common/static/js/vendor/jasmine-imagediff.js
+382
-0
common/static/js_test.yml
+1
-0
lms/static/js_test.yml
+1
-0
No files found.
cms/static/coffee/spec/main.coffee
View file @
6e01ce50
...
...
@@ -34,6 +34,7 @@ requirejs.config({
"sinon"
:
"xmodule_js/common_static/js/vendor/sinon-1.7.1"
,
"squire"
:
"xmodule_js/common_static/js/vendor/Squire"
,
"jasmine-jquery"
:
"xmodule_js/common_static/js/vendor/jasmine-jquery"
,
"jasmine-imagediff"
:
"xmodule_js/common_static/js/vendor/jasmine-imagediff"
,
"jasmine-stealth"
:
"xmodule_js/common_static/js/vendor/jasmine-stealth"
,
"jasmine.async"
:
"xmodule_js/common_static/js/vendor/jasmine.async"
,
"draggabilly"
:
"xmodule_js/common_static/js/vendor/draggabilly.pkgd"
,
...
...
@@ -151,6 +152,9 @@ requirejs.config({
"jasmine-jquery"
:
{
deps
:
[
"jasmine"
]
},
"jasmine-imagediff"
:
{
deps
:
[
"jasmine"
]
},
"jasmine-stealth"
:
{
deps
:
[
"jasmine"
]
},
...
...
cms/static/js_test.yml
View file @
6e01ce50
...
...
@@ -47,6 +47,7 @@ lib_paths:
-
xmodule_js/common_static/js/vendor/Squire.js
-
xmodule_js/common_static/js/vendor/jasmine-jquery.js
-
xmodule_js/common_static/js/vendor/jasmine-stealth.js
-
xmodule_js/common_static/js/vendor/jasmine-imagediff.js
-
xmodule_js/common_static/js/vendor/jasmine.async.js
-
xmodule_js/common_static/js/vendor/jquery.maskedinput.min.js
-
xmodule_js/common_static/js/vendor/CodeMirror/codemirror.js
...
...
cms/static/js_test_squire.yml
View file @
6e01ce50
...
...
@@ -46,6 +46,7 @@ lib_paths:
-
xmodule_js/common_static/js/vendor/Squire.js
-
xmodule_js/common_static/js/vendor/jasmine-jquery.js
-
xmodule_js/common_static/js/vendor/jasmine-stealth.js
-
xmodule_js/common_static/js/vendor/jasmine-imagediff.js
-
xmodule_js/common_static/js/vendor/jasmine.async.js
-
xmodule_js/common_static/js/vendor/CodeMirror/codemirror.js
-
xmodule_js/src/xmodule.js
...
...
common/lib/xmodule/xmodule/js/js_test.yml
View file @
6e01ce50
...
...
@@ -36,6 +36,7 @@ lib_paths:
-
common_static/coffee/src/ajax_prefix.js
-
common_static/coffee/src/logger.js
-
common_static/js/vendor/jasmine-jquery.js
-
common_static/js/vendor/jasmine-imagediff.js
-
common_static/js/vendor/require.js
-
RequireJS-namespace-undefine.js
-
common_static/js/vendor/jquery.min.js
...
...
common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee
View file @
6e01ce50
...
...
@@ -303,6 +303,114 @@ describe 'Problem', ->
expect
(
$
(
'input#1_2_1_choiceinput_2bc'
).
attr
(
'disabled'
)).
not
.
toEqual
(
'disabled'
)
expect
(
$
(
'input#1_2_1'
).
attr
(
'disabled'
)).
not
.
toEqual
(
'disabled'
)
describe
'imageinput'
,
->
imageinput_html
=
'''
<section class="problem">
<div class="imageinput capa_inputtype" id="inputtype_1_2_1">
<input class="imageinput" type="hidden" name="input_1_2_1" id="input_1_2_1">
<div style="position:relative;">
<div id="imageinput_1_2_1">test</div>
<div id="answer_1_2_1" data-width="100" data-height="100"></div>
</div>
</div>
</section>
'''
states
=
[
{
desc
:
'rectangle is drawn correctly'
,
data
:
{
'rectangle'
:
'(10,10)-(30,30)'
}
},
{
desc
:
'region is drawn correctly'
,
data
:
{
'regions'
:
'[[10,10],[30,30],[70,30],[20,30]]'
}
},
{
desc
:
'mixed shapes are drawn correctly'
,
data
:
{
'rectangle'
:
'(10,10)-(30,30);(5,5)-(20,20)'
,
'regions'
:
'''[
[[50,50],[40,40],[70,30],[50,70]],
[[90,95],[95,95],[90,70],[70,70]]
]'''
}
},
]
beforeEach
->
@
problem
=
new
Problem
(
$
(
'.xblock-student_view'
))
@
problem
.
el
.
prepend
imageinput_html
stubRequest
=
(
data
)
=>
spyOn
(
$
,
'postWithPrefix'
).
andCallFake
(
url
,
callback
)
->
callback
answers
:
"1_2_1"
:
data
getImage
=
(
coords
,
c_width
,
c_height
)
=>
types
=
rectangle
:
(
coords
)
=>
reg
=
/^\(([0-9]+),([0-9]+)\)-\(([0-9]+),([0-9]+)\)$/
rects
=
coords
.
replace
(
/\s*/g
,
''
).
split
(
/;/
)
$
.
each
rects
,
(
index
,
rect
)
=>
abs
=
Math
.
abs
points
=
reg
.
exec
(
rect
)
if
points
# width
width
=
abs
(
points
[
3
]
-
points
[
1
])
# height
height
=
abs
(
points
[
4
]
-
points
[
2
])
ctx
.
rect
(
points
[
1
],
points
[
2
],
width
,
height
)
ctx
.
stroke
()
ctx
.
fill
()
regions
:
(
coords
)
=>
parseCoords
=
(
coords
)
=>
reg
=
JSON
.
parse
(
coords
)
if
typeof
reg
[
0
][
0
][
0
]
==
"undefined"
reg
=
[
reg
]
return
reg
$
.
each
parseCoords
(
coords
),
(
index
,
region
)
=>
ctx
.
beginPath
()
$
.
each
region
,
(
index
,
point
)
=>
if
index
is
0
ctx
.
moveTo
(
point
[
0
],
point
[
1
])
else
ctx
.
lineTo
(
point
[
0
],
point
[
1
]);
ctx
.
closePath
()
ctx
.
stroke
()
ctx
.
fill
()
canvas
=
document
.
createElement
(
'canvas'
)
canvas
.
width
=
c_width
or
100
canvas
.
height
=
c_height
or
100
if
canvas
.
getContext
ctx
=
canvas
.
getContext
(
'2d'
)
else
return
console
.
log
'Canvas is not supported.'
ctx
.
fillStyle
=
'rgba(255,255,255,.3)'
;
ctx
.
strokeStyle
=
"#FF0000"
;
ctx
.
lineWidth
=
"2"
;
$
.
each
coords
,
(
key
,
value
)
=>
types
[
key
](
value
)
if
types
[
key
]
?
return
canvas
$
.
each
states
,
(
index
,
state
)
=>
it
state
.
desc
,
->
stubRequest
(
state
.
data
)
@
problem
.
show
()
img
=
getImage
(
state
.
data
)
expect
(
img
).
toImageDiffEqual
(
$
(
'canvas'
)[
0
])
describe
'when the answers are already shown'
,
->
beforeEach
->
@
problem
.
el
.
addClass
'showed'
...
...
@@ -409,4 +517,3 @@ describe 'Problem', ->
expect
(
@
problem
.
answers
).
toEqual
"input_1_1=one&input_1_2=two"
common/lib/xmodule/xmodule/js/spec/helper.coffee
View file @
6e01ce50
...
...
@@ -162,6 +162,8 @@ beforeEach ->
toBeInArray
:
(
array
)
->
return
$
.
inArray
(
@
.
actual
,
array
)
>
-
1
@
addMatchers
imagediff
.
jasmine
# Stub jQuery.cookie
$
.
cookie
=
jasmine
.
createSpy
(
'jQuery.cookie'
).
andReturn
'1.0'
...
...
common/lib/xmodule/xmodule/js/src/capa/display.coffee
View file @
6e01ce50
...
...
@@ -506,18 +506,18 @@ class @Problem
parseCoords
=
(
coords
)
=>
reg
=
JSON
.
parse
(
coords
)
if
typeof
reg
[
0
][
0
]
is
undefined
if
typeof
reg
[
0
][
0
]
[
0
]
==
"undefined"
reg
=
[
reg
]
return
reg
$
.
each
parseCoords
(
coords
),
(
index
,
region
s
)
=>
$
.
each
parseCoords
(
coords
),
(
index
,
region
)
=>
ctx
.
beginPath
()
$
.
each
region
s
,
(
index
,
points
)
=>
$
.
each
region
,
(
index
,
point
)
=>
if
index
is
0
ctx
.
moveTo
(
point
s
[
0
],
points
[
1
])
ctx
.
moveTo
(
point
[
0
],
point
[
1
])
else
ctx
.
lineTo
(
point
s
[
0
],
points
[
1
]);
ctx
.
lineTo
(
point
[
0
],
point
[
1
]);
ctx
.
closePath
()
ctx
.
stroke
()
...
...
common/static/js/vendor/jasmine-imagediff.js
0 → 100644
View file @
6e01ce50
This diff is collapsed.
Click to expand it.
common/static/js_test.yml
View file @
6e01ce50
...
...
@@ -30,6 +30,7 @@ prepend_path: common/static
lib_paths
:
-
js/vendor/jquery.min.js
-
js/vendor/jasmine-jquery.js
-
js/vendor/jasmine-imagediff.js
-
js/vendor/underscore-min.js
-
js/vendor/backbone-min.js
-
js/vendor/jquery.timeago.js
...
...
lms/static/js_test.yml
View file @
6e01ce50
...
...
@@ -31,6 +31,7 @@ lib_paths:
-
xmodule_js/common_static/coffee/src/ajax_prefix.js
-
xmodule_js/common_static/coffee/src/logger.js
-
xmodule_js/common_static/js/vendor/jasmine-jquery.js
-
xmodule_js/common_static/js/vendor/jasmine-imagediff.js
-
xmodule_js/common_static/js/vendor/require.js
-
js/RequireJS-namespace-undefine.js
-
xmodule_js/common_static/js/vendor/jquery.min.js
...
...
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