Skip to content

Commit

Permalink
Merge pull request #104 from avdev4j/feat/ENG-1372-fix-tests
Browse files Browse the repository at this point in the history
Feat/eng 1372 fix tests
  • Loading branch information
firegloves committed Oct 20, 2020
2 parents f187e82 + 755b9d0 commit d31144a
Show file tree
Hide file tree
Showing 9 changed files with 897 additions and 60 deletions.
5 changes: 2 additions & 3 deletions generators/common/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const chalk = require('chalk');

const EntityServerGenerator = require('generator-jhipster/generators/common');
const CommonGenerator = require('generator-jhipster/generators/common');

const entandoBlueprintWritingPhase = require('./phases/writing');

module.exports = class extends EntityServerGenerator {
module.exports = class extends CommonGenerator {
constructor(args, opts) {
super(args, { fromBlueprint: true, ...opts }); // fromBlueprint variable is important

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import <%= entityClass %>Details from 'components/<%= entityClass %>Details';
import <%= entityInstance %>Mock from 'components/__mocks__/<%= entityInstance %>Mocks';

describe('<%= entityClass %>Details component', () => {
<%_ if(fields && fields.length){_%>
test('renders data in details widget', () => {
const { getByText } = render(<<%= entityClass %>Details <%= entityInstance %>={<%= entityInstance %>Mock} />);
<%# TODO: THIS ONLY APPLIES IF THE DATA IS NOT SHOWN AS A DIFFERENT ITEM (e.g. Boolean as checkbox) #%>
<%_ const firstField = fields[0].fieldName; _%>
expect(getByText('entities.<%= entityInstance %>.<%= firstField %>')).toBeInTheDocument();
expect(getByText('entities.<%= entityInstance %>.<%= fields[0].fieldName %>')).toBeInTheDocument();
});
<%_ } _%>
});
4 changes: 2 additions & 2 deletions generators/server/phases/writing/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const serverFiles = {
{
templates: ['package.json'],
},
],
bundle: [
{
templates: [
{ file: 'prepareMicrofrontends.sh', method: 'copy', noEjs: true },
Expand All @@ -47,11 +49,9 @@ const serverFiles = {
PATH: '.',
templates: [
{
useBluePrint: true,
file: 'bundle/descriptor.yaml',
},
{
useBluePrint: true,
file: 'bundle/plugins/myplugin.yaml',
renameTo: generator => `bundle/plugins/${generator.baseName.toLowerCase()}-plugin.yaml`,
},
Expand Down
54 changes: 54 additions & 0 deletions test/app.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const constants = require('generator-jhipster/generators/generator-constants');
const expectedFiles = require('./utils/expected-files');

const appBaseName = 'entandoPlugin';
const { SERVER_MAIN_RES_DIR } = constants;

describe('Subgenerator app of entando JHipster blueprint', () => {
describe('With default blueprint configuration', () => {
before(done => {
helpers
.run('generator-jhipster/generators/app')
.withOptions({
'from-cli': true,
skipInstall: true,
blueprint: 'entando',
skipChecks: true,
})
.withGenerators([
[
require('../generators/app/index.js'), // eslint-disable-line global-require
'jhipster-entando:app',
path.join(__dirname, '../generators/app/index.js'),
],
])
.withPrompts({
baseName: appBaseName,
packageName: 'com.mycompany.myapp',
applicationType: 'microservice',
databaseType: 'sql',
devDatabaseType: 'h2Disk',
prodDatabaseType: 'mysql',
cacheProvider: 'ehcache',
authenticationType: 'oauth2',
enableTranslation: true,
nativeLanguage: 'en',
languages: ['fr', 'de'],
buildTool: 'maven',
rememberMeKey: '2bb60a80889aa6e6767e9ccd8714982681152aa5',
})
.on('end', done);
});

it('creates expected files for the blueprint', () => {
assert.file(expectedFiles.microservices);
});

it('microservice index.html contains Entando data', () => {
assert.fileContent(`${SERVER_MAIN_RES_DIR}static/index.html`, 'https://dev.entando.org/');
});
});
});
52 changes: 52 additions & 0 deletions test/common.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');

describe('Subgenerator common of entando JHipster blueprint', () => {
describe('With default blueprint configuration', () => {
before(done => {
helpers
.run('generator-jhipster/generators/common')
.withOptions({
'from-cli': true,
skipInstall: true,
blueprint: 'entando',
skipChecks: true,
})
.withGenerators([
[
require('../generators/common/index.js'), // eslint-disable-line global-require
'jhipster-entando:common',
path.join(__dirname, '../generators/common/index.js'),
],
])
.withPrompts({
baseName: 'entandoPlugin',
packageName: 'com.mycompany.myapp',
applicationType: 'microservice',
databaseType: 'sql',
devDatabaseType: 'h2Disk',
prodDatabaseType: 'mysql',
cacheProvider: 'ehcache',
authenticationType: 'oauth2',
enableTranslation: true,
nativeLanguage: 'en',
languages: ['fr', 'de'],
buildTool: 'maven',
rememberMeKey: '2bb60a80889aa6e6767e9ccd8714982681152aa5',
})
.on('end', done);
});

it('creates expected files for the blueprint', () => {
assert.fileContent(
'.gitignore',
'######################\n' +
'# Entando bundles\n' +
'######################\n' +
'bundle/\n' +
'# !/bundle/descriptor.yaml',
);
});
});
});
170 changes: 166 additions & 4 deletions test/entity.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ const fse = require('fs-extra');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');

const expectedFiles = require('./utils/expected-files');

describe('Subgenerator entity of entando JHipster blueprint', () => {
describe('Sample test', () => {
describe('With default blueprint configuration', () => {
before(done => {
helpers
.run('generator-jhipster/generators/entity')
Expand Down Expand Up @@ -35,9 +37,169 @@ describe('Subgenerator entity of entando JHipster blueprint', () => {
.on('end', done);
});

it('it works', () => {
// Adds your tests here
assert.textEqual('Write your own tests!', 'Write your own tests!');
it('creates expected files for the blueprint', () => {
assert.file(expectedFiles.entity.server.common);
});

it('creates expected details widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.detailsWidget);
});

it('creates expected details widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.formWidget);
});

it('creates expected table widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.tableWidget);
});
});

describe('With noDb blueprint configuration', () => {
before(done => {
helpers
.run('generator-jhipster/generators/entity')
.inTmpDir(dir => {
fse.copySync(path.join(__dirname, '../test/templates/ngx-blueprint-noDb'), dir);
})
.withOptions({
'from-cli': true,
skipInstall: true,
blueprint: 'entando',
skipChecks: true,
})
.withGenerators([
[
require('../generators/entity/index.js'), // eslint-disable-line global-require
'jhipster-entando:entity',
path.join(__dirname, '../generators/entity/index.js'),
],
])
.withArguments(['foo'])
.withPrompts({
fieldAdd: false,
relationshipAdd: false,
dto: 'no',
service: 'no',
pagination: 'infinite-scroll',
})
.on('end', done);
});

it('creates expected files for the blueprint', () => {
assert.file(expectedFiles.entity.server.common);
assert.file(expectedFiles.entity.server.noDb);
});

it('creates expected details widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.detailsWidget);
});

it('creates expected details widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.formWidget);
});

it('creates expected table widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.tableWidget);
});
});

describe('With noDb with serviceClass blueprint configuration', () => {
before(done => {
helpers
.run('generator-jhipster/generators/entity')
.inTmpDir(dir => {
fse.copySync(path.join(__dirname, '../test/templates/ngx-blueprint-noDb'), dir);
})
.withOptions({
'from-cli': true,
skipInstall: true,
blueprint: 'entando',
skipChecks: true,
})
.withGenerators([
[
require('../generators/entity/index.js'), // eslint-disable-line global-require
'jhipster-entando:entity',
path.join(__dirname, '../generators/entity/index.js'),
],
])
.withArguments(['foo'])
.withPrompts({
fieldAdd: false,
relationshipAdd: false,
dto: 'no',
service: 'serviceClass',
pagination: 'infinite-scroll',
})
.on('end', done);
});

it('creates expected files for the blueprint', () => {
assert.file(expectedFiles.entity.server.common);
assert.file(expectedFiles.entity.server.noDb);
assert.file(expectedFiles.entity.server.serviceClass);
});

it('creates expected details widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.detailsWidget);
});

it('creates expected details widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.formWidget);
});

it('creates expected table widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.tableWidget);
});
});

describe('With noDb with serviceImpl blueprint configuration', () => {
before(done => {
helpers
.run('generator-jhipster/generators/entity')
.inTmpDir(dir => {
fse.copySync(path.join(__dirname, '../test/templates/ngx-blueprint-noDb'), dir);
})
.withOptions({
'from-cli': true,
skipInstall: true,
blueprint: 'entando',
skipChecks: true,
})
.withGenerators([
[
require('../generators/entity/index.js'), // eslint-disable-line global-require
'jhipster-entando:entity',
path.join(__dirname, '../generators/entity/index.js'),
],
])
.withArguments(['foo'])
.withPrompts({
fieldAdd: false,
relationshipAdd: false,
dto: 'no',
service: 'serviceImpl',
pagination: 'infinite-scroll',
})
.on('end', done);
});

it('creates expected files for the blueprint', () => {
assert.file(expectedFiles.entity.server.common);
assert.file(expectedFiles.entity.server.noDb);
assert.file(expectedFiles.entity.server.serviceImpl);
});

it('creates expected details widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.detailsWidget);
});

it('creates expected details widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.formWidget);
});

it('creates expected table widget files for the blueprint', () => {
assert.file(expectedFiles.entity.widget.tableWidget);
});
});
});
Loading

0 comments on commit d31144a

Please sign in to comment.