describe("View", function() { it("is the object that helps the UI", function() { expect(typeof View === "object").toBeTruthy(); }); describe("initialize", function() { it("is called on DOM ready", function() { spyOn(View, "initialize"); $(View.initialize); expect(View.initialize).toHaveBeenCalled(); }); }); describe("fancyBoxButtons", function() { describe("selectors", function() { it("is an array of all the selectors that will have fancybox attached", function() { expect(typeof View.fancyBoxButtons.selectors === "object").toBeTruthy(); expect($.isArray(View.fancyBoxButtons.selectors)).toBeTruthy(); }); }); }); describe("debug", function() { describe("click", function() { beforeEach(function() { jasmine.Clock.useMock(); $("#jasmine_content").html( '
' + '
DEBUG INFO
' + '' + '
' ); }); it("is called when the user clicks an element matching the selector", function() { spyOn(View.debug, "click"); View.initialize(); $(View.debug.selector).click(); jasmine.Clock.tick(200); expect(View.debug.click).toHaveBeenCalled(); expect($(View.debug.selector).css("display")).toEqual("block"); }); }); }); describe("flashes", function() { describe("animate", function() { beforeEach(function() { $("#jasmine_content").html( '
' + 'flash! flash! flash!' + '
' ); }); it("is called when the DOM is ready", function() { spyOn(View.flashes, "animate").andCallThrough(); View.initialize(); expect(View.flashes.animate).toHaveBeenCalled(); }); }); }); describe("newRequest", function() { beforeEach(function() { $("#jasmine_content").html( '
' + '
' + '
' + '' + '' + '' + '' + '
' ); }); describe("submit", function() { it("is called when the user submits the form", function() { spyOn(View.newRequest, "submit").andCallThrough(); View.initialize(); $(View.newRequest.selector).submit(function(evt) { evt.preventDefault(); }); $(View.newRequest.selector).trigger("submit"); expect(View.newRequest.submit).toHaveBeenCalled(); expect($(View.newRequest.selector + " .message").css("display")).toEqual("block"); }); }); }); describe("publisher", function() { beforeEach(function() { $("#jasmine_content").html( '
' + '
' + '' + '
' + '
' ); }); describe("keydown", function() { it("is called when the user types", function() { spyOn(View.publisher, "keydown"); View.initialize(); $(View.publisher.selector).trigger("keydown"); expect(View.publisher.keydown).toHaveBeenCalled(); }); it("submits the form if the user hits enter while the textarea is focused", function() { spyOn($.fn, "submit"); View.initialize(); $(View.publisher.selector).focus(); var event = $.Event("keydown"); event.ShiftKey = true; event.keyCode = 13; $(View.publisher.selector).trigger(event); expect($.fn.submit).toHaveBeenCalled(); }); }); }); describe("search", function() { beforeEach(function() { $("#jasmine_content").html( '' ); }); describe("focus", function() { it("adds the class 'active' when the user focuses the text field", function() { View.initialize(); $(View.search.selector).focus(); expect($(View.search.selector)).toHaveClass("active"); }); }); describe("blur", function() { it("removes the class 'active' when the user blurs the text field", function() { View.initialize(); $(View.search.selector).focus().blur(); expect($(View.search.selector)).not.toHaveClass("active"); }); }); }); describe("tooltips", function() { describe("bindAll", function() { //Someone shorten this plz <3 it("enumerates through the tooltips object, called the method 'bind' on any sibling that is not the bindAll method", function() { spyOn($, "noop"); View.initialize(); View.tooltips.myToolTip = { bind: $.noop }; View.tooltips.bindAll(); expect($.noop).toHaveBeenCalled(); }); }); }); describe("userMenu", function() { beforeEach(function() { $("#jasmine_content").html( '' ); }); describe("click", function() { it("adds the class 'active' when the user clicks the ul", function() { View.initialize(); $(View.userMenu.selector).click(); expect($(View.userMenu.selector)).toHaveClass("active"); }); }); describe("removeFocus", function() { it("removes the class 'active' if the user clicks anywhere that isnt the userMenu", function() { View.initialize(); $(View.userMenu.selector).click(); expect($(View.userMenu.selector)).toHaveClass("active"); var event = $.Event("click"); event.target = document.body; $(document.body).trigger(event); expect($(View.userMenu.selector)).not.toHaveClass("active"); }); }); }); describe("webFingerForm", function() { beforeEach(function() { $("#jasmine_content").html( '
' + '

' + 'Add a new contact' + '

' + '
' + '' + '' + '
' + '' + '' + '
' ); // Prevent the form from being submitted $(View.webFingerForm.selector).submit(function(evt) { evt.preventDefault(); }); }); describe("submit", function() { it("shows the ajax loader after the user submits the form", function() { View.initialize(); $(View.webFingerForm.selector).submit(); expect($(View.webFingerForm.selector).siblings("#loader").css("display")).toEqual("block"); }); it("hides the first list item in the result ul after the user submits the form", function() { View.initialize(); $(View.webFingerForm.selector).submit(); expect($("#request_result li:first").css("display")).toEqual("none"); }); }); }); });