summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/search/search_trigger.spec.js
blob: c547df7a89bde430756f4e4793418b921483caad (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
/*global jasmine */
/*global Pixelated */

describeComponent('search/search_trigger', function () {
  'use strict';
  var self;

  beforeEach(function () {
    setupComponent();
    self = this;
  });

  function submitSearch(queryString) {
    self.component.select('input').val(queryString);
    self.component.select('form').submit();
  }

  it('should trigger search when the submit occurs', function () {
    var spy = spyOnEvent(document, Pixelated.events.search.perform);

    submitSearch('tanana');
    expect(spy).toHaveBeenTriggeredOnAndWith(document, { query: 'tanana' });
  });

  it('should select the "all" tag when submit occurs but should skip mail list refresh', function  (){
    var tagSelectEvent = spyOnEvent(document, Pixelated.events.ui.tag.select);

    submitSearch('tanana');

    expect(tagSelectEvent).toHaveBeenTriggeredOnAndWith(document, {
      tag: 'all',
      skipMailListRefresh: true
    });
  });

  it('should select the "all" tag when an empty submit occurs and shoud refresh mail list', function() {
    var tagSelectEvent = spyOnEvent(document, Pixelated.events.ui.tag.select);
    var emptySearchEvent = spyOnEvent(document, Pixelated.events.search.empty);

    submitSearch('');

    expect(emptySearchEvent).toHaveBeenTriggeredOn(document);
    expect(tagSelectEvent).toHaveBeenTriggeredOnAndWith(document, { tag: 'all'});

  });

  it('should clear input when selecting a new tag', function(){
    submitSearch('tanana');
    $(document).trigger(Pixelated.events.ui.tag.selected, { tag: 'inbox'});
    expect(self.component.select('input').val()).toBe('');
  });

  it('should add place holder on input value after doing a search', function(){
    submitSearch('teste');
    expect(self.component.select('input').val()).toBe('Search results for: teste');
  });

  it('should remove place holder on input value when input is on focus', function(){
    submitSearch('teste');
    this.component.select('input').focus();
    expect(self.component.select('input').val()).toBe('teste');
  });

  it('should remove place holder on input value when input is not on focus', function(){
    submitSearch('teste');
    this.component.select('input').focus();
    this.component.select('input').blur();
    expect(self.component.select('input').val()).toBe('Search results for: teste');
  });

  it('should not change input value when input is empty', function(){
    submitSearch('');
    this.component.select('input').focus();
    expect(self.component.select('input').val()).toBe('');
  });


});