Commit 10df7db7 by Will Daly

Merge pull request #359 from edx/will/TIM-588

Bugfix: TIM-588
parents 0ad5906e 632ac0a8
......@@ -67,7 +67,7 @@
{% endfor %}
</ol>
{% if is_course_staff %}
{% if show_staff_debug_info %}
<div id="openassessment__staff-info"></div>
{% endif %}
</div>
......
......@@ -227,7 +227,7 @@ class OpenAssessmentBlock(
"question": self.prompt,
"rubric_criteria": self.rubric_criteria,
"rubric_assessments": ui_models,
"is_course_staff": self.is_course_staff,
"show_staff_debug_info": self.is_course_staff and not self.in_studio_preview,
}
template = get_template("openassessmentblock/oa_base.html")
......
......@@ -2,6 +2,7 @@
{
"template": "openassessmentblock/oa_base.html",
"context": {
"show_staff_debug_info": false,
"title": "Test title",
"question": "Test prompt",
"rubric_criteria": [],
......@@ -35,6 +36,42 @@
"output": "oa_base.html"
},
{
"template": "openassessmentblock/oa_base.html",
"context": {
"show_staff_debug_info": true,
"title": "Test title",
"question": "Test prompt",
"rubric_criteria": [],
"rubric_assessments": [
{
"name": "submission",
"class_id": "openassessment__response",
"navigation_text": "Your response to this problem",
"title": "Your Response"
},
{
"name": "peer-assessment",
"class_id": "openassessment__peer-assessment",
"navigation_text": "Your assessment(s) of peer responses",
"title": "Assess Peers' Responses"
},
{
"name": "self-assessment",
"class_id": "openassessment__self-assessment",
"navigation_text": "Your assessment of your response",
"title": "Assess Your Response"
},
{
"name": "grade",
"class_id": "openassessment__grade",
"navigation_text": "Your grade for this problem",
"title": "Your Grade:"
}
]
},
"output": "oa_base_course_staff.html"
},
{
"template": "openassessmentblock/response/oa_response.html",
"context": {
"saved_response": "",
......@@ -345,5 +382,36 @@
"template": "openassessmentblock/oa_edit.html",
"context": {},
"output": "oa_edit.html"
},
{
"template": "openassessmentblock/staff_debug/staff_debug.html",
"context": {
"status_counts": {
"self": 1,
"peer": 2,
"waiting": 3,
"done": 4
},
"num_submissions": 10,
"item_id": "test_item",
"step_dates": [
{
"step": "submission",
"start": "2014-01-01",
"due": "N/A"
},
{
"step": "peer",
"start": "2014-02-02",
"due": "N/A"
},
{
"step": "self",
"start": "2014-03-03",
"due": "2015-04-05"
}
]
},
"output": "oa_staff_info.html"
}
]
/**
Tests for staff info.
**/
describe("OpenAssessment.StaffInfoView", function() {
// Stub server that returns dummy data for the staff info view
var StubServer = function() {
// Remember which fragments have been loaded
this.fragmentsLoaded = [];
// Render the template for the staff info view
this.render = function(component) {
var server = this;
this.fragmentsLoaded.push(component);
return $.Deferred(function(defer) {
fragment = readFixtures("oa_staff_info.html");
defer.resolveWith(this, [fragment]);
});
};
};
// Stub base view
var StubBaseView = function() {
this.showLoadError = function(msg) {};
this.toggleActionError = function(msg, step) {};
this.setUpCollapseExpand = function(sel) {};
this.scrollToTop = function() {};
this.loadAssessmentModules = function() {};
this.loadMessageView = function() {};
};
// Stubs
var baseView = null;
var server = null;
/**
Initialize the staff info view, then check whether it makes
an AJAX call to load the staff info section.
**/
var assertStaffInfoAjaxCall = function(shouldCall) {
// Load the staff info view
var el = $("#openassessment-base").get(0);
var view = new OpenAssessment.StaffInfoView(el, server, baseView);
view.load();
// Check whether it tried to load staff info from the server
var expectedFragments = [];
if (shouldCall) { expectedFragments = ['staff_info']; }
expect(server.fragmentsLoaded).toEqual(expectedFragments);
};
beforeEach(function() {
// Configure the Jasmine fixtures path
jasmine.getFixtures().fixturesPath = 'base/fixtures';
// Create a new stub server
server = new StubServer();
// Create the stub base view
baseView = new StubBaseView();
});
it("Loads staff info if the page contains a course staff section", function() {
// Load the fixture for the container page that DOES include a course staff section
loadFixtures('oa_base_course_staff.html');
assertStaffInfoAjaxCall(true);
});
it("Does NOT load staff info if the page does NOT contain a course staff section", function() {
// Load the fixture for the container page that does NOT include a course staff section
loadFixtures('oa_base.html');
assertStaffInfoAjaxCall(false);
});
});
......@@ -23,15 +23,21 @@ OpenAssessment.StaffInfoView.prototype = {
**/
load: function() {
var view = this;
this.server.render('staff_info').done(
function(html) {
// Load the HTML and install event handlers
$('#openassessment__staff-info', view.element).replaceWith(html);
view.installHandlers();
}
).fail(function(errMsg) {
view.baseView.showLoadError('staff_info');
});
// If we're course staff, the base template should contain a section
// for us to render the staff info to. If that doesn't exist,
// then we're not staff, so we don't need to send the AJAX request.
if ($('#openassessment__staff-info', view.element).length > 0) {
this.server.render('staff_info').done(
function(html) {
// Load the HTML and install event handlers
$('#openassessment__staff-info', view.element).replaceWith(html);
view.installHandlers();
}
).fail(function(errMsg) {
view.baseView.showLoadError('staff_info');
});
}
},
/**
......
......@@ -74,7 +74,6 @@ class TestCourseStaff(XBlockHandlerTestCase):
resp = self.request(xblock, 'render_student_info', json.dumps({}))
self.assertIn("couldn\'t find a response for this student.", resp.decode('utf-8').lower())
@scenario('data/basic_scenario.xml')
def test_hide_course_staff_debug_info_in_studio_preview(self, xblock):
# If we are in Studio preview mode, don't show the staff debug info
......@@ -83,8 +82,15 @@ class TestCourseStaff(XBlockHandlerTestCase):
xblock.xmodule_runtime = self._create_mock_runtime(
xblock.scope_ids.usage_id, True, "Bob"
)
# If the client requests the staff info directly, they should get an error
resp = self.request(xblock, 'render_staff_info', json.dumps({}))
self.assertNotIn("course staff information", resp.decode('utf-8').lower())
self.assertIn("do not have permission", resp.decode('utf-8').lower())
# The container page should not contain a staff info section at all
xblock_fragment = self.runtime.render(xblock, 'student_view')
self.assertNotIn(u'staff-info', xblock_fragment.body_html())
@scenario('data/staff_dates_scenario.xml', user_id='Bob')
def test_staff_debug_dates_table(self, xblock):
......@@ -258,4 +264,4 @@ class TestCourseStaff(XBlockHandlerTestCase):
get_anonymous_student_id=lambda user_id, course_id: anonymous_user_id
)
)
return mock_runtime
\ No newline at end of file
return mock_runtime
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