Commit 77175872 by Victor Shnayder

Fix some of the CMS jasmine tests.

* still a few that I haven't tracked down...
parent 80b8529f
...@@ -2,7 +2,7 @@ describe "CMS", -> ...@@ -2,7 +2,7 @@ describe "CMS", ->
beforeEach -> beforeEach ->
CMS.unbind() CMS.unbind()
it "should iniitalize Models", -> it "should initialize Models", ->
expect(CMS.Models).toBeDefined() expect(CMS.Models).toBeDefined()
it "should initialize Views", -> it "should initialize Views", ->
......
...@@ -11,14 +11,25 @@ describe "CMS.Models.Module", -> ...@@ -11,14 +11,25 @@ describe "CMS.Models.Module", ->
@fakeModule = jasmine.createSpy("fakeModuleObject") @fakeModule = jasmine.createSpy("fakeModuleObject")
window.FakeModule = jasmine.createSpy("FakeModule").andReturn(@fakeModule) window.FakeModule = jasmine.createSpy("FakeModule").andReturn(@fakeModule)
@module = new CMS.Models.Module(type: "FakeModule") @module = new CMS.Models.Module(type: "FakeModule")
@stubElement = $("<div>") @stubDiv = $('<div />')
@module.loadModule(@stubElement) @stubElement = $('<div class="xmodule_edit" />')
@stubElement.data('type', "FakeModule")
@stubDiv.append(@stubElement)
@module.loadModule(@stubDiv)
afterEach -> afterEach ->
window.FakeModule = undefined window.FakeModule = undefined
it "initialize the module", -> it "initialize the module", ->
expect(window.FakeModule).toHaveBeenCalledWith(@stubElement) expect(window.FakeModule).toHaveBeenCalled()
# Need to compare underlying nodes, because jquery selectors
# aren't equal even when they point to the same node.
# http://stackoverflow.com/questions/9505437/how-to-test-jquery-with-jasmine-for-element-id-if-used-as-this
expectedNode = @stubElement[0]
actualNode = window.FakeModule.mostRecentCall.args[0][0]
expect(actualNode).toEqual(expectedNode)
expect(@module.module).toEqual(@fakeModule) expect(@module.module).toEqual(@fakeModule)
describe "when the module does not exists", -> describe "when the module does not exists", ->
...@@ -32,7 +43,8 @@ describe "CMS.Models.Module", -> ...@@ -32,7 +43,8 @@ describe "CMS.Models.Module", ->
window.console = @previousConsole window.console = @previousConsole
it "print out error to log", -> it "print out error to log", ->
expect(window.console.error).toHaveBeenCalledWith("Unable to load HTML.") expect(window.console.error).toHaveBeenCalled()
expect(window.console.error.mostRecentCall.args[0]).toMatch("^Unable to load")
describe "editUrl", -> describe "editUrl", ->
......
...@@ -8,11 +8,11 @@ describe "CMS.Views.ModuleEdit", -> ...@@ -8,11 +8,11 @@ describe "CMS.Views.ModuleEdit", ->
<a href="#" class="cancel">cancel</a> <a href="#" class="cancel">cancel</a>
<ol> <ol>
<li> <li>
<a href="#" class="module-edit" data-id="i4x://mitx.edu/course/module" data-type="html">submodule</a> <a href="#" class="module-edit" data-id="i4x://mitx/course/html/module" data-type="html">submodule</a>
</li> </li>
</ol> </ol>
</div> </div>
""" """ #"
CMS.unbind() CMS.unbind()
describe "defaults", -> describe "defaults", ->
...@@ -27,7 +27,7 @@ describe "CMS.Views.ModuleEdit", -> ...@@ -27,7 +27,7 @@ describe "CMS.Views.ModuleEdit", ->
@stubModule.editUrl.andReturn("/edit_item?id=stub_module") @stubModule.editUrl.andReturn("/edit_item?id=stub_module")
new CMS.Views.ModuleEdit(el: $("#module-edit"), model: @stubModule) new CMS.Views.ModuleEdit(el: $("#module-edit"), model: @stubModule)
it "load the edit from via ajax and pass to the model", -> it "load the edit via ajax and pass to the model", ->
expect($.fn.load).toHaveBeenCalledWith("/edit_item?id=stub_module", jasmine.any(Function)) expect($.fn.load).toHaveBeenCalledWith("/edit_item?id=stub_module", jasmine.any(Function))
if $.fn.load.mostRecentCall if $.fn.load.mostRecentCall
$.fn.load.mostRecentCall.args[1]() $.fn.load.mostRecentCall.args[1]()
...@@ -37,9 +37,9 @@ describe "CMS.Views.ModuleEdit", -> ...@@ -37,9 +37,9 @@ describe "CMS.Views.ModuleEdit", ->
beforeEach -> beforeEach ->
@stubJqXHR = jasmine.createSpy("stubJqXHR") @stubJqXHR = jasmine.createSpy("stubJqXHR")
@stubJqXHR.success = jasmine.createSpy("stubJqXHR.success").andReturn(@stubJqXHR) @stubJqXHR.success = jasmine.createSpy("stubJqXHR.success").andReturn(@stubJqXHR)
@stubJqXHR.error= jasmine.createSpy("stubJqXHR.success").andReturn(@stubJqXHR) @stubJqXHR.error = jasmine.createSpy("stubJqXHR.error").andReturn(@stubJqXHR)
@stubModule.save = jasmine.createSpy("stubModule.save").andReturn(@stubJqXHR) @stubModule.save = jasmine.createSpy("stubModule.save").andReturn(@stubJqXHR)
new CMS.Views.ModuleEdit(el: $("#module-edit"), model: @stubModule) new CMS.Views.ModuleEdit(el: $(".module-edit"), model: @stubModule)
spyOn(window, "alert") spyOn(window, "alert")
$(".save-update").click() $(".save-update").click()
...@@ -77,5 +77,5 @@ describe "CMS.Views.ModuleEdit", -> ...@@ -77,5 +77,5 @@ describe "CMS.Views.ModuleEdit", ->
expect(CMS.pushView).toHaveBeenCalledWith @view expect(CMS.pushView).toHaveBeenCalledWith @view
expect(CMS.Views.ModuleEdit).toHaveBeenCalledWith model: @model expect(CMS.Views.ModuleEdit).toHaveBeenCalledWith model: @model
expect(CMS.Models.Module).toHaveBeenCalledWith expect(CMS.Models.Module).toHaveBeenCalledWith
id: "i4x://mitx.edu/course/module" id: "i4x://mitx/course/html/module"
type: "html" type: "html"
describe "CMS.Views.Module", -> describe "CMS.Views.Module", ->
beforeEach -> beforeEach ->
setFixtures """ setFixtures """
<div id="module" data-id="i4x://mitx.edu/course/module" data-type="html"> <div id="module" data-id="i4x://mitx/course/html/module" data-type="html">
<a href="#" class="module-edit">edit</a> <a href="#" class="module-edit">edit</a>
</div> </div>
""" """
...@@ -20,5 +20,5 @@ describe "CMS.Views.Module", -> ...@@ -20,5 +20,5 @@ describe "CMS.Views.Module", ->
expect(CMS.replaceView).toHaveBeenCalledWith @view expect(CMS.replaceView).toHaveBeenCalledWith @view
expect(CMS.Views.ModuleEdit).toHaveBeenCalledWith model: @model expect(CMS.Views.ModuleEdit).toHaveBeenCalledWith model: @model
expect(CMS.Models.Module).toHaveBeenCalledWith expect(CMS.Models.Module).toHaveBeenCalledWith
id: "i4x://mitx.edu/course/module" id: "i4x://mitx/course/html/module"
type: "html" type: "html"
describe "CMS.Views.Week", -> describe "CMS.Views.Week", ->
beforeEach -> beforeEach ->
setFixtures """ setFixtures """
<div id="week" data-id="i4x://mitx.edu/course/week"> <div id="week" data-id="i4x://mitx/course/chapter/week">
<div class="editable"></div> <div class="editable"></div>
<textarea class="editable-textarea"></textarea> <textarea class="editable-textarea"></textarea>
<a href="#" class="week-edit" >edit</a> <a href="#" class="week-edit" >edit</a>
......
...@@ -4,7 +4,8 @@ class CMS.Models.Module extends Backbone.Model ...@@ -4,7 +4,8 @@ class CMS.Models.Module extends Backbone.Model
data: '' data: ''
loadModule: (element) -> loadModule: (element) ->
@module = XModule.loadModule($(element).find('.xmodule_edit')) elt = $(element).find('.xmodule_edit').first()
@module = XModule.loadModule(elt)
editUrl: -> editUrl: ->
"/edit_item?#{$.param(id: @get('id'))}" "/edit_item?#{$.param(id: @get('id'))}"
......
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