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

router_spec.js « app « javascripts « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 14e6dd2df9be68532dd0369190afe35e6811b49e (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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
describe('app.Router', function () {
  describe('followed_tags', function() {
    beforeEach(function() {
      factory.preloads({tagFollowings: []});
      spec.loadFixture("aspects_index");
    });

    it('decodes name before passing it into TagFollowingAction', function () {
      var followed_tags = spyOn(app.router, 'followed_tags').and.callThrough();
      var tag_following_action = spyOn(app.views, 'TagFollowingAction').and.callFake(function() {
        return {render: function() { return {el: ""}}};
      });

      app.router.followed_tags(encodeURIComponent('օբյեկտիվ'));
      expect(followed_tags).toHaveBeenCalled();
      expect(tag_following_action).toHaveBeenCalledWith({tagText: 'օբյեկտիվ'});
    });

    it('navigates to the downcase version of the corresponding tag', function () {
      var followed_tags = spyOn(app.router, 'followed_tags').and.callThrough();
      var tag_following_action = spyOn(app.views, 'TagFollowingAction').and.callFake(function() {
        return {render: function() { return {el: ""}}};
      });

      app.router.followed_tags('SomethingWithCapitalLetters');
      expect(followed_tags).toHaveBeenCalled();
      expect(tag_following_action).toHaveBeenCalledWith({tagText: 'somethingwithcapitalletters'});
    });

    it("does not add the TagFollowingAction if not logged in", function() {
      var followedTags = spyOn(app.router, "followed_tags").and.callThrough();
      var tagFollowingAction = spyOn(app.views, "TagFollowingAction");
      logout();

      app.router.followed_tags("some_tag");
      expect(followedTags).toHaveBeenCalled();
      expect(tagFollowingAction).not.toHaveBeenCalled();
    });
  });

  describe("when routing to /stream and hiding inactive stream lists", function() {
    var router;
    var aspects;
    var tagFollowings;

    beforeEach(function() {
      router = new app.Router();
    });

    it('hides the aspects list', function(){
      setFixtures('<div id="aspects_list" />');
      aspects = new app.collections.AspectSelections([
        factory.aspectAttrs({selected:true}),
        factory.aspectAttrs()
      ]);
      var aspectsListView = new app.views.AspectsList({collection: aspects}).render();
      router.aspectsList = aspectsListView;

      expect(aspectsListView.$el.html()).not.toBe("");
      router.stream();
      expect(aspectsListView.$el.html()).toBe("");
    });

    it('hides the followed tags view', function(){
      tagFollowings = new app.collections.TagFollowings();
      var followedTagsView = new app.views.TagFollowingList({collection: tagFollowings}).render();
      router.followedTagsView = followedTagsView;

      expect(followedTagsView.$el.html()).not.toBe("");
      router.stream();
      expect(followedTagsView.$el.html()).toBe("");
    });
  });

  describe("aspects", function() {
    it("calls _initializeStreamView", function() {
      spyOn(app.router, "_initializeStreamView");
      app.router.aspects();
      expect(app.router._initializeStreamView).toHaveBeenCalled();
    });
  });

  describe("bookmarklet", function() {
    it('routes to bookmarklet even if params have linefeeds', function()  {
      var router = new app.Router();
      var route = jasmine.createSpy('bookmarklet route');
      router.on('route:bookmarklet', route);
      router.navigate("/bookmarklet?\n\nfeefwefwewef\n", {trigger: true});
      expect(route).toHaveBeenCalled();
    });
  });

  describe("conversations", function() {
    beforeEach(function() {
      this.router = new app.Router();
    });

    it("doesn't do anything if no conversation id is passed", function() {
      spyOn(app.views.ConversationsInbox.prototype, "renderConversation");
      this.router.conversations();
      expect(app.views.ConversationsInbox.prototype.renderConversation).not.toHaveBeenCalled();
    });

    it("doesn't do anything if id is not a readable number", function() {
      spyOn(app.views.ConversationsInbox.prototype, "renderConversation");
      this.router.conversations("yolo");
      expect(app.views.ConversationsInbox.prototype.renderConversation).not.toHaveBeenCalled();
    });

    it("renders the conversation if id is a readable number", function() {
      spyOn(app.views.ConversationsInbox.prototype, "renderConversation");
      this.router.conversations("12");
      expect(app.views.ConversationsInbox.prototype.renderConversation).toHaveBeenCalledWith("12");
    });

    it("passes conversation_id parameter to ConversationsInbox initializer when passed in URL", function() {
      app.conversations = undefined;
      spyOn(app.views.ConversationsInbox.prototype, "initialize");
      this.router.navigate("/conversations?conversation_id=45", {trigger: true});
      expect(app.views.ConversationsInbox.prototype.initialize).toHaveBeenCalledWith("45");
    });
  });

  describe("stream", function() {
    it("calls _initializeStreamView", function() {
      spyOn(app.router, "_initializeStreamView");
      app.router.stream();
      expect(app.router._initializeStreamView).toHaveBeenCalled();
    });
  });

  describe("gettingStarted", function() {
    beforeEach(function() {
      spec.content().append($("<div id='hello-there'>"));
    });

    it("renders app.pages.GettingStarted", function() {
      app.router.navigate("/getting_started", {trigger: true});
      expect(app.page.$el.is($("#hello-there"))).toBe(true);
    });

    it("renders app.pages.GettingStarted when the URL has a trailing slash", function() {
      app.router.navigate("/getting_started/", {trigger: true});
      expect(app.page.$el.is($("#hello-there"))).toBe(true);
    });
  });

  describe("_initializeStreamView", function() {
    beforeEach(function() {
      delete app.page;
      delete app.publisher;
      delete app.shortcuts;
      spec.loadFixture("aspects_index");
    });

    it("sets app.page", function() {
      expect(app.page).toBeUndefined();
      app.router._initializeStreamView();
      expect(app.page).toBeDefined();
    });

    it("sets app.publisher", function() {
      expect(app.publisher).toBeUndefined();
      app.router._initializeStreamView();
      expect(app.publisher).toBeDefined();
    });

    it("doesn't set app.publisher if already defined", function() {
      app.publisher = { jasmineTestValue: 42 };
      app.router._initializeStreamView();
      expect(app.publisher.jasmineTestValue).toEqual(42);
    });

    it("doesn't set app.publisher if there is no publisher element in page", function() {
      $("#publisher").remove();
      app.router._initializeStreamView();
      expect(app.publisher).toBeUndefined();
    });

    it("sets app.shortcuts", function() {
      expect(app.shortcuts).toBeUndefined();
      app.router._initializeStreamView();
      expect(app.shortcuts).toBeDefined();
    });

    it("doesn't set app.shortcuts if already defined", function() {
      app.shortcuts = { jasmineTestValue: 42 };
      app.router._initializeStreamView();
      expect(app.shortcuts.jasmineTestValue).toEqual(42);
    });

    it("unbinds inf scroll for old instances of app.page", function() {
      var pageSpy = jasmine.createSpyObj("page", ["remove", "unbindInfScroll"]);
      app.page = pageSpy;
      app.router._initializeStreamView();
      expect(pageSpy.unbindInfScroll).toHaveBeenCalled();
    });

    it("calls _hideInactiveStreamLists", function() {
      spyOn(app.router, "_hideInactiveStreamLists");
      app.router._initializeStreamView();
      expect(app.router._hideInactiveStreamLists).toHaveBeenCalled();
    });
  });
});