Newer
Older
danielgrippi
a validé
beforeEach(function(){
loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
this.posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
this.stream = new app.models.Stream()
this.stream.add(this.posts);
this.view = new app.views.Stream({model : this.stream});
app.stream.bind("fetched", this.collectionFetched, this) //untested
danielgrippi
a validé
// 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);
danielgrippi
a validé
})
describe("initialize", function(){
it("binds an infinite scroll listener", function(){
spyOn($.fn, "scroll");
new app.views.Stream({model : this.stream});
expect($.fn.scroll).toHaveBeenCalled()
danielgrippi
a validé
})
})
danielgrippi
a validé
danielgrippi
a validé
describe("#render", function(){
beforeEach(function(){
this.statusMessage = this.stream.posts.models[0];
this.reshare = this.stream.posts.models[1];
this.statusElement = $(this.view.$("#" + this.statusMessage.get("guid")));
danielgrippi
a validé
this.reshareElement = $(this.view.$("#" + this.reshare.get("guid")));
})
context("when rendering a Status Mesasage", function(){
it("shows the status message in the content area", function(){
expect(this.statusElement.find(".post-content p").text()).toContain("you're gonna love this") //markdown'ed
danielgrippi
a validé
})
})
danielgrippi
a validé
describe("infScroll", function(){
danielgrippi
a validé
// NOTE: inf scroll happens at 500px
danielgrippi
a validé
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")
danielgrippi
a validé
this.view.infScroll();
expect(this.view.render).toHaveBeenCalled();
danielgrippi
a validé
})
})
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.mostRecentCall.object.selector).toBe("window")
expect($.fn.unbind).toHaveBeenCalledWith("scroll")
})
})