diaspora/spec/javascripts/app/views/stream_view_spec.js
2012-04-17 19:18:12 -07:00

69 lines
2.1 KiB
JavaScript

describe("app.views.Stream", function() {
beforeEach(function() {
loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
this.posts = $.parseJSON(spec.readFixture("stream_json"))["posts"];
this.stream = new app.models.Stream();
this.stream.add(this.posts);
this.view = new app.views.Stream({model : this.stream});
// do this manually because we've moved loadMore into render??
this.view.render();
_.each(this.view.collection.models, function(post) {
this.view.addPost(post);
}, this);
});
describe("initialize", function() {
it("binds an infinite scroll listener", function() {
spyOn($.fn, "scroll");
new app.views.Stream({model : this.stream});
expect($.fn.scroll).toHaveBeenCalled();
});
});
describe("#render", function() {
beforeEach(function() {
this.statusMessage = this.stream.posts.models[0];
this.statusElement = $(this.view.$(".stream_element")[0]);
});
context("when rendering a status message", function() {
it("shows the message in the content area", function() {
expect(this.statusElement.find(".post-content p").text()).toContain("LONG POST"); //markdown'ed
});
});
});
describe("infScroll", function() {
// NOTE: inf scroll happens at 500px
it("calls render when the user is at the bottom of the page", function() {
spyOn($.fn, "height").andReturn(0);
spyOn($.fn, "scrollTop").andReturn(100);
spyOn(this.view, "render");
this.view.infScroll();
expect(this.view.render).toHaveBeenCalled();
});
});
describe("removeLoader", function() {
it("emptys the pagination div when the stream is fetched", function() {
$("#jasmine_content").append($('<div id="paginate">OMG</div>'));
expect($("#paginate").text()).toBe("OMG");
this.view.stream.trigger("fetched");
expect($("#paginate")).toBeEmpty();
});
});
describe("unbindInfScroll", function() {
it("unbinds scroll", function() {
spyOn($.fn, "unbind");
this.view.unbindInfScroll();
expect($.fn.unbind).toHaveBeenCalledWith("scroll");
});
});
});