var getDocFromAliasFactory = require('../../services/getDocFromAlias');
var aliasMapFactory = require('../../../base/services/aliasMap');
var mockLogFactory = require('dgeni/lib/mocks/log');
var getDocFromAlias, aliasMap, mockLog;

describe("getDocFromAlias", function() {
  beforeEach(function() {
    aliasMap = aliasMapFactory();
    mockLog = mockLogFactory();
    getDocFromAlias = getDocFromAliasFactory(aliasMap, mockLog);
  });

  it("should return an array of docs that match the alias", function() {
    var doc1 = { aliases: ['a','b','c'] };
    var doc2 = { aliases: ['a','b'] };
    var doc3 = { aliases: ['a'] };
    aliasMap.addDoc(doc1);
    aliasMap.addDoc(doc2);
    aliasMap.addDoc(doc3);

    expect(getDocFromAlias('a')).toEqual([doc1, doc2, doc3]);
    expect(getDocFromAlias('b')).toEqual([doc1, doc2]);
    expect(getDocFromAlias('c')).toEqual([doc1]);
  });

  it("should return docs that match the alias and originating doc's area", function() {
    var doc1 = { aliases: ['a'], area: 'api'};
    var doc2 = { aliases: ['a'], area: 'api'};
    var doc3 = { aliases: ['a'], area: 'other'};
    aliasMap.addDoc(doc1);
    aliasMap.addDoc(doc2);
    aliasMap.addDoc(doc3);

    expect(getDocFromAlias('a', {area: 'api'})).toEqual([doc1, doc2]);
  });

  it("should return docs that match the alias and originating doc's area and module", function() {
    var doc1 = { aliases: ['a'], area: 'api', module: 'ng'};
    var doc2 = { aliases: ['a'], area: 'api', module: 'ngMock'};
    var doc3 = { aliases: ['a'], area: 'other', module: 'ng'};
    aliasMap.addDoc(doc1);
    aliasMap.addDoc(doc2);
    aliasMap.addDoc(doc3);

    expect(getDocFromAlias('a', {area: 'api', module:'ng'})).toEqual([doc1]);
  });
});
var mockPackage = require('dgeni-packages/ngdoc/spec/mockPackage');
var Dgeni = require('dgeni');

var getDocFromAlias, aliasMap;

describe("getDocFromAlias", function() {
  beforeEach(function() {
    var dgeni = new Dgeni([mockPackage()]);
    var injector = dgeni.configureInjector();
    aliasMap = injector.get('aliasMap');
    getDocFromAlias = injector.get('getDocFromAlias');
  });

  it("should return an array of docs that match the alias", function() {
    var doc1 = { aliases: ['a','b','c'] };
    var doc2 = { aliases: ['a','b'] };
    var doc3 = { aliases: ['a'] };
    aliasMap.addDoc(doc1);
    aliasMap.addDoc(doc2);
    aliasMap.addDoc(doc3);

    expect(getDocFromAlias('a')).toEqual([doc1, doc2, doc3]);
    expect(getDocFromAlias('b')).toEqual([doc1, doc2]);
    expect(getDocFromAlias('c')).toEqual([doc1]);
  });

  it("should return docs that match the alias and originating doc's area", function() {
    var doc1 = { aliases: ['a'], area: 'api'};
    var doc2 = { aliases: ['a'], area: 'api'};
    var doc3 = { aliases: ['a'], area: 'other'};
    aliasMap.addDoc(doc1);
    aliasMap.addDoc(doc2);
    aliasMap.addDoc(doc3);

    expect(getDocFromAlias('a', {area: 'api'})).toEqual([doc1, doc2]);
  });

  it("should return docs that match the alias and originating doc's area and module", function() {
    var doc1 = { aliases: ['a'], area: 'api', module: 'ng'};
    var doc2 = { aliases: ['a'], area: 'api', module: 'ngMock'};
    var doc3 = { aliases: ['a'], area: 'other', module: 'ng'};
    aliasMap.addDoc(doc1);
    aliasMap.addDoc(doc2);
    aliasMap.addDoc(doc3);

    expect(getDocFromAlias('a', {area: 'api', module:'ng'})).toEqual([doc1]);
  });
});
test with mockPackage