From cc36162df1b68660dfc058ba95d5ec3a5f17ca27 Mon Sep 17 00:00:00 2001 From: Waheed Ahmed Date: Mon, 2 Jun 2014 14:16:50 +0500 Subject: [PATCH] Fixed links for units loaded via ajax. LMS-2711 --- .../test/acceptance/pages/lms/staff_view.py | 13 +++-- .../test/acceptance/tests/test_staff_view.py | 47 ++++++++++++++++++- lms/static/js/staff_debug_actions.js | 7 +-- lms/templates/staff_problem_info.html | 6 +-- 4 files changed, 63 insertions(+), 10 deletions(-) diff --git a/common/test/acceptance/pages/lms/staff_view.py b/common/test/acceptance/pages/lms/staff_view.py index 749842a190..46d814e86c 100644 --- a/common/test/acceptance/pages/lms/staff_view.py +++ b/common/test/acceptance/pages/lms/staff_view.py @@ -38,6 +38,13 @@ class StaffPage(PageObject): self.q(css='input.check').first.click() self.wait_for_ajax() + def load_problem_via_ajax(self): + """ + Load problem via ajax by clicking next. + """ + self.q(css="li.next").click() + self.wait_for_ajax() + class StaffDebugPage(PageObject): """ @@ -56,7 +63,7 @@ class StaffDebugPage(PageObject): """ if user: self.q(css='input[id^=sd_fu_]').first.fill(user) - self.q(css='section.staff-modal a#staff-debug-reset').click() + self.q(css='section.staff-modal a.staff-debug-reset').click() def delete_state(self, user=None): """ @@ -64,7 +71,7 @@ class StaffDebugPage(PageObject): """ if user: self.q(css='input[id^=sd_fu_]').fill(user) - self.q(css='section.staff-modal a#staff-debug-sdelete').click() + self.q(css='section.staff-modal a.staff-debug-sdelete').click() def rescore(self, user=None): """ @@ -73,7 +80,7 @@ class StaffDebugPage(PageObject): """ if user: self.q(css='input[id^=sd_fu_]').first.fill(user) - self.q(css='section.staff-modal a#staff-debug-rescore').click() + self.q(css='section.staff-modal a.staff-debug-rescore').click() @property def idash_msg(self): diff --git a/common/test/acceptance/tests/test_staff_view.py b/common/test/acceptance/tests/test_staff_view.py index 53b4c8f18e..7187df18ba 100644 --- a/common/test/acceptance/tests/test_staff_view.py +++ b/common/test/acceptance/tests/test_staff_view.py @@ -43,7 +43,8 @@ class StaffDebugTest(UniqueCourseTest): course_fix.add_children( XBlockFixtureDesc('chapter', 'Test Section').add_children( XBlockFixtureDesc('sequential', 'Test Subsection').add_children( - XBlockFixtureDesc('problem', 'Test Problem 1', data=problem_data) + XBlockFixtureDesc('problem', 'Test Problem 1', data=problem_data), + XBlockFixtureDesc('problem', 'Test Problem 2', data=problem_data) ) ) ).install() @@ -149,3 +150,47 @@ class StaffDebugTest(UniqueCourseTest): msg = staff_debug_page.idash_msg[0] self.assertEqual(u'Failed to delete student state. ' 'User does not exist.', msg) + + def test_reset_attempts_for_problem_loaded_via_ajax(self): + """ + Successfully reset the student attempts for problem loaded via ajax. + """ + staff_page = self._goto_staff_page() + staff_page.load_problem_via_ajax() + staff_page.answer_problem() + + staff_debug_page = staff_page.open_staff_debug_info() + staff_debug_page.reset_attempts() + msg = staff_debug_page.idash_msg[0] + self.assertEqual(u'Successfully reset the attempts ' + 'for user {}'.format(self.USERNAME), msg) + + def test_rescore_state_for_problem_loaded_via_ajax(self): + """ + Rescore the student for problem loaded via ajax. + """ + staff_page = self._goto_staff_page() + staff_page.load_problem_via_ajax() + staff_page.answer_problem() + + staff_debug_page = staff_page.open_staff_debug_info() + staff_debug_page.rescore() + msg = staff_debug_page.idash_msg[0] + # Since we aren't running celery stuff, this will fail badly + # for now, but is worth excercising that bad of a response + self.assertEqual(u'Failed to rescore problem. ' + 'Unknown Error Occurred.', msg) + + def test_student_state_delete_for_problem_loaded_via_ajax(self): + """ + Successfully delete the student state for problem loaded via ajax. + """ + staff_page = self._goto_staff_page() + staff_page.load_problem_via_ajax() + staff_page.answer_problem() + + staff_debug_page = staff_page.open_staff_debug_info() + staff_debug_page.delete_state() + msg = staff_debug_page.idash_msg[0] + self.assertEqual(u'Successfully deleted student state ' + 'for user {}'.format(self.USERNAME), msg) diff --git a/lms/static/js/staff_debug_actions.js b/lms/static/js/staff_debug_actions.js index c5a49f39fb..3dc5f6df33 100644 --- a/lms/static/js/staff_debug_actions.js +++ b/lms/static/js/staff_debug_actions.js @@ -114,15 +114,16 @@ var StaffDebug = (function(){ // Register click handlers $(document).ready(function() { - $('.staff-debug-reset').click(function() { + var $courseContent = $('.course-content'); + $courseContent.on("click", '.staff-debug-reset', function() { StaffDebug.reset($(this).parent().data('location-name'), $(this).parent().data('location')); return false; }); - $('.staff-debug-sdelete').click(function() { + $courseContent.on("click", '.staff-debug-sdelete', function() { StaffDebug.sdelete($(this).parent().data('location-name'), $(this).parent().data('location')); return false; }); - $('.staff-debug-rescore').click(function() { + $courseContent.on("click", '.staff-debug-rescore', function() { StaffDebug.rescore($(this).parent().data('location-name'), $(this).parent().data('location')); return false; }); diff --git a/lms/templates/staff_problem_info.html b/lms/templates/staff_problem_info.html index cef8e430b0..6bed4a7d68 100644 --- a/lms/templates/staff_problem_info.html +++ b/lms/templates/staff_problem_info.html @@ -63,12 +63,12 @@ ${block_content}
[ - ${_('Reset Student Attempts')} + ${_('Reset Student Attempts')} % if has_instructor_access: | - ${_('Delete Student State')} + ${_('Delete Student State')} | - ${_('Rescore Student Submission')} + ${_('Rescore Student Submission')} % endif ]