From 8144a1dfafe3bc8115b514565443748bf38d93ef Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Wed, 30 Jan 2013 17:25:13 -0500 Subject: [PATCH] Add in next_problem jasmine tests --- .../combinedopenended/display_spec.coffee | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/spec/combinedopenended/display_spec.coffee b/common/lib/xmodule/xmodule/js/spec/combinedopenended/display_spec.coffee index 7c26bda213..6777d8c794 100644 --- a/common/lib/xmodule/xmodule/js/spec/combinedopenended/display_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/combinedopenended/display_spec.coffee @@ -40,9 +40,8 @@ describe 'CombinedOpenEnded', -> expect(window.queuePollerID).toBe(5) it 'polling stops properly', => - $.postWithPrefix = jasmine.createSpy("$.postWithPrefix") fakeResponseDone = state: "done" - $.postWithPrefix.andCallFake (url, callback) -> callback(fakeResponseDone) + spyOn($, 'postWithPrefix').andCallFake (url, callback) -> callback(fakeResponseDone) @combined.poll() expect(window.queuePollerID).toBeUndefined() expect(window.setTimeout).not.toHaveBeenCalled() @@ -80,3 +79,34 @@ describe 'CombinedOpenEnded', -> @combined.rebind() expect(@combined.answer_area.attr("disabled")).toBe("disabled") expect(@combined.next_problem).toHaveBeenCalled() + + describe 'next_problem', -> + beforeEach -> + @combined = new CombinedOpenEnded @element + @combined.child_state = 'done' + + it 'handling a successful call', -> + fakeResponse = + success: true + html: "dummy html" + allow_reset: false + spyOn($, 'postWithPrefix').andCallFake (url, val, callback) -> callback(fakeResponse) + spyOn(@combined, 'reinitialize') + spyOn(@combined, 'rebind') + @combined.next_problem() + expect($.postWithPrefix).toHaveBeenCalled() + expect(@combined.reinitialize).toHaveBeenCalledWith(@combined.element) + expect(@combined.rebind).toHaveBeenCalled() + expect(@combined.answer_area.val()).toBe('') + expect(@combined.child_state).toBe('initial') + + it 'handling an unsuccessful call', -> + fakeResponse = + success: false + error: 'This is an error' + spyOn($, 'postWithPrefix').andCallFake (url, val, callback) -> callback(fakeResponse) + @combined.next_problem() + expect(@combined.errors_area.html()).toBe(fakeResponse.error) + + +