"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

function _chai() {
  const data = require("chai");

  _chai = function () {
    return data;
  };

  return data;
}

function _sinon() {
  const data = _interopRequireDefault(require("sinon"));

  _sinon = function () {
    return data;
  };

  return data;
}

function _consumer() {
  const data = _interopRequireDefault(require("../consumer/consumer"));

  _consumer = function () {
    return data;
  };

  return data;
}

function _exceptions() {
  const data = require("./bit-map/exceptions");

  _exceptions = function () {
    return data;
  };

  return data;
}

describe('Consumer', function () {
  this.timeout(0);
  let sandbox;

  const getConsumerInstance = () => {
    sandbox.stub(_consumer().default.prototype, 'warnForMissingDriver').returns();
    const consumer = new (_consumer().default)({
      projectPath: '',
      config: {}
    });
    return consumer;
  };

  describe('getComponentIdFromNodeModulesPath', () => {
    let consumer;
    before(() => {
      sandbox = _sinon().default.createSandbox();
      consumer = getConsumerInstance(sandbox);
    });
    after(() => {
      sandbox.restore();
    });
    it('should parse the path correctly when a component is not in bitMap and has one dot', () => {
      const result = consumer.getComponentIdFromNodeModulesPath('../../../node_modules/@bit/q207wrk9-remote.comp/file2.js', '@bit');
      (0, _chai().expect)(result.scope).to.equal('q207wrk9-remote');
      (0, _chai().expect)(result.name).to.equal('comp');
    });
    it('should parse the path correctly when a component is not in bitMap and has two dots', () => {
      const result = consumer.getComponentIdFromNodeModulesPath('../../../node_modules/@bit/q207wrk9-remote.comp.comp2/file2.js', '@bit');
      (0, _chai().expect)(result.scope).to.equal('q207wrk9-remote.comp');
      (0, _chai().expect)(result.name).to.equal('comp2');
    });
    it('should parse the path correctly when a component is not in bitMap and has three dots', () => {
      const result = consumer.getComponentIdFromNodeModulesPath('../../../node_modules/@bit/q207wrk9-remote.comp.comp2.comp3/file2.js', '@bit');
      (0, _chai().expect)(result.scope).to.equal('q207wrk9-remote.comp');
      (0, _chai().expect)(result.name).to.equal('comp2/comp3');
    });
  });
  describe('getParsedId', () => {
    let consumer;
    before(() => {
      sandbox = _sinon().default.createSandbox();
      consumer = getConsumerInstance(sandbox);
    });
    after(() => {
      sandbox.restore();
    });
    it('should throw an error for a missing component', () => {
      const func = () => consumer.getParsedId('non-exist-comp');

      (0, _chai().expect)(func).to.throw(_exceptions().MissingBitMapComponent);
    });
  });
  describe('getParsedIdIfExist', () => {
    let consumer;
    before(() => {
      sandbox = _sinon().default.createSandbox();
      consumer = getConsumerInstance(sandbox);
    });
    after(() => {
      sandbox.restore();
    });
    it('should throw an error for a missing component', () => {
      const func = () => consumer.getParsedIdIfExist('non-exist-comp');

      (0, _chai().expect)(func).to.not.throw(_exceptions().MissingBitMapComponent);
    });
  });
});