Commit e873da76 by Diana Huang

Wrap reload to allow us to mock it. Add in some polling testing.

parent b38595f1
......@@ -3,6 +3,7 @@ describe 'CombinedOpenEnded', ->
spyOn Logger, 'log'
# load up some fixtures
loadFixtures 'combined-open-ended.html'
jasmine.Clock.useMock()
@element = $('.course-content')
......@@ -27,3 +28,25 @@ describe 'CombinedOpenEnded', ->
expect(@combined.answer_area.attr("disabled")).toBe("disabled")
expect(@combined.submit_button.val()).toBe("Submit assessment")
describe 'poll', ->
beforeEach =>
# setup the spies
@combined = new CombinedOpenEnded @element
spyOn(@combined, 'reload').andCallFake -> return 0
window.setTimeout = jasmine.createSpy().andCallFake (callback, timeout) -> return 5
it 'we are setting the timeout', =>
fakeResponseContinue = state: 'not done'
spyOn($, 'postWithPrefix').andCallFake (url, callback) -> callback(fakeResponseContinue)
@combined.poll()
expect(window.setTimeout).toHaveBeenCalledWith(@combined.poll, 10000)
expect(window.queuePollerID).toBe(5)
it 'we are stopping polling properly', =>
$.postWithPrefix = jasmine.createSpy("$.postWithPrefix")
fakeResponseDone = state: "done"
$.postWithPrefix.andCallFake (url, callback) -> callback(fakeResponseDone)
@combined.poll()
expect(window.queuePollerID).toBeUndefined()
expect(window.setTimeout).not.toHaveBeenCalled()
expect(@combined.reload).toHaveBeenCalled()
......@@ -281,6 +281,10 @@ class @CombinedOpenEnded
$.postWithPrefix "#{@ajax_url}/check_for_score", (response) =>
if response.state == "done" or response.state=="post_assessment"
delete window.queuePollerID
location.reload()
@reload()
else
window.queuePollerID = window.setTimeout(@poll, 10000)
# wrap this so that it can be mocked
reload: ->
location.reload()
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