DH DC don't render feedback view on public posts
This commit is contained in:
parent
33772a27d9
commit
dec3006b50
13 changed files with 65 additions and 37 deletions
|
|
@ -1,5 +1,5 @@
|
|||
<div class="right controls">
|
||||
<% if(author.id != current_user.id) { %>
|
||||
<% if(author.id != (!!current_user && current_user.id)) { %>
|
||||
<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/deletelabel.png" class="delete control_icon hide_post" title="<%= Diaspora.I18n.t('stream.hide') %>" />
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ app.views.Base = Backbone.View.extend({
|
|||
|
||||
defaultPresenter : function(){
|
||||
var modelJson = this.model ? this.model.toJSON() : {}
|
||||
return _.extend(modelJson, app.user());
|
||||
return _.extend(modelJson, { current_user: app.user().current_user });
|
||||
},
|
||||
|
||||
render : function() {
|
||||
|
|
@ -17,7 +17,8 @@ app.views.Base = Backbone.View.extend({
|
|||
},
|
||||
|
||||
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
|
||||
$(this.el).html(this.template(presenter));
|
||||
this.postRenderTemplate();
|
||||
|
|
|
|||
|
|
@ -29,11 +29,20 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
//subviews
|
||||
this.commentStreamView = new app.views.CommentStream({ 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;
|
||||
},
|
||||
|
||||
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(){
|
||||
var normalizedClass = this.model.get("post_type").replace(/::/, "__");
|
||||
var postClass = app.views[normalizedClass] || app.views.StatusMessage;
|
||||
|
|
|
|||
4
public/javascripts/app/views/reshare_feedback_view.js
Normal file
4
public/javascripts/app/views/reshare_feedback_view.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
app.views.ReshareFeedback = Backbone.View.extend({
|
||||
|
||||
|
||||
});
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
describe("app.views.Feedback", 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 : {
|
||||
'like' : "Like",
|
||||
|
|
|
|||
|
|
@ -1,23 +1,20 @@
|
|||
describe("app.views.Header", function() {
|
||||
beforeEach(function() {
|
||||
// should be jasmine helper
|
||||
window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
|
||||
this.userAttrs = {name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}
|
||||
|
||||
loginAs(this.userAttrs);
|
||||
|
||||
spec.loadFixture("aspects_index");
|
||||
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(){
|
||||
window.current_user = _.extend(window.current_user, {notifications_count : 1})
|
||||
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}))
|
||||
this.view.render();
|
||||
expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(false);
|
||||
expect(this.view.$("#notification_badge .badge_count").text()).toContain("1");
|
||||
})
|
||||
|
||||
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();
|
||||
expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(true);
|
||||
})
|
||||
|
|
@ -25,14 +22,14 @@ describe("app.views.Header", function() {
|
|||
|
||||
context("messages badge", 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();
|
||||
expect(this.view.$("#message_inbox_badge .badge_count").hasClass('hidden')).toBe(false);
|
||||
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(){
|
||||
window.current_user = _.extend(window.current_user, {unread_messages_count : 0})
|
||||
loginAs(_.extend(this.userAttrs, {unread_messages_count : 0}))
|
||||
this.view.render();
|
||||
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(){
|
||||
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();
|
||||
expect(this.view.$("#user_menu").html()).toContain("/admins");
|
||||
})
|
||||
|
||||
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();
|
||||
expect(this.view.$("#user_menu").html()).not.toContain("/admins");
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
describe("app.views.LikesInfo", 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 : {
|
||||
likes : {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ describe("app.views.Post", function(){
|
|||
|
||||
describe("#render", 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 : {
|
||||
reshares : {
|
||||
|
|
@ -18,6 +18,14 @@ describe("app.views.Post", function(){
|
|||
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(){
|
||||
this.statusMessage.set({reshares_count : 2})
|
||||
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(){
|
||||
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();
|
||||
expect(view.feedbackView).toBeFalsy();
|
||||
expect(view.feedbackView()).toBeFalsy();
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
describe("app.views.Publisher", function() {
|
||||
beforeEach(function() {
|
||||
// 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");
|
||||
this.view = new app.views.Publisher();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
describe("app.views.Stream", function(){
|
||||
beforeEach(function(){
|
||||
// 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"}});
|
||||
|
||||
this.posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,4 @@
|
|||
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(){
|
||||
beforeEach(function(){
|
||||
var staticTemplateClass = app.views.Base.extend({ template_name : "#static-text-template" })
|
||||
|
|
|
|||
|
|
@ -40,6 +40,25 @@ afterEach(function() {
|
|||
var context = describe;
|
||||
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() {
|
||||
var events = jQuery.data(document, "events");
|
||||
for (prop in events) {
|
||||
|
|
@ -63,6 +82,7 @@ spec.loadFixture = function(fixtureName) {
|
|||
spec.loadFixtureCount++;
|
||||
};
|
||||
|
||||
|
||||
// Returns fixture markup as a string. Useful for fixtures that
|
||||
// represent the response text of ajax requests.
|
||||
spec.readFixture = function(fixtureName) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ factory = {
|
|||
return _.extend(defaultAttrs, overrides)
|
||||
},
|
||||
|
||||
author : function(overrides){
|
||||
userAttrs : function(overrides){
|
||||
var id = this.id.next()
|
||||
var defaultAttrs = {
|
||||
"name":"Awesome User" + id,
|
||||
|
|
@ -60,3 +60,5 @@ factory = {
|
|||
return new app.models.Post(_.extend(defaultAttrs, overrides))
|
||||
}
|
||||
}
|
||||
|
||||
factory.author = factory.userAttrs
|
||||
|
|
|
|||
Loading…
Reference in a new issue