'use strict';

var _regenerator;

function _load_regenerator() {
  return _regenerator = _interopRequireDefault(require('babel-runtime/regenerator'));
}

var _bluebird;

function _load_bluebird() {
  return _bluebird = require('bluebird');
}

var _chai;

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

var _withCompiler;

function _load_withCompiler() {
  return _withCompiler = _interopRequireDefault(require('../../../fixtures/consumer-components/with-compiler/with-compiler.json'));
}

var _consumerComponent;

function _load_consumerComponent() {
  return _consumerComponent = _interopRequireDefault(require('./consumer-component'));
}

var _compilerExtension;

function _load_compilerExtension() {
  return _compilerExtension = _interopRequireDefault(require('../../extensions/compiler-extension'));
}

var _sources;

function _load_sources() {
  return _sources = require('./sources');
}

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

describe('ConsumerComponent', function () {
  var _this = this;

  this.timeout(0);
  describe('fromString()', function () {
    describe('component with compiler', function () {
      var component = void 0;
      before((0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee() {
        return (_regenerator || _load_regenerator()).default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return (_consumerComponent || _load_consumerComponent()).default.fromString(JSON.stringify((_withCompiler || _load_withCompiler()).default));

              case 2:
                component = _context.sent;

              case 3:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, _this);
      })));
      it('should not crash and return a ConsumerComponent Object', (0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee2() {
        return (_regenerator || _load_regenerator()).default.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                (0, (_chai || _load_chai()).expect)(component).to.be.instanceOf((_consumerComponent || _load_consumerComponent()).default);

              case 1:
              case 'end':
                return _context2.stop();
            }
          }
        }, _callee2, _this);
      })));
      it('should convert the compiler object to a Compiler instance', function () {
        (0, (_chai || _load_chai()).expect)(component.compiler).to.be.instanceOf((_compilerExtension || _load_compilerExtension()).default);
      });
    });
  });
  describe('docs', function () {
    var componentProps = {
      name: 'is-string',
      mainFile: 'is-string.js',
      files: [new (_sources || _load_sources()).SourceFile({ base: '.', path: 'is-string.js', contents: Buffer.from(''), test: false })]
    };
    it('should return an empty array when there is no docs', function () {
      var component = new (_consumerComponent || _load_consumerComponent()).default(componentProps);
      (0, (_chai || _load_chai()).expect)(component.docs).to.deep.equal([]);
    });
    it('should return the docs when a file has a jsdoc block', (0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee3() {
      var src, sourceFile, component;
      return (_regenerator || _load_regenerator()).default.wrap(function _callee3$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              src = `/**
      * is a given variable a string
      */
      function isString() {}`;
              sourceFile = new (_sources || _load_sources()).SourceFile({ base: '.', path: 'is-string.js', contents: Buffer.from(src), test: false });

              componentProps.files = [sourceFile];
              component = new (_consumerComponent || _load_consumerComponent()).default(componentProps);

              (0, (_chai || _load_chai()).expect)(component.docs).to.have.lengthOf(1);
              (0, (_chai || _load_chai()).expect)(component.docs[0].description).to.equal('is a given variable a string');

            case 6:
            case 'end':
              return _context3.stop();
          }
        }
      }, _callee3, _this);
    })));
    it('should return the docs only for non-test files with jsdocs', (0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee4() {
      var src, sourceFile, sourceFileSpec, component;
      return (_regenerator || _load_regenerator()).default.wrap(function _callee4$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              src = `/**
      * is a given variable a string
      */
      function isString() {}`;
              sourceFile = new (_sources || _load_sources()).SourceFile({ base: '.', path: 'is-string.js', contents: Buffer.from(src), test: false });
              sourceFileSpec = new (_sources || _load_sources()).SourceFile({
                base: '.',
                path: 'is-string.spec.js',
                contents: Buffer.from(src),
                test: true
              });

              componentProps.files = [sourceFile, sourceFileSpec];
              component = new (_consumerComponent || _load_consumerComponent()).default(componentProps);

              (0, (_chai || _load_chai()).expect)(component.docs).to.have.lengthOf(1);

            case 6:
            case 'end':
              return _context4.stop();
          }
        }
      }, _callee4, _this);
    })));
  });
});