all files / src/ componentGenerator_spec.js

97.06% Statements 33/34
100% Branches 0/0
100% Functions 7/7
97.06% Lines 33/34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                                                           
'use strict';
 
let path = require('path');
let fse = require('fs-extra');
let expect = require('chai').expect;
let ConfigResolver = require('./configResolver');
let ComponentGenerator = require('./componentGenerator');
 
const config = new ConfigResolver();
const componentName = 'userlist';
const testPath = path.join(config.getComponentsRoot(), componentName);
 
describe('ComponentGenerator functionalities', function () {
 
  before(function () {
  });
 
  it('should create the folder structure for the new component when initialized', function () {
 
    new ComponentGenerator(componentName, config);
 
    checkIfDirectoriesExists(componentName);
  });
 
  it('should create all the files needed for the new component', function () {
    var cg = new ComponentGenerator(componentName, config);
 
    cg._createNewFiles();
 
    chekIfFilesExistsAndAreCorrects();
  });
 
 
  after(function () {
    fse.removeSync('./src/ts');
  });
 
});
 
 
function checkIfDirectoriesExists() {
  var check = false;
  try {
    fse.accessSync(testPath, fse.F_OK);
    check = true;
  } catch (e) {
    check = false;
  }
 
  expect(check).to.be.true;
}
 
function chekIfFilesExistsAndAreCorrects() {
  var componentFile = fse.readFileSync(testPath + path.sep + `${componentName}.component.ts`, 'utf8');
  expect(componentFile, '[componentFile]').to.have.string(`export class ${componentName}Component`);
 
  var controllerFile = fse.readFileSync(testPath + path.sep + `${componentName}.controller.ts`, 'utf8');
  expect(controllerFile, '[controllerFile]').to.have.string(`export class ${componentName}Controller`);
 
  var moduleFile = fse.readFileSync(testPath + path.sep + `${componentName}.module.ts`, 'utf8');
  expect(moduleFile, '[moduleFile]').to.have.string(`export let ${componentName}Module`);
  expect(moduleFile, '[moduleFile]').to.not.have.string(`.config(${componentName}Route);`);
}