'use strict';

var _chai;

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

var _linkGenerator;

function _load_linkGenerator() {
  return _linkGenerator = _interopRequireWildcard(require('./link-generator'));
}

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

describe('link-generator', function () {
  describe('getLinkContent', function () {
    it('should generate content for simple js file', function () {
      var result = (_linkGenerator || _load_linkGenerator()).getLinkContent('my-path.js');
      (0, (_chai || _load_chai()).expect)(result).to.equal("module.exports = require('./my-path');");
    });
    it('should generate correct content for npm vue package without .vue extension', function () {
      var result = (_linkGenerator || _load_linkGenerator()).getLinkContent('../../../src/pages/my-page.vue', undefined, true, '@bit/david.scope.components.vue-page');
      (0, (_chai || _load_chai()).expect)(result).to.have.string("module.exports = require('@bit/david.scope.components.vue-page');");
      (0, (_chai || _load_chai()).expect)(result).to.not.have.string("module.exports = require('@bit/david.scope.components.vue-page.vue');");
    });
    describe('es6 with link files', function () {
      var exportDefaultForm = 'exports.default =';
      var exportNonDefaultForm = 'exports.isString =';
      var importDefaultForm = "= _isString && _isString.hasOwnProperty('default') ? _isString.default : _isString;";
      var importNonDefaultForm = '= _isString.isString';
      describe('mainFile is not default and linkFile is default', function () {
        var linkContent = void 0;
        before(function () {
          var importSpecifier = [{
            mainFile: { isDefault: false, name: 'isString' },
            linkFile: { isDefault: true, name: 'isString' }
          }];
          linkContent = (_linkGenerator || _load_linkGenerator()).getLinkContent('is-string.js', importSpecifier);
        });
        it('the generated link should export non-default', function () {
          (0, (_chai || _load_chai()).expect)(linkContent).to.have.string(exportNonDefaultForm);
          (0, (_chai || _load_chai()).expect)(linkContent).to.not.have.string(exportDefaultForm);
        });
        it('the generated link should import default', function () {
          (0, (_chai || _load_chai()).expect)(linkContent).to.have.string(importDefaultForm);
          (0, (_chai || _load_chai()).expect)(linkContent).to.not.have.string(importNonDefaultForm);
        });
      });
      describe('mainFile and linkFile are both default', function () {
        var linkContent = void 0;
        before(function () {
          var importSpecifier = [{
            mainFile: { isDefault: true, name: 'isString' },
            linkFile: { isDefault: true, name: 'isString' }
          }];
          linkContent = (_linkGenerator || _load_linkGenerator()).getLinkContent('is-string.js', importSpecifier);
        });
        it('the generated link should export default', function () {
          (0, (_chai || _load_chai()).expect)(linkContent).to.have.string(exportDefaultForm);
          (0, (_chai || _load_chai()).expect)(linkContent).to.not.have.string(exportNonDefaultForm);
        });
        it('the generated link should import default', function () {
          (0, (_chai || _load_chai()).expect)(linkContent).to.have.string(importDefaultForm);
          (0, (_chai || _load_chai()).expect)(linkContent).to.not.have.string(importNonDefaultForm);
        });
      });
      describe('mainFile and linkFile are both non-default', function () {
        var linkContent = void 0;
        before(function () {
          var importSpecifier = [{
            mainFile: { isDefault: false, name: 'isString' },
            linkFile: { isDefault: false, name: 'isString' }
          }];
          linkContent = (_linkGenerator || _load_linkGenerator()).getLinkContent('is-string.js', importSpecifier);
        });
        it('the generated link should export non-default', function () {
          (0, (_chai || _load_chai()).expect)(linkContent).to.have.string(exportNonDefaultForm);
          (0, (_chai || _load_chai()).expect)(linkContent).to.not.have.string(exportDefaultForm);
        });
        it('the generated link should import non-default', function () {
          (0, (_chai || _load_chai()).expect)(linkContent).to.have.string(importNonDefaultForm);
          (0, (_chai || _load_chai()).expect)(linkContent).to.not.have.string(importDefaultForm);
        });
      });
      describe('mainFile is default and link file is not default', function () {
        var linkContent = void 0;
        before(function () {
          var importSpecifier = [{
            mainFile: { isDefault: true, name: 'isString' },
            linkFile: { isDefault: false, name: 'isString' }
          }];
          linkContent = (_linkGenerator || _load_linkGenerator()).getLinkContent('is-string.js', importSpecifier);
        });
        it('the generated link should export default', function () {
          (0, (_chai || _load_chai()).expect)(linkContent).to.have.string(exportDefaultForm);
          (0, (_chai || _load_chai()).expect)(linkContent).to.not.have.string(exportNonDefaultForm);
        });
        it('the generated link should import non-default', function () {
          (0, (_chai || _load_chai()).expect)(linkContent).to.have.string(importNonDefaultForm);
          (0, (_chai || _load_chai()).expect)(linkContent).to.not.have.string(importDefaultForm);
        });
      });
    });
  });
});