'use strict';

var path = require('path');
var os = require('os');
var helpers = require('yeoman-generator').test;
var assert = require('yeoman-generator').assert;

describe('Launching style tests', function () {

  var bangular, bangStyle, tmpDir;
  var bangDir = process.cwd();

  describe('', function () {

    before(function (done) {

      tmpDir = path.join(os.tmpdir(), '/tmp');

      helpers.testDirectory(tmpDir, function (err) {
        bangular = helpers.createGenerator('bangular:app',
          [path.join(bangDir, '/app')],
        false, { 'skipInstall': true, 'skipLog': true });

        helpers.mockPrompt(bangular, { name: 'Test', backend: 'json', modules: [] });
        bangular.run(done);
      });

    });

    it('should create a style file and not import it in the app scss', function (done) {

      bangStyle = helpers.createGenerator('bangular:style', [bangDir + '/style'], 'bootstrap');
      helpers.mockPrompt(bangStyle, { 'import': false });
      bangStyle.run(function () {
        setTimeout(function () {
          assert.file('client/styles/bootstrap.scss');
          assert.noFileContent('client/styles/app.scss', 'bootstrap');
          done();
        }, 50);
      });

    });

    it('should create a style file and import it in the app scss', function (done) {

      bangStyle = helpers.createGenerator('bangular:style', [bangDir + '/style'], 'flexbox');
      helpers.mockPrompt(bangStyle, { 'import': true });
      bangStyle.run(function () {
        setTimeout(function () {
          assert.file('client/styles/flexbox.scss');
          assert.fileContent('client/styles/app.scss', '@import "flexbox";');
          done();
        }, 50);
      });

    });

  });

});

@@ -56,24 +56,48 @@
 uire('os');%0A
+var fs = require('fs');%0A
 var helpers 
@@ -1731,16 +1731,552 @@
    %7D);%0A%0A
+%0A    it('should insert the import on needle', function (done) %7B%0A%0A      bangStyle = helpers.createGenerator('bangular:style', %5BbangDir + '/style'%5D, 'gold');%0A      helpers.mockPrompt(bangStyle, %7B 'import': true %7D);%0A      fs.appendFileSync('client/styles/app.scss', '// imports');%0A      bangStyle.run(function () %7B%0A        setTimeout(function () %7B%0A          assert.file('client/styles/gold.scss');%0A          assert.fileContent('client/styles/app.scss', '// imports%5Cn@import %22gold%22;');%0A          done();%0A        %7D, 50);%0A      %7D);%0A    %7D);%0A%0A%0A
   %7D);%0A%0A%7D

add test for insert needle or on top util