Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit 852dd81

Browse files
committed
fix(tests): Add test for grid generator
1 parent 3d6039d commit 852dd81

24 files changed

Lines changed: 760 additions & 42 deletions

package-lock.json

Lines changed: 18 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
"srcgen"
4747
],
4848
"devDependencies": {
49-
"@types/chai": "^4.0.7",
49+
"@types/chai": "^4.0.8",
5050
"@types/mocha": "^2.2.44",
51-
"@types/node": "^8.0.54",
51+
"@types/node": "^8.0.55",
5252
"@types/sinon": "^4.0.0",
5353
"chai": "^4.1.2",
5454
"mocha": "^4.0.1",
@@ -77,7 +77,7 @@
7777
"del": "^3.0.0",
7878
"del-cli": "^1.1.0",
7979
"dotenv": "^4.0.0",
80-
"fs-extra": "^4.0.2",
80+
"fs-extra": "^4.0.3",
8181
"gh-pages": "^1.1.0",
8282
"inflection": "^1.12.0",
8383
"lodash": "^4.17.4",
@@ -88,7 +88,7 @@
8888
"po2json": "^0.4.5",
8989
"recursive-readdir": "^2.2.1",
9090
"sort-paths": "^1.1.0",
91-
"srcgen": "^0.3.1",
91+
"srcgen": "^0.3.3",
9292
"tmp": "0.0.33"
9393
}
9494
}

src/bin/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class App {
6060
.description('extract-translate + po2ts + make-ts-list')
6161
.option('-lcp, --list-components-postfix [name]',
6262
'components postfix for collect to name-value object, example {\'users\': UsersGridComponent} it for list-components-postfix="grid" with component class file name="users-grid.component.ts"')
63-
.action(async (command) => {
63+
.action(async (dummy, command) => {
6464
await (new PrepareCommand(_.merge(this.program, command))).process();
6565
});
6666
this.program
@@ -104,14 +104,14 @@ export class App {
104104
.option('-lcp, --list-components-postfix [name]',
105105
'components postfix for collect to name-value object, example {\'users\': UsersGridComponent} it for list-components-postfix="grid" with component class file name="users-grid.component.ts"')
106106
.description('make index.ts with import all ts files in application/library')
107-
.action(async (command) => {
107+
.action(async (dummy, command) => {
108108
await (new MakeTsListCommand(_.merge(this.program, command))).process();
109109
});
110110
this.program
111111
.command('grid')
112112
.option('-en, --entity-name [name]', 'generator name')
113113
.description('scaffold model, service, grid, lookup input, modal for edit row in grid, modal for select items from grid with items')
114-
.action(async (command) => {
114+
.action(async (dummy, command) => {
115115
await (new GeneratorCommand(_.merge(this.program, command))).processGrid();
116116
});
117117
this.program.parse(process.argv);

src/commands/generator.command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { BaseCommand } from './base.command';
44
export class GeneratorCommand extends BaseCommand {
55
constructor(public options: any) {
66
super(options);
7+
this.log('generator=>').info(options);
78
}
89
async processGrid() {
910
this.log('generator').info('Run generator for ' + this.rootFolder);

src/generators/grid.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ export class GridGenerator extends Base {
3939
(customOptions && customOptions.project.libsConfigs[1] && customOptions &&
4040
customOptions.project.libsConfigs[1].shortName) ?
4141
customOptions && customOptions.project.libsConfigs[1].shortName : 'web';
42-
let coreFolder =
43-
(customOptions && customOptions.project.libsConfigs[0] && customOptions &&
44-
customOptions.project.libsConfigs[0].rootPath) ?
45-
customOptions && customOptions.project.libsConfigs[0].rootPath : 'core';
46-
let platformFolder =
47-
(customOptions && customOptions.project.libsConfigs[1] && customOptions &&
48-
customOptions.project.libsConfigs[1].rootPath) ?
49-
customOptions && customOptions.project.libsConfigs[1].rootPath : 'web';
42+
let coreFolder =
43+
(customOptions && customOptions.project.libsConfigs[0] && customOptions &&
44+
customOptions.project.libsConfigs[0].rootPath) ?
45+
customOptions && customOptions.project.libsConfigs[0].rootPath : 'core';
46+
let platformFolder =
47+
(customOptions && customOptions.project.libsConfigs[1] && customOptions &&
48+
customOptions.project.libsConfigs[1].rootPath) ?
49+
customOptions && customOptions.project.libsConfigs[1].rootPath : 'web';
5050
let coreLocalFolder =
5151
(customOptions && customOptions.project.libsConfigs[0] && customOptions &&
5252
customOptions.project.libsConfigs[0].localPath) ?
@@ -142,7 +142,8 @@ export class GridGenerator extends Base {
142142
rootFolder,
143143
'generatorGrid',
144144
'grid.select.input.modal',
145-
options
145+
options,
146+
rootFolder
146147
);
147148
}
148149
}

test/cmd-grid-generator-spec.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import * as chai from 'chai';
2+
import * as del from 'del';
3+
import { config } from 'dotenv';
4+
import * as fsExtra from 'fs-extra';
5+
import * as path from 'path';
6+
7+
import { Base } from '../src/lib/base';
8+
9+
const npmRun = require('npm-run');
10+
const assert = chai.assert;
11+
12+
describe('Grid-generator: create base model, service and components for entity "apple"', () => {
13+
config();
14+
const debug = process.env.TEST_DEBUG === 'true';
15+
describe('#prepare()', () => {
16+
const items: any[] = [];
17+
const dirRoot = path.resolve(__dirname + '/../');
18+
let _dirLocal = 'fixture/libs/lib1'
19+
let _dir = path.resolve(`${__dirname}/${_dirLocal}`);
20+
items.push({
21+
dir: _dir,
22+
dirLocal: `test/${_dirLocal}`,
23+
files: [
24+
path.resolve(`${_dir}/src/shared/models/apple.model.ts`),
25+
path.resolve(`${_dir}/src/shared/services/apples.service.ts`),
26+
]
27+
});
28+
_dirLocal = 'fixture/libs/subFolder/lib2'
29+
_dir = path.resolve(`${__dirname}/${_dirLocal}`);
30+
items.push({
31+
dir: _dir,
32+
dirLocal: `test/${_dirLocal}`,
33+
files: [
34+
path.resolve(`${_dir}/src/grids/apples-grid/apple-modal/apple-modal.component.html`),
35+
path.resolve(`${_dir}/src/grids/apples-grid/apple-modal/apple-modal.component.scss`),
36+
path.resolve(`${_dir}/src/grids/apples-grid/apple-modal/apple-modal.component.ts`),
37+
path.resolve(`${_dir}/src/grids/apples-grid/apple-modal/apple-modal.module.ts`),
38+
path.resolve(`${_dir}/src/grids/apples-grid/apple-select-input/apple-select-input.component.html`),
39+
path.resolve(`${_dir}/src/grids/apples-grid/apple-select-input/apple-select-input.component.scss`),
40+
path.resolve(`${_dir}/src/grids/apples-grid/apple-select-input/apple-select-input.component.ts`),
41+
path.resolve(`${_dir}/src/grids/apples-grid/apple-select-input/apple-select-input.module.ts`),
42+
path.resolve(`${_dir}/src/grids/apples-grid/apples-grid.component.html`),
43+
path.resolve(`${_dir}/src/grids/apples-grid/apples-grid.component.scss`),
44+
path.resolve(`${_dir}/src/grids/apples-grid/apples-grid.component.ts`),
45+
path.resolve(`${_dir}/src/grids/apples-grid/apples-grid.module.ts`),
46+
path.resolve(`${_dir}/src/grids/apples-grid/apples-list-modal/apples-list-modal.component.html`),
47+
path.resolve(`${_dir}/src/grids/apples-grid/apples-list-modal/apples-list-modal.component.scss`),
48+
path.resolve(`${_dir}/src/grids/apples-grid/apples-list-modal/apples-list-modal.component.ts`),
49+
path.resolve(`${_dir}/src/grids/apples-grid/apples-list-modal/apples-list-modal.module.ts`),
50+
]
51+
});
52+
beforeEach(() => {
53+
items.forEach(({
54+
dir: dir,
55+
dirLocal: dirLocal,
56+
files: files
57+
}) => {
58+
files.forEach((file: string) => {
59+
if (fsExtra.existsSync(file)) {
60+
del.sync([file]);
61+
}
62+
});
63+
});
64+
});
65+
items.forEach(({
66+
dir: dir,
67+
dirLocal: dirLocal,
68+
files: files
69+
}) => {
70+
it(`not exists files generated for "${dirLocal}"`, () => {
71+
files.forEach((file: string) => {
72+
assert.equal(fsExtra.existsSync(file), false);
73+
});
74+
});
75+
});
76+
it('tsc --pretty', (done: any) => {
77+
const file = path.resolve(`${dirRoot}/dist/bin/app.js`);
78+
const commandString = './node_modules/.bin/tsc --pretty';
79+
80+
const base = new Base('', dirRoot);
81+
base.debug = debug;
82+
base.commandRunner(commandString).then((data: boolean) => {
83+
assert.equal(fsExtra.existsSync(file), true);
84+
done();
85+
}).catch((e: any) => {
86+
done(e);
87+
});
88+
});
89+
it(`rucken grid --entity-name apple --root ./test/fixture`, (done) => {
90+
const file = path.resolve(`${dirRoot}/dist/bin/app.js`);
91+
const commandString = 'node . grid --entity-name apple --root ./test/fixture ' + (debug ? ' --verbose' : '');
92+
93+
assert.equal(fsExtra.existsSync(file), true);
94+
95+
const base = new Base('', dirRoot);
96+
base.debug = debug;
97+
base.commandRunner(commandString).then((data: boolean) => {
98+
items.forEach(({
99+
dir: dir,
100+
dirLocal: dirLocal,
101+
files: files
102+
}) => {
103+
files.forEach((file: string) => {
104+
assert.equal(fsExtra.existsSync(file), true);
105+
});
106+
});
107+
done();
108+
}).catch((e: any) => {
109+
done(e);
110+
});
111+
});
112+
});
113+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { BaseResourceModel, translate } from '@rucken/core';
2+
3+
export class Apple extends BaseResourceModel {
4+
static titles: any = {
5+
id: translate('Id'),
6+
name: translate('Name'),
7+
title: translate('Title'),
8+
createdAt: translate('CreatedAt'),
9+
updatedAt: translate('UpdatedAt'),
10+
11+
};
12+
static dateFields: any = ["createdAt","updatedAt"];
13+
static fields: any = [
14+
'id',
15+
'name',
16+
'title',
17+
'createdAt',
18+
'updatedAt',
19+
20+
];
21+
22+
id: number;
23+
name: string;
24+
title: string;
25+
createdAt: Date;
26+
updatedAt: Date;
27+
28+
static meta() {
29+
const meta: any = Apple;
30+
return meta;
31+
}
32+
constructor(obj ?: any) {
33+
super(obj);
34+
}
35+
parse(obj: any) {
36+
this.parseByFields(obj, Apple.meta());
37+
}
38+
format() {
39+
const result = this.formatByFields(Apple.meta());
40+
return result;
41+
}
42+
get asString() {
43+
return this.pk;
44+
}
45+
}

0 commit comments

Comments
 (0)