@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)!
205 lines • 9.04 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('add-routing Module or standalone', () => {
const schematicRunner = new testing_1.SchematicTestRunner('@dlr-eoc/schematics', collectionPath);
let appTree;
const ngAddOptions = {
project: 'ukisapp',
addFiles: true,
updateFiles: true
};
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/update app files', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/app/app.component.html',
'/src/app/app.component.ts',
'/src/app/app.routes.ts',
'/src/app/route-components/README.md',
'/src/app/route-components/example-route/example-route.component.html',
'/src/app/route-components/example-route/example-route.component.ts',
'/src/app/route-components/example-route/example-route.component.scss'
];
const tree = yield schematicRunner.runSchematic('add-routing', ngAddOptions, appTree);
testFiles.every(f => {
expect(tree.files).toContain(f);
});
}));
});
describe('add-routing Module App', () => {
const schematicRunner = new testing_1.SchematicTestRunner('@dlr-eoc/schematics', collectionPath);
let appTree;
const ngAddOptions = {
project: 'ukisapp',
addFiles: true,
updateFiles: true
};
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 app files', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/app/app.routes.ts',
'/src/app/app-routing.module.ts',
];
const tree = yield schematicRunner.runSchematic('add-routing', ngAddOptions, appTree);
testFiles.every(f => {
expect(tree.files).toContain(f);
});
}));
it('should not have app.config.ts', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/app/app.config.ts'
];
const tree = yield schematicRunner.runSchematic('add-routing', ngAddOptions, appTree);
testFiles.every(f => {
expect(tree.files).not.toContain(f);
});
}));
it('should add Imports', () => __awaiter(void 0, void 0, void 0, function* () {
const testImports = [
'AppRoutingModule',
'ExampleRouteComponent'
];
const tree = yield schematicRunner.runSchematic('add-routing', ngAddOptions, appTree);
const appModule = tree.readContent('/src/app/app.module.ts');
testImports.every(i => {
expect(appModule).toContain(i);
});
}));
it('should remove imports from views if routing is true', () => __awaiter(void 0, void 0, void 0, function* () {
const testImports = [
'ExampleViewComponent'
];
const routingOptions = Object.assign({}, ngAddOptions, { routing: true });
const tree = yield schematicRunner.runSchematic('ng-add', routingOptions, appTree);
const appModuleSource = tree.readContent('/src/app/app.module.ts').split('@NgModule');
const appModule = appModuleSource[0];
testImports.map(i => {
expect(appModule).not.toContain(i);
});
}));
it('should remove Declarations from views if routing is true', () => __awaiter(void 0, void 0, void 0, function* () {
const testDeclarations = [
'ExampleViewComponent'
];
const routingOptions = Object.assign({}, ngAddOptions, { routing: true });
const tree = yield schematicRunner.runSchematic('ng-add', routingOptions, appTree);
const appModuleSource = tree.readContent('/src/app/app.module.ts').split('@NgModule');
const appNgModule = `@NgModule${appModuleSource[1]}`;
testDeclarations.map(i => {
expect(appNgModule).not.toContain(i);
});
}));
});
describe('add-routing standalone App', () => {
const schematicRunner = new testing_1.SchematicTestRunner('@dlr-eoc/schematics', collectionPath);
let appTree;
const ngAddOptions = {
project: 'ukisapp',
addFiles: true,
updateFiles: true
};
const workspaceOptions = {
name: 'workspace',
newProjectRoot: 'projects',
version: '9.0.0',
};
const appOptions = {
name: 'ukisapp',
projectRoot: '',
standalone: true, // 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 app files', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/app/app.config.ts',
];
const tree = yield schematicRunner.runSchematic('add-routing', ngAddOptions, appTree);
testFiles.every(f => {
expect(tree.files).toContain(f);
});
}));
it('should not have app-routing.module.ts', () => __awaiter(void 0, void 0, void 0, function* () {
const testFiles = [
'/src/app/app-routing.module.ts'
];
const tree = yield schematicRunner.runSchematic('add-routing', ngAddOptions, appTree);
testFiles.every(f => {
expect(tree.files).not.toContain(f);
});
}));
it('should remove import view from app if routing is true', () => __awaiter(void 0, void 0, void 0, function* () {
const testImports = [
'ExampleViewComponent'
];
const routingOptions = Object.assign({}, ngAddOptions, { routing: true });
const tree = yield schematicRunner.runSchematic('ng-add', routingOptions, appTree);
const appComponentSource = tree.readContent('/src/app/app.component.ts').split('@Component');
const appComponent = appComponentSource[0];
testImports.map(i => {
expect(appComponent).not.toContain(i);
});
}));
it('should have Routes in app.config.ts', () => __awaiter(void 0, void 0, void 0, function* () {
const tree = yield schematicRunner.runSchematic('add-routing', ngAddOptions, appTree);
const appConfig = tree.readContent('/src/app/app.config.ts');
expect(appConfig).toContain(`import { routes } from './app.routes'`);
expect(appConfig).toContain(`provideRouter(routes)`);
}));
});
//# sourceMappingURL=index_spec.js.map