Commit 57756344 by Carson Gee

Added jasmine tests and factored out javascript functions to new file

parent c7713064
......@@ -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
describe('StaffDebugActions', function() {
var loc = 'test_loc';
var fixture_id = 'sd_fu_' + loc;
var fixture = $('<input id="' + fixture_id + '" placeholder="userman" />');
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();
});
});
});
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('<p id="idash_msg"><font color="red">' + gettext('Something has gone wrong with this request. The server replied with a status of: ') + error + '</font></p>');
},
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
}
})();
......@@ -51,6 +51,7 @@ lib_paths:
src_paths:
- coffee/src
- js/src
- js
# Paths to spec (test) JavaScript files
spec_paths:
......
<%namespace name='static' file='/static_content.html'/>
<script type="text/javascript" src="${static.url('js/vendor/jquery.leanModal.min.js')}"></script>
<script type="text/javascript" src="${static.url('js/staff_debug_actions.js')}"></script>
<script type="text/javascript">
function setup_debug(element_id, edit_link, staff_context){
......@@ -91,4 +92,4 @@ function getlog(element_id, staff_context){
};
</script>
\ No newline at end of file
</script>
<%! 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}
<h2>${_('Staff Debug')}</h2>
</header>
<script type="text/javascript">
var StaffDebug = (function(){
geturl = function(action){
var pathname = window.location.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 = "${user.username}";
}
return uname;
}
do_idash_action = function(locname, idaction){
var pdata = {'csrfmiddlewaretoken': "${csrf_token}",
'action': idaction,
'problem_for_student': locname,
'unique_student_identifier': get_user(locname)
}
$.ajax({
type: "POST",
url: geturl('instructor'),
data: pdata,
success: function(data){
var msg = $("#idash_msg", data);
$("#result_" + locname).html( msg );
},
error: function(request, status, error) {
$("#result_" + locname).html('<p id="idash_msg"><font color="red">${_('Something has gone wrong with this request. The server replied with a status of: ')}' + error + '</font></p>')
},
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
}
})();
</script>
<hr />
<h3>Actions</h3>
<div>
......
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