'use strict';

var _path;

function _load_path() {
  return _path = _interopRequireDefault(require('path'));
}

var _chai;

function _load_chai() {
  return _chai = require('chai');
}

var _bitMap;

function _load_bitMap() {
  return _bitMap = _interopRequireDefault(require('./bit-map'));
}

var _bitId;

function _load_bitId() {
  return _bitId = require('../../bit-id');
}

var _constants;

function _load_constants() {
  return _constants = require('../../constants');
}

var _logger;

function _load_logger() {
  return _logger = _interopRequireDefault(require('../../logger/logger'));
}

var _configDir;

function _load_configDir() {
  return _configDir = _interopRequireDefault(require('./config-dir'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var bitMapFixtureDir = (_path || _load_path()).default.join(__dirname, '../../../fixtures/bitmap-fixtures');

var addComponentParamsFixture = {
  componentId: new (_bitId || _load_bitId()).BitId({ name: 'is-string' }),
  files: [{ name: 'is-string.js', relativePath: 'is-string.js', test: false }],
  mainFile: 'is-string.js',
  origin: (_constants || _load_constants()).COMPONENT_ORIGINS.AUTHORED
};

var addComponentParamsImportedFixture = {
  componentId: new (_bitId || _load_bitId()).BitId({ scope: 'my-scope', name: 'is-string-imported', version: '0.0.1' }),
  files: [{ name: 'is-string-imported.js', relativePath: 'is-string-imported.js', test: false }],
  mainFile: 'is-string-imported.js',
  origin: (_constants || _load_constants()).COMPONENT_ORIGINS.IMPORTED,
  rootDir: 'utils'
};

describe('BitMap', function () {
  (_logger || _load_logger()).default.debug = function () {};
  (_logger || _load_logger()).default.info = function () {};
  describe('toObject', function () {
    var bitMap = void 0;
    var componentMap = void 0;
    before(function () {
      bitMap = (_bitMap || _load_bitMap()).default.load(__dirname);
      bitMap.addComponent(addComponentParamsFixture);
      var allComponents = bitMap.toObjects();
      componentMap = allComponents['is-string'];
    });
    it('should remove the "id" property', function () {
      (0, (_chai || _load_chai()).expect)(componentMap).to.not.have.property('id');
    });
    it('should add "exported" property to authored components', function () {
      (0, (_chai || _load_chai()).expect)(componentMap).to.have.property('exported');
      (0, (_chai || _load_chai()).expect)(componentMap.exported).to.be.false;
    });
    it('should not add "exported" property to imported components', function () {
      bitMap.addComponent(addComponentParamsImportedFixture);
      var allComponents = bitMap.toObjects();
      var componentMapImported = allComponents['my-scope/is-string-imported@0.0.1'];
      (0, (_chai || _load_chai()).expect)(componentMapImported).to.not.have.property('exported');
    });
  });
  describe('getAuthoredExportedComponents', function () {
    it('should return an empty array when there are no authored components', function () {
      var bitMap = (_bitMap || _load_bitMap()).default.load((_path || _load_path()).default.join(bitMapFixtureDir, 'only-imported'));
      var results = bitMap.getAuthoredExportedComponents();
      (0, (_chai || _load_chai()).expect)(results).to.be.an('array');
      (0, (_chai || _load_chai()).expect)(results).to.have.lengthOf(0);
    });
  });
  describe('resolveIgnoreFilesAndDirs', function () {
    it('should ignore whole folder if the config dir is not in component dir', function () {
      var res = (_bitMap || _load_bitMap()).default.resolveIgnoreFilesAndDirs('conf-dir', 'my-comp-dir', ['./.babelrc'], ['./mochaConf.js']);
      (0, (_chai || _load_chai()).expect)(res.dirs).to.contain('conf-dir');
    });
    it('should ignore nothing if there is no config dir', function () {
      var res = (_bitMap || _load_bitMap()).default.resolveIgnoreFilesAndDirs(null, 'my-comp-dir', ['./.babelrc'], ['./mochaConf.js']);
      (0, (_chai || _load_chai()).expect)(res.dirs).to.be.empty;
      (0, (_chai || _load_chai()).expect)(res.files).to.be.empty;
    });
    it('should ignore nested dir inside the component dir', function () {
      var res = (_bitMap || _load_bitMap()).default.resolveIgnoreFilesAndDirs('{COMPONENT_DIR}/nested-dir/{ENV_TYPE}', 'my-comp-dir', ['./compiler/.babelrc'], ['./tester/mochaConf.js']);
      (0, (_chai || _load_chai()).expect)(res.dirs).to.contain('my-comp-dir/nested-dir');
    });
    it('should ignore env types folders if {ENV_TYPE} exists', function () {
      var res = (_bitMap || _load_bitMap()).default.resolveIgnoreFilesAndDirs('{COMPONENT_DIR}/{ENV_TYPE}', 'my-comp-dir', ['./compiler/.babelrc'], ['./tester/mochaConf.js']);
      (0, (_chai || _load_chai()).expect)(res.dirs).to.contain('my-comp-dir/compiler');
      (0, (_chai || _load_chai()).expect)(res.dirs).to.contain('my-comp-dir/tester');
    });
    it('should ignore all compiler and tester files when {ENV_TYPE} exists', function () {
      var res = (_bitMap || _load_bitMap()).default.resolveIgnoreFilesAndDirs('{COMPONENT_DIR}/{ENV_TYPE}', 'my-comp-dir', ['./compiler/.babelrc'], ['./tester/mochaConf.js']);
      (0, (_chai || _load_chai()).expect)(res.files).to.contain('my-comp-dir/compiler/.babelrc');
      (0, (_chai || _load_chai()).expect)(res.files).to.contain('my-comp-dir/tester/mochaConf.js');
    });
    it('should ignore all compiler and tester files when {ENV_TYPE} not exists', function () {
      var res = (_bitMap || _load_bitMap()).default.resolveIgnoreFilesAndDirs('{COMPONENT_DIR}', 'my-comp-dir', ['./.babelrc'], ['./mochaConf.js']);
      (0, (_chai || _load_chai()).expect)(res.files).to.contain('my-comp-dir/.babelrc');
      (0, (_chai || _load_chai()).expect)(res.files).to.contain('my-comp-dir/mochaConf.js');
    });
  });
  describe('parseConfigDir', function () {
    it('without any place holder', function () {
      var results = (_bitMap || _load_bitMap()).default.parseConfigDir(new (_configDir || _load_configDir()).default('config-dir'), 'root-dir');
      (0, (_chai || _load_chai()).expect)(results.compiler).to.equal('config-dir');
      (0, (_chai || _load_chai()).expect)(results.tester).to.equal('config-dir');
    });
    it('with {COMPONENT_DIR}', function () {
      var results = (_bitMap || _load_bitMap()).default.parseConfigDir(new (_configDir || _load_configDir()).default('{COMPONENT_DIR}'), 'root-dir');
      (0, (_chai || _load_chai()).expect)(results.compiler).to.equal('root-dir');
      (0, (_chai || _load_chai()).expect)(results.tester).to.equal('root-dir');
    });
    it('with {COMPONENT_DIR}/{ENV_TYPE}', function () {
      var results = (_bitMap || _load_bitMap()).default.parseConfigDir(new (_configDir || _load_configDir()).default('{COMPONENT_DIR}/{ENV_TYPE}'), 'root-dir');
      (0, (_chai || _load_chai()).expect)(results.compiler).to.equal('root-dir/compiler');
      (0, (_chai || _load_chai()).expect)(results.tester).to.equal('root-dir/tester');
    });
    it('with dir/{ENV_TYPE}', function () {
      var results = (_bitMap || _load_bitMap()).default.parseConfigDir(new (_configDir || _load_configDir()).default('dir/{ENV_TYPE}'), 'root-dir');
      (0, (_chai || _load_chai()).expect)(results.compiler).to.equal('dir/compiler');
      (0, (_chai || _load_chai()).expect)(results.tester).to.equal('dir/tester');
    });
  });
});