'use strict';

var _chai;

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

var _sinon;

function _load_sinon() {
  return _sinon = _interopRequireDefault(require('sinon'));
}

var _consumer;

function _load_consumer() {
  return _consumer = _interopRequireDefault(require('../../src/consumer/consumer'));
}

var _exceptions;

function _load_exceptions() {
  return _exceptions = require('./bit-map/exceptions');
}

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

describe('Consumer', function () {
  var sandbox = void 0;
  var getConsumerInstance = function getConsumerInstance() {
    sandbox.stub((_consumer || _load_consumer()).default.prototype, 'warnForMissingDriver').returns();
    var consumer = new (_consumer || _load_consumer()).default({ projectPath: '', bitJson: {} });
    return consumer;
  };
  describe('getComponentIdFromNodeModulesPath', function () {
    var consumer = void 0;
    before(function () {
      sandbox = (_sinon || _load_sinon()).default.createSandbox();
      consumer = getConsumerInstance(sandbox);
    });
    after(function () {
      sandbox.restore();
    });
    it('should parse the path correctly when a component is not in bitMap and has one dot', function () {
      var result = consumer.getComponentIdFromNodeModulesPath('../../../node_modules/@bit/q207wrk9-remote.comp/file2.js', '@bit');
      (0, (_chai || _load_chai()).expect)(result.scope).to.equal('q207wrk9-remote');
      (0, (_chai || _load_chai()).expect)(result.name).to.equal('comp');
    });
    it('should parse the path correctly when a component is not in bitMap and has two dots', function () {
      var result = consumer.getComponentIdFromNodeModulesPath('../../../node_modules/@bit/q207wrk9-remote.comp.comp2/file2.js', '@bit');
      (0, (_chai || _load_chai()).expect)(result.scope).to.equal('q207wrk9-remote.comp');
      (0, (_chai || _load_chai()).expect)(result.name).to.equal('comp2');
    });
    it('should parse the path correctly when a component is not in bitMap and has three dots', function () {
      var result = consumer.getComponentIdFromNodeModulesPath('../../../node_modules/@bit/q207wrk9-remote.comp.comp2.comp3/file2.js', '@bit');
      (0, (_chai || _load_chai()).expect)(result.scope).to.equal('q207wrk9-remote.comp');
      (0, (_chai || _load_chai()).expect)(result.name).to.equal('comp2/comp3');
    });
  });
  describe('getParsedId', function () {
    var consumer = void 0;
    before(function () {
      sandbox = (_sinon || _load_sinon()).default.createSandbox();
      consumer = getConsumerInstance(sandbox);
    });
    after(function () {
      sandbox.restore();
    });
    it('should throw an error for a missing component', function () {
      var func = function func() {
        return consumer.getParsedId('non-exist-comp');
      };
      (0, (_chai || _load_chai()).expect)(func).to.throw((_exceptions || _load_exceptions()).MissingBitMapComponent);
    });
  });
  describe('getParsedIdIfExist', function () {
    var consumer = void 0;
    before(function () {
      sandbox = (_sinon || _load_sinon()).default.createSandbox();
      consumer = getConsumerInstance(sandbox);
    });
    after(function () {
      sandbox.restore();
    });
    it('should throw an error for a missing component', function () {
      var func = function func() {
        return consumer.getParsedIdIfExist('non-exist-comp');
      };
      (0, (_chai || _load_chai()).expect)(func).to.not.throw((_exceptions || _load_exceptions()).MissingBitMapComponent);
    });
  });
});