DH DC don't render feedback view on public posts

This commit is contained in:
Dennis Collinson 2012-01-12 17:04:11 -08:00
parent 33772a27d9
commit dec3006b50
13 changed files with 65 additions and 37 deletions

View file

@ -1,5 +1,5 @@
<div class="right controls"> <div class="right controls">
<% if(author.id != current_user.id) { %> <% if(author.id != (!!current_user && current_user.id)) { %>
<a href="#" rel=nofollow> <a href="#" rel=nofollow>
<img src="/images/icons/ignoreuser.png" alt="Ignoreuser" class="block_user control_icon" title= "<%= Diaspora.I18n.t('ignore') %>" /> <img src="/images/icons/ignoreuser.png" alt="Ignoreuser" class="block_user control_icon" title= "<%= Diaspora.I18n.t('ignore') %>" />
<img src="/images/deletelabel.png" class="delete control_icon hide_post" title="<%= Diaspora.I18n.t('stream.hide') %>" /> <img src="/images/deletelabel.png" class="delete control_icon hide_post" title="<%= Diaspora.I18n.t('stream.hide') %>" />

View file

@ -5,7 +5,7 @@ app.views.Base = Backbone.View.extend({
defaultPresenter : function(){ defaultPresenter : function(){
var modelJson = this.model ? this.model.toJSON() : {} var modelJson = this.model ? this.model.toJSON() : {}
return _.extend(modelJson, app.user()); return _.extend(modelJson, { current_user: app.user().current_user });
}, },
render : function() { render : function() {
@ -17,7 +17,8 @@ app.views.Base = Backbone.View.extend({
}, },
renderTemplate : function(){ renderTemplate : function(){
this.template = _.template($(this.template_name).html()); var templateHTML = $(this.template_name).html(); //don't forget to regenerate your jasmine fixtures ;-)
this.template = _.template(templateHTML);
var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter
$(this.el).html(this.template(presenter)); $(this.el).html(this.template(presenter));
this.postRenderTemplate(); this.postRenderTemplate();

View file

@ -29,11 +29,20 @@ app.views.Post = app.views.StreamObject.extend({
//subviews //subviews
this.commentStreamView = new app.views.CommentStream({ model : this.model}); this.commentStreamView = new app.views.CommentStream({ model : this.model});
this.likesInfoView = new app.views.LikesInfo({ model : this.model}); this.likesInfoView = new app.views.LikesInfo({ model : this.model});
this.feedbackView = window.app.user().current_user && new app.views.Feedback({model : this.model});
return this; return this;
}, },
feedbackView : function(){
if(!window.app.user().current_user ) { return null }
var feedbackViewClass = this.resharedContent() ? app.views.ReshareFeedback : app.views.Feedback
return new feedbackViewClass({model : this.model});
},
resharedContent : function(){
return this.model.get('root')
},
postContentView: function(){ postContentView: function(){
var normalizedClass = this.model.get("post_type").replace(/::/, "__"); var normalizedClass = this.model.get("post_type").replace(/::/, "__");
var postClass = app.views[normalizedClass] || app.views.StatusMessage; var postClass = app.views[normalizedClass] || app.views.StatusMessage;

View file

@ -0,0 +1,4 @@
app.views.ReshareFeedback = Backbone.View.extend({
});

View file

@ -1,6 +1,6 @@
describe("app.views.Feedback", function(){ describe("app.views.Feedback", function(){
beforeEach(function(){ beforeEach(function(){
window.current_user = app.user({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); loginAs({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
Diaspora.I18n.loadLocale({stream : { Diaspora.I18n.loadLocale({stream : {
'like' : "Like", 'like' : "Like",

View file

@ -1,23 +1,20 @@
describe("app.views.Header", function() { describe("app.views.Header", function() {
beforeEach(function() { beforeEach(function() {
// should be jasmine helper this.userAttrs = {name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}
window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
loginAs(this.userAttrs);
spec.loadFixture("aspects_index"); spec.loadFixture("aspects_index");
this.view = new app.views.Header().render(); this.view = new app.views.Header().render();
}); });
describe("render", function(){ context("notifications badge", function(){ it("displays a count when the current user has a notification", function(){ loginAs(_.extend(this.userAttrs, {notifications_count : 1}))
describe("render", function(){
context("notifications badge", function(){
it("displays a count when the current user has a notification", function(){
window.current_user = _.extend(window.current_user, {notifications_count : 1})
this.view.render(); this.view.render();
expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(false); expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(false);
expect(this.view.$("#notification_badge .badge_count").text()).toContain("1"); expect(this.view.$("#notification_badge .badge_count").text()).toContain("1");
}) })
it("does not display a count when the current user has a notification", function(){ it("does not display a count when the current user has a notification", function(){
window.current_user = _.extend(window.current_user, {notifications_count : 0}) loginAs(_.extend(this.userAttrs, {notifications_count : 0}))
this.view.render(); this.view.render();
expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(true); expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(true);
}) })
@ -25,14 +22,14 @@ describe("app.views.Header", function() {
context("messages badge", function(){ context("messages badge", function(){
it("displays a count when the current user has a notification", function(){ it("displays a count when the current user has a notification", function(){
window.current_user = _.extend(window.current_user, {unread_messages_count : 1}) loginAs(_.extend(this.userAttrs, {unread_messages_count : 1}))
this.view.render(); this.view.render();
expect(this.view.$("#message_inbox_badge .badge_count").hasClass('hidden')).toBe(false); expect(this.view.$("#message_inbox_badge .badge_count").hasClass('hidden')).toBe(false);
expect(this.view.$("#message_inbox_badge .badge_count").text()).toContain("1"); expect(this.view.$("#message_inbox_badge .badge_count").text()).toContain("1");
}) })
it("does not display a count when the current user has a notification", function(){ it("does not display a count when the current user has a notification", function(){
window.current_user = _.extend(window.current_user, {unread_messages_count : 0}) loginAs(_.extend(this.userAttrs, {unread_messages_count : 0}))
this.view.render(); this.view.render();
expect(this.view.$("#message_inbox_badge .badge_count").hasClass('hidden')).toBe(true); expect(this.view.$("#message_inbox_badge .badge_count").hasClass('hidden')).toBe(true);
}) })
@ -40,13 +37,13 @@ describe("app.views.Header", function() {
context("admin link", function(){ context("admin link", function(){
it("displays if the current user is an admin", function(){ it("displays if the current user is an admin", function(){
window.current_user = _.extend(window.current_user, {admin : true}) loginAs(_.extend(this.userAttrs, {admin : true}))
this.view.render(); this.view.render();
expect(this.view.$("#user_menu").html()).toContain("/admins"); expect(this.view.$("#user_menu").html()).toContain("/admins");
}) })
it("does not display if the current user is not an admin", function(){ it("does not display if the current user is not an admin", function(){
window.current_user = _.extend(window.current_user, {admin : false}) loginAs(_.extend(this.userAttrs, {admin : false}))
this.view.render(); this.view.render();
expect(this.view.$("#user_menu").html()).not.toContain("/admins"); expect(this.view.$("#user_menu").html()).not.toContain("/admins");
}) })

View file

@ -1,6 +1,6 @@
describe("app.views.LikesInfo", function(){ describe("app.views.LikesInfo", function(){
beforeEach(function(){ beforeEach(function(){
window.current_user = app.user({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); loginAs({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
Diaspora.I18n.loadLocale({stream : { Diaspora.I18n.loadLocale({stream : {
likes : { likes : {

View file

@ -2,7 +2,7 @@ describe("app.views.Post", function(){
describe("#render", function(){ describe("#render", function(){
beforeEach(function(){ beforeEach(function(){
window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
Diaspora.I18n.loadLocale({stream : { Diaspora.I18n.loadLocale({stream : {
reshares : { reshares : {
@ -18,6 +18,14 @@ describe("app.views.Post", function(){
this.reshare = this.collection.models[1]; this.reshare = this.collection.models[1];
}) })
context("for a reshare", function(){
it("should display ReshareFeedback", function(){
spyOn(app.views, "ReshareFeedback").andReturn(stubView("these are special reshare actions"));
var view = new app.views.Post({model : this.reshare}).render();
expect(view.$(".feedback").text().trim()).toBe("these are special reshare actions");
})
})
it("displays a reshare count", function(){ it("displays a reshare count", function(){
this.statusMessage.set({reshares_count : 2}) this.statusMessage.set({reshares_count : 2})
var view = new app.views.Post({model : this.statusMessage}).render(); var view = new app.views.Post({model : this.statusMessage}).render();
@ -161,10 +169,9 @@ describe("app.views.Post", function(){
context("user not signed in", function(){ context("user not signed in", function(){
it("does not provide a Feedback view", function(){ it("does not provide a Feedback view", function(){
window.current_user = app.user(null); logout()
var view = new app.views.Post({model : this.statusMessage}).render(); var view = new app.views.Post({model : this.statusMessage}).render();
expect(view.feedbackView).toBeFalsy(); expect(view.feedbackView()).toBeFalsy();
}) })
}) })

View file

@ -1,7 +1,7 @@
describe("app.views.Publisher", function() { describe("app.views.Publisher", function() {
beforeEach(function() { beforeEach(function() {
// should be jasmine helper // should be jasmine helper
window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
spec.loadFixture("aspects_index"); spec.loadFixture("aspects_index");
this.view = new app.views.Publisher(); this.view = new app.views.Publisher();

View file

@ -1,7 +1,6 @@
describe("app.views.Stream", function(){ describe("app.views.Stream", function(){
beforeEach(function(){ beforeEach(function(){
// should be jasmine helper loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
this.posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"]; this.posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];

View file

@ -1,15 +1,4 @@
describe("app.views.Base", function(){ describe("app.views.Base", function(){
function stubView(text){
var stubClass = Backbone.View.extend({
render : function(){
$(this.el).html(text)
return this
}
})
return new stubClass
}
describe("#render", function(){ describe("#render", function(){
beforeEach(function(){ beforeEach(function(){
var staticTemplateClass = app.views.Base.extend({ template_name : "#static-text-template" }) var staticTemplateClass = app.views.Base.extend({ template_name : "#static-text-template" })

View file

@ -40,6 +40,25 @@ afterEach(function() {
var context = describe; var context = describe;
var spec = {}; var spec = {};
window.stubView = function stubView(text){
var stubClass = Backbone.View.extend({
render : function(){
$(this.el).html(text);
return this
}
})
return new stubClass
}
window.loginAs = function loginAs(attrs){
return window.current_user = app.user({current_user: factory.userAttrs(attrs)})
}
window.logout = function logout(){
return window.current_user = app.user({current_user: null})
}
spec.clearLiveEventBindings = function() { spec.clearLiveEventBindings = function() {
var events = jQuery.data(document, "events"); var events = jQuery.data(document, "events");
for (prop in events) { for (prop in events) {
@ -63,6 +82,7 @@ spec.loadFixture = function(fixtureName) {
spec.loadFixtureCount++; spec.loadFixtureCount++;
}; };
// Returns fixture markup as a string. Useful for fixtures that // Returns fixture markup as a string. Useful for fixtures that
// represent the response text of ajax requests. // represent the response text of ajax requests.
spec.readFixture = function(fixtureName) { spec.readFixture = function(fixtureName) {

View file

@ -21,7 +21,7 @@ factory = {
return _.extend(defaultAttrs, overrides) return _.extend(defaultAttrs, overrides)
}, },
author : function(overrides){ userAttrs : function(overrides){
var id = this.id.next() var id = this.id.next()
var defaultAttrs = { var defaultAttrs = {
"name":"Awesome User" + id, "name":"Awesome User" + id,
@ -60,3 +60,5 @@ factory = {
return new app.models.Post(_.extend(defaultAttrs, overrides)) return new app.models.Post(_.extend(defaultAttrs, overrides))
} }
} }
factory.author = factory.userAttrs