summaryrefslogtreecommitdiff
path: root/web-ui/test/spec/search/search_trigger.spec.js
blob: 6ba47489168804da8857b46c584690bafc7b6184 (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
describeComponent('search/search_trigger', function () {
  'use strict';
  var self;

  beforeEach(function () {
    this.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 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('');
  });


});