Merge branch 'next-minor' into develop
This commit is contained in:
commit
cc8eff9efb
13 changed files with 389 additions and 195 deletions
|
|
@ -14,10 +14,11 @@
|
|||
* Make the session cookies HttpOnly again [#7041](https://github.com/diaspora/diaspora/pull/7041)
|
||||
|
||||
## Bug fixes
|
||||
* Post comments no longer get collapsed when interacting with a post [#7045](https://github.com/diaspora/diaspora/pull/7045)
|
||||
* Post comments no longer get collapsed when interacting with a post [#7040](https://github.com/diaspora/diaspora/pull/7040)
|
||||
|
||||
## Features
|
||||
* The "subscribe" indicator on a post now gets toggled when you like or rehsare a post [#7045](https://github.com/diaspora/diaspora/pull/7045)
|
||||
* Deleted comments will be removed when loading more comments [#7045](https://github.com/diaspora/diaspora/pull/7045)
|
||||
* The "subscribe" indicator on a post now gets toggled when you like or rehsare a post [#7040](https://github.com/diaspora/diaspora/pull/7040)
|
||||
|
||||
# 0.6.0.0
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ app.models.Post.Interactions = Backbone.Model.extend({
|
|||
var self = this;
|
||||
this.likes.create({}, {
|
||||
success: function() {
|
||||
self.post.set({participation: true});
|
||||
self.trigger("change");
|
||||
self.set({"likes_count" : self.get("likes_count") + 1});
|
||||
},
|
||||
|
|
@ -94,6 +95,7 @@ app.models.Post.Interactions = Backbone.Model.extend({
|
|||
this.comments.make(text).fail(function () {
|
||||
app.flashMessages.error(Diaspora.I18n.t("failed_to_comment"));
|
||||
}).done(function() {
|
||||
self.post.set({participation: true});
|
||||
self.trigger('change'); //updates after sync
|
||||
});
|
||||
|
||||
|
|
@ -109,6 +111,7 @@ app.models.Post.Interactions = Backbone.Model.extend({
|
|||
.done(function(reshare) {
|
||||
app.flashMessages.success(Diaspora.I18n.t("reshares.successful"));
|
||||
interactions.reshares.add(reshare);
|
||||
interactions.post.set({participation: true});
|
||||
if (app.stream && /^\/(?:stream|activity|aspects)/.test(app.stream.basePath())) {
|
||||
app.stream.addNow(reshare);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
|
||||
|
||||
//=require "./feedback_view"
|
||||
app.views.FeedbackActions = app.views.Feedback.extend({
|
||||
id : "user-controls",
|
||||
templateName : "feedback-actions",
|
||||
events: {},
|
||||
initialize: function(){}
|
||||
});
|
||||
// @license-end
|
||||
|
||||
|
|
@ -8,10 +8,6 @@ app.views.Feedback = app.views.Base.extend({
|
|||
events: {
|
||||
"click .like" : "toggleLike",
|
||||
"click .reshare" : "resharePost",
|
||||
|
||||
"click .post_report" : "report",
|
||||
"click .block_user" : "blockUser",
|
||||
"click .hide_post" : "hidePost"
|
||||
},
|
||||
|
||||
tooltipSelector : ".label",
|
||||
|
|
@ -43,39 +39,6 @@ app.views.Feedback = app.views.Base.extend({
|
|||
if(evt) { evt.preventDefault(); }
|
||||
if(!window.confirm(Diaspora.I18n.t("reshares.post", {name: this.model.reshareAuthor().name}))) { return }
|
||||
this.model.interactions.reshare();
|
||||
},
|
||||
|
||||
blockUser: function(evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
if(!confirm(Diaspora.I18n.t("ignore_user"))) { return; }
|
||||
|
||||
this.model.blockAuthor()
|
||||
.done(function() {
|
||||
// return to stream
|
||||
document.location.href = "/stream";
|
||||
})
|
||||
.fail(function() {
|
||||
app.flashMessages.error(Diaspora.I18n.t("hide_post_failed"));
|
||||
});
|
||||
},
|
||||
|
||||
hidePost : function(evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
if(!confirm(Diaspora.I18n.t("hide_post"))) { return; }
|
||||
|
||||
$.ajax({
|
||||
url : "/share_visibilities/42",
|
||||
type : "PUT",
|
||||
data : {
|
||||
post_id : this.model.id
|
||||
}
|
||||
}).done(function() {
|
||||
// return to stream
|
||||
document.location.href = "/stream";
|
||||
})
|
||||
.fail(function() {
|
||||
app.flashMessages.error(Diaspora.I18n.t("ignore_post_failed"));
|
||||
});
|
||||
}
|
||||
});
|
||||
// @license-end
|
||||
|
|
|
|||
81
app/assets/javascripts/app/views/post_controls_view.js
Normal file
81
app/assets/javascripts/app/views/post_controls_view.js
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
|
||||
|
||||
app.views.PostControls = app.views.Base.extend({
|
||||
templateName: "post-controls",
|
||||
className: "control-icons",
|
||||
|
||||
events: {
|
||||
"click .remove_post": "destroyModel",
|
||||
"click .hide_post": "hidePost",
|
||||
"click .post_report": "report",
|
||||
"click .block_user": "blockUser",
|
||||
"click .create_participation": "createParticipation",
|
||||
"click .destroy_participation": "destroyParticipation"
|
||||
},
|
||||
|
||||
tooltipSelector: [".post_report",
|
||||
".block_user",
|
||||
".delete",
|
||||
".create_participation",
|
||||
".destroy_participation"].join(", "),
|
||||
|
||||
initialize: function(opts) {
|
||||
this.model.bind("change", this.render, this);
|
||||
this.post = opts.post;
|
||||
},
|
||||
|
||||
presenter: function() {
|
||||
return _.extend(this.defaultPresenter(), {
|
||||
authorIsCurrentUser: app.currentUser.isAuthorOf(this.model)
|
||||
});
|
||||
},
|
||||
|
||||
blockUser: function(evt) {
|
||||
if (evt) { evt.preventDefault(); }
|
||||
if (!confirm(Diaspora.I18n.t("ignore_user"))) { return; }
|
||||
|
||||
this.model.blockAuthor().done(function() {
|
||||
if (this.singlePost) { app._changeLocation(Routes.stream()); }
|
||||
}.bind(this)).fail(function() {
|
||||
app.flashMessages.error(Diaspora.I18n.t("ignore_failed"));
|
||||
});
|
||||
},
|
||||
|
||||
hidePost: function(evt) {
|
||||
if (evt) { evt.preventDefault(); }
|
||||
if (!confirm(Diaspora.I18n.t("confirm_dialog"))) { return; }
|
||||
|
||||
$.ajax({
|
||||
url: Routes.shareVisibility(42),
|
||||
type: "PUT",
|
||||
data: {
|
||||
/* eslint-disable camelcase */
|
||||
post_id: this.model.id
|
||||
/* eslint-enable camelcase */
|
||||
}
|
||||
}).done(function() {
|
||||
if (this.singlePost) {
|
||||
app._changeLocation(Routes.stream());
|
||||
} else {
|
||||
this.post.remove();
|
||||
}
|
||||
}.bind(this)).fail(function() {
|
||||
app.flashMessages.error(Diaspora.I18n.t("hide_post_failed"));
|
||||
});
|
||||
},
|
||||
|
||||
createParticipation: function(evt) {
|
||||
if (evt) { evt.preventDefault(); }
|
||||
$.post(Routes.postParticipation(this.model.get("id")), {}, function() {
|
||||
this.model.set({participation: true});
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
destroyParticipation: function(evt) {
|
||||
if (evt) { evt.preventDefault(); }
|
||||
$.post(Routes.postParticipation(this.model.get("id")), {_method: "delete"}, function() {
|
||||
this.model.set({participation: false});
|
||||
}.bind(this));
|
||||
}
|
||||
});
|
||||
// @license-end
|
||||
|
|
@ -1,31 +1,12 @@
|
|||
app.views.SinglePostModeration = app.views.Feedback.extend({
|
||||
app.views.SinglePostModeration = app.views.PostControls.extend({
|
||||
templateName: "single-post-viewer/single-post-moderation",
|
||||
|
||||
className: "control-icons",
|
||||
|
||||
events: function() {
|
||||
return _.defaults({
|
||||
"click .remove_post": "destroyModel",
|
||||
"click .create_participation": "createParticipation",
|
||||
"click .destroy_participation": "destroyParticipation"
|
||||
}, app.views.Feedback.prototype.events);
|
||||
},
|
||||
|
||||
presenter: function() {
|
||||
return _.extend(this.defaultPresenter(), {
|
||||
authorIsCurrentUser : this.authorIsCurrentUser()
|
||||
});
|
||||
},
|
||||
singlePost: true,
|
||||
|
||||
renderPluginWidgets : function() {
|
||||
app.views.Base.prototype.renderPluginWidgets.apply(this);
|
||||
this.$("a").tooltip({placement: "bottom"});
|
||||
},
|
||||
|
||||
authorIsCurrentUser: function() {
|
||||
return app.currentUser.authenticated() && this.model.get("author").id === app.user().id;
|
||||
},
|
||||
|
||||
destroyModel: function(evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
var url = this.model.urlRoot + "/" + this.model.id;
|
||||
|
|
@ -41,24 +22,4 @@ app.views.SinglePostModeration = app.views.Feedback.extend({
|
|||
});
|
||||
}
|
||||
},
|
||||
|
||||
createParticipation: function (evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
var self = this;
|
||||
$.post(Routes.postParticipation(this.model.get("id")), {}, function () {
|
||||
self.model.set({participation: true});
|
||||
self.render();
|
||||
});
|
||||
},
|
||||
|
||||
destroyParticipation: function (evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
var self = this;
|
||||
$.post(Routes.postParticipation(this.model.get("id")), { _method: "delete" }, function () {
|
||||
self.model.set({participation: false});
|
||||
self.render();
|
||||
});
|
||||
},
|
||||
|
||||
participation: function(){ return this.model.get("participation"); }
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,38 +5,26 @@ app.views.StreamPost = app.views.Post.extend({
|
|||
className : "stream_element loaded",
|
||||
|
||||
subviews : {
|
||||
".feedback" : "feedbackView",
|
||||
".likes" : "likesInfoView",
|
||||
".reshares" : "resharesInfoView",
|
||||
".comments" : "commentStreamView",
|
||||
".post-content" : "postContentView",
|
||||
".oembed" : "oEmbedView",
|
||||
".opengraph" : "openGraphView",
|
||||
".poll" : "pollView",
|
||||
".status-message-location" : "postLocationStreamView"
|
||||
".feedback": "feedbackView",
|
||||
".comments": "commentStreamView",
|
||||
".likes": "likesInfoView",
|
||||
".reshares": "resharesInfoView",
|
||||
".post-controls": "postControlsView",
|
||||
".post-content": "postContentView",
|
||||
".oembed": "oEmbedView",
|
||||
".opengraph": "openGraphView",
|
||||
".poll": "pollView",
|
||||
".status-message-location": "postLocationStreamView"
|
||||
},
|
||||
|
||||
events: {
|
||||
"click .focus_comment_textarea": "focusCommentTextarea",
|
||||
"click .show_nsfw_post": "removeNsfwShield",
|
||||
"click .toggle_nsfw_state": "toggleNsfwState",
|
||||
|
||||
"click .remove_post": "destroyModel",
|
||||
"click .hide_post": "hidePost",
|
||||
"click .post_report": "report",
|
||||
"click .block_user": "blockUser",
|
||||
|
||||
"click .create_participation": "createParticipation",
|
||||
"click .destroy_participation": "destroyParticipation"
|
||||
"click .toggle_nsfw_state": "toggleNsfwState"
|
||||
},
|
||||
|
||||
tooltipSelector : [".timeago",
|
||||
".post_scope",
|
||||
".post_report",
|
||||
".block_user",
|
||||
".delete",
|
||||
".create_participation",
|
||||
".destroy_participation",
|
||||
".permalink"].join(", "),
|
||||
|
||||
initialize : function(){
|
||||
|
|
@ -51,6 +39,9 @@ app.views.StreamPost = app.views.Post.extend({
|
|||
this.pollView = new app.views.Poll({model : this.model});
|
||||
},
|
||||
|
||||
postControlsView: function() {
|
||||
return new app.views.PostControls({model: this.model, post: this});
|
||||
},
|
||||
|
||||
likesInfoView : function(){
|
||||
return new app.views.LikesInfo({model : this.model});
|
||||
|
|
@ -87,60 +78,12 @@ app.views.StreamPost = app.views.Post.extend({
|
|||
app.currentUser.toggleNsfwState();
|
||||
},
|
||||
|
||||
|
||||
blockUser: function(evt){
|
||||
if(evt) { evt.preventDefault(); }
|
||||
if(!confirm(Diaspora.I18n.t("ignore_user"))) { return }
|
||||
|
||||
this.model.blockAuthor()
|
||||
.fail(function() {
|
||||
app.flashMessages.error(Diaspora.I18n.t("ignore_failed"));
|
||||
});
|
||||
},
|
||||
|
||||
remove : function() {
|
||||
$(this.el).slideUp(400, _.bind(function(){this.$el.remove()}, this));
|
||||
app.stream.remove(this.model);
|
||||
return this;
|
||||
},
|
||||
|
||||
hidePost : function(evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
if(!confirm(Diaspora.I18n.t("confirm_dialog"))) { return }
|
||||
|
||||
var self = this;
|
||||
$.ajax({
|
||||
url : "/share_visibilities/42",
|
||||
type : "PUT",
|
||||
data : {
|
||||
post_id : this.model.id
|
||||
}
|
||||
}).done(function() {
|
||||
self.remove();
|
||||
})
|
||||
.fail(function() {
|
||||
app.flashMessages.error(Diaspora.I18n.t("hide_post_failed"));
|
||||
});
|
||||
},
|
||||
|
||||
createParticipation: function (evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
var that = this;
|
||||
$.post(Routes.postParticipation(this.model.get("id")), {}, function () {
|
||||
that.model.set({participation: true});
|
||||
that.render();
|
||||
});
|
||||
},
|
||||
|
||||
destroyParticipation: function (evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
var that = this;
|
||||
$.post(Routes.postParticipation(this.model.get("id")), { _method: "delete" }, function () {
|
||||
that.model.set({participation: false});
|
||||
that.render();
|
||||
});
|
||||
},
|
||||
|
||||
focusCommentTextarea: function(evt){
|
||||
evt.preventDefault();
|
||||
this.$(".new-comment-form-wrapper").removeClass("hidden");
|
||||
|
|
@ -148,6 +91,5 @@ app.views.StreamPost = app.views.Post.extend({
|
|||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
// @license-end
|
||||
|
|
|
|||
24
app/assets/templates/post-controls_tpl.jst.hbs
Normal file
24
app/assets/templates/post-controls_tpl.jst.hbs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{{#if authorIsCurrentUser}}
|
||||
<a href="#" rel="nofollow" class="delete remove_post" title="{{t "delete"}}">
|
||||
<i class="entypo-trash"></i>
|
||||
</a>
|
||||
{{else}}
|
||||
<a href="#" rel="nofollow" data-type="Post" class="post_report" title="{{t "report.name"}}">
|
||||
<i class="entypo-warning"></i>
|
||||
</a>
|
||||
<a href="#" rel="nofollow" class="block_user" title="{{t "ignore"}}">
|
||||
<i class="entypo-block"></i>
|
||||
</a>
|
||||
{{#if participation}}
|
||||
<a href="#" rel="nofollow" class="destroy_participation" title="{{t "stream.disable_post_notifications"}}">
|
||||
<i class="entypo-bell"></i>
|
||||
</a>
|
||||
{{else}}
|
||||
<a href="#" rel="nofollow" class="create_participation" title="{{t "stream.enable_post_notifications"}}">
|
||||
<i class="entypo-bell"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
<a href="#" rel="nofollow" class="delete hide_post" title="{{t "stream.hide"}}">
|
||||
<i class="entypo-cross"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
|
|
@ -7,34 +7,7 @@
|
|||
|
||||
<div class="bd">
|
||||
{{#if loggedIn}}
|
||||
<div class="control-icons">
|
||||
{{#unless preview}}
|
||||
{{#if authorIsCurrentUser}}
|
||||
<a href="#" rel="nofollow" class="delete remove_post" title="{{t "delete"}}">
|
||||
<i class="entypo-trash"></i>
|
||||
</a>
|
||||
{{else}}
|
||||
<a href="#" rel="nofollow" data-type="Post" class="post_report" title="{{t "report.name"}}">
|
||||
<i class="entypo-warning"></i>
|
||||
</a>
|
||||
<a href="#" rel="nofollow" class="block_user" title="{{t "ignore"}}">
|
||||
<i class="entypo-block"></i>
|
||||
</a>
|
||||
{{#if participation}}
|
||||
<a href="#" rel="nofollow" class="destroy_participation" title="{{t "stream.disable_post_notifications"}}">
|
||||
<i class="entypo-bell"></i>
|
||||
</a>
|
||||
{{else}}
|
||||
<a href="#" rel="nofollow" class="create_participation" title="{{t "stream.enable_post_notifications"}}">
|
||||
<i class="entypo-bell"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
<a href="#" rel="nofollow" class="delete hide_post" title="{{t "stream.hide"}}">
|
||||
<i class="entypo-cross"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
</div>
|
||||
<div class="post-controls"></div>
|
||||
{{/if}}
|
||||
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -14,9 +14,11 @@ Feature: Liking posts
|
|||
And I sign in as "alice@alice.alice"
|
||||
|
||||
Scenario: Liking and unliking a post from the stream
|
||||
Then I should not have activated notifications for the post
|
||||
When I like the post "I like unicorns" in the stream
|
||||
Then I should see "Unlike" within ".stream_element .feedback"
|
||||
And I should see a ".likes .media" within "#main_stream .stream_element"
|
||||
And I should have activated notifications for the post
|
||||
|
||||
When I unlike the post "I like unicorns" in the stream
|
||||
Then I should see "Like" within ".stream_element .feedback"
|
||||
|
|
@ -25,8 +27,10 @@ Feature: Liking posts
|
|||
|
||||
Scenario: Liking and unliking a post from a single post page
|
||||
When I open the show page of the "I like unicorns" post
|
||||
And I click to like the post
|
||||
Then I should not have activated notifications for the post in the single post view
|
||||
When I click to like the post
|
||||
Then I should see a ".count" within "#single-post-interactions"
|
||||
And I should have activated notifications for the post in the single post view
|
||||
|
||||
When I click to unlike the post
|
||||
Then I should not see a ".count" within "#single-post-interactions"
|
||||
|
|
|
|||
|
|
@ -5,3 +5,14 @@ end
|
|||
When /^I filter notifications by mentions$/ do
|
||||
step %(I follow "Mentioned" within "#notifications_container .list-group")
|
||||
end
|
||||
|
||||
Then /^I should( not)? have activated notifications for the post( in the single post view)?$/ do |negate, spv|
|
||||
selector = spv ? "#single-post-moderation" : "#main_stream .stream_element"
|
||||
if negate
|
||||
expect(find(selector, match: :first)).to have_no_css(".destroy_participation", visible: false)
|
||||
expect(find(selector, match: :first)).to have_css(".create_participation", visible: false)
|
||||
else
|
||||
expect(find(selector, match: :first)).to have_css(".destroy_participation", visible: false)
|
||||
expect(find(selector, match: :first)).to have_no_css(".create_participation", visible: false)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
describe("app.models.Post.Interactions", function(){
|
||||
var ajaxSuccess = {status: 200, responseText: "{\"id\": 1}"};
|
||||
|
||||
beforeEach(function(){
|
||||
this.interactions = factory.post().interactions;
|
||||
this.post = factory.post();
|
||||
this.interactions = this.post.interactions;
|
||||
this.author = factory.author({guid: "loggedInAsARockstar"});
|
||||
loginAs({guid: "loggedInAsARockstar"});
|
||||
|
||||
|
|
@ -30,6 +33,13 @@ describe("app.models.Post.Interactions", function(){
|
|||
this.interactions.like();
|
||||
expect(this.interactions.likes.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("sets the participation flag for the post", function() {
|
||||
expect(this.post.get("participation")).toBeFalsy();
|
||||
this.interactions.like();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess);
|
||||
expect(this.post.get("participation")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("unlike", function(){
|
||||
|
|
@ -42,8 +52,6 @@ describe("app.models.Post.Interactions", function(){
|
|||
});
|
||||
|
||||
describe("reshare", function() {
|
||||
var ajaxSuccess = { status: 200, responseText: "{\"id\": 1}" };
|
||||
|
||||
beforeEach(function(){
|
||||
this.reshare = this.interactions.post.reshare();
|
||||
});
|
||||
|
|
@ -81,6 +89,13 @@ describe("app.models.Post.Interactions", function(){
|
|||
expect(app.stream.addNow).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("sets the participation flag for the post", function() {
|
||||
expect(this.post.get("participation")).toBeFalsy();
|
||||
this.interactions.reshare();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess);
|
||||
expect(this.post.get("participation")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("userLike", function(){
|
||||
|
|
|
|||
227
spec/javascripts/app/views/post_controls_view_spec.js
Normal file
227
spec/javascripts/app/views/post_controls_view_spec.js
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
describe("app.views.PostControls", function() {
|
||||
describe("render", function() {
|
||||
beforeEach(function() {
|
||||
this.model = factory.post();
|
||||
this.view = new app.views.PostControls({model: this.model});
|
||||
});
|
||||
|
||||
context("in a post of the current user", function() {
|
||||
beforeEach(function() {
|
||||
app.currentUser = new app.models.User(this.model.attributes.author);
|
||||
this.view.render();
|
||||
});
|
||||
|
||||
it("shows a delete button", function() {
|
||||
expect(this.view.$(".delete.remove_post").length).toBe(1);
|
||||
});
|
||||
|
||||
it("doesn't show a report button", function() {
|
||||
expect(this.view.$(".post_report").length).toBe(0);
|
||||
});
|
||||
|
||||
it("doesn't show an ignore button", function() {
|
||||
expect(this.view.$(".block_user").length).toBe(0);
|
||||
});
|
||||
|
||||
it("doesn't show participation buttons", function() {
|
||||
expect(this.view.$(".create_participation").length).toBe(0);
|
||||
expect(this.view.$(".destroy_participation").length).toBe(0);
|
||||
});
|
||||
|
||||
it("doesn't show a hide button", function() {
|
||||
expect(this.view.$(".delete.hide_post").length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
context("in a post of another user", function() {
|
||||
beforeEach(function() {
|
||||
this.view.render();
|
||||
});
|
||||
|
||||
it("doesn't show a delete button", function() {
|
||||
expect(this.view.$(".delete.remove_post").length).toBe(0);
|
||||
});
|
||||
|
||||
it("shows a report button", function() {
|
||||
expect(this.view.$(".post_report").length).toBe(1);
|
||||
});
|
||||
|
||||
it("shows an ignore button", function() {
|
||||
expect(this.view.$(".block_user").length).toBe(1);
|
||||
});
|
||||
|
||||
it("shows a create participation button", function() {
|
||||
expect(this.view.$(".create_participation").length).toBe(1);
|
||||
expect(this.view.$(".destroy_participation").length).toBe(0);
|
||||
});
|
||||
|
||||
it("shows a destroy participation button if the user participated", function() {
|
||||
this.model.set({participation: true});
|
||||
this.view.render();
|
||||
expect(this.view.$(".create_participation").length).toBe(0);
|
||||
expect(this.view.$(".destroy_participation").length).toBe(1);
|
||||
});
|
||||
|
||||
it("shows a hide button", function() {
|
||||
expect(this.view.$(".delete.hide_post").length).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("events", function() {
|
||||
beforeEach(function() {
|
||||
this.model = factory.post();
|
||||
});
|
||||
|
||||
it("calls destroyModel when removing a post", function() {
|
||||
spyOn(app.views.PostControls.prototype, "destroyModel");
|
||||
app.currentUser = new app.models.User(this.model.attributes.author);
|
||||
this.view = new app.views.PostControls({model: this.model});
|
||||
this.view.render();
|
||||
this.view.$(".remove_post.delete").click();
|
||||
expect(app.views.PostControls.prototype.destroyModel).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls hidePost when hiding a post", function() {
|
||||
spyOn(app.views.PostControls.prototype, "hidePost");
|
||||
this.view = new app.views.PostControls({model: this.model});
|
||||
this.view.render();
|
||||
this.view.$(".hide_post.delete").click();
|
||||
expect(app.views.PostControls.prototype.hidePost).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls report when reporting a post", function() {
|
||||
spyOn(app.views.PostControls.prototype, "report");
|
||||
this.view = new app.views.PostControls({model: this.model});
|
||||
this.view.render();
|
||||
this.view.$(".post_report").click();
|
||||
expect(app.views.PostControls.prototype.report).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls blockUser when blocking the user", function() {
|
||||
spyOn(app.views.PostControls.prototype, "blockUser");
|
||||
this.view = new app.views.PostControls({model: this.model});
|
||||
this.view.render();
|
||||
this.view.$(".block_user").click();
|
||||
expect(app.views.PostControls.prototype.blockUser).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls createParticipation when creating a participation", function() {
|
||||
spyOn(app.views.PostControls.prototype, "createParticipation");
|
||||
this.view = new app.views.PostControls({model: this.model});
|
||||
this.view.render();
|
||||
this.view.$(".create_participation").click();
|
||||
expect(app.views.PostControls.prototype.createParticipation).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls destroyParticipation when destroying a participation", function() {
|
||||
spyOn(app.views.PostControls.prototype, "destroyParticipation");
|
||||
this.model.set({participation: true});
|
||||
this.view = new app.views.PostControls({model: this.model});
|
||||
this.view.render();
|
||||
this.view.$(".destroy_participation").click();
|
||||
expect(app.views.PostControls.prototype.destroyParticipation).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("initialize", function() {
|
||||
it("rerenders the view when the model has been changed", function() {
|
||||
spyOn(app.views.PostControls.prototype, "render");
|
||||
this.model = factory.post();
|
||||
this.view = new app.views.PostControls({model: this.model});
|
||||
expect(app.views.PostControls.prototype.render).not.toHaveBeenCalled();
|
||||
this.model.trigger("change");
|
||||
expect(app.views.PostControls.prototype.render).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("blockUser", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(window, "confirm").and.returnValue(true);
|
||||
this.model = factory.post();
|
||||
this.view = new app.views.PostControls({model: this.model});
|
||||
this.view.render();
|
||||
});
|
||||
|
||||
it("asks for a confirmation", function() {
|
||||
this.view.blockUser();
|
||||
expect(window.confirm).toHaveBeenCalledWith(Diaspora.I18n.t("ignore_user"));
|
||||
});
|
||||
|
||||
it("calls blockAuthor", function() {
|
||||
spyOn(this.model, "blockAuthor").and.callThrough();
|
||||
this.view.blockUser();
|
||||
expect(this.model.blockAuthor).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("doesn't redirect to the stream page on success", function() {
|
||||
spyOn(app, "_changeLocation");
|
||||
this.view.blockUser();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
|
||||
expect(app._changeLocation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("redirects to the stream page on success from the single post view", function() {
|
||||
spyOn(app, "_changeLocation");
|
||||
this.view.singlePost = true;
|
||||
this.view.blockUser();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
|
||||
expect(app._changeLocation).toHaveBeenCalledWith(Routes.stream());
|
||||
});
|
||||
|
||||
it("shows a flash message when errors occur", function() {
|
||||
spyOn(app.flashMessages, "error");
|
||||
this.view.blockUser();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 422});
|
||||
expect(app.flashMessages.error).toHaveBeenCalledWith(Diaspora.I18n.t("ignore_failed"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("hidePost", function() {
|
||||
beforeEach(function() {
|
||||
spyOn(window, "confirm").and.returnValue(true);
|
||||
this.postView = {remove: function() { return; }};
|
||||
this.model = factory.post();
|
||||
this.view = new app.views.PostControls({model: this.model, post: this.postView});
|
||||
this.view.render();
|
||||
});
|
||||
|
||||
it("asks for a confirmation", function() {
|
||||
this.view.hidePost();
|
||||
expect(window.confirm).toHaveBeenCalledWith(Diaspora.I18n.t("confirm_dialog"));
|
||||
});
|
||||
|
||||
it("sends an ajax request with the correct post id", function() {
|
||||
this.view.hidePost();
|
||||
expect(jasmine.Ajax.requests.mostRecent().url).toBe(Routes.shareVisibility(42));
|
||||
expect(jasmine.Ajax.requests.mostRecent().data().post_id).toEqual(["" + this.model.get("id")]);
|
||||
expect(jasmine.Ajax.requests.mostRecent().method).toBe("PUT");
|
||||
});
|
||||
|
||||
it("removes the post on success", function() {
|
||||
spyOn(this.view.post, "remove");
|
||||
spyOn(app, "_changeLocation");
|
||||
this.view.hidePost();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
|
||||
expect(this.view.post.remove).toHaveBeenCalled();
|
||||
expect(app._changeLocation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("redirects to the stream page on success from the single post view", function() {
|
||||
spyOn(this.view.post, "remove");
|
||||
spyOn(app, "_changeLocation");
|
||||
this.view.singlePost = true;
|
||||
this.view.hidePost();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
|
||||
expect(this.view.post.remove).not.toHaveBeenCalled();
|
||||
expect(app._changeLocation).toHaveBeenCalledWith(Routes.stream());
|
||||
});
|
||||
|
||||
it("shows a flash message when errors occur", function() {
|
||||
spyOn(app.flashMessages, "error");
|
||||
this.view.hidePost();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 422});
|
||||
expect(app.flashMessages.error).toHaveBeenCalledWith(Diaspora.I18n.t("hide_post_failed"));
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue