diff --git a/common/test/acceptance/pages/lms/staff_view.py b/common/test/acceptance/pages/lms/staff_view.py index d5a9a88709..ef755339e6 100644 --- a/common/test/acceptance/pages/lms/staff_view.py +++ b/common/test/acceptance/pages/lms/staff_view.py @@ -79,5 +79,8 @@ class StaffDebugPage(PageObject): @property def idash_msg(self): + """ + Returns the value of #idash_msg + """ self.wait_for_ajax() return self.q(css='#idash_msg').text diff --git a/lms/static/js/spec/staff_debug_actions_spec.js b/lms/static/js/spec/staff_debug_actions_spec.js new file mode 100644 index 0000000000..f1a175e1c4 --- /dev/null +++ b/lms/static/js/spec/staff_debug_actions_spec.js @@ -0,0 +1,65 @@ +describe('StaffDebugActions', function() { + var loc = 'test_loc'; + var fixture_id = 'sd_fu_' + loc; + var fixture = $(''); + + describe('get_url ', function() { + it('defines url to courseware ajax entry point', function() { + spyOn(StaffDebug, "get_current_url").andReturn("/courses/edX/Open_DemoX/edx_demo_course/courseware/stuff"); + expect(StaffDebug.get_url('instructor')).toBe('/courses/edX/Open_DemoX/edx_demo_course/instructor'); + }); + }); + + describe('get_user', function() { + + it('gets the placeholder username if input field is empty', function() { + $('body').append(fixture); + expect(StaffDebug.get_user(loc)).toBe('userman'); + $('#' + fixture_id).remove(); + }); + it('gets a filled in name if there is one', function() { + $('body').append(fixture); + $('#' + fixture_id).val('notuserman'); + expect(StaffDebug.get_user(loc)).toBe('notuserman'); + + $('#' + fixture_id).val(''); + $('#' + fixture_id).remove(); + }); + }); + + describe('reset', function() { + it('makes an ajax call with the expected parameters', function() { + $('body').append(fixture); + + spyOn($, 'ajax'); + StaffDebug.reset(loc) + + expect($.ajax.mostRecentCall.args[0]['type']).toEqual('POST'); + expect($.ajax.mostRecentCall.args[0]['data']).toEqual({ + 'action': "Reset student's attempts", + 'problem_for_student': loc, + 'unique_student_identifier': 'userman' + }); + expect($.ajax.mostRecentCall.args[0]['url']).toEqual('/instructor'); + $('#' + fixture_id).remove(); + }); + }); + describe('sdelete', function() { + it('makes an ajax call with the expected parameters', function() { + $('body').append(fixture); + + spyOn($, 'ajax'); + StaffDebug.sdelete(loc) + + expect($.ajax.mostRecentCall.args[0]['type']).toEqual('POST'); + expect($.ajax.mostRecentCall.args[0]['data']).toEqual({ + 'action': "Delete student state for module", + 'problem_for_student': loc, + 'unique_student_identifier': 'userman' + }); + expect($.ajax.mostRecentCall.args[0]['url']).toEqual('/instructor'); + $('#' + fixture_id).remove(); + }); + }); +}); + diff --git a/lms/static/js/staff_debug_actions.js b/lms/static/js/staff_debug_actions.js new file mode 100644 index 0000000000..dcdf500cc2 --- /dev/null +++ b/lms/static/js/staff_debug_actions.js @@ -0,0 +1,57 @@ +var StaffDebug = (function(){ + + get_current_url = function() { + return window.location.pathname; + } + + get_url = function(action){ + var pathname = this.get_current_url(); + console.log(pathname) + var url = pathname.substr(0,pathname.indexOf('/courseware')) + '/' + action; + return url; + } + + get_user = function(locname){ + var uname = $('#sd_fu_' + locname).val(); + if (uname==""){ + uname = $('#sd_fu_' + locname).attr('placeholder'); + } + return uname; + } + + do_idash_action = function(locname, idaction){ + var pdata = {'action': idaction, + 'problem_for_student': locname, + 'unique_student_identifier': get_user(locname) + } + $.ajax({ + type: "POST", + url: get_url('instructor'), + data: pdata, + success: function(data){ + var msg = $("#idash_msg", data); + $("#result_" + locname).html( msg ); + }, + error: function(request, status, error) { + $("#result_" + locname).html('
' + gettext('Something has gone wrong with this request. The server replied with a status of: ') + error + '
'); + }, + dataType: 'html' + }); + } + + reset = function(locname){ + do_idash_action(locname, "Reset student's attempts"); + } + + sdelete = function(locname){ + do_idash_action(locname, "Delete student state for module"); + } + + return {reset: reset, + sdelete: sdelete, + do_idash_action: do_idash_action, + get_current_url: get_current_url, + get_url: get_url, + get_user: get_user + } +})(); diff --git a/lms/static/js_test.yml b/lms/static/js_test.yml index 4cec8c06e7..06132bb559 100644 --- a/lms/static/js_test.yml +++ b/lms/static/js_test.yml @@ -51,6 +51,7 @@ lib_paths: src_paths: - coffee/src - js/src + - js # Paths to spec (test) JavaScript files spec_paths: diff --git a/lms/templates/courseware/xqa_interface.html b/lms/templates/courseware/xqa_interface.html index 84d509d3f5..c63a726402 100644 --- a/lms/templates/courseware/xqa_interface.html +++ b/lms/templates/courseware/xqa_interface.html @@ -1,6 +1,7 @@ <%namespace name='static' file='/static_content.html'/> + \ No newline at end of file + diff --git a/lms/templates/staff_problem_info.html b/lms/templates/staff_problem_info.html index d855359ac3..fd075e8e25 100644 --- a/lms/templates/staff_problem_info.html +++ b/lms/templates/staff_problem_info.html @@ -1,4 +1,5 @@ <%! from django.utils.translation import ugettext as _ %> +<%namespace name='static' file='/static_content.html'/> ## The JS for this is defined in xqa_interface.html ${block_content} @@ -53,58 +54,6 @@ ${block_content}