Commit a10a3209 by Jay Zoldak

Fix all but 4 broken tests.

parent 6ae0add9
<section class='xmodule_display xmodule_CapaModule' data-type='Problem'> <section class='xmodule_display xmodule_CapaModule' data-type='Problem'>
<section id='problem_101' <section id='problem_1'
class='problems-wrapper' class='problems-wrapper'
data-problem-id='i4x://edX/101/problem/Problem101' data-problem-id='i4x://edX/101/problem/Problem1'
data-url='/problem/Problem101/'> data-url='/problem/Problem1'>
</section> </section>
</section> </section>
\ No newline at end of file
...@@ -8,7 +8,10 @@ describe 'Problem', -> ...@@ -8,7 +8,10 @@ describe 'Problem', ->
MathJax.Hub.getAllJax.andReturn [@stubbedJax] MathJax.Hub.getAllJax.andReturn [@stubbedJax]
window.update_schematics = -> window.update_schematics = ->
# load this function from spec/helper.coffee # Load this function from spec/helper.coffee
# Note that if your test fails with a message like:
# 'External request attempted for blah, which is not defined.'
# this msg is coming from the stubRequests function else clause.
jasmine.stubRequests() jasmine.stubRequests()
# note that the fixturesPath is set in spec/helper.coffee # note that the fixturesPath is set in spec/helper.coffee
...@@ -34,8 +37,8 @@ describe 'Problem', -> ...@@ -34,8 +37,8 @@ describe 'Problem', ->
expect(@problem999.element_id).toBe 'problem_999' expect(@problem999.element_id).toBe 'problem_999'
it 'set the element from loadFixtures', -> it 'set the element from loadFixtures', ->
@problem101 = new Problem($('.xmodule_display')) @problem1 = new Problem($('.xmodule_display'))
expect(@problem101.element_id).toBe 'problem_101' expect(@problem1.element_id).toBe 'problem_1'
describe 'bind', -> describe 'bind', ->
beforeEach -> beforeEach ->
...@@ -53,7 +56,7 @@ describe 'Problem', -> ...@@ -53,7 +56,7 @@ describe 'Problem', ->
expect($('section.action input:button')).toHandleWith 'click', @problem.refreshAnswers expect($('section.action input:button')).toHandleWith 'click', @problem.refreshAnswers
it 'bind the check button', -> it 'bind the check button', ->
expect($('section.action input.check')).toHandleWith 'click', @problem.check expect($('section.action input.check')).toHandleWith 'click', @problem.check_fd
it 'bind the reset button', -> it 'bind the reset button', ->
expect($('section.action input.reset')).toHandleWith 'click', @problem.reset expect($('section.action input.reset')).toHandleWith 'click', @problem.reset
...@@ -101,6 +104,10 @@ describe 'Problem', -> ...@@ -101,6 +104,10 @@ describe 'Problem', ->
it 're-bind the content', -> it 're-bind the content', ->
expect(@problem.bind).toHaveBeenCalled() expect(@problem.bind).toHaveBeenCalled()
describe 'check_fd', ->
xit 'should have specs written for this functionality', ->
expect(false)
describe 'check', -> describe 'check', ->
beforeEach -> beforeEach ->
@problem = new Problem($('.xmodule_display')) @problem = new Problem($('.xmodule_display'))
...@@ -113,24 +120,28 @@ describe 'Problem', -> ...@@ -113,24 +120,28 @@ describe 'Problem', ->
it 'submit the answer for check', -> it 'submit the answer for check', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@problem.check() @problem.check()
expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/problem_check', 'foo=1&bar=2', jasmine.any(Function) expect($.postWithPrefix).toHaveBeenCalledWith '/problem/Problem1/problem_check',
'foo=1&bar=2', jasmine.any(Function)
describe 'when the response is correct', -> describe 'when the response is correct', ->
it 'call render with returned content', -> it 'call render with returned content', ->
spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) -> callback(success: 'correct', contents: 'Correct!') spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) ->
callback(success: 'correct', contents: 'Correct!')
@problem.check() @problem.check()
expect(@problem.el.html()).toEqual 'Correct!' expect(@problem.el.html()).toEqual 'Correct!'
describe 'when the response is incorrect', -> describe 'when the response is incorrect', ->
it 'call render with returned content', -> it 'call render with returned content', ->
spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) -> callback(success: 'incorrect', contents: 'Correct!') spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) ->
callback(success: 'incorrect', contents: 'Incorrect!')
@problem.check() @problem.check()
expect(@problem.el.html()).toEqual 'Correct!' expect(@problem.el.html()).toEqual 'Incorrect!'
describe 'when the response is undetermined', -> describe 'when the response is undetermined', ->
it 'alert the response', -> it 'alert the response', ->
spyOn window, 'alert' spyOn window, 'alert'
spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) -> callback(success: 'Number Only!') spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) ->
callback(success: 'Number Only!')
@problem.check() @problem.check()
expect(window.alert).toHaveBeenCalledWith 'Number Only!' expect(window.alert).toHaveBeenCalledWith 'Number Only!'
...@@ -146,7 +157,8 @@ describe 'Problem', -> ...@@ -146,7 +157,8 @@ describe 'Problem', ->
it 'POST to the problem reset page', -> it 'POST to the problem reset page', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@problem.reset() @problem.reset()
expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/problem_reset', { id: 1 }, jasmine.any(Function) expect($.postWithPrefix).toHaveBeenCalledWith '/problem/Problem1/problem_reset',
{ id: 'i4x://edX/101/problem/Problem1' }, jasmine.any(Function)
it 'render the returned content', -> it 'render the returned content', ->
spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) -> spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) ->
...@@ -165,12 +177,14 @@ describe 'Problem', -> ...@@ -165,12 +177,14 @@ describe 'Problem', ->
it 'log the problem_show event', -> it 'log the problem_show event', ->
@problem.show() @problem.show()
expect(Logger.log).toHaveBeenCalledWith 'problem_show', problem: 1 expect(Logger.log).toHaveBeenCalledWith 'problem_show',
problem: 'i4x://edX/101/problem/Problem1'
it 'fetch the answers', -> it 'fetch the answers', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@problem.show() @problem.show()
expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/problem_show', jasmine.any(Function) expect($.postWithPrefix).toHaveBeenCalledWith '/problem/Problem1/problem_show',
jasmine.any(Function)
it 'show the answers', -> it 'show the answers', ->
spyOn($, 'postWithPrefix').andCallFake (url, callback) -> spyOn($, 'postWithPrefix').andCallFake (url, callback) ->
...@@ -245,7 +259,8 @@ describe 'Problem', -> ...@@ -245,7 +259,8 @@ describe 'Problem', ->
it 'POST to save problem', -> it 'POST to save problem', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@problem.save() @problem.save()
expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/problem_save', 'foo=1&bar=2', jasmine.any(Function) expect($.postWithPrefix).toHaveBeenCalledWith '/problem/Problem1/problem_save',
'foo=1&bar=2', jasmine.any(Function)
it 'alert to the user', -> it 'alert to the user', ->
spyOn window, 'alert' spyOn window, 'alert'
...@@ -308,3 +323,6 @@ describe 'Problem', -> ...@@ -308,3 +323,6 @@ describe 'Problem', ->
it 'serialize all answers', -> it 'serialize all answers', ->
@problem.refreshAnswers() @problem.refreshAnswers()
expect(@problem.answers).toEqual "input_1_1=one&input_1_2=two" expect(@problem.answers).toEqual "input_1_1=one&input_1_2=two"
...@@ -23,9 +23,9 @@ jasmine.stubRequests = -> ...@@ -23,9 +23,9 @@ jasmine.stubRequests = ->
else if settings.url.match /.+\/problem_get$/ else if settings.url.match /.+\/problem_get$/
settings.success html: readFixtures('problem_content.html') settings.success html: readFixtures('problem_content.html')
else if settings.url == '/calculate' || else if settings.url == '/calculate' ||
settings.url.match(/modx\/.+\/goto_position$/) || settings.url.match(/.+\/goto_position$/) ||
settings.url.match(/event$/) || settings.url.match(/event$/) ||
settings.url.match(/modx\/.+\/problem_(check|reset|show|save)$/) settings.url.match(/.+\/problem_(check|reset|show|save)$/)
# do nothing # do nothing
else else
throw "External request attempted for #{settings.url}, which is not defined." throw "External request attempted for #{settings.url}, which is not defined."
......
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