"use strict";

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

function _bluebird() {
  const data = require("bluebird");

  _bluebird = function () {
    return data;
  };

  return data;
}

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

  _chai = function () {
    return data;
  };

  return data;
}

function _withCompiler() {
  const data = _interopRequireDefault(require("../../../fixtures/consumer-components/with-compiler/with-compiler.json"));

  _withCompiler = function () {
    return data;
  };

  return data;
}

function _consumerComponent() {
  const data = _interopRequireDefault(require("./consumer-component"));

  _consumerComponent = function () {
    return data;
  };

  return data;
}

function _compilerExtension() {
  const data = _interopRequireDefault(require("../../extensions/compiler-extension"));

  _compilerExtension = function () {
    return data;
  };

  return data;
}

function _sources() {
  const data = require("./sources");

  _sources = function () {
    return data;
  };

  return data;
}

describe('ConsumerComponent', function () {
  this.timeout(0);
  describe('fromString()', () => {
    describe('component with compiler', () => {
      let component;
      before(
      /*#__PURE__*/
      (0, _bluebird().coroutine)(function* () {
        component = yield _consumerComponent().default.fromString(JSON.stringify(_withCompiler().default));
      }));
      it('should not crash and return a ConsumerComponent Object',
      /*#__PURE__*/
      (0, _bluebird().coroutine)(function* () {
        (0, _chai().expect)(component).to.be.instanceOf(_consumerComponent().default);
      }));
      it('should convert the compiler object to a Compiler instance', () => {
        (0, _chai().expect)(component.compiler).to.be.instanceOf(_compilerExtension().default);
      });
    });
  });
  describe('docs', () => {
    const componentProps = {
      name: 'is-string',
      mainFile: 'is-string.js',
      files: [new (_sources().SourceFile)({
        base: '.',
        path: 'is-string.js',
        contents: Buffer.from(''),
        test: false
      })]
    };
    it('should return an empty array when there is no docs', () => {
      const component = new (_consumerComponent().default)(componentProps);
      (0, _chai().expect)(component.docs).to.deep.equal([]);
    });
    it('should return the docs when a file has a jsdoc block',
    /*#__PURE__*/
    (0, _bluebird().coroutine)(function* () {
      const src = `/**
      * is a given variable a string
      */
      function isString() {}`;
      const sourceFile = new (_sources().SourceFile)({
        base: '.',
        path: 'is-string.js',
        contents: Buffer.from(src),
        test: false
      });
      componentProps.files = [sourceFile];
      const component = new (_consumerComponent().default)(componentProps);
      (0, _chai().expect)(component.docs).to.have.lengthOf(1);
      (0, _chai().expect)(component.docs[0].description).to.equal('is a given variable a string');
    }));
    it('should return the docs only for non-test files with jsdocs',
    /*#__PURE__*/
    (0, _bluebird().coroutine)(function* () {
      const src = `/**
      * is a given variable a string
      */
      function isString() {}`;
      const sourceFile = new (_sources().SourceFile)({
        base: '.',
        path: 'is-string.js',
        contents: Buffer.from(src),
        test: false
      });
      const sourceFileSpec = new (_sources().SourceFile)({
        base: '.',
        path: 'is-string.spec.js',
        contents: Buffer.from(src),
        test: true
      });
      componentProps.files = [sourceFile, sourceFileSpec];
      const component = new (_consumerComponent().default)(componentProps);
      (0, _chai().expect)(component.docs).to.have.lengthOf(1);
    }));
  });
});