aboutsummaryrefslogtreecommitdiffstats
path: root/docs/component-spec/docsSearchSpec.js
blob: 38e6937a9ce88bc9ac0dfb0204682e6c63cc17cc (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
describe("docsSearch", function() {

  beforeEach(module('docsApp'));

  var interceptedLunrResults;
  beforeEach(function() {
    interceptedLunrResults = [];
  });

  beforeEach(function() {
    module(function($provide) {
      var results = [];
      results[0] = { section: 'tutorial', shortName: 'item one', keywords: 'item, one, 1' };
      results[1] = { section: 'tutorial', shortName: 'item man', keywords: 'item, man' };
      results[2] = { section: 'api', shortName: 'item other', keywords: 'item, other' };
      results[3] = { section: 'cookbook', shortName: 'item cookbook', keywords: 'item, other' };
      results[4] = { section: 'api', shortName: 'ngRepeat', keywords: 'item, other' };

      $provide.value('NG_PAGES', results);
      $provide.factory('lunrSearch', function() {
        return function() {
          return {
            store : function(value) {
              interceptedLunrResults.push(value);
            },
            search : function(q) {
              var data = [];
              angular.forEach(results, function(res, i) {
                data.push({ ref : i });
              });
              return data;
            }
          } 
        };
      });
    });
  });

  it("should lookup and organize values properly", inject(function(docsSearch) {
    var items = docsSearch('item');
    expect(items['api'].length).toBe(2);
  }));

  it("should place cookbook items in the tutorial", inject(function(docsSearch) {
    var items = docsSearch('item');
    expect(items['tutorial'].length).toBe(3);
  }));

  it("should return all results without a search", inject(function(docsSearch) {
    var items = docsSearch();
    expect(items['tutorial'].length).toBe(3);
    expect(items['api'].length).toBe(2);
  }));

  it("should store values with and without a ng prefix", inject(function(docsSearch) {
    expect(interceptedLunrResults[4].title).toBe('ngRepeat repeat');
  }));

});