Welcome to mirror list, hosted at ThFree Co, Russian Federation.

stream_post_spec.js « views « app « javascripts « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2aa9f41fc36655e7a91af85473d39f3d9d357e00 (plain)
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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
describe("app.views.StreamPost", function(){
  beforeEach(function(){
    // This puts `app.page` into the proper state.
    delete app.page;
    new app.Router().stream();

    this.PostViewClass = app.views.StreamPost;

    var posts = $.parseJSON(spec.readFixture("stream_json"));
    this.collection = new app.collections.Posts(posts);
    this.statusMessage = this.collection.models[0];
    this.reshare = this.collection.models[1];
    app.stream = new app.models.Stream();
  });

  describe("events", function(){
    var _PostViewClass,
        authorId;

    beforeEach(function(){
      _PostViewClass = this.PostViewClass;
      authorId = this.statusMessage.get('author').id;
    });

    describe("remove posts for blocked person", function(){
      it("setup remove:author:posts:#{id} to #remove", function(){
        spyOn(_PostViewClass.prototype, 'remove');
        new _PostViewClass({model : this.statusMessage});
        app.events.trigger('person:block:'+authorId);
        expect(_PostViewClass.prototype.remove).toHaveBeenCalled();
      });
    });
  });

  describe("#render", function(){
    var o_embed_cache = {
      "data" : {
        "html" : "some html"
      }
    };

    var open_graph_cache = {
      "url": "http://example.com/articles/123",
      "title": "Example title",
      "description": "Test description",
      "image": "http://example.com/thumb.jpg",
      "ob_type": "article"
    };

    var open_graph_cache_extralong = {
      "url": "http://example.com/articles/123",
      "title": "Example title",
      "description": Array(62).join("Test description"), // 992 chars
      "image": "http://example.com/thumb.jpg",
      "ob_type": "article"
    };

    beforeEach(function(){
      loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
    });

    context("reshares", function(){
      it("displays a reshare count", function(){
        this.statusMessage.interactions.set({"reshares_count": 2});
        var view = new this.PostViewClass({model : this.statusMessage}).render();
        expect($(view.el).html()).toContain(Diaspora.I18n.t('stream.reshares', {count: 2}));
      });

      it("does not display a reshare count for 'zero'", function(){
        this.statusMessage.interactions.set({"reshares_count": 0});
        var view = new this.PostViewClass({model : this.statusMessage}).render();
        expect($(view.el).html()).not.toContain("0 Reshares");
      });
    });

    context("likes", function(){
      it("displays a like count", function(){
        this.statusMessage.interactions.set({likes_count : 1});
        var view = new this.PostViewClass({model : this.statusMessage}).render();
        expect($(view.el).html()).toContain(Diaspora.I18n.t('stream.likes', {count: 1}));
      });

      it("does not display a like count for 'zero'", function(){
        this.statusMessage.interactions.set({likes_count : 0});
        var view = new this.PostViewClass({model : this.statusMessage}).render();
        expect($(view.el).html()).not.toContain("0 Likes");
      });
    });

    context("embed_html", function(){
      it("provides oembed html from the model response", function(){
        this.statusMessage.set({"o_embed_cache" : o_embed_cache});

        var view = new app.views.StreamPost({model : this.statusMessage}).render();
        expect(view.$el.html()).toContain(o_embed_cache.data.html);
      });
    });

    context("og_html", function(){
      it("provides opengraph preview based on the model reponse", function(){
        this.statusMessage.set({"open_graph_cache" : open_graph_cache});

        var view = new app.views.StreamPost({model : this.statusMessage}).render();
        expect(view.$el.html()).toContain(open_graph_cache.title);
      });
      it("does not provide opengraph preview, when oembed is available", function(){
        this.statusMessage.set({
          "o_embed_cache" : o_embed_cache,
          "open_graph_cache" : open_graph_cache
        });

        var view = new app.views.StreamPost({model : this.statusMessage}).render();
        expect(view.$el.html()).not.toContain(open_graph_cache.title);
      });
      it("truncates long opengraph descriptions in stream view to be 250 chars or less", function() {
        this.statusMessage.set({"open_graph_cache" : open_graph_cache_extralong});

        var view = new app.views.StreamPost({model : this.statusMessage}).render();
        expect(view.$el.find('.og-description').html().length).toBeLessThan(251);
      });
    });

    context("user not signed in", function(){
      it("does not provide a Feedback view", function(){
        logout();
        var view = new this.PostViewClass({model : this.statusMessage}).render();
        expect(view.feedbackView()).toBeFalsy();
      });
    });

    context("NSFW", function(){
      beforeEach(function(){
        this.statusMessage.set({nsfw: true});
        this.view = new this.PostViewClass({model : this.statusMessage}).render();

        this.hiddenPosts = function(){
          return this.view.$(".media.shield-active .nsfw-shield");
        };
      });

      it("contains a shield element", function(){
        expect(this.hiddenPosts().length).toBe(1);
      });

      it("does not contain a shield element when nsfw is false", function(){
        this.statusMessage.set({nsfw: false});
        this.view.render();
        expect(this.hiddenPosts()).not.toExist();
      });

      context("showing a single post", function(){
        it("removes the shields when the post is clicked", function(){
          expect(this.hiddenPosts()).toExist();
          this.view.$(".nsfw-shield .show_nsfw_post").click();
          expect(this.hiddenPosts()).not.toExist();
        });
      });

      context("clicking the toggle nsfw link toggles it on the user", function(){
        it("calls toggleNsfw on the user", function(){
          spyOn(app.user(), "toggleNsfwState");
          this.view.$(".toggle_nsfw_state").first().click();
          expect(app.user().toggleNsfwState).toHaveBeenCalled();
        });
      });
    });

    context("user views their own post", function(){
      beforeEach(function(){
        this.statusMessage.set({ author: {
          id : app.user().id
        }});
        this.view = new this.PostViewClass({model : this.statusMessage}).render();
      });

      it("contains remove post", function(){
        expect(this.view.$(".remove_post")).toExist();
      });

      it("destroys the view when they delete a their post from the show page", function(){
        spyOn(window, "confirm").and.returnValue(true);

        this.view.$(".remove_post").click();

        expect(window.confirm).toHaveBeenCalled();
        expect(this.view.el).not.toBeInDOM();
      });
    });

  });
});