Commit 68bb45ab by Felix Sun

Added jasmine tests to crowdsource_hinter. UI is not covered; only event-inteception is covered.

parent e6067d88
<li id="vert-0" data-id="i4x://Me/19.002/crowdsource_hinter/crowdsource_hinter_def7a1142dd0">
<section class="xmodule_display xmodule_CrowdsourceHinterModule" data-type="Hinter" id="hinter-root">
<section class="xmodule_display xmodule_CapaModule" data-type="Problem" id="problem">
<section id="problem_i4x-Me-19_002-problem-Numerical_Input" class="problems-wrapper" data-problem-id="i4x://Me/19.002/problem/Numerical_Input" data-url="/courses/Me/19.002/Test/modx/i4x://Me/19.002/problem/Numerical_Input" data-progress_status="done" data-progress_detail="1/1">
<h2 class="problem-header">
Numerical Input
</h2>
<section class="problem-progress">(1/1 points)</section>
<section class="problem">
<div><p>The answer is 2*x^2*y + 5
</p><span><br><span> Answer =</span>
<section id="inputtype_i4x-Me-19_002-problem-Numerical_Input_2_1" class="text-input-dynamath capa_inputtype ">
<div class="correct " id="status_i4x-Me-19_002-problem-Numerical_Input_2_1">
<input type="text" name="input_i4x-Me-19_002-problem-Numerical_Input_2_1" id="input_i4x-Me-19_002-problem-Numerical_Input_2_1" aria-describedby="answer_i4x-Me-19_002-problem-Numerical_Input_2_1" value="2*x^2*y +5" class="math" size="40">
</div></section></span>
<input type="file" />
<section class="solution-span"><span id="solution_i4x-Me-19_002-problem-Numerical_Input_solution_1"></span></section></div>
<section class="action">
<input type="hidden" name="problem_id" value="Numerical Input">
<input class="check Check" type="button" value="Check">
<button class="show"><span class="show-label">Show Answer(s)</span> <span class="sr">(for question(s) above - adjacent to each field)</span></button>
</section>
</section>
</section>
</section>
<div id="i4x_Me_19_002_problem_Numerical_Input_setup"></div>
<section class="crowdsource-wrapper" data-url="/courses/Me/19.002/Test/modx/i4x://Me/19.002/crowdsource_hinter/crowdsource_hinter_def7a1142dd0" data-child-url="/courses/Me/19.002/Test/modx/i4x://Me/19.002/problem/Numerical_Input" style="display: none;"> </section>
</section>
</li>
\ No newline at end of file
...@@ -125,9 +125,10 @@ describe 'Problem', -> ...@@ -125,9 +125,10 @@ describe 'Problem', ->
expect(@problem.bind).toHaveBeenCalled() expect(@problem.bind).toHaveBeenCalled()
describe 'check_fd', -> describe 'check_fd', ->
xit 'should have specs written for this functionality', -> xit 'should have more specs written for this functionality', ->
expect(false) expect(false)
describe 'check', -> describe 'check', ->
beforeEach -> beforeEach ->
@problem = new Problem($('.xmodule_display')) @problem = new Problem($('.xmodule_display'))
...@@ -137,6 +138,15 @@ describe 'Problem', -> ...@@ -137,6 +138,15 @@ describe 'Problem', ->
@problem.check() @problem.check()
expect(Logger.log).toHaveBeenCalledWith 'problem_check', 'foo=1&bar=2' expect(Logger.log).toHaveBeenCalledWith 'problem_check', 'foo=1&bar=2'
it 'log the problem_graded event, after the problem is done grading.', ->
spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) ->
response =
success: 'correct'
contents: 'mock grader response'
callback(response)
@problem.check()
expect(Logger.log).toHaveBeenCalledWith 'problem_graded', ['foo=1&bar=2', 'mock grader response'], @problem.url
it 'submit the answer for check', -> it 'submit the answer for check', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@problem.check() @problem.check()
......
describe 'Crowdsourced hinter', ->
beforeEach ->
window.update_schematics = ->
jasmine.stubRequests()
# note that the fixturesPath is set in spec/helper.coffee
loadFixtures 'crowdsource_hinter.html'
@hinter = new Hinter($('#hinter-root'))
describe 'high-level integration tests', ->
# High-level, happy-path tests for integration with capa problems.
beforeEach ->
# Make a more thorough $.postWithPrefix mock.
spyOn($, 'postWithPrefix').andCallFake( ->
last_argument = arguments[arguments.length - 1]
if typeof last_argument == 'function'
response =
success: 'incorrect'
contents: 'mock grader response'
last_argument(response)
)
@problem = new Problem($('#problem'))
@problem.bind()
it 'knows when a capa problem is graded, using check.', ->
@problem.answers = 'test answer'
@problem.check()
expect($.postWithPrefix).toHaveBeenCalledWith("#{@hinter.url}/get_hint", 'test answer', jasmine.any(Function))
it 'knows when a capa problem is graded usig check_fd.', ->
spyOn($, 'ajaxWithPrefix').andCallFake((url, settings) ->
response =
success: 'incorrect'
contents: 'mock grader response'
settings.success(response)
)
@problem.answers = 'test answer'
@problem.check_fd()
expect($.postWithPrefix).toHaveBeenCalledWith("#{@hinter.url}/get_hint", 'test answer', jasmine.any(Function))
describe 'capture_problem', ->
beforeEach ->
spyOn($, 'postWithPrefix').andReturn(null)
it 'gets hints for an incorrect answer', ->
data = ['some answers', '<thing class="incorrect">']
@hinter.capture_problem('problem_graded', data, 'fake element')
expect($.postWithPrefix).toHaveBeenCalledWith("#{@hinter.url}/get_hint", 'some answers', jasmine.any(Function))
it 'gets feedback for a correct answer', ->
data = ['some answers', '<thing class="correct">']
@hinter.capture_problem('problem_graded', data, 'fake element')
expect($.postWithPrefix).toHaveBeenCalledWith("#{@hinter.url}/get_feedback", 'some answers', jasmine.any(Function))
...@@ -19,7 +19,6 @@ class @Problem ...@@ -19,7 +19,6 @@ class @Problem
problem_prefix = @element_id.replace(/problem_/,'') problem_prefix = @element_id.replace(/problem_/,'')
@inputs = @$("[id^=input_#{problem_prefix}_]") @inputs = @$("[id^=input_#{problem_prefix}_]")
@$('section.action input:button').click @refreshAnswers @$('section.action input:button').click @refreshAnswers
@$('section.action input.check').click @check_fd @$('section.action input.check').click @check_fd
@$('section.action input.reset').click @reset @$('section.action input.reset').click @reset
......
...@@ -96,7 +96,7 @@ class @Hinter ...@@ -96,7 +96,7 @@ class @Hinter
$(obj).css('margin-top', (viewbox_height - view_height) + 'px') $(obj).css('margin-top', (viewbox_height - view_height) + 'px')
) )
render: (content) => render: (content) ->
if content if content
# Trim leading and trailing whitespace # Trim leading and trailing whitespace
content = content.replace /^\s+|\s+$/g, "" content = content.replace /^\s+|\s+$/g, ""
......
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