Commit 7533a112 by Stephen Sanchez

Some quick cleanup on Javascript and tests.

parent e29f446d
......@@ -243,7 +243,6 @@ describe("OpenAssessment.Server", function() {
assessments: ASSESSMENTS,
editorAssessmentsOrder: EDITOR_ASSESSMENTS_ORDER,
imageSubmissionEnabled: true,
latexEnabled: false,
leaderboardNum: 15
});
expect($.ajax).toHaveBeenCalledWith({
......@@ -259,7 +258,6 @@ describe("OpenAssessment.Server", function() {
assessments: ASSESSMENTS,
editor_assessments_order: EDITOR_ASSESSMENTS_ORDER,
allow_file_upload: true,
latexEnabled: false,
leaderboard_show: 15
})
});
......
......@@ -52,9 +52,6 @@ OpenAssessment.PeerView.prototype = {
// Load the HTML and install event handlers
$('#openassessment__peer-assessment', view.element).replaceWith(html);
view.installHandlers(true);
if (MathJax != undefined && MathJax != null) {
MathJax.Hub.Typeset($('#openassessment__peer-assessment', view.element)[0]);
}
}
).fail(function(errMsg) {
view.baseView.showLoadError('peer-assessment');
......
......@@ -101,9 +101,7 @@ OpenAssessment.ResponseView.prototype = {
// Render in mathjax
sel.find('#submission__preview__item').show();
if (MathJax !== undefined && MathJax !== null) {
MathJax.Hub.Queue(['Typeset', MathJax.Hub, preview_container[0]]);
}
MathJax.Hub.Queue(['Typeset', MathJax.Hub, preview_container[0]]);
}
);
......
......@@ -64,9 +64,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
dataType: "html"
}).done(function(data) {
defer.resolveWith(this, [data]);
if (window.MathJax) {
that.renderLatex();
}
that.renderLatex(data);
}).fail(function(data) {
defer.rejectWith(this, [gettext('This section could not be loaded.')]);
});
......@@ -75,17 +73,16 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
/**
Render Latex for all new DOM elements with class 'allow--latex'.
Once rendered, remove the class so that a single element does
not get rendered multiple times.
Args:
element: The element to modify.
**/
renderLatex: function() {
var i, latex_elems = $('.allow--latex');
if (latex_elems && latex_elems.length !== 0) {
for (i = 0; i < latex_elems.length; i++) {
MathJax.Hub.Queue(['Typeset', MathJax.Hub, latex_elems[i]]);
renderLatex: function(element) {
$('.allow--latex', element).each(
function() {
MathJax.Hub.Queue(['Typeset', MathJax.Hub, this]);
}
}
latex_elems.removeClass('allow--latex');
);
},
/**
......@@ -104,6 +101,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
)
**/
renderContinuedPeer: function() {
var view = this;
var url = this.url('render_peer_assessment');
return $.Deferred(function(defer) {
$.ajax({
......@@ -113,6 +111,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
data: {continue_grading: true}
}).done(function(data) {
defer.resolveWith(this, [data]);
view.renderLatex(data);
}).fail(function(data) {
defer.rejectWith(this, [gettext('This section could not be loaded.')]);
});
......
......@@ -36,4 +36,15 @@ if (typeof window.Logger === 'undefined') {
window.Logger = {
log: function(event_type, data, kwargs) {}
};
}
// Stub MathJax is the runtime doesn't provide it
if (typeof window.MathJax === 'undefined') {
window.MathJax = {
Hub: {
Typeset: function(data){},
Queue: function(list){}
}
};
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
"training_num_current": 1,
"training_num_available": 2,
"training_essay": "This is my answer.",
"allow_latex": False,
"allow_latex": false,
"training_rubric": {
"criteria": [
{
......
......@@ -24,7 +24,6 @@ class StudentTrainingTest(XBlockHandlerTestCase):
'submission': u'Thé őbjéćt őf édúćátíőń íś tő téáćh úś tő ĺővé ẃhát íś béáútífúĺ.'
}
def assert_path_and_context(self, xblock, expected_path, expected_context):
"""
Render the student training step and verify that the expected template
......@@ -49,7 +48,7 @@ class StudentTrainingTest(XBlockHandlerTestCase):
else:
self.assertEqual(context[key], expected_context[key])
# Verify that we render without error
# Verify that we render without error
resp = self.request(xblock, 'render_student_training', json.dumps({}))
self.assertGreater(len(resp), 0)
......@@ -163,7 +162,7 @@ class StudentTrainingAssessTest(StudentTrainingTest):
# Expect that we were correct
self.assertTrue(resp['success'], msg=resp.get('msg'))
self.assertFalse(resp['corrections'])
expected_context = {}
expected_context = {"allow_latex": False}
expected_template = "openassessmentblock/student_training/student_training_complete.html"
self.assert_path_and_context(xblock, expected_template, expected_context)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment