From 1107aa2b7f6b134dd16c45ec453e25b24f01e179 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Mon, 17 Feb 2014 11:45:50 +0000 Subject: [PATCH] Fix bug multiple choice with video. BLD-788. The Video element contains an input with type file. When the Check button was clicked for the multiple choice problem, the code was acting in different ways when there as a Video on the page and when there wasn't. This is because in the check_fd() method there was a selector that was looking for inputs of type file on the whole page instead of just in the current problem. When there was a Video pn the page, the page-wide selector returned the Video's file input, and the check_fd() method went on believing that the multiple choice has a file input. The correct way is to look for file inputs only in the current element. Added a Jasmine JavaScript unit test. BLD-788. --- .../xmodule/xmodule/js/spec/capa/display_spec.coffee | 12 ++++++++---- .../lib/xmodule/xmodule/js/src/capa/display.coffee | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) 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 ddb5f1b0f6..79ce05250d 100644 --- a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee @@ -124,9 +124,15 @@ describe 'Problem', -> expect(@problem.bind).toHaveBeenCalled() describe 'check_fd', -> - xit 'should have more specs written for this functionality', -> - expect(false) + beforeEach -> + # Insert an input of type file outside of the problem. + $('.xblock-student_view').after('') + @problem = new Problem($('.xblock-student_view')) + spyOn(@problem, 'check') + it 'check method is called if input of type file is not in problem', -> + @problem.check_fd() + expect(@problem.check).toHaveBeenCalled() describe 'check', -> beforeEach -> @@ -509,5 +515,3 @@ describe 'Problem', -> xit 'serialize all answers', -> @problem.refreshAnswers() expect(@problem.answers).toEqual "input_1_1=one&input_1_2=two" - - diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 4a193cc418..da0e63019b 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -195,7 +195,7 @@ class @Problem ### check_fd: => # If there are no file inputs in the problem, we can fall back on @check - if $('input:file').length == 0 + if @el.find('input:file').length == 0 @check() return