11import { SchematicTestRunner , UnitTestTree } from '@angular-devkit/schematics/testing' ;
22import { Schema as WorkspaceOptions } from '@schematics/angular/workspace/schema' ;
3+ import {
4+ NodeDependencyType ,
5+ addPackageJsonDependency ,
6+ removePackageJsonDependency
7+ } from '@schematics/angular/utility/dependencies' ;
38import * as path from 'path' ;
49
510import { modifyJSONFile } from '../utility/modify-json-file' ;
@@ -32,14 +37,14 @@ describe('layout', () => {
3237 const schematicRunner = new SchematicTestRunner ( '@schematics/angular' , angularSchematicsCollection ) ;
3338 let appTree : UnitTestTree ;
3439
35- beforeEach ( ( ) => {
36- appTree = schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
37- appTree = schematicRunner . runSchematic ( 'application' , appOptions , appTree ) ;
40+ beforeEach ( async ( ) => {
41+ appTree = await schematicRunner . runSchematicAsync ( 'workspace' , workspaceOptions ) . toPromise ( ) ;
42+ appTree = await schematicRunner . runSchematicAsync ( 'application' , appOptions , appTree ) . toPromise ( ) ;
3843 } ) ;
3944
40- it ( 'should add layout with override' , ( ) => {
45+ it ( 'should add layout with override' , async ( ) => {
4146 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
42- const tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
47+ const tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
4348
4449 expect ( tree . files )
4550 . toContain ( '/devextreme.json' ) ;
@@ -106,17 +111,37 @@ describe('layout', () => {
106111 expect ( appContent ) . toContain ( 'styleUrls: [\'./app.component.scss\']' ) ;
107112 expect ( appContent ) . toContain ( 'selector: \'app-root\',' ) ;
108113 expect ( appContent ) . toContain ( `import { AuthService, ScreenService, AppInfoService } from './shared/services';` ) ;
114+
115+ const navigationMenu = tree . readContent (
116+ '/src/app/shared/components/side-navigation-menu/side-navigation-menu.component.ts' ) ;
117+ expect ( navigationMenu ) . toContain ( '@ViewChild(DxTreeViewComponent, { static: true })' ) ;
109118 } ) ;
110119
111- it ( 'should add npm scripts' , ( ) => {
120+ it ( 'should add npm scripts' , async ( ) => {
112121 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
113- const tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
122+ const tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
114123 const packageConfig = JSON . parse ( tree . readContent ( 'package.json' ) ) ;
115124 expect ( packageConfig . scripts [ 'build-themes' ] ) . toBe ( 'devextreme build' ) ;
116125 expect ( packageConfig . scripts [ 'postinstall' ] ) . toBe ( 'npm run build-themes' ) ;
117126 } ) ;
118127
119- it ( 'should add npm scripts safely' , ( ) => {
128+ it ( 'should set static flag' , async ( ) => {
129+ removePackageJsonDependency ( appTree , '@angular/core' ) ;
130+ addPackageJsonDependency ( appTree , {
131+ type : NodeDependencyType . Default ,
132+ name : '@angular/core' ,
133+ version : '7.0.0'
134+ } ) ;
135+
136+ const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
137+ const tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
138+ const navigationMenu = tree . readContent (
139+ '/src/app/shared/components/side-navigation-menu/side-navigation-menu.component.ts' ) ;
140+
141+ expect ( navigationMenu ) . toContain ( '@ViewChild(DxTreeViewComponent)' ) ;
142+ } ) ;
143+
144+ it ( 'should add npm scripts safely' , async ( ) => {
120145 modifyJSONFile ( appTree , './package.json' , config => {
121146 const scripts = config [ 'scripts' ] ;
122147
@@ -127,28 +152,28 @@ describe('layout', () => {
127152 } ) ;
128153
129154 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
130- const tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
155+ const tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
131156 const packageConfig = JSON . parse ( tree . readContent ( 'package.json' ) ) ;
132157 expect ( packageConfig . scripts [ 'origin-build-themes' ] ) . toBe ( 'prev value 1' ) ;
133158 expect ( packageConfig . scripts [ 'origin-postinstall' ] ) . toBe ( 'prev value 2' ) ;
134159 expect ( packageConfig . scripts [ 'build-themes' ] ) . toBe ( 'npm run origin-build-themes && devextreme build' ) ;
135160 expect ( packageConfig . scripts [ 'postinstall' ] ) . toBe ( 'npm run origin-postinstall && npm run build-themes' ) ;
136161 } ) ;
137162
138- it ( 'should add angular/cdk dependency' , ( ) => {
163+ it ( 'should add angular/cdk dependency' , async ( ) => {
139164 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
140- const tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
165+ const tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
141166 const packageConfig = JSON . parse ( tree . readContent ( 'package.json' ) ) ;
142167
143168 expect ( packageConfig . dependencies [ '@angular/cdk' ] ) . toBeDefined ( ) ;
144169 } ) ;
145170
146- it ( 'should update budgets if updateBudgets option is true' , ( ) => {
171+ it ( 'should update budgets if updateBudgets option is true' , async ( ) => {
147172 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
148- const tree = runner . runSchematic ( 'add-layout' , {
173+ const tree = await runner . runSchematicAsync ( 'add-layout' , {
149174 ...options ,
150175 updateBudgets : true
151- } , appTree ) ;
176+ } , appTree ) . toPromise ( ) ;
152177
153178 const angularContent = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
154179 const budgets = angularContent . projects . testApp . architect . build . configurations . production . budgets ;
@@ -161,9 +186,9 @@ describe('layout', () => {
161186 } ) ;
162187 } ) ;
163188
164- it ( 'should not update budgets if updateBudgets option is not defined or false' , ( ) => {
189+ it ( 'should not update budgets if updateBudgets option is not defined or false' , async ( ) => {
165190 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
166- const tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
191+ const tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
167192
168193 const angularContent = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
169194 const budgets = angularContent . projects . testApp . architect . build . configurations . production . budgets ;
@@ -177,11 +202,11 @@ describe('layout', () => {
177202 expect ( budgets [ 0 ] ) . toEqual ( defaultBudget ) ;
178203 } ) ;
179204
180- it ( 'should add layout without override' , ( ) => {
205+ it ( 'should add layout without override' , async ( ) => {
181206 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
182207
183208 options . resolveConflicts = 'createNew' ;
184- const tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
209+ const tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
185210
186211 expect ( tree . files ) . toContain ( '/src/app/app1.component.ts' ) ;
187212
@@ -201,14 +226,15 @@ describe('layout', () => {
201226 expect ( appInfo ) . toContain ( `return 'TestApp';` ) ;
202227 } ) ;
203228
204- it ( 'should add routing to layout' , ( ) => {
205- let newAppTree = schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
229+ it ( 'should add routing to layout' , async ( ) => {
230+ let newAppTree = await schematicRunner . runSchematicAsync ( 'workspace' , workspaceOptions ) . toPromise ( ) ;
206231
207232 appOptions . routing = false ;
208- newAppTree = schematicRunner . runSchematic ( 'application' , appOptions , newAppTree ) ;
233+ newAppTree = await schematicRunner . runSchematicAsync (
234+ 'application' , appOptions , newAppTree ) . toPromise ( ) ;
209235
210236 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
211- const tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
237+ const tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
212238
213239 expect ( tree . files ) . toContain ( '/src/app/app-routing.module.ts' ) ;
214240 const moduleContent = tree . readContent ( '/src/app/app-routing.module.ts' ) ;
@@ -223,49 +249,49 @@ describe('layout', () => {
223249 }` ) ;
224250 } ) ;
225251
226- it ( 'should use selected layout' , ( ) => {
252+ it ( 'should use selected layout' , async ( ) => {
227253 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
228254 options . layout = 'side-nav-inner-toolbar' ;
229255 options . resolveConflicts = 'override' ;
230- const tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
256+ const tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
231257 const content = tree . readContent ( '/src/app/app.component.html' ) ;
232258
233259 expect ( content ) . toContain ( 'app-side-nav-inner-toolbar title="{{appInfo.title}}"' ) ;
234260 } ) ;
235261
236- it ( 'should consider the `project` option' , ( ) => {
237- appTree = schematicRunner . runSchematic ( 'application' , {
262+ it ( 'should consider the `project` option' , async ( ) => {
263+ appTree = await schematicRunner . runSchematicAsync ( 'application' , {
238264 ...appOptions ,
239265 name : 'testApp2' ,
240266 projectRoot : 'projects/testApp2'
241- } , appTree ) ;
267+ } , appTree ) . toPromise ( ) ;
242268
243269 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
244- const tree = runner . runSchematic ( 'add-layout' , {
270+ const tree = await runner . runSchematicAsync ( 'add-layout' , {
245271 ...options ,
246272 project : 'testApp2'
247- } , appTree ) ;
273+ } , appTree ) . toPromise ( ) ;
248274
249275 expect ( tree . files )
250276 . toContain ( '/devextreme.json' ) ;
251277 expect ( tree . files )
252278 . toContain ( '/projects/testApp2/src/themes/metadata.base.json' ) ;
253279 } ) ;
254280
255- it ( 'should merge build commands in devextreme.json file' , ( ) => {
256- appTree = schematicRunner . runSchematic ( 'application' , {
281+ it ( 'should merge build commands in devextreme.json file' , async ( ) => {
282+ appTree = await schematicRunner . runSchematicAsync ( 'application' , {
257283 ...appOptions ,
258284 name : 'testApp2' ,
259285 prefix : 'app2' ,
260286 projectRoot : 'projects/testApp2'
261- } , appTree ) ;
287+ } , appTree ) . toPromise ( ) ;
262288
263289 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
264- let tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
265- tree = runner . runSchematic ( 'add-layout' , {
290+ let tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
291+ tree = await runner . runSchematicAsync ( 'add-layout' , {
266292 ...options ,
267293 project : 'testApp2'
268- } , appTree ) ;
294+ } , appTree ) . toPromise ( ) ;
269295
270296 const appContent = tree . readContent ( 'projects/testApp2/src/app/app.component.ts' ) ;
271297 expect ( appContent ) . toContain ( 'selector: \'app2-root\',' ) ;
@@ -275,19 +301,19 @@ describe('layout', () => {
275301 expect ( content ) . toContain ( '"inputFile": "projects/testApp2/src/themes/metadata.base.json",' ) ;
276302 } ) ;
277303
278- it ( 'should add e2e tests only for default project' , ( ) => {
279- appTree = schematicRunner . runSchematic ( 'application' , {
304+ it ( 'should add e2e tests only for default project' , async ( ) => {
305+ appTree = await schematicRunner . runSchematicAsync ( 'application' , {
280306 ...appOptions ,
281307 name : 'testApp2' ,
282308 projectRoot : 'projects/testApp2'
283- } , appTree ) ;
309+ } , appTree ) . toPromise ( ) ;
284310
285311 const runner = new SchematicTestRunner ( 'schematics' , collectionPath ) ;
286- let tree = runner . runSchematic ( 'add-layout' , options , appTree ) ;
287- tree = runner . runSchematic ( 'add-layout' , {
312+ let tree = await runner . runSchematicAsync ( 'add-layout' , options , appTree ) . toPromise ( ) ;
313+ tree = await runner . runSchematicAsync ( 'add-layout' , {
288314 ...options ,
289315 project : 'testApp2'
290- } , appTree ) ;
316+ } , appTree ) . toPromise ( ) ;
291317
292318 const testContent = tree . readContent ( '/e2e/src/app.e2e-spec.ts' ) ;
293319 expect ( testContent ) . toContain ( 'Welcome to TestApp!' ) ;
0 commit comments