import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { getFileContent } from '@schematics/angular/utility/test'; import { createTestApp } from '../../utils/testing'; import { Schema } from './schema'; describe('PrimrNG sidebar', () => { let runner: SchematicTestRunner; const baseOptions: Schema = { name: 'foo', project: 'prime-ng', }; beforeEach(() => { runner = new SchematicTestRunner('schematics', require.resolve('../../collection.json')); }); it('should create sidebar files and add them to module', () => { const tree = runner.runSchematic('primengSidebar', { ...baseOptions }, createTestApp()); const files = tree.files; expect(files).toContain('/src/app/foo/foo.component.css'); expect(files).toContain('/src/app/foo/foo.component.html'); expect(files).toContain('/src/app/foo/foo.component.spec.ts'); expect(files).toContain('/src/app/foo/foo.component.ts'); const moduleContent = getFileContent(tree, '/src/app/app.module.ts'); expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo\/foo.component'/); expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooComponent\r?\n/m); }); it('should add sidebar imports to module', () => { const tree = runner.runSchematic('primengSidebar', { ...baseOptions }, createTestApp()); const moduleContent = getFileContent(tree, '/src/app/app.module.ts'); expect(moduleContent).toContain('SidebarModule'); expect(moduleContent).toContain('ButtonModule'); }); });