port some more JS specs to jasmine 2.0... still a lot to do
This commit is contained in:
parent
43f156420d
commit
c81379d38f
6 changed files with 79 additions and 78 deletions
|
|
@ -19,13 +19,12 @@ app.models.Stream = Backbone.Collection.extend({
|
|||
var defaultOpts = {
|
||||
remove: false // tell backbone to keep existing items in the collection
|
||||
};
|
||||
return _.extend({}, defaultOpts, opts);
|
||||
return _.extend({ url: this.url() }, defaultOpts, opts);
|
||||
},
|
||||
|
||||
fetch: function() {
|
||||
if( this.isFetching() ) return false;
|
||||
var url = this.url();
|
||||
this.deferred = this.items.fetch(this._fetchOpts({url : url}))
|
||||
this.deferred = this.items.fetch( this._fetchOpts() )
|
||||
.done(_.bind(this.triggerFetchedEvents, this));
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
describe("app.collections.Aspects", function(){
|
||||
beforeEach(function(){
|
||||
Diaspora.I18n.load({
|
||||
'and' : "and",
|
||||
'comma' : ",",
|
||||
'my_aspects' : "My Aspects"
|
||||
});
|
||||
var my_aspects = [{ name: 'Work', selected: true },
|
||||
{ name: 'Friends', selected: false },
|
||||
{ name: 'Acquaintances', selected: false }]
|
||||
var locale = {
|
||||
and: 'and',
|
||||
comma: ',',
|
||||
my_aspects: 'My Aspects'
|
||||
};
|
||||
var my_aspects = [
|
||||
{ name: 'Work', selected: true },
|
||||
{ name: 'Friends', selected: false },
|
||||
{ name: 'Acquaintances', selected: false }
|
||||
];
|
||||
|
||||
Diaspora.I18n.load(locale);
|
||||
this.aspects = new app.collections.Aspects(my_aspects);
|
||||
});
|
||||
|
||||
|
|
@ -44,25 +48,21 @@ describe("app.collections.Aspects", function(){
|
|||
describe("#toSentence", function(){
|
||||
describe('without aspects', function(){
|
||||
beforeEach(function(){
|
||||
this.aspects = new app.collections.Aspects({ name: 'Work', selected: false })
|
||||
spyOn(this.aspects, 'selectedAspects').andCallThrough();
|
||||
this.aspects = new app.collections.Aspects([{ name: 'Work', selected: false }]);
|
||||
});
|
||||
|
||||
it("returns the name of the aspect", function(){
|
||||
expect(this.aspects.toSentence()).toEqual('My Aspects');
|
||||
expect(this.aspects.selectedAspects).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("with one aspect", function(){
|
||||
beforeEach(function(){
|
||||
this.aspects = new app.collections.Aspects({ name: 'Work', selected: true })
|
||||
spyOn(this.aspects, 'selectedAspects').andCallThrough();
|
||||
this.aspects = new app.collections.Aspects([{ name: 'Work', selected: true }]);
|
||||
});
|
||||
|
||||
it("returns the name of the aspect", function(){
|
||||
expect(this.aspects.toSentence()).toEqual('Work');
|
||||
expect(this.aspects.selectedAspects).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,43 @@
|
|||
describe("app.models.Post.Interactions", function(){
|
||||
beforeEach(function(){
|
||||
this.interactions = factory.post()
|
||||
this.interactions = this.interactions.interactions
|
||||
this.interactions = factory.post().interactions;
|
||||
this.author = factory.author({guid: "loggedInAsARockstar"})
|
||||
loginAs({guid: "loggedInAsARockstar"})
|
||||
|
||||
this.userLike = new app.models.Like({author : this.author})
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
describe("toggleLike", function(){
|
||||
it("calls unliked when the user_like exists", function(){
|
||||
spyOn(this.interactions, "unlike").and.returnValue(true);
|
||||
this.interactions.likes.add(this.userLike)
|
||||
spyOn(this.interactions, "unlike").andReturn(true);
|
||||
this.interactions.toggleLike();
|
||||
|
||||
expect(this.interactions.unlike).toHaveBeenCalled();
|
||||
})
|
||||
});
|
||||
|
||||
it("calls liked when the user_like does not exist", function(){
|
||||
spyOn(this.interactions, "like").and.returnValue(true);
|
||||
this.interactions.likes.reset([]);
|
||||
spyOn(this.interactions, "like").andReturn(true);
|
||||
this.interactions.toggleLike();
|
||||
|
||||
expect(this.interactions.like).toHaveBeenCalled();
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe("like", function(){
|
||||
it("calls create on the likes collection", function(){
|
||||
spyOn(this.interactions.likes, "create");
|
||||
|
||||
this.interactions.like();
|
||||
expect(this.interactions.likes.create).toHaveBeenCalled();
|
||||
})
|
||||
})
|
||||
expect(this.interactions.likes.length).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("unlike", function(){
|
||||
it("calls destroy on the likes collection", function(){
|
||||
this.interactions.likes.add(this.userLike)
|
||||
spyOn(this.userLike, "destroy");
|
||||
|
||||
this.interactions.unlike();
|
||||
expect(this.userLike.destroy).toHaveBeenCalled();
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
expect(this.interactions.likes.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ describe("app.models.StreamAspects", function() {
|
|||
beforeEach(function(){
|
||||
fetch = new $.Deferred();
|
||||
stream = new app.models.StreamAspects([], {aspects_ids: [1,2]});
|
||||
spyOn(stream.items, "fetch").andCallFake(function(options){
|
||||
spyOn(stream.items, "fetch").and.callFake(function(options){
|
||||
stream.items.set([{name: 'a'}, {name: 'b'}, {name: 'c'}], options);
|
||||
fetch.resolve();
|
||||
return fetch;
|
||||
|
|
|
|||
|
|
@ -1,55 +1,59 @@
|
|||
describe("app.models.Stream", function() {
|
||||
var stream,
|
||||
expectedPath;
|
||||
|
||||
beforeEach(function(){
|
||||
this.stream = new app.models.Stream(),
|
||||
this.expectedPath = document.location.pathname;
|
||||
})
|
||||
|
||||
describe(".fetch", function() {
|
||||
var postFetch
|
||||
beforeEach(function(){
|
||||
postFetch = new $.Deferred()
|
||||
|
||||
spyOn(this.stream.items, "fetch").andCallFake(function(){
|
||||
return postFetch
|
||||
})
|
||||
})
|
||||
stream = new app.models.Stream();
|
||||
expectedPath = document.location.pathname;
|
||||
});
|
||||
|
||||
describe("#_fetchOpts", function() {
|
||||
it("it fetches posts from the window's url, and ads them to the collection", function() {
|
||||
this.stream.fetch()
|
||||
expect(this.stream.items.fetch).toHaveBeenCalledWith({ remove: false, url: this.expectedPath});
|
||||
expect( stream._fetchOpts() ).toEqual({ remove: false, url: expectedPath});
|
||||
});
|
||||
|
||||
it("returns the json path with max_time if the collection has models", function() {
|
||||
var post = new app.models.Post();
|
||||
spyOn(post, "createdAt").andReturn(1234);
|
||||
this.stream.add(post);
|
||||
var post = new app.models.Post({created_at: 1234000});
|
||||
stream.add(post);
|
||||
|
||||
this.stream.fetch()
|
||||
expect(this.stream.items.fetch).toHaveBeenCalledWith({ remove: false, url: this.expectedPath + "?max_time=1234"});
|
||||
expect( stream._fetchOpts() ).toEqual({ remove: false, url: expectedPath + "?max_time=1234"});
|
||||
});
|
||||
});
|
||||
|
||||
describe("events", function() {
|
||||
var postFetch,
|
||||
fetchedSpy;
|
||||
|
||||
beforeEach(function(){
|
||||
postFetch = new $.Deferred();
|
||||
fetchedSpy = jasmine.createSpy();
|
||||
spyOn(stream.items, "fetch").and.callFake(function(){
|
||||
return postFetch;
|
||||
});
|
||||
});
|
||||
|
||||
it("triggers fetched on the stream when it is fetched", function(){
|
||||
var fetchedSpy = jasmine.createSpy()
|
||||
this.stream.bind('fetched', fetchedSpy)
|
||||
this.stream.fetch()
|
||||
postFetch.resolve([1,2,3])
|
||||
expect(fetchedSpy).toHaveBeenCalled()
|
||||
})
|
||||
stream.bind('fetched', fetchedSpy);
|
||||
stream.fetch();
|
||||
postFetch.resolve([1,2,3]);
|
||||
|
||||
expect(fetchedSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("triggers allItemsLoaded on the stream when zero posts are returned", function(){
|
||||
var fetchedSpy = jasmine.createSpy()
|
||||
this.stream.bind('allItemsLoaded', fetchedSpy)
|
||||
this.stream.fetch()
|
||||
postFetch.resolve([])
|
||||
expect(fetchedSpy).toHaveBeenCalled()
|
||||
})
|
||||
stream.bind('allItemsLoaded', fetchedSpy);
|
||||
stream.fetch();
|
||||
postFetch.resolve([]);
|
||||
|
||||
expect(fetchedSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("triggers allItemsLoaded on the stream when a Post is returned", function(){
|
||||
var fetchedSpy = jasmine.createSpy()
|
||||
this.stream.bind('allItemsLoaded', fetchedSpy)
|
||||
this.stream.fetch()
|
||||
postFetch.resolve(factory.post().attributes)
|
||||
expect(fetchedSpy).toHaveBeenCalled()
|
||||
})
|
||||
stream.bind('allItemsLoaded', fetchedSpy);
|
||||
stream.fetch();
|
||||
postFetch.resolve(factory.post().attributes);
|
||||
|
||||
expect(fetchedSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ factory = {
|
|||
"id" : this.id.next(),
|
||||
"text" : "This is a comment!"
|
||||
}
|
||||
|
||||
|
||||
return new app.models.Comment(_.extend(defaultAttrs, overrides))
|
||||
},
|
||||
|
||||
|
|
@ -162,4 +162,4 @@ factory = {
|
|||
}
|
||||
}
|
||||
|
||||
factory.author = factory.userAttrs
|
||||
factory.author = factory.userAttrs;
|
||||
|
|
|
|||
Loading…
Reference in a new issue