From b11b9169065f3bbd0dbf58d1d334e322b3a9ce55 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Thu, 5 Jul 2012 23:31:50 -0400 Subject: [PATCH] CMS.Views.Course fixed and tested --- .../coffee/spec/views/course_spec.coffee | 85 +++++++++++++++++++ cms/static/coffee/src/views/course.coffee | 6 +- 2 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 cms/static/coffee/spec/views/course_spec.coffee diff --git a/cms/static/coffee/spec/views/course_spec.coffee b/cms/static/coffee/spec/views/course_spec.coffee new file mode 100644 index 0000000000..f6a430ac2d --- /dev/null +++ b/cms/static/coffee/spec/views/course_spec.coffee @@ -0,0 +1,85 @@ +describe "CMS.Views.Course", -> + beforeEach -> + setFixtures """ +
+
+
    +
  1. +
  2. +
+
+ """ + CMS.unbind() + + describe "render", -> + beforeEach -> + spyOn(CMS.Views, "Week").andReturn(jasmine.createSpyObj("Week", ["render"])) + new CMS.Views.Course(el: $("#main-section")).render() + + it "create week view for each week",-> + expect(CMS.Views.Week.calls[0].args[0]) + .toEqual({ el: $(".week-one").get(0), height: 101 }) + expect(CMS.Views.Week.calls[1].args[0]) + .toEqual({ el: $(".week-two").get(0), height: 101 }) + + describe "on content.show", -> + beforeEach -> + @view = new CMS.Views.Course(el: $("#main-section")) + @subView = jasmine.createSpyObj("subView", ["render"]) + @subView.render.andReturn(el: "Subview Content") + spyOn(@view, "contentHeight").andReturn(100) + CMS.trigger("content.show", @subView) + + afterEach -> + $("body").removeClass("content") + + it "add content class to body", -> + expect($("body").attr("class")).toEqual("content") + + it "replace content in .main-content", -> + expect($(".main-content")).toHaveHtml("Subview Content") + + it "set height on calendar", -> + expect($(".cal")).toHaveCss(height: "100px") + + it "set minimum height on all sections", -> + expect($("#main-section>section")).toHaveCss(minHeight: "100px") + + describe "on content.hide", -> + beforeEach -> + $("body").addClass("content") + @view = new CMS.Views.Course(el: $("#main-section")) + $(".cal").css(height: 100) + $("#main-section>section").css(minHeight: 100) + CMS.trigger("content.hide") + + afterEach -> + $("body").removeClass("content") + + it "remove content class from body", -> + expect($("body").attr("class")).toEqual("") + + it "remove content from .main-content", -> + expect($(".main-content")).toHaveHtml("") + + it "reset height on calendar", -> + expect($(".cal")).not.toHaveCss(height: "100px") + + it "reset minimum height on all sections", -> + expect($("#main-section>section")).not.toHaveCss(minHeight: "100px") + + describe "maxWeekHeight", -> + it "return maximum height of the week element", -> + @view = new CMS.Views.Course(el: $("#main-section")) + expect(@view.maxWeekHeight()).toEqual(101) + + describe "contentHeight", -> + beforeEach -> + $("body").append($('
').height(100).hide()) + + afterEach -> + $("body>header#test").remove() + + it "return the window height minus the header bar", -> + @view = new CMS.Views.Course(el: $("#main-section")) + expect(@view.contentHeight()).toEqual($(window).height() - 100) diff --git a/cms/static/coffee/src/views/course.coffee b/cms/static/coffee/src/views/course.coffee index 86085ffff8..2a5a012c07 100644 --- a/cms/static/coffee/src/views/course.coffee +++ b/cms/static/coffee/src/views/course.coffee @@ -21,8 +21,8 @@ class CMS.Views.Course extends Backbone.View @$('>section').css minHeight: '' maxWeekHeight: -> - _.max($('#weeks > li').map -> $(this).height()) + 1 + weekElementBorderSize = 1 + _.max($('#weeks > li').map -> $(this).height()) + weekElementBorderSize contentHeight: -> - padding = 29 - $(window).height() - padding + $(window).height() - $('body>header').outerHeight()