summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/tags/data/tags.spec.js
blob: 8e7d33c3e4a4be9ced418025278643faa8026344 (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
describeComponent('tags/data/tags', function () {
  'use strict';

  beforeEach(function () {
    setupComponent();
  });

  it('asks the server for tags when receiving the tags:want event', function() {
    spyOn($, 'ajax').andReturn({done: function() {}});

    this.component.trigger(Smail.events.tags.want);

    expect($.ajax.mostRecentCall.args[0]).toEqual('/tags');
  });

  it('triggers an event on the initial sender after receiving tags', function() {
    var f;
    spyOn($, 'ajax').andReturn({done: function(d) { f = d; }});
    var me = {};
    var eventSpy = spyOnEvent(me, Smail.events.tags.received);

    this.component.trigger(Smail.events.tags.want, { caller: me});

    f(['foo', 'bar', 'quux/bar']);
    expect(eventSpy).toHaveBeenTriggeredOn(me);
  });

  it('triggers an event containing the returned tags', function() {
    var f;
    spyOn($, 'ajax').andReturn({done: function(d) { f = d; }});
    var me = {};
    var eventSpy = spyOnEvent(me, Smail.events.tags.received);
    this.component.trigger(Smail.events.tags.want, { caller: me });
    var tags = ['foo', 'bar', 'quux/bar'];
    f(tags);
    tags.push(this.component.all);
    expect(eventSpy.mostRecentCall.data).toEqual({tags: tags});
  });
});