UNPKG

@nstudio/angular

Version:

Angular Plugin for xplat

131 lines (130 loc) 7.64 kB
"use strict"; 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('ngrx schematic', () => { let appTree; const defaultOptions = { name: 'auth', }; beforeEach(() => { appTree = schematics_1.Tree.empty(); appTree = (0, testing_1.createXplatWithNativeScriptWeb)(appTree, null, 'angular'); }); it('should create root state in libs 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); const options = Object.assign({}, defaultOptions); options.root = true; tree = yield (0, testing_2.runSchematic)('ngrx', options, tree); const files = tree.files; // console.log(files.slice(91,files.length)); expect(files.indexOf('/libs/xplat/core/src/lib/state/auth.actions.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/libs/xplat/core/src/lib/state/auth.effects.spec.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/libs/xplat/core/src/lib/state/auth.effects.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/libs/xplat/core/src/lib/state/auth.reducer.spec.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/libs/xplat/core/src/lib/state/auth.reducer.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/libs/xplat/core/src/lib/state/auth.state.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/libs/xplat/core/src/lib/state/index.ts')).toBeGreaterThanOrEqual(0); // file content let content = (0, testing_1.getFileContent)(tree, '/libs/xplat/core/src/lib/state/auth.actions.ts'); // console.log(content); expect(content.indexOf(`AuthActions`)).toBeGreaterThanOrEqual(0); expect(content.indexOf(`[@testing/auth] init'`)).toBeGreaterThanOrEqual(0); content = (0, testing_1.getFileContent)(tree, '/libs/xplat/core/src/lib/index.ts'); // console.log('/libs/core/index.ts:', content); expect(content.indexOf(`export * from './state';`)).toBeGreaterThanOrEqual(0); let modulePath = '/libs/xplat/core/src/lib/core.module.ts'; let moduleContent = (0, testing_1.getFileContent)(tree, modulePath); // console.log(modulePath + ':'); // console.log(moduleContent); expect(moduleContent.indexOf(`StoreModule.forRoot`)).toBeGreaterThanOrEqual(0); })); it('should create ngrx state 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: 'auth', feature: 'foo', projects: 'nativescript-viewer,web-viewer', }; tree = yield (0, testing_2.runSchematic)('ngrx', options, tree); const files = tree.files; // console.log(files. slice(91,files.length)); // state should not be setup to share expect(files.indexOf('/libs/xplat/core/src/lib/state/auth.actions.ts')).toBe(-1); expect(files.indexOf('/libs/xplat/nativescript/features/src/lib/foo/state/auth.actions.ts')).toBe(-1); expect(files.indexOf('/libs/xplat/web/features/src/lib/foo/state/auth.actions.ts')).toBe(-1); // state should be project specific expect(files.indexOf('/apps/nativescript-viewer/src/features/foo/state/auth.actions.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/apps/web-viewer/src/app/features/foo/state/auth.actions.ts')).toBeGreaterThanOrEqual(0); // file content let indexPath = '/apps/nativescript-viewer/src/features/foo/state/auth.actions.ts'; let content = (0, testing_1.getFileContent)(tree, indexPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); // symbol should be at end of collection expect(content.indexOf(`AuthActions`)).toBeGreaterThanOrEqual(0); let modulePath = '/apps/nativescript-viewer/src/features/foo/foo.module.ts'; content = (0, testing_1.getFileContent)(tree, modulePath); // console.log(modulePath + ':'); // console.log(content); // symbol should be at end of collection expect(content.indexOf(`StoreModule.forFeature`)).toBeGreaterThanOrEqual(0); indexPath = '/apps/web-viewer/src/app/features/foo/state/auth.actions.ts'; content = (0, testing_1.getFileContent)(tree, indexPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); expect(content.indexOf(`AuthActions`)).toBeGreaterThanOrEqual(0); modulePath = '/apps/web-viewer/src/app/features/foo/foo.module.ts'; content = (0, testing_1.getFileContent)(tree, modulePath); // console.log('content:', content) expect(content.indexOf(`StoreModule.forFeature`)).toBeGreaterThanOrEqual(0); })); it('should create ngrx state for Nx lib only', () => __awaiter(void 0, void 0, void 0, function* () { // console.log('appTree:', appTree); appTree = schematics_1.Tree.empty(); appTree = (0, testing_1.createXplatWithNativeScriptWeb)(appTree, null, 'angular', 'sample'); const options = { name: 'auth', feature: '@testing/sample', }; let tree = yield (0, testing_2.runSchematic)('ngrx', options, appTree); const files = tree.files; // console.log(files. slice(91,files.length)); // state should not be setup in xplat architecture expect(files.indexOf(`/libs/xplat/core/src/lib/state/auth.actions.ts`)).toBe(-1); // state should be lib specific expect(files.indexOf(`/libs/sample/src/lib/state/auth.actions.ts`)).toBeGreaterThanOrEqual(0); // file content let indexPath = `/libs/sample/src/lib/state/auth.actions.ts`; let content = (0, testing_1.getFileContent)(tree, indexPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); // symbol should be at end of collection expect(content.indexOf(`AuthActions`)).toBeGreaterThanOrEqual(0); let modulePath = '/libs/sample/src/lib/sample.module.ts'; content = (0, testing_1.getFileContent)(tree, modulePath); // console.log(modulePath + ':'); // console.log(content); // symbol should be at end of collection expect(content.indexOf(`StoreModule.forFeature`)).toBeGreaterThanOrEqual(0); })); });