From 1cd932c92b64003aad2e5b280e1a066ed54f95a7 Mon Sep 17 00:00:00 2001 From: "Dave St.Germain" Date: Mon, 31 Mar 2014 12:20:18 -0400 Subject: [PATCH] Fixes LMS-2474 by ensuring that readElts reads always reads an element --- common/lib/xmodule/xmodule/js/js_test.yml | 1 + .../xmodule/js/spec/capa/display_spec.coffee | 32 ++++++++++++++++--- .../xmodule/js/src/capa/display.coffee | 1 + common/static/js/src/accessibility_tools.js | 4 +-- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/js_test.yml b/common/lib/xmodule/xmodule/js/js_test.yml index 8aeeaba122..ff24f8c9ba 100644 --- a/common/lib/xmodule/xmodule/js/js_test.yml +++ b/common/lib/xmodule/xmodule/js/js_test.yml @@ -58,6 +58,7 @@ lib_paths: - common_static/js/test/add_ajax_prefix.js - common_static/js/src/utility.js - public/js/split_test_staff.js + - common_static/js/src/accessibility_tools.js # Paths to spec (test) JavaScript files spec_paths: diff --git a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee index 33927ed1f9..c0ec84a912 100644 --- a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee @@ -7,10 +7,8 @@ describe 'Problem', -> @stubbedJax = root: jasmine.createSpyObj('jax.root', ['toMathML']) MathJax.Hub.getAllJax.andReturn [@stubbedJax] window.update_schematics = -> - # mock the screen reader alert - window.SR = - readElts: `function(){}` - readText: `function(){}` + spyOn SR, 'readElts' + spyOn SR, 'readText' # Load this function from spec/helper.coffee # Note that if your test fails with a message like: @@ -168,6 +166,7 @@ describe 'Problem', -> callback(success: 'correct', contents: 'Correct!') @problem.check() expect(@problem.el.html()).toEqual 'Correct!' + expect(window.SR.readElts).toHaveBeenCalled() describe 'when the response is incorrect', -> it 'call render with returned content', -> @@ -175,6 +174,7 @@ describe 'Problem', -> callback(success: 'incorrect', contents: 'Incorrect!') @problem.check() expect(@problem.el.html()).toEqual 'Incorrect!' + expect(window.SR.readElts).toHaveBeenCalled() # TODO: figure out why failing xdescribe 'when the response is undetermined', -> @@ -237,12 +237,25 @@ describe 'Problem', -> spyOn($, 'postWithPrefix').andCallFake (url, callback) -> callback(answers: {}) @problem.show() expect($('.show .show-label')).toHaveText 'Hide Answer' + expect(window.SR.readElts).toHaveBeenCalled() it 'add the showed class to element', -> spyOn($, 'postWithPrefix').andCallFake (url, callback) -> callback(answers: {}) @problem.show() expect(@problem.el).toHaveClass 'showed' + it 'reads the answers', -> + runs -> + spyOn($, 'postWithPrefix').andCallFake (url, callback) -> callback(answers: 'answers') + @problem.show() + + waitsFor (-> + return jQuery.active == 0 + ), "jQuery requests finished", 1000 + + runs -> + expect(window.SR.readElts).toHaveBeenCalled() + describe 'multiple choice question', -> beforeEach -> @problem.el.prepend ''' @@ -487,6 +500,17 @@ describe 'Problem', -> expect($.postWithPrefix).toHaveBeenCalledWith '/problem/Problem1/problem_save', 'foo=1&bar=2', jasmine.any(Function) + it 'reads the save message', -> + runs -> + spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) -> callback(success: 'OK') + @problem.save() + waitsFor (-> + return jQuery.active == 0 + ), "jQuery requests finished", 1000 + + runs -> + expect(window.SR.readElts).toHaveBeenCalled() + # TODO: figure out why failing xit 'alert to the user', -> spyOn window, 'alert' diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index c79a858a6c..97dd7cf10b 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -366,6 +366,7 @@ class @Problem alert_elem = "
" + msg + "
" @el.find('.action').after(alert_elem) @el.find('.capa_alert').css(opacity: 0).animate(opacity: 1, 700) + window.SR.readElts @el.find('.capa_alert') save: => if not @check_save_waitfor(@save_internal) diff --git a/common/static/js/src/accessibility_tools.js b/common/static/js/src/accessibility_tools.js index 5d626568b0..b26992e33d 100644 --- a/common/static/js/src/accessibility_tools.js +++ b/common/static/js/src/accessibility_tools.js @@ -158,9 +158,7 @@ $(function(){ }; SRAlert.prototype.readElts = function(elts) { - var feedback, - _this = this; - feedback = ''; + var feedback = ''; $.each(elts, function(idx, value) { return feedback += '

' + $(value).html() + '

\n'; });