From 2b01273f7f106e1c4863ef0fcde61733be7f3750 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 15 May 2013 17:51:50 -0400 Subject: [PATCH] Added some Jasmine tests for section views in Backbone --- .../fixtures/section-name-edit.underscore | 1 + .../coffee/spec/views/feedback_spec.coffee | 5 +- .../coffee/spec/views/section_spec.coffee | 79 +++++++++++++++++++ cms/static/js/views/section.js | 2 +- 4 files changed, 83 insertions(+), 4 deletions(-) create mode 120000 cms/static/coffee/fixtures/section-name-edit.underscore create mode 100644 cms/static/coffee/spec/views/section_spec.coffee diff --git a/cms/static/coffee/fixtures/section-name-edit.underscore b/cms/static/coffee/fixtures/section-name-edit.underscore new file mode 120000 index 0000000000..89284ccf90 --- /dev/null +++ b/cms/static/coffee/fixtures/section-name-edit.underscore @@ -0,0 +1 @@ +../../../templates/js/section-name-edit.underscore \ No newline at end of file diff --git a/cms/static/coffee/spec/views/feedback_spec.coffee b/cms/static/coffee/spec/views/feedback_spec.coffee index b6aba107d9..cd96e3b2e2 100644 --- a/cms/static/coffee/spec/views/feedback_spec.coffee +++ b/cms/static/coffee/spec/views/feedback_spec.coffee @@ -20,9 +20,8 @@ describe "CMS.Views.Alert as base class", -> view = new CMS.Views.Alert({model: @model}) expect(view.$(".action-close")).toBeDefined() expect(view.$('.wrapper')).toHaveClass("is-shown") - text = view.$el.text() - expect(text).toMatch(/Portal/) - expect(text).toMatch(/Aperture Science/) + expect(view.$el).toContainText(@model.get("title")) + expect(view.$el).toContainText(@model.get("message")) it "close button sends a .hide() message", -> spyOn(CMS.Views.Alert.prototype, 'hide').andCallThrough() diff --git a/cms/static/coffee/spec/views/section_spec.coffee b/cms/static/coffee/spec/views/section_spec.coffee new file mode 100644 index 0000000000..c05dd3040e --- /dev/null +++ b/cms/static/coffee/spec/views/section_spec.coffee @@ -0,0 +1,79 @@ +describe "CMS.Views.SectionShow", -> + describe "Basic", -> + beforeEach -> + spyOn(CMS.Views.SectionShow.prototype, "switchToEditView") + .andCallThrough() + @model = new CMS.Models.Section({ + id: 42 + name: "Life, the Universe, and Everything" + }) + @view = new CMS.Views.SectionShow({model: @model}) + @view.render() + + it "should contain the model name", -> + expect(@view.$el).toHaveText(@model.get('name')) + + it "should call switchToEditView when clicked", -> + @view.$el.click() + expect(@view.switchToEditView).toHaveBeenCalled() + + it "should pass the same element to SectionEdit when switching views", -> + spyOn(CMS.Views.SectionEdit.prototype, 'initialize').andCallThrough() + @view.switchToEditView() + expect(CMS.Views.SectionEdit.prototype.initialize).toHaveBeenCalled() + expect(CMS.Views.SectionEdit.prototype.initialize.mostRecentCall.args[0].el).toEqual(@view.el) + +describe "CMS.Views.SectionEdit", -> + describe "Basic", -> + tpl = readFixtures('section-name-edit.underscore') + + beforeEach -> + setFixtures($("