Commit 7533a112 by Stephen Sanchez

Some quick cleanup on Javascript and tests.

parent e29f446d
...@@ -243,7 +243,6 @@ describe("OpenAssessment.Server", function() { ...@@ -243,7 +243,6 @@ describe("OpenAssessment.Server", function() {
assessments: ASSESSMENTS, assessments: ASSESSMENTS,
editorAssessmentsOrder: EDITOR_ASSESSMENTS_ORDER, editorAssessmentsOrder: EDITOR_ASSESSMENTS_ORDER,
imageSubmissionEnabled: true, imageSubmissionEnabled: true,
latexEnabled: false,
leaderboardNum: 15 leaderboardNum: 15
}); });
expect($.ajax).toHaveBeenCalledWith({ expect($.ajax).toHaveBeenCalledWith({
...@@ -259,7 +258,6 @@ describe("OpenAssessment.Server", function() { ...@@ -259,7 +258,6 @@ describe("OpenAssessment.Server", function() {
assessments: ASSESSMENTS, assessments: ASSESSMENTS,
editor_assessments_order: EDITOR_ASSESSMENTS_ORDER, editor_assessments_order: EDITOR_ASSESSMENTS_ORDER,
allow_file_upload: true, allow_file_upload: true,
latexEnabled: false,
leaderboard_show: 15 leaderboard_show: 15
}) })
}); });
......
...@@ -52,9 +52,6 @@ OpenAssessment.PeerView.prototype = { ...@@ -52,9 +52,6 @@ OpenAssessment.PeerView.prototype = {
// Load the HTML and install event handlers // Load the HTML and install event handlers
$('#openassessment__peer-assessment', view.element).replaceWith(html); $('#openassessment__peer-assessment', view.element).replaceWith(html);
view.installHandlers(true); view.installHandlers(true);
if (MathJax != undefined && MathJax != null) {
MathJax.Hub.Typeset($('#openassessment__peer-assessment', view.element)[0]);
}
} }
).fail(function(errMsg) { ).fail(function(errMsg) {
view.baseView.showLoadError('peer-assessment'); view.baseView.showLoadError('peer-assessment');
......
...@@ -101,9 +101,7 @@ OpenAssessment.ResponseView.prototype = { ...@@ -101,9 +101,7 @@ OpenAssessment.ResponseView.prototype = {
// Render in mathjax // Render in mathjax
sel.find('#submission__preview__item').show(); 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) { ...@@ -64,9 +64,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
dataType: "html" dataType: "html"
}).done(function(data) { }).done(function(data) {
defer.resolveWith(this, [data]); defer.resolveWith(this, [data]);
if (window.MathJax) { that.renderLatex(data);
that.renderLatex();
}
}).fail(function(data) { }).fail(function(data) {
defer.rejectWith(this, [gettext('This section could not be loaded.')]); defer.rejectWith(this, [gettext('This section could not be loaded.')]);
}); });
...@@ -75,17 +73,16 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -75,17 +73,16 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
/** /**
Render Latex for all new DOM elements with class 'allow--latex'. 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() { renderLatex: function(element) {
var i, latex_elems = $('.allow--latex'); $('.allow--latex', element).each(
if (latex_elems && latex_elems.length !== 0) { function() {
for (i = 0; i < latex_elems.length; i++) { MathJax.Hub.Queue(['Typeset', MathJax.Hub, this]);
MathJax.Hub.Queue(['Typeset', MathJax.Hub, latex_elems[i]]);
} }
} );
latex_elems.removeClass('allow--latex');
}, },
/** /**
...@@ -104,6 +101,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -104,6 +101,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
) )
**/ **/
renderContinuedPeer: function() { renderContinuedPeer: function() {
var view = this;
var url = this.url('render_peer_assessment'); var url = this.url('render_peer_assessment');
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ $.ajax({
...@@ -113,6 +111,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -113,6 +111,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
data: {continue_grading: true} data: {continue_grading: true}
}).done(function(data) { }).done(function(data) {
defer.resolveWith(this, [data]); defer.resolveWith(this, [data]);
view.renderLatex(data);
}).fail(function(data) { }).fail(function(data) {
defer.rejectWith(this, [gettext('This section could not be loaded.')]); defer.rejectWith(this, [gettext('This section could not be loaded.')]);
}); });
......
...@@ -36,4 +36,15 @@ if (typeof window.Logger === 'undefined') { ...@@ -36,4 +36,15 @@ if (typeof window.Logger === 'undefined') {
window.Logger = { window.Logger = {
log: function(event_type, data, kwargs) {} 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 @@ ...@@ -6,7 +6,7 @@
"training_num_current": 1, "training_num_current": 1,
"training_num_available": 2, "training_num_available": 2,
"training_essay": "This is my answer.", "training_essay": "This is my answer.",
"allow_latex": False, "allow_latex": false,
"training_rubric": { "training_rubric": {
"criteria": [ "criteria": [
{ {
......
...@@ -24,7 +24,6 @@ class StudentTrainingTest(XBlockHandlerTestCase): ...@@ -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úĺ.' '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): def assert_path_and_context(self, xblock, expected_path, expected_context):
""" """
Render the student training step and verify that the expected template Render the student training step and verify that the expected template
...@@ -49,7 +48,7 @@ class StudentTrainingTest(XBlockHandlerTestCase): ...@@ -49,7 +48,7 @@ class StudentTrainingTest(XBlockHandlerTestCase):
else: else:
self.assertEqual(context[key], expected_context[key]) 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({})) resp = self.request(xblock, 'render_student_training', json.dumps({}))
self.assertGreater(len(resp), 0) self.assertGreater(len(resp), 0)
...@@ -163,7 +162,7 @@ class StudentTrainingAssessTest(StudentTrainingTest): ...@@ -163,7 +162,7 @@ class StudentTrainingAssessTest(StudentTrainingTest):
# Expect that we were correct # Expect that we were correct
self.assertTrue(resp['success'], msg=resp.get('msg')) self.assertTrue(resp['success'], msg=resp.get('msg'))
self.assertFalse(resp['corrections']) self.assertFalse(resp['corrections'])
expected_context = {} expected_context = {"allow_latex": False}
expected_template = "openassessmentblock/student_training/student_training_complete.html" expected_template = "openassessmentblock/student_training/student_training_complete.html"
self.assert_path_and_context(xblock, expected_template, expected_context) 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