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
200da37c
Commit
200da37c
authored
Aug 09, 2013
by
Peter Baratta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Leave loading icon on when waiting for error messages
parent
ef30e3e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
45 deletions
+50
-45
common/static/js/capa/spec/formula_equation_preview_spec.js
+46
-43
common/static/js/capa/src/formula_equation_preview.js
+4
-2
No files found.
common/static/js/capa/spec/formula_equation_preview_spec.js
View file @
200da37c
...
@@ -77,33 +77,37 @@ describe("Formula Equation Preview", function () {
...
@@ -77,33 +77,37 @@ describe("Formula Equation Preview", function () {
});
});
describe
(
'Ajax requests'
,
function
()
{
describe
(
'Ajax requests'
,
function
()
{
beforeEach
(
function
()
{
it
(
'has an initial request with the correct parameters'
,
function
()
{
// This is common to all tests on ajax requests.
formulaEquationPreview
.
enable
();
formulaEquationPreview
.
enable
();
expect
(
MathJax
.
Hub
.
Queue
).
toHaveBeenCalled
();
// Do what Queue would've done--call the function.
var
args
=
MathJax
.
Hub
.
Queue
.
mostRecentCall
.
args
;
args
[
1
].
call
(
args
[
0
]);
// This part may be asynchronous, so wait.
// This part may be asynchronous, so wait.
waitsFor
(
function
()
{
waitsFor
(
function
()
{
return
Problem
.
inputAjax
.
wasCalled
;
return
Problem
.
inputAjax
.
wasCalled
;
},
"AJAX never called initially"
,
1000
);
},
"AJAX never called initially"
,
1000
);
});
it
(
'has an initial request with the correct parameters'
,
function
()
{
runs
(
function
()
{
expect
(
Problem
.
inputAjax
.
callCount
).
toEqual
(
1
);
expect
(
Problem
.
inputAjax
.
callCount
).
toEqual
(
1
);
// Use `.toEqual` rather than `.toHaveBeenCalledWith`
// Use `.toEqual` rather than `.toHaveBeenCalledWith`
// since it supports `jasmine.any`.
// since it supports `jasmine.any`.
expect
(
Problem
.
inputAjax
.
mostRecentCall
.
args
).
toEqual
([
expect
(
Problem
.
inputAjax
.
mostRecentCall
.
args
).
toEqual
([
"THE_URL"
,
"THE_URL"
,
"THE_ID"
,
"THE_ID"
,
"preview_formcalc"
,
"preview_formcalc"
,
{
formula
:
"prefilled_value"
,
{
formula
:
"prefilled_value"
,
request_start
:
jasmine
.
any
(
Number
)},
request_start
:
jasmine
.
any
(
Number
)},
jasmine
.
any
(
Function
)
jasmine
.
any
(
Function
)
]);
]);
});
});
});
it
(
'makes a request on user input'
,
function
()
{
it
(
'makes a request on user input'
,
function
()
{
Problem
.
inputAjax
.
reset
();
formulaEquationPreview
.
enable
();
$
(
'#input_THE_ID'
).
val
(
'user_input'
).
trigger
(
'input'
);
$
(
'#input_THE_ID'
).
val
(
'user_input'
).
trigger
(
'input'
);
// This part is probably asynchronous
// This part is probably asynchronous
...
@@ -118,7 +122,8 @@ describe("Formula Equation Preview", function () {
...
@@ -118,7 +122,8 @@ describe("Formula Equation Preview", function () {
});
});
it
(
"shouldn't be requested for empty input"
,
function
()
{
it
(
"shouldn't be requested for empty input"
,
function
()
{
Problem
.
inputAjax
.
reset
();
formulaEquationPreview
.
enable
();
MathJax
.
Hub
.
Queue
.
reset
();
// When we make an input of '',
// When we make an input of '',
$
(
'#input_THE_ID'
).
val
(
''
).
trigger
(
'input'
);
$
(
'#input_THE_ID'
).
val
(
''
).
trigger
(
'input'
);
...
@@ -137,7 +142,9 @@ describe("Formula Equation Preview", function () {
...
@@ -137,7 +142,9 @@ describe("Formula Equation Preview", function () {
});
});
it
(
'should limit the number of requests per second'
,
function
()
{
it
(
'should limit the number of requests per second'
,
function
()
{
var
minDelay
=
formulaEquationPreview
.
minDelay
;
formulaEquationPreview
.
enable
();
var
minDelay
=
formulaEquationPreview
.
minDelay
;
var
end
=
Date
.
now
()
+
minDelay
*
1.1
;
var
end
=
Date
.
now
()
+
minDelay
*
1.1
;
var
step
=
10
;
// ms
var
step
=
10
;
// ms
...
@@ -172,35 +179,23 @@ describe("Formula Equation Preview", function () {
...
@@ -172,35 +179,23 @@ describe("Formula Equation Preview", function () {
describe
(
"Visible results (icon and mathjax)"
,
function
()
{
describe
(
"Visible results (icon and mathjax)"
,
function
()
{
it
(
'should display a loading icon when requests are open'
,
function
()
{
it
(
'should display a loading icon when requests are open'
,
function
()
{
formulaEquationPreview
.
enable
();
var
$img
=
$
(
"img.loading"
);
var
$img
=
$
(
"img.loading"
);
expect
(
$img
.
css
(
'visibility'
)).
toEqual
(
'hidden'
);
expect
(
$img
.
css
(
'visibility'
)).
toEqual
(
'hidden'
);
formulaEquationPreview
.
enable
();
expect
(
$img
.
css
(
'visibility'
)).
toEqual
(
'visible'
);
// This part could be asynchronous
waitsFor
(
function
()
{
return
Problem
.
inputAjax
.
wasCalled
;
},
"AJAX never called initially"
,
1000
);
runs
(
function
()
{
expect
(
$img
.
css
(
'visibility'
)).
toEqual
(
'visible'
);
// Reset and send another request.
$img
.
css
(
'visibility'
,
'hidden'
);
$
(
"#input_THE_ID"
).
val
(
"different"
).
trigger
(
'input'
);
expect
(
$img
.
css
(
'visibility'
)).
toEqual
(
'visible
'
);
$
(
"#input_THE_ID"
).
val
(
"different"
).
trigger
(
'input
'
);
}
);
expect
(
$img
.
css
(
'visibility'
)).
toEqual
(
'visible'
);
// Don't let it fail later.
// Don't let it fail later.
waitsFor
(
function
()
{
waitsFor
(
function
()
{
var
args
=
Problem
.
inputAjax
.
mostRecentCall
.
args
;
return
Problem
.
inputAjax
.
wasCalled
;
return
args
[
3
].
formula
==
"different"
;
});
});
});
});
it
(
'should update MathJax and loading icon on callback'
,
function
()
{
it
(
'should update MathJax and loading icon on callback'
,
function
()
{
formulaEquationPreview
.
enable
();
formulaEquationPreview
.
enable
();
$
(
'#input_THE_ID'
).
val
(
'user_input'
).
trigger
(
'input'
);
waitsFor
(
function
()
{
waitsFor
(
function
()
{
return
Problem
.
inputAjax
.
wasCalled
;
return
Problem
.
inputAjax
.
wasCalled
;
},
"AJAX never called initially"
,
1000
);
},
"AJAX never called initially"
,
1000
);
...
@@ -229,7 +224,11 @@ describe("Formula Equation Preview", function () {
...
@@ -229,7 +224,11 @@ describe("Formula Equation Preview", function () {
});
});
it
(
'should display errors from the server well'
,
function
()
{
it
(
'should display errors from the server well'
,
function
()
{
var
$img
=
$
(
"img.loading"
);
formulaEquationPreview
.
enable
();
formulaEquationPreview
.
enable
();
MathJax
.
Hub
.
Queue
.
reset
();
$
(
"#input_THE_ID"
).
val
(
"different"
).
trigger
(
'input'
);
waitsFor
(
function
()
{
waitsFor
(
function
()
{
return
Problem
.
inputAjax
.
wasCalled
;
return
Problem
.
inputAjax
.
wasCalled
;
},
"AJAX never called initially"
,
1000
);
},
"AJAX never called initially"
,
1000
);
...
@@ -242,6 +241,7 @@ describe("Formula Equation Preview", function () {
...
@@ -242,6 +241,7 @@ describe("Formula Equation Preview", function () {
request_start
:
args
[
3
].
request_start
request_start
:
args
[
3
].
request_start
});
});
expect
(
MathJax
.
Hub
.
Queue
).
not
.
toHaveBeenCalled
();
expect
(
MathJax
.
Hub
.
Queue
).
not
.
toHaveBeenCalled
();
expect
(
$img
.
css
(
'visibility'
)).
toEqual
(
'visible'
);
});
});
var
errorDelay
=
formulaEquationPreview
.
errorDelay
*
1.1
;
var
errorDelay
=
formulaEquationPreview
.
errorDelay
*
1.1
;
...
@@ -255,6 +255,7 @@ describe("Formula Equation Preview", function () {
...
@@ -255,6 +255,7 @@ describe("Formula Equation Preview", function () {
[
'Text'
,
this
.
jax
,
'
\\
text{OOPSIE}'
],
[
'Text'
,
this
.
jax
,
'
\\
text{OOPSIE}'
],
[
'Reprocess'
,
this
.
jax
]
[
'Reprocess'
,
this
.
jax
]
);
);
expect
(
$img
.
css
(
'visibility'
)).
toEqual
(
'hidden'
);
});
});
});
});
});
});
...
@@ -262,14 +263,16 @@ describe("Formula Equation Preview", function () {
...
@@ -262,14 +263,16 @@ describe("Formula Equation Preview", function () {
describe
(
'Multiple callbacks'
,
function
()
{
describe
(
'Multiple callbacks'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
formulaEquationPreview
.
enable
();
formulaEquationPreview
.
enable
();
MathJax
.
Hub
.
Queue
.
reset
();
$
(
'#input_THE_ID'
).
val
(
'different'
).
trigger
(
'input'
);
waitsFor
(
function
()
{
waitsFor
(
function
()
{
return
Problem
.
inputAjax
.
wasCalled
;
return
Problem
.
inputAjax
.
wasCalled
;
});
});
runs
(
function
()
{
runs
(
function
()
{
$
(
'#input_THE_ID'
).
val
(
'different'
).
trigger
(
'input'
);
$
(
"#input_THE_ID"
).
val
(
"different2"
).
trigger
(
'input'
);
});
});
waitsFor
(
function
()
{
waitsFor
(
function
()
{
return
Problem
.
inputAjax
.
callCount
>
1
;
return
Problem
.
inputAjax
.
callCount
>
1
;
...
...
common/static/js/capa/src/formula_equation_preview.js
View file @
200da37c
...
@@ -58,8 +58,8 @@ formulaEquationPreview.enable = function () {
...
@@ -58,8 +58,8 @@ formulaEquationPreview.enable = function () {
};
};
$this
.
on
(
"input"
,
initializeRequest
);
$this
.
on
(
"input"
,
initializeRequest
);
// send an initial
// send an initial
initializeRequest
.
call
(
this
);
MathJax
.
Hub
.
Queue
(
this
,
initializeRequest
);
}
}
/**
/**
...
@@ -139,8 +139,10 @@ formulaEquationPreview.enable = function () {
...
@@ -139,8 +139,10 @@ formulaEquationPreview.enable = function () {
}
}
if
(
response
.
error
)
{
if
(
response
.
error
)
{
inputData
.
$img
.
css
(
'visibility'
,
'visible'
);
inputData
.
errorWaitTimeout
=
window
.
setTimeout
(
function
()
{
inputData
.
errorWaitTimeout
=
window
.
setTimeout
(
function
()
{
display
(
"
\\
text{"
+
response
.
error
+
"}"
);
display
(
"
\\
text{"
+
response
.
error
+
"}"
);
inputData
.
$img
.
css
(
'visibility'
,
'hidden'
);
},
formulaEquationPreview
.
errorDelay
);
},
formulaEquationPreview
.
errorDelay
);
}
else
{
}
else
{
display
(
response
.
preview
);
display
(
response
.
preview
);
...
...
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