Commit 609c299f by David Baumgold

Finished backbone model tests for textbooks

parent 207453a3
......@@ -67,3 +67,69 @@ describe "CMS.Models.Textbook input/output", ->
model = new CMS.Models.Textbook(serverModelSpec, {parse: true})
expect(deepAttributes(model)).toEqual(clientModelSpec)
expect(model.toJSON()).toEqual(serverModelSpec)
describe "CMS.Collections.TextbookSet", ->
beforeEach ->
window.TEXTBOOK_URL = "/textbooks"
@collection = new CMS.Collections.TextbookSet()
afterEach ->
delete window.TEXTBOOK_URL
it "should have a url set", ->
expect(_.result(@collection, "url"), window.TEXTBOOK_URL)
it "can call save", ->
spyOn(@collection, "sync")
@collection.save()
expect(@collection.sync).toHaveBeenCalledWith("update", @collection, undefined)
it "should respond to editOne events", ->
model = new CMS.Models.Textbook()
@collection.trigger('editOne', model)
expect(@collection.editing).toEqual(model)
describe "CMS.Models.Chapter", ->
beforeEach ->
@model = new CMS.Models.Chapter()
it "should have a name by default", ->
expect(@model.get("name")).toEqual("")
it "should have an asset_path by default", ->
expect(@model.get("asset_path")).toEqual("")
it "should have an order by default", ->
expect(@model.get("order")).toEqual(1)
it "should be empty by default", ->
expect(@model.isEmpty()).toBeTruthy()
describe "CMS.Collections.ChapterSet", ->
beforeEach ->
@collection = new CMS.Collections.ChapterSet()
it "is empty by default", ->
expect(@collection.isEmpty()).toBeTruthy()
it "is empty if all chapters are empty", ->
@collection.add([{}, {}, {}])
expect(@collection.isEmpty()).toBeTruthy()
it "is not empty if a chapter is not empty", ->
@collection.add([{}, {name: "full"}, {}])
expect(@collection.isEmpty()).toBeFalsy()
it "should have a nextOrder function", ->
expect(@collection.nextOrder()).toEqual(1)
@collection.add([{}])
expect(@collection.nextOrder()).toEqual(2)
@collection.add([{}])
expect(@collection.nextOrder()).toEqual(3)
# verify that it doesn't just return an incrementing value each time
expect(@collection.nextOrder()).toEqual(3)
# try going back one
@collection.remove(@collection.last())
expect(@collection.nextOrder()).toEqual(2)
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