From 10ec6046301c61b0c7f5afd8548c8d174eb3b3fe Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 14 May 2013 13:23:01 -0400 Subject: [PATCH] Got jasmine tests working with fixtures properly --- .../fixtures/system-feedback.underscore | 1 + cms/static/coffee/spec/helpers.coffee | 2 ++ .../coffee/spec/views/feedback_spec.coffee | 32 +++++++++++++------ 3 files changed, 26 insertions(+), 9 deletions(-) create mode 120000 cms/static/coffee/fixtures/system-feedback.underscore diff --git a/cms/static/coffee/fixtures/system-feedback.underscore b/cms/static/coffee/fixtures/system-feedback.underscore new file mode 120000 index 0000000000..10893f87c4 --- /dev/null +++ b/cms/static/coffee/fixtures/system-feedback.underscore @@ -0,0 +1 @@ +../../../templates/js/system-feedback.underscore \ No newline at end of file diff --git a/cms/static/coffee/spec/helpers.coffee b/cms/static/coffee/spec/helpers.coffee index 91a411a8fc..116983edf5 100644 --- a/cms/static/coffee/spec/helpers.coffee +++ b/cms/static/coffee/spec/helpers.coffee @@ -1,3 +1,5 @@ +jasmine.getFixtures().fixturesPath = 'fixtures' + # Stub jQuery.cookie @stubCookies = csrftoken: "stubCSRFToken" diff --git a/cms/static/coffee/spec/views/feedback_spec.coffee b/cms/static/coffee/spec/views/feedback_spec.coffee index 374e465927..f454d62e3f 100644 --- a/cms/static/coffee/spec/views/feedback_spec.coffee +++ b/cms/static/coffee/spec/views/feedback_spec.coffee @@ -1,19 +1,19 @@ describe "CMS.Views.SystemFeedback", -> + tpl = readFixtures('system-feedback.underscore') + # CMS.Views.SystemFeedback looks for a template on the page when the code + # is loaded, and even if we set that template on the page using a fixture, + # CMS.Views.SystemFeedback has already been loaded, and so that template + # won't be picked up. This is a dirty hack, to load that template into + # the code after the code has been loaded already. + CMS.Views.SystemFeedback.prototype.template = _.template(tpl) + beforeEach -> setFixtures(sandbox({id: "page-notification"})) - # CMS.Views.SystemFeedback looks for a template on the page when the code - # is loaded, and even if we set that template on the page using a fixture, - # CMS.Views.SystemFeedback has already been loaded, and so that template - # won't be picked up. This is a dirty hack, to load that template into - # the code after the code has been loaded already. - CMS.Views.SystemFeedback.prototype.template = _.template """ -

<%= title %>

-

<%= message %>

- """ @model = new CMS.Models.ConfirmationMessage({ "title": "Portal" "message": "Welcome to the Aperture Science Computer-Aided Enrichment Center" + close: true }) # it will be interesting to see when this.render is called, so lets spy on it spyOn(CMS.Views.SystemFeedback.prototype, 'render').andCallThrough() @@ -24,7 +24,21 @@ describe "CMS.Views.SystemFeedback", -> it "renders the template", -> view = new CMS.Views.Notification({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/) + it "close button sends a .hide() message", -> + spyOn(CMS.Views.SystemFeedback.prototype, 'hide').andCallThrough() + + view = new CMS.Views.Notification({model: @model}) + view.$(".action-close").click() + + expect(CMS.Views.SystemFeedback.prototype.hide).toHaveBeenCalled() + expect(view.$('.wrapper')).not.toHaveClass("is-shown") + expect(view.$('.wrapper')).toHaveClass("is-hiding") + + +