@nstudio/angular
Version:
Angular Plugin for xplat
160 lines (159 loc) • 10.1 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 schematics_1 = require("@angular-devkit/schematics");
const testing_1 = require("@nstudio/xplat/testing");
const testing_2 = require("../../utils/testing");
describe('directive schematic', () => {
let appTree;
const defaultOptions = {
name: 'active-link',
};
beforeEach(() => {
appTree = schematics_1.Tree.empty();
appTree = (0, testing_1.createXplatWithNativeScriptWeb)(appTree, null, 'angular');
});
it('should create directive in libs by default for use across any platform and apps', () => __awaiter(void 0, void 0, void 0, function* () {
// console.log('appTree:', appTree);
let tree = yield (0, testing_2.runSchematic)('feature', {
name: 'foo',
platforms: 'nativescript,web',
}, appTree);
let options = Object.assign({}, defaultOptions);
// Directives without the feature option are added to the ui-feature
tree = yield (0, testing_2.runSchematic)('directive', options, tree);
let files = tree.files;
// console.log(files.slice(91,files.length));
// component
expect(files.indexOf('/libs/xplat/features/src/lib/ui/directives/active-link.directive.ts')).toBeGreaterThanOrEqual(0);
// file content
let content = (0, testing_1.getFileContent)(tree, '/libs/xplat/features/src/lib/ui/directives/active-link.directive.ts');
// console.log(content);
expect(content.indexOf(`@Directive({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`selector: '[active-link]'`)).toBeGreaterThanOrEqual(0);
let modulePath = '/libs/xplat/features/src/lib/ui/ui.module.ts';
let moduleContent = (0, testing_1.getFileContent)(tree, modulePath);
// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`...UI_DIRECTIVES`)).toBeGreaterThanOrEqual(0);
// Directives added to the foo-feature
options = Object.assign(Object.assign({}, defaultOptions), { feature: 'foo' });
tree = yield (0, testing_2.runSchematic)('directive', options, tree);
files = tree.files;
// console.log(files.slice(91,files.length));
expect(files.indexOf('/libs/xplat/features/src/lib/foo/directives/active-link.directive.ts')).toBeGreaterThanOrEqual(0);
// file content
content = (0, testing_1.getFileContent)(tree, '/libs/xplat/features/src/lib/foo/directives/active-link.directive.ts');
// console.log(content);
expect(content.indexOf(`@Directive({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`selector: '[active-link]'`)).toBeGreaterThanOrEqual(0);
modulePath = '/libs/xplat/features/src/lib/foo/foo.module.ts';
moduleContent = (0, testing_1.getFileContent)(tree, modulePath);
// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`...FOO_DIRECTIVES`)).toBeGreaterThanOrEqual(0);
}));
it('should create directive across various xplat folders with platforms specified', () => __awaiter(void 0, void 0, void 0, function* () {
// console.log('appTree:', appTree);
let tree = yield (0, testing_2.runSchematic)('feature', {
name: 'foo',
platforms: 'nativescript,web',
}, appTree);
let options = Object.assign({}, defaultOptions);
options.platforms = 'nativescript,web';
// Directives without the feature option are added to the ui-feature
tree = yield (0, testing_2.runSchematic)('directive', options, tree);
let files = tree.files;
// console.log(files.slice(91,files.length));
expect(tree.exists('/libs/xplat/features/src/lib/ui/directives/active-link.directive.ts')).toBeFalsy();
expect(tree.exists('/libs/xplat/web/features/src/lib/ui/directives/active-link.directive.ts')).toBeTruthy();
expect(tree.exists('/libs/xplat/nativescript/features/src/lib/ui/directives/active-link.directive.ts')).toBeTruthy();
// file content
let content = (0, testing_1.getFileContent)(tree, '/libs/xplat/web/features/src/lib/ui/directives/active-link.directive.ts');
// console.log(content);
expect(content.indexOf(`@Directive({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`selector: '[active-link]'`)).toBeGreaterThanOrEqual(0);
content = (0, testing_1.getFileContent)(tree, '/libs/xplat/nativescript/features/src/lib/ui/directives/active-link.directive.ts');
// console.log(content);
expect(content.indexOf(`@Directive({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`selector: '[active-link]'`)).toBeGreaterThanOrEqual(0);
let modulePath = '/libs/xplat/web/features/src/lib/ui/ui.module.ts';
let moduleContent = (0, testing_1.getFileContent)(tree, modulePath);
// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`...UI_DIRECTIVES`)).toBeGreaterThanOrEqual(0);
modulePath = '/libs/xplat/nativescript/features/src/lib/ui/ui.module.ts';
moduleContent = (0, testing_1.getFileContent)(tree, modulePath);
expect(moduleContent.indexOf(`...UI_DIRECTIVES`)).toBeGreaterThanOrEqual(0);
// Directives added to the foo-feature
options = Object.assign(Object.assign({}, defaultOptions), { feature: 'foo' });
options.platforms = 'nativescript,web';
tree = yield (0, testing_2.runSchematic)('directive', options, tree);
files = tree.files;
// console.log(files.slice(91,files.length));
expect(tree.exists('/libs/xplat/web/features/src/lib/foo/directives/active-link.directive.ts')).toBeTruthy();
expect(tree.exists('/libs/xplat/nativescript/features/src/lib/foo/directives/active-link.directive.ts')).toBeTruthy();
// file content
content = (0, testing_1.getFileContent)(tree, '/libs/xplat/web/features/src/lib/foo/directives/active-link.directive.ts');
// console.log(content);
expect(content.indexOf(`@Directive({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`selector: '[active-link]'`)).toBeGreaterThanOrEqual(0);
content = (0, testing_1.getFileContent)(tree, '/libs/xplat/nativescript/features/src/lib/foo/directives/active-link.directive.ts');
// console.log(content);
expect(content.indexOf(`@Directive({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`selector: '[active-link]'`)).toBeGreaterThanOrEqual(0);
modulePath = '/libs/xplat/web/features/src/lib/foo/foo.module.ts';
moduleContent = (0, testing_1.getFileContent)(tree, modulePath);
// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`...FOO_DIRECTIVES`)).toBeGreaterThanOrEqual(0);
modulePath = '/libs/xplat/nativescript/features/src/lib/foo/foo.module.ts';
moduleContent = (0, testing_1.getFileContent)(tree, modulePath);
// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`...FOO_DIRECTIVES`)).toBeGreaterThanOrEqual(0);
}));
it('should create directive for specified projects only', () => __awaiter(void 0, void 0, void 0, function* () {
// console.log('appTree:', appTree);
let tree = yield (0, testing_2.runSchematic)('feature', {
name: 'foo',
projects: 'nativescript-viewer,web-viewer',
onlyProject: true,
}, appTree);
const options = {
name: 'active-link',
feature: 'foo',
projects: 'nativescript-viewer,web-viewer',
};
tree = yield (0, testing_2.runSchematic)('directive', options, tree);
const files = tree.files;
// console.log(files. slice(91,files.length));
// directive should not be setup to share
expect(files.indexOf('/libs/xplat/features/src/lib/ui/directives/active-link.directive.ts')).toBe(-1);
expect(files.indexOf('/libs/xplat/nativescript/features/src/lib/foo/directives/active-link.directive.ts')).toBe(-1);
expect(files.indexOf('/libs/xplat/web/features/src/lib/foo/directives/active-link.directive.ts')).toBe(-1);
// directive should be project specific
expect(files.indexOf('/apps/nativescript-viewer/src/features/foo/directives/active-link.directive.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/apps/web-viewer/src/app/features/foo/directives/active-link.directive.ts')).toBeGreaterThanOrEqual(0);
// file content
let indexPath = '/apps/nativescript-viewer/src/features/foo/directives/index.ts';
let index = (0, testing_1.getFileContent)(tree, indexPath);
// console.log(barrelPath + ':');
// console.log(barrelIndex);
// symbol should be at end of collection
expect(index.indexOf(`ActiveLinkDirective`)).toBeGreaterThanOrEqual(0);
indexPath = '/apps/web-viewer/src/app/features/foo/directives/index.ts';
index = (0, testing_1.getFileContent)(tree, indexPath);
// console.log(barrelPath + ':');
// console.log(barrelIndex);
expect(index.indexOf(`ActiveLinkDirective`)).toBeGreaterThanOrEqual(0);
}));
});
;