From dd3ddeb9464c37d269bac3a16fd57269778f5bd5 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 6 Jul 2012 00:05:08 -0400 Subject: [PATCH] CMS.Views.Week is tested --- cms/static/coffee/spec/views/week_spec.coffee | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 cms/static/coffee/spec/views/week_spec.coffee diff --git a/cms/static/coffee/spec/views/week_spec.coffee b/cms/static/coffee/spec/views/week_spec.coffee new file mode 100644 index 0000000000..f205a82752 --- /dev/null +++ b/cms/static/coffee/spec/views/week_spec.coffee @@ -0,0 +1,71 @@ +describe "CMS.Views.Week", -> + beforeEach -> + setFixtures """ +
+
+ + edit + +
+ """ + CMS.unbind() + + describe "render", -> + beforeEach -> + spyOn(CMS.Views, "Module").andReturn(jasmine.createSpyObj("Module", ["render"])) + $.fn.inlineEdit = jasmine.createSpy("$.fn.inlineEdit") + @view = new CMS.Views.Week(el: $("#week"), height: 100).render() + + it "set the height of the element", -> + expect(@view.el).toHaveCss(height: "100px") + + it "make .editable as inline editor", -> + expect($.fn.inlineEdit.calls[0].object.get(0)) + .toEqual($(".editable").get(0)) + + it "make .editable-test as inline editor", -> + expect($.fn.inlineEdit.calls[1].object.get(0)) + .toEqual($(".editable-textarea").get(0)) + + it "create module subview for each module", -> + expect(CMS.Views.Module.calls[0].args[0]) + .toEqual({ el: $("#module-one").get(0) }) + expect(CMS.Views.Module.calls[1].args[0]) + .toEqual({ el: $("#module-two").get(0) }) + + describe "edit", -> + beforeEach -> + @view = new CMS.Views.Week(el: $("#week"), height: 100).render() + spyOn(CMS, "replaceView") + spyOn(CMS.Views, "WeekEdit") + .andReturn(@view = jasmine.createSpy("Views.WeekEdit")) + spyOn(CMS.Models, "Week") + .andReturn(@model = jasmine.createSpy("Models.Week")) + $(".week-edit").click() + + it "replace the content with edit week view", -> + expect(CMS.replaceView).toHaveBeenCalledWith @view + expect(CMS.Views.WeekEdit).toHaveBeenCalledWith model: @model + expect(CMS.Models.Week).toHaveBeenCalledWith + id: "i4x://mitx.edu/course/week" + + describe "on content.show", -> + beforeEach -> + @view = new CMS.Views.Week(el: $("#week"), height: 100).render() + @view.$el.height("") + @view.setHeight() + + it "set the correct height", -> + expect(@view.el).toHaveCss(height: "100px") + + describe "on content.hide", -> + beforeEach -> + @view = new CMS.Views.Week(el: $("#week"), height: 100).render() + @view.$el.height("100px") + @view.resetHeight() + + it "remove height from the element", -> + expect(@view.el).not.toHaveCss(height: "100px")