103 lines
4.6 KiB
JavaScript
103 lines
4.6 KiB
JavaScript
describe("Diaspora.Mobile.Comments", function(){
|
|
describe("toggleComments", function() {
|
|
beforeEach(function() {
|
|
spec.loadFixture("aspects_index_mobile_post_with_comments");
|
|
this.link = $(".stream .show-comments").first();
|
|
spyOn(Diaspora.Mobile.Comments, "showComments");
|
|
spyOn(Diaspora.Mobile.Comments, "hideComments");
|
|
});
|
|
|
|
it("calls showComments", function() {
|
|
Diaspora.Mobile.Comments.toggleComments(this.link);
|
|
expect(Diaspora.Mobile.Comments.showComments).toHaveBeenCalled();
|
|
expect(Diaspora.Mobile.Comments.hideComments).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("calls hideComments if the link class is 'active'", function() {
|
|
this.link.addClass("active");
|
|
Diaspora.Mobile.Comments.toggleComments(this.link);
|
|
expect(Diaspora.Mobile.Comments.showComments).not.toHaveBeenCalled();
|
|
expect(Diaspora.Mobile.Comments.hideComments).toHaveBeenCalled();
|
|
});
|
|
|
|
it("doesn't call any function if the link class is 'loading'", function() {
|
|
this.link.addClass("loading");
|
|
Diaspora.Mobile.Comments.toggleComments(this.link);
|
|
expect(Diaspora.Mobile.Comments.showComments).not.toHaveBeenCalled();
|
|
expect(Diaspora.Mobile.Comments.hideComments).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("showUnloadedComments", function() {
|
|
beforeEach(function() {
|
|
spec.loadFixture("aspects_index_mobile_post_with_comments");
|
|
this.link = $(".stream .show-comments").first();
|
|
this.bottomBar = this.link.closest(".bottom-bar").first();
|
|
this.commentActionLink = this.bottomBar.find("a.comment-action");
|
|
});
|
|
|
|
it("adds the 'loading' class to the link", function() {
|
|
Diaspora.Mobile.Comments.showUnloadedComments(this.link, this.bottomBar, this.commentActionLink);
|
|
expect($(".show-comments").first()).toHaveClass("loading");
|
|
});
|
|
|
|
it("removes the 'loading' class if the request failed", function() {
|
|
Diaspora.Mobile.Comments.showUnloadedComments(this.link, this.bottomBar, this.commentActionLink);
|
|
jasmine.Ajax.requests.mostRecent().respondWith({status: 400});
|
|
expect($(".show-comments").first()).not.toHaveClass("loading");
|
|
});
|
|
|
|
it("adds the 'active' class if the request succeeded", function() {
|
|
Diaspora.Mobile.Comments.showUnloadedComments(this.link, this.bottomBar, this.commentActionLink);
|
|
jasmine.Ajax.requests.mostRecent().respondWith({status: 200, contentType: "text/plain", responseText: "test"});
|
|
expect($(".show-comments").first()).toHaveClass("active");
|
|
expect($(".show-comments").first()).not.toHaveClass("loading");
|
|
});
|
|
|
|
it("calls showCommentBox", function() {
|
|
spyOn(Diaspora.Mobile.Comments, "showCommentBox");
|
|
Diaspora.Mobile.Comments.showUnloadedComments(this.link, this.bottomBar, this.commentActionLink);
|
|
jasmine.Ajax.requests.mostRecent().respondWith({status: 200, contentType: "text/plain", responseText: "test"});
|
|
expect(Diaspora.Mobile.Comments.showCommentBox).toHaveBeenCalledWith(this.commentActionLink);
|
|
});
|
|
|
|
it("adds the response text to the comments list", function() {
|
|
Diaspora.Mobile.Comments.showUnloadedComments(this.link, this.bottomBar, this.commentActionLink);
|
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
status: 200,
|
|
contentType: "text/plain",
|
|
responseText: "<div class=\"commentContainerForTest\">new comments</div>"
|
|
});
|
|
expect($(".stream .stream_element").first()).toContainElement(".commentContainerForTest");
|
|
});
|
|
|
|
it("shows and hides the mobile spinner", function(){
|
|
Diaspora.Mobile.Comments.showComments(this.link);
|
|
expect($(".ajax-loader").first()).toBeVisible();
|
|
jasmine.Ajax.requests.mostRecent().respondWith({status: 200, contentType: "text/plain", responseText: "test"});
|
|
expect($(".ajax-loader").first()).not.toBeVisible();
|
|
});
|
|
});
|
|
|
|
describe("createComment", function () {
|
|
beforeEach(function() {
|
|
spec.loadFixture("aspects_index_mobile_post_with_comments");
|
|
var commentBoxHtml = spec.fixtureHtml("comments_mobile_commentbox");
|
|
var link = $(".stream .comment-action").first();
|
|
Diaspora.Mobile.Comments.showCommentBox(link);
|
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
status: 200,
|
|
contentType: "text/html",
|
|
responseText: commentBoxHtml
|
|
});
|
|
$(".stream .new_comment").submit(Diaspora.Mobile.Comments.submitComment);
|
|
});
|
|
|
|
it("doesn't submit an empty comment", function() {
|
|
var form = $(".stream .new_comment").first();
|
|
spyOn(jQuery, "ajax");
|
|
form.submit();
|
|
expect(jQuery.ajax).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|