From 60d43559c622e1692afc36f4b7d9d11fd9b5f5e0 Mon Sep 17 00:00:00 2001 From: rabiaiftikhar Date: Thu, 23 Mar 2017 16:51:53 +0500 Subject: [PATCH] TNl-6436 Fix '(capa) show answer' disabled even after answer is no longer shown --- .../xmodule/js/fixtures/checkbox_problem.html | 5 ++ .../js/fixtures/radiobutton_problem.html | 5 ++ .../xmodule/js/spec/capa/display_spec.coffee | 68 ++++++++++++------- .../xmodule/xmodule/js/src/capa/display.js | 2 + 4 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 common/lib/xmodule/xmodule/js/fixtures/checkbox_problem.html create mode 100644 common/lib/xmodule/xmodule/js/fixtures/radiobutton_problem.html diff --git a/common/lib/xmodule/xmodule/js/fixtures/checkbox_problem.html b/common/lib/xmodule/xmodule/js/fixtures/checkbox_problem.html new file mode 100644 index 0000000000..baf9eee0ee --- /dev/null +++ b/common/lib/xmodule/xmodule/js/fixtures/checkbox_problem.html @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file diff --git a/common/lib/xmodule/xmodule/js/fixtures/radiobutton_problem.html b/common/lib/xmodule/xmodule/js/fixtures/radiobutton_problem.html new file mode 100644 index 0000000000..a06388b40e --- /dev/null +++ b/common/lib/xmodule/xmodule/js/fixtures/radiobutton_problem.html @@ -0,0 +1,5 @@ +
+ + + +
\ No newline at end of file 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 104d258d4f..964a4cdcba 100644 --- a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee @@ -258,6 +258,7 @@ describe 'Problem', -> expect(@problem.submitButton).not.toHaveAttr('disabled') describe 'submit button on problems', -> + beforeEach -> @problem = new Problem($('.xblock-student_view')) @submitDisabled = (disabled) => @@ -274,15 +275,11 @@ describe 'Problem', -> @submitDisabled true describe 'some advanced tests for submit button', -> + radioButtonProblemHtml = readFixtures('radiobutton_problem.html') + checkboxProblemHtml = readFixtures('checkbox_problem.html') + it 'should become enabled after a checkbox is checked', -> - html = ''' -
- - - -
- ''' - $('#input_example_1').replaceWith(html) + $('#input_example_1').replaceWith(checkboxProblemHtml) @problem.submitAnswersAndSubmitButton true @submitDisabled true $('#input_1_1_1').click() @@ -291,14 +288,7 @@ describe 'Problem', -> @submitDisabled true it 'should become enabled after a radiobutton is checked', -> - html = ''' -
- - - -
- ''' - $('#input_example_1').replaceWith(html) + $('#input_example_1').replaceWith(radioButtonProblemHtml) @problem.submitAnswersAndSubmitButton true @submitDisabled true $('#input_1_1_1').attr('checked', true).trigger('click') @@ -325,14 +315,7 @@ describe 'Problem', -> @submitDisabled true it 'should become enabled after a radiobutton is checked and a value is entered into the text box', -> - html = ''' -
- - - -
- ''' - $(html).insertAfter('#input_example_1') + $(radioButtonProblemHtml).insertAfter('#input_example_1') @problem.submitAnswersAndSubmitButton true @submitDisabled true $('#input_1_1_1').attr('checked', true).trigger('click') @@ -802,3 +785,40 @@ describe 'Problem', -> # verify that codemirror textarea has correct `aria-describedby` attribute value expect($(CodeMirrorTextArea).attr('aria-describedby')).toEqual('cm-editor-exit-message-101 status_101') + + + describe 'show answer button', -> + + radioButtonProblemHtml = readFixtures('radiobutton_problem.html') + checkboxProblemHtml = readFixtures('checkbox_problem.html') + + beforeEach -> + @problem = new Problem($('.xblock-student_view')) + + @checkAssertionsAfterClickingAnotherOption = => + # verify that 'show answer button is no longer disabled' + expect(@problem.el.find('.show').attr('disabled')).not.toEqual('disabled') + + # verify that displayed answer disappears + expect(@problem.el.find('div.choicegroup')).not.toHaveClass('choicegroup_correct') + + # verify that radio/checkbox label has no span having class '.status.correct' + expect(@problem.el.find('div.choicegroup')).not.toHaveAttr('span.status.correct') + + it 'should become enabled after a radiobutton is selected', -> + $('#input_example_1').replaceWith(radioButtonProblemHtml) + # assume that 'ShowAnswer' button is clicked, + # clicking make it disabled. + @problem.el.find('.show').attr('disabled', 'disabled') + # bind click event to input fields + @problem.submitAnswersAndSubmitButton true + # selects option 2 + $('#input_1_1_2').attr('checked', true).trigger('click') + @checkAssertionsAfterClickingAnotherOption() + + it 'should become enabled after a checkbox is selected', -> + $('#input_example_1').replaceWith(checkboxProblemHtml) + @problem.el.find('.show').attr('disabled', 'disabled') + @problem.submitAnswersAndSubmitButton true + $('#input_1_1_2').click() + @checkAssertionsAfterClickingAnotherOption() diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.js b/common/lib/xmodule/xmodule/js/src/capa/display.js index 51b62293a5..8a40513cd3 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.js +++ b/common/lib/xmodule/xmodule/js/src/capa/display.js @@ -872,6 +872,7 @@ if (bind) { $(checkboxOrRadio).on('click', function() { that.saveNotification.hide(); + that.el.find('.show').removeAttr('disabled'); that.showAnswerNotification.hide(); that.submitAnswersAndSubmitButton(); }); @@ -953,6 +954,7 @@ id: 'status_' + id }); } + $element.find('label').find('span.status.correct').remove(); return $element.find('label').removeAttr('class'); }); },