port router specs, don't test backbone - our own code is enough

This commit is contained in:
Florian Staudacher 2014-03-05 20:36:30 +01:00 committed by Jonne Haß
parent c81379d38f
commit adf7aa98dd
4 changed files with 43 additions and 43 deletions

View file

@ -59,7 +59,7 @@ app.Router = Backbone.Router.extend({
$("#main_stream").html(app.page.render().el);
$('#selected_aspect_contacts .content').html(streamFacesView.render().el);
this.hideInactiveStreamLists();
this._hideInactiveStreamLists();
},
photos : function() {
@ -84,7 +84,7 @@ app.Router = Backbone.Router.extend({
);
$("#author_info").prepend(followedTagsAction.render().el)
}
this.hideInactiveStreamLists();
this._hideInactiveStreamLists();
},
aspects : function(){
@ -107,10 +107,10 @@ app.Router = Backbone.Router.extend({
$("#main_stream").html(app.page.render().el);
$('#selected_aspect_contacts .content').html(streamFacesView.render().el);
this.hideInactiveStreamLists();
this._hideInactiveStreamLists();
},
hideInactiveStreamLists: function() {
_hideInactiveStreamLists: function() {
if(this.aspects_list && Backbone.history.fragment != "aspects")
this.aspects_list.hideAspectsList();

View file

@ -1,33 +1,27 @@
describe('app.Router', function () {
describe('followed_tags', function() {
beforeEach(function() {
factory.preloads({tagFollowings: []});
});
it('decodes name before passing it into TagFollowingAction', function () {
var followed_tags = spyOn(app.router, 'followed_tags').andCallThrough();
var tag_following_action = spyOn(app.views, 'TagFollowingAction').andCallFake(function(data) {
var followed_tags = spyOn(app.router, 'followed_tags').and.callThrough();
var tag_following_action = spyOn(app.views, 'TagFollowingAction').and.callFake(function(data) {
return {render: function() { return {el: ""}}};
});
spyOn(window.history, 'pushState').andCallFake(function (data, title, url) {
var route = app.router._routeToRegExp("tags/:name");
var args = app.router._extractParameters(route, url.replace(/^\//, ""));
app.router.followed_tags(args[0]);
});
window.preloads = {tagFollowings: []};
app.router.navigate('/tags/'+encodeURIComponent('օբյեկտիվ'));
app.router.followed_tags(encodeURIComponent('օբյեկտիվ'));
expect(followed_tags).toHaveBeenCalled();
expect(tag_following_action).toHaveBeenCalledWith({tagText: 'օբյեկտիվ'});
});
it('navigates to the downcase version of the corresponding tag', function () {
var followed_tags = spyOn(app.router, 'followed_tags').andCallThrough();
var tag_following_action = spyOn(app.views, 'TagFollowingAction').andCallFake(function(data) {
var followed_tags = spyOn(app.router, 'followed_tags').and.callThrough();
var tag_following_action = spyOn(app.views, 'TagFollowingAction').and.callFake(function(data) {
return {render: function() { return {el: ""}}};
});
spyOn(window.history, 'pushState').andCallFake(function (data, title, url) {
var route = app.router._routeToRegExp("tags/:name");
var args = app.router._extractParameters(route, url.replace(/^\//, ""));
app.router.followed_tags(args[0]);
});
window.preloads = {tagFollowings: []};
app.router.navigate('/tags/'+encodeURIComponent('SomethingWithCapitalLetters'));
app.router.followed_tags('SomethingWithCapitalLetters');
expect(followed_tags).toHaveBeenCalled();
expect(tag_following_action).toHaveBeenCalledWith({tagText: 'somethingwithcapitalletters'});
});
@ -42,31 +36,28 @@ describe('app.Router', function () {
router = new app.Router();
});
it('calls hideInactiveStreamLists', function () {
var hideInactiveStreamLists = spyOn(router, 'hideInactiveStreamLists').andCallThrough();
router.stream();
expect(hideInactiveStreamLists).toHaveBeenCalled();
});
it('hides the aspects list', function(){
aspects = new app.collections.Aspects([{ name: 'Work', selected: true }]);
var aspectsListView = new app.views.AspectsList({collection: aspects});
var hideAspectsList = spyOn(aspectsListView, 'hideAspectsList').andCallThrough();
setFixtures('<div id="aspects_list" />');
aspects = new app.collections.Aspects([
{ name: 'Work', selected: true },
{ name: 'Fun', selected: false }
]);
var aspectsListView = new app.views.AspectsList({collection: aspects}).render();
router.aspects_list = aspectsListView;
expect(aspectsListView.$el.html()).not.toBe("");
router.stream();
expect(hideAspectsList).toHaveBeenCalled();
expect(aspectsListView.$el.html()).toBe("");
});
it('hides the followed tags view', function(){
tagFollowings = new app.collections.TagFollowings();
var followedTagsView = new app.views.TagFollowingList({collection: tagFollowings});
var hideFollowedTags = spyOn(followedTagsView, 'hideFollowedTags').andCallThrough();
var followedTagsView = new app.views.TagFollowingList({collection: tagFollowings}).render();
router.followedTagsView = followedTagsView;
expect(followedTagsView.$el.html()).not.toBe("");
router.stream();
expect(hideFollowedTags).toHaveBeenCalled();
expect(followedTagsView.$el.html()).toBe("");
});
});

View file

@ -151,14 +151,23 @@ factory = {
comment: function(overrides) {
var defaultAttrs = {
"text" : "This is an awesome comment!",
"created_at" : "2012-01-03T19:53:13Z",
"author" : this.author(),
"guid" : this.guid(),
"id": this.id.next()
}
id: this.id.next(),
guid: this.guid(),
text: "This is an awesome comment!",
author: this.author(),
created_at: "2012-01-03T19:53:13Z"
};
return new app.models.Comment(_.extend(defaultAttrs, overrides))
},
preloads: function(overrides) {
var defaults = {
aspect_ids: []
};
window.gon = { preloads: {} };
_.extend(window.gon.preloads, defaults, overrides);
}
}

View file

@ -200,4 +200,4 @@ beforeEach(function() {
afterEach(function() {
jasmine.getFixtures().cleanUp();
});
});