Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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");
});
});
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
describe("showCommentBox", function() {
beforeEach(function() {
spec.loadFixture("aspects_index_mobile_post_with_comments");
this.link = $(".stream .comment-action").first();
});
it("adds the 'loading' class to the link", function() {
Diaspora.Mobile.Comments.showCommentBox(this.link);
expect($(".comment-action").first()).toHaveClass("loading");
});
it("removes the 'loading' class if the request failed", function() {
Diaspora.Mobile.Comments.showCommentBox(this.link);
jasmine.Ajax.requests.mostRecent().respondWith({status: 400});
expect($(".comment-action").first()).not.toHaveClass("loading");
});
it("fires an AJAX call", function() {
spyOn(jQuery, "ajax");
Diaspora.Mobile.Comments.showCommentBox(this.link);
expect(jQuery.ajax).toHaveBeenCalled();
});
it("calls appendCommentBox", function() {
spyOn(Diaspora.Mobile.Comments, "appendCommentBox");
Diaspora.Mobile.Comments.showCommentBox(this.link);
jasmine.Ajax.requests.mostRecent().respondWith({status: 200, contentType: "text/plain", responseText: "test"});
expect(Diaspora.Mobile.Comments.appendCommentBox).toHaveBeenCalledWith(this.link, "test");
});
it("doesn't do anything if the link class is 'loading'", function() {
spyOn(jQuery, "ajax");
this.link.addClass("loading");
Diaspora.Mobile.Comments.showCommentBox(this.link);
expect(jQuery.ajax).not.toHaveBeenCalled();
});
it("doesn't do anything if the link class is not 'inactive'", function() {
spyOn(jQuery, "ajax");
this.link.removeClass("inactive");
Diaspora.Mobile.Comments.showCommentBox(this.link);
expect(jQuery.ajax).not.toHaveBeenCalled();
});
});