@dlr-eoc/core-ui
Version:
This project includes schematics to add the base UKIS-Layout to an angular application. The Layout is based on Clarity so [add this first](https://clarity.design/get-started/developing/angular)!
340 lines • 17.3 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const testing_1 = require("@angular-devkit/schematics/testing");
const schema_1 = require("@schematics/angular/application/schema");
const path = require("path");
const collectionPath = require.resolve(path.join(__dirname, '../collection.json'));
describe('ng-add Module or standalone', () => {
const schematicRunner = new testing_1.SchematicTestRunner('@dlr-eoc/schematics', collectionPath);
let appTree;
const ngAddOptions = {
project: 'ukisapp',
routing: false,
addClr: false,
addFiles: true,
updateFiles: true, // TODO: this has to be implemented first
addMap: false, // TODO: this has to be implemented first
auth: false, // TODO: this has to be implemented first
};
const workspaceOptions = {
name: 'workspace',
newProjectRoot: 'projects',
version: '9.0.0'
};
const appOptions = {
name: 'ukisapp',
projectRoot: '',
standalone: false, // no standalone API.
inlineStyle: false,
inlineTemplate: false,
routing: true,
style: schema_1.Style.Css,
skipTests: false
};
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
appTree = yield schematicRunner.runExternalSchematic('@schematics/angular', 'workspace', workspaceOptions);
appTree = yield schematicRunner.runExternalSchematic('@schematics/angular', 'application', appOptions, appTree);
}));
it('should have no workspace schematics', () => __awaiter(void 0, void 0, void 0, function* () {
const projectFile = JSON.parse(appTree.readContent('/angular.json'));
expect(projectFile.schematics).toBeFalsy();
}));
it('should have no projects schematics for style because -> app style: Style.Css', () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const projectFile = JSON.parse(appTree.readContent('/angular.json'));
expect((_a = projectFile.projects[appOptions.name].schematics['@schematics/angular:component']) === null || _a === void 0 ? void 0 : _a.style).toBeUndefined();
}));
it('should include the angular project file', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
expect(tree.files.includes('/angular.json')).toBe(true);
}));
it('should replace style extension in project.targets.options.styles', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
const projectFile = JSON.parse(tree.readContent('/angular.json'));
['build', 'test'].forEach(target => {
const styles = projectFile.projects[appOptions.name].architect[target].options.styles;
styles.forEach(path => {
if (path.includes('styles.')) {
expect(path.includes('.scss')).toBeTrue();
}
});
});
}));
it('should add assets', () => __awaiter(void 0, void 0, void 0, function* () {
const dimensions = [72, 96, 128, 144, 152, 192, 384, 512];
const iconBasePath = `/src/assets/icons/icon-`;
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
dimensions.every(d => {
const iconPath = `${iconBasePath}${d}x${d}.png`;
expect(tree.files).toContain(iconPath);
// expect(tree.exists(iconPath)).toBeTruthy();
});
expect(tree.files).toContain('/src/favicon.ico');
}));
it('should add style files', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/styles.scss',
'/src/styles/_clr-vertival-nav-layout.scss',
'/src/styles/_overwrites-clr-variables.scss',
'/src/styles/_ukis-core-ui-layout.scss',
'/src/styles/_ukis-inputs.scss',
'/src/styles/_ukis-layer-nav.scss',
'/src/styles/_ukis-theme.scss',
'/src/styles/_ukis-variables.scss'
];
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
testFiles.every(f => {
expect(tree.files).toContain(f);
// expect(tree.exists(f)).toBeTruthy();
});
}));
it('should add app files', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/app/app.component.html',
'/src/app/app.component.scss',
'/src/app/app.component.ts',
'/src/app/components/README.md',
'/src/app/components/header/header.component.html',
'/src/app/components/header/header.component.scss',
'/src/app/components/header/header.component.spec.ts',
'/src/app/components/header/header.component.ts',
'/src/app/components/icons/eoc_white.svg',
'/src/app/components/icons/ukis-01-01.svg',
'/src/app/components/icons/ukis.svg',
'/src/app/components/icons/ukis.ts',
'src/app/components/global-alert/alert.service.spec.ts',
'src/app/components/global-alert/alert.service.ts',
'src/app/components/global-alert/global-alert.component.html',
'src/app/components/global-alert/global-alert.component.scss',
'src/app/components/global-alert/global-alert.component.spec.ts',
'src/app/components/global-alert/global-alert.component.ts',
'src/app/components/global-progress/global-progress.component.html',
'src/app/components/global-progress/global-progress.component.scss',
'src/app/components/global-progress/global-progress.component.spec.ts',
'src/app/components/global-progress/global-progress.component.ts',
'src/app/components/global-progress/progress.service.spec.ts',
'src/app/components/global-progress/progress.service.ts',
'src/app/views/example-view/example-view.component.html',
'src/app/views/example-view/example-view.component.scss',
'src/app/views/example-view/example-view.component.spec.ts',
'src/app/views/example-view/example-view.component.ts'
];
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
testFiles.every(f => {
expect(tree.files).toContain(f);
// expect(tree.exists(f)).toBeTruthy();
});
}));
it('should add project schematics', () => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
const projectFile = JSON.parse(tree.readContent('/angular.json'));
expect((_b = (_a = projectFile.projects[appOptions.name]) === null || _a === void 0 ? void 0 : _a.schematics['@schematics/angular:component']) === null || _b === void 0 ? void 0 : _b.style).toBe('scss');
}));
it('should update the tsconfig file', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
const configs = ['/tsconfig.json', '/tsconfig.base.json'];
configs.forEach(configFilePath => {
var _a, _b;
if (tree.exists(configFilePath)) {
const tsconfigFile = JSON.parse(tree.readContent(configFilePath));
const paths = (_a = tsconfigFile === null || tsconfigFile === void 0 ? void 0 : tsconfigFile.compilerOptions) === null || _a === void 0 ? void 0 : _a.paths;
expect(paths).toBeTruthy();
if (paths) {
expect('@dlr-eoc/*' in paths).toBe(true);
}
const skipLibCheck = (_b = tsconfigFile === null || tsconfigFile === void 0 ? void 0 : tsconfigFile.compilerOptions) === null || _b === void 0 ? void 0 : _b.skipLibCheck;
expect(skipLibCheck).toBeTruthy();
if (skipLibCheck !== undefined) {
expect(skipLibCheck).toBe(true);
}
}
});
}));
it('should update html files', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
const tsconfigFile = tree.readContent('/src/index.html');
expect(tsconfigFile).toContain('<meta name="description" content="This should be the description for');
}));
it('should skip add style files', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/styles/_overwrites-clr-variables.scss',
'/src/styles/_clr-vertival-nav-layout.scss',
'/src/styles/_ukis-core-ui-layout.scss',
'/src/styles/_ukis-inputs.scss',
'/src/styles/_ukis-layer-nav.scss',
'/src/styles/_ukis-theme.scss',
'/src/styles/_ukis-variables.scss',
];
const skipOptions = Object.assign({}, ngAddOptions, { addFiles: false });
const tree = yield schematicRunner.runSchematic('ng-add', skipOptions, appTree);
testFiles.map(f => {
expect(tree.files.includes(f)).toBe(false);
});
}));
it('should remove /src/app/views files if routing is true', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/app/views/example-view/example-view.component.html',
'/src/app/views/example-view/example-view.component.scss',
'/src/app/views/example-view/example-view.component.spec.ts',
'/src/app/views/example-view/example-view.component.ts',
];
const routingOptions = Object.assign({}, ngAddOptions, { routing: true });
const tree = yield schematicRunner.runSchematic('ng-add', routingOptions, appTree);
testFiles.every(f => {
expect(tree.files).not.toContain(f);
// expect(tree.files).toContain(f);
});
}));
});
// ---------------------------------------------------------------------------------------------------
describe('ng-add Module App', () => {
const schematicRunner = new testing_1.SchematicTestRunner('@dlr-eoc/schematics', collectionPath);
let appTree;
const ngAddOptions = {
project: 'ukisapp',
routing: false,
addClr: false,
addFiles: true,
updateFiles: true, // TODO: this has to be implemented first
addMap: false, // TODO: this has to be implemented first
auth: false, // TODO: this has to be implemented first
};
const workspaceOptions = {
name: 'workspace',
newProjectRoot: 'projects',
version: '9.0.0'
};
const appOptions = {
name: 'ukisapp',
projectRoot: '',
standalone: false, // no standalone API.
inlineStyle: false,
inlineTemplate: false,
routing: true,
style: schema_1.Style.Css,
skipTests: false
};
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
appTree = yield schematicRunner.runExternalSchematic('@schematics/angular', 'workspace', workspaceOptions);
appTree = yield schematicRunner.runExternalSchematic('@schematics/angular', 'application', appOptions, appTree);
}));
it('should add Imports', () => __awaiter(void 0, void 0, void 0, function* () {
const testImports = [
'HeaderComponent',
'GlobalAlertComponent',
'AlertService',
'GlobalProgressComponent',
'ProgressService',
'ExampleViewComponent'
];
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
const appModule = tree.readContent('/src/app/app.module.ts');
testImports.map(i => {
expect(appModule).toContain(i);
});
}));
});
// ---------------------------------------------------------------------------------------------------
describe('ng-add standalone App', () => {
const schematicRunner = new testing_1.SchematicTestRunner('@dlr-eoc/schematics', collectionPath);
let appTree;
const ngAddOptions = {
project: 'ukisapp',
routing: false,
addClr: false,
addFiles: true,
updateFiles: true, // TODO: this has to be implemented first
addMap: false, // TODO: this has to be implemented first
auth: false, // TODO: this has to be implemented first
};
const workspaceOptions = {
name: 'workspace',
newProjectRoot: 'projects',
version: '9.0.0'
};
const appOptions = {
name: 'ukisapp',
projectRoot: '',
standalone: true, // We have not yet migrated to the standalone API.
inlineStyle: false,
inlineTemplate: false,
routing: true,
style: schema_1.Style.Css,
skipTests: false
};
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
appTree = yield schematicRunner.runExternalSchematic('@schematics/angular', 'workspace', workspaceOptions);
appTree = yield schematicRunner.runExternalSchematic('@schematics/angular', 'application', appOptions, appTree);
}));
it('should be standalone App', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/main.ts',
'/src/app/app.config.ts'
];
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
testFiles.every(f => {
expect(tree.files).toContain(f);
});
}));
it('should add config to main', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
const mainFile = tree.readContent('/src/main.ts');
expect(mainFile).toContain('app.config');
}));
// this should not be the case if ngAddOptions.routing = false ???
it('should have standalone routes', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
expect(tree.files).toContain('/src/app/app.routes.ts');
}));
it('should add app files', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/app/app.component.html',
'/src/app/app.component.scss',
'/src/app/app.component.ts',
'src/app/components/global-alert/alert.service.spec.ts',
'src/app/components/global-alert/alert.service.ts',
'src/app/components/global-alert/global-alert.component.html',
'src/app/components/global-alert/global-alert.component.scss',
'src/app/components/global-alert/global-alert.component.spec.ts',
'src/app/components/global-alert/global-alert.component.ts',
'src/app/components/global-progress/global-progress.component.html',
'src/app/components/global-progress/global-progress.component.scss',
'src/app/components/global-progress/global-progress.component.spec.ts',
'src/app/components/global-progress/global-progress.component.ts',
'src/app/components/global-progress/progress.service.spec.ts',
'src/app/components/global-progress/progress.service.ts',
'src/app/views/example-view/example-view.component.html',
'src/app/views/example-view/example-view.component.scss',
'src/app/views/example-view/example-view.component.spec.ts',
'src/app/views/example-view/example-view.component.ts'
];
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
testFiles.every(f => {
expect(tree.files).toContain(f);
// expect(tree.exists(f)).toBeTruthy();
});
}));
it('should add Providers', () => __awaiter(void 0, void 0, void 0, function* () {
const testProviders = [
'AlertService',
'ProgressService',
];
const tree = yield schematicRunner.runSchematic('ng-add', ngAddOptions, appTree);
const appConfig = tree.readContent('/src/app/app.config.ts');
testProviders.map(i => {
expect(appConfig).toContain(i);
expect(appConfig).toContain(`import { ${i} }`);
});
}));
});
//# sourceMappingURL=index_spec.js.map