'use strict';

describe('search', function() {
  var createTokens = function() {
    return {
      '01' : {
        id: '01',
        string: 'Arma'
      },
      '02': {
        id: '02',
        string: 'virum'
      },
      '03': {
        id: '03',
        string: 'virum'
      }
    };
  };

  var mockConfigurator = {
    configurationFor: function(name) {
      return {};
    },

    getRetrievers: function(name) {
      return {};
    }
  };

  beforeEach(module('arethusa.core', function($provide) {
    $provide.value('configurator', mockConfigurator);
  }));

  beforeEach(module('arethusa.search'));

  var search;
  var state;
  beforeEach(inject(function(_search_, _state_) {
    search = _search_;
    state = _state_;
    state.tokens = createTokens();
    search.init();
  }));

  describe('this.findByRegex', function() {
    describe('finds tokens by a regex and returns their id in an array', function() {
      it('with simple regex', function() {
        var arg = 'um';
        expect(search.findByRegex(arg)).toEqual(['02', '03']);
      });
    });

    describe('with meta characters', function() {
      it('with .', function() {
        var arg = 'r.m';
        expect(search.findByRegex(arg)).toEqual(['02', '03']);
      });

      it('...', function() {
        // more tests to follow
      });
    });
  });

  describe('this.collectTokenStrings', function() {
    it('collects all strings of tokens as keys with their ids as values in an array', function() {
      var res = {'Arma': ['01'], 'virum': ['02', '03']};
      expect(search.collectTokenStrings()).toEqual(res);
    });
  });

  describe('this.pluginsWithSearch', function() {
    it('returns an array of plugins that have a search function', function() {
      var pluginA = { canSearch: true };
      var pluginB = { canSearch: false };
      var pluginC = { canSearch: true };
      var plugins = { "a": pluginA, "b": pluginB, "c": pluginC };
      expect(search.pluginsWithSearch(plugins)).toEqual([ pluginA, pluginC ]);
    });
  });
});

@@ -269,24 +269,88 @@
 ng: 'virum'%0A
+      %7D,%0A      '04': %7B%0A        id: '04',%0A        string: 'cano'%0A
       %7D%0A    
@@ -1397,32 +1397,761 @@
 %0A    %7D);%0A  %7D);%0A%0A
+  describe('this.queryTokens', function() %7B%0A    describe('returns a multiselection', function() %7B%0A      it('with one search lemma', function() %7B%0A        search.tokenQuery = 'virum';%0A        var res = state.multiSelect(%5B'02', '03'%5D);%0A        expect(search.queryTokens()).toEqual(res);%0A      %7D);%0A%0A      it('with two search lemmata', function() %7B%0A        search.tokenQuery = 'Arma virum';%0A        var res = state.multiSelect(%5B'01', '02', '03'%5D);%0A        expect(search.queryTokens()).toEqual(res);%0A      %7D);%0A%0A      it('with a lemma and a regex', function() %7B%0A        search.tokenQuery = 'Arma v.*m';%0A        var res = state.multiSelect(%5B'01', '02', '03'%5D);%0A        expect(search.queryTokens()).toEqual(res);%0A      %7D);%0A    %7D);%0A  %7D);%0A%0A
   describe('this
@@ -2339,16 +2339,32 @@
 ', '03'%5D
+, 'cano': %5B'04'%5D
 %7D;%0A     

Add specs for queryTokens()