import * as chai from 'chai';
import * as mocha from 'mocha';
import { parse } from 'path';
import * as fs from 'fs-extra';

const expect = chai.expect;
const should = chai.should;
const assert = chai.assert;

import { Mustr } from '../src';

const mu = new Mustr({
  configDir: './src/blueprints',
  outputDir: './test/output'
});

// Load up configs.
mu.load();

let template;

let authorPartial = '/**\n* Author: {{author}}\n* Copyright: {{copyright}}\n* Email: {{email}}\n * License: {{license}}\n*/';

describe('Mustr', () => {

  before((done) => {

    // Remove output test files from prev. run.
    fs.removeSync('./test/output');

    // Register the template.
    mu.register({
      name: 'DB',
      template: 'example.class',
      partials: 'example.author'
    });

    // Update metadata at time of render as a test.
    template = mu.configure('DB', 'examples/db.tsx', {
      author: 'Origin1 Technologies'
    });

    done();

  });

  it('should register a template named "DB".', () => {

    // Ensure templates contains registered template.
    assert.deepProperty(mu.templates, 'db');

  });

  it('should generate the template "DB".', () => {

    // Parse the output path.
    const parsed = parse(template.outputPath);

    // Ensure component name and casing.
    assert.equal(template.metadata.component, 'DbExample');

    // Ensure suffix and extension in output name.
    assert.equal(parsed.base, 'db.example.tsx');

  });

  it('should output the generated DbExample template.', (done) => {

    // Render the template.
    mu.render(template, () => {

      // Ensure the file was output and exists.
      assert.equal(fs.existsSync(template.outputPath), true);

      // Have to call done as this is an async test.
      done();

    });

  });

  it('it should inject value into rendered template.', (done) => {

    mu.inject('examples/db.example.tsx', '// INJECT', 'after', "import * as async from 'async';", done);

  });


});