From 8ba21ca34ab436ea0c1c062ff529ecd6de7ab554 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Fri, 14 Jun 2013 16:05:28 -0400 Subject: [PATCH] More backbone view tests --- cms/static/coffee/fixtures/chapter.underscore | 1 + .../coffee/fixtures/textbook-edit.underscore | 1 + .../coffee/spec/views/textbook_spec.coffee | 79 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 120000 cms/static/coffee/fixtures/chapter.underscore create mode 120000 cms/static/coffee/fixtures/textbook-edit.underscore diff --git a/cms/static/coffee/fixtures/chapter.underscore b/cms/static/coffee/fixtures/chapter.underscore new file mode 120000 index 0000000000..75b8edddaa --- /dev/null +++ b/cms/static/coffee/fixtures/chapter.underscore @@ -0,0 +1 @@ +../../../templates/js/chapter.underscore \ No newline at end of file diff --git a/cms/static/coffee/fixtures/textbook-edit.underscore b/cms/static/coffee/fixtures/textbook-edit.underscore new file mode 120000 index 0000000000..c341cb36c0 --- /dev/null +++ b/cms/static/coffee/fixtures/textbook-edit.underscore @@ -0,0 +1 @@ +../../../templates/js/textbook-edit.underscore \ No newline at end of file diff --git a/cms/static/coffee/spec/views/textbook_spec.coffee b/cms/static/coffee/spec/views/textbook_spec.coffee index 666bb30f49..276ab05862 100644 --- a/cms/static/coffee/spec/views/textbook_spec.coffee +++ b/cms/static/coffee/spec/views/textbook_spec.coffee @@ -21,6 +21,7 @@ describe "CMS.Views.TextbookShow", -> appendSetFixtures(sandbox({id: "page-prompt"})) @model = new CMS.Models.Textbook({name: "Life Sciences"}) @collection = new CMS.Collections.TextbookSet() + spyOn(@collection, 'save') @collection.add(@model) @view = new CMS.Views.TextbookShow({model: @model}) @@ -33,3 +34,81 @@ describe "CMS.Views.TextbookShow", -> @view.render().$(".edit").click() expect(@collection.trigger).toHaveBeenCalledWith("editOne", @model) expect(@collection.editing).toEqual(@model) + + it "should pop a delete confirmation when the delete button is clicked", -> + promptSpies = spyOnConstructor(CMS.Views, "Prompt") + @view.render().$(".delete").click() + expect(promptSpies.constructor).toHaveBeenCalled() + msg = promptSpies.constructor.mostRecentCall.args[0].model + expect(msg.get("title")).toMatch(/Life Sciences/) + # hasn't actually been removed + expect(@collection).toContain(@model) + expect(@collection.save).not.toHaveBeenCalled() + # run the primary function to indicate confirmation + view = jasmine.createSpyObj('view', ['hide']) + msg.get("actions").primary.click.call(msg, view) + # now it's been removed + expect(@collection).not.toContain(@model) + expect(@collection.save).toHaveBeenCalled() + + it "should show chapters appropriately", -> + @model.get("chapters").add([{}, {}, {}]) + @model.set('showChapters', false) + @view.render().$(".show-chapters").click() + expect(@model.get('showChapters')).toBeTruthy() + + it "should hide chapters appropriately", -> + @model.get("chapters").add([{}, {}, {}]) + @model.set('showChapters', true) + @view.render().$(".hide-chapters").click() + expect(@model.get('showChapters')).toBeFalsy() + + + +describe "CMS.Views.TextbookEdit", -> + describe "Basic", -> + tpl = readFixtures('textbook-edit.underscore') + chapterTpl = readFixtures('chapter.underscore') + + beforeEach -> + setFixtures($("