1- import { SchematicTestRunner } from '@angular-devkit/schematics/testing' ;
1+ import { SchematicTestRunner , UnitTestTree } from '@angular-devkit/schematics/testing' ;
22import { createTestApp , getFileContent } from '@angular/cdk/schematics/testing' ;
33
44import { Schema } from './schema' ;
55
6- describe ( 'material-nav -schematic' , ( ) => {
6+ describe ( 'material-navigation -schematic' , ( ) => {
77 let runner : SchematicTestRunner ;
88
99 const baseOptions : Schema = {
@@ -15,9 +15,27 @@ describe('material-nav-schematic', () => {
1515 runner = new SchematicTestRunner ( 'schematics' , require . resolve ( '../../collection.json' ) ) ;
1616 } ) ;
1717
18- it ( 'should create nav files and add them to module' , async ( ) => {
18+ function expectNavigationSchematicModuleImports ( tree : UnitTestTree ) {
19+ const moduleContent = getFileContent ( tree , '/projects/material/src/app/app.module.ts' ) ;
20+ expect ( moduleContent ) . toMatch ( / L a y o u t M o d u l e , \s + / ) ;
21+ expect ( moduleContent ) . toMatch ( / M a t T o o l b a r M o d u l e , \s + / ) ;
22+ expect ( moduleContent ) . toMatch ( / M a t B u t t o n M o d u l e , \s + / ) ;
23+ expect ( moduleContent ) . toMatch ( / M a t S i d e n a v M o d u l e , \s + / ) ;
24+ expect ( moduleContent ) . toMatch ( / M a t I c o n M o d u l e , \s + / ) ;
25+ expect ( moduleContent ) . toMatch ( / M a t L i s t M o d u l e \s + ] ,/ ) ;
26+ expect ( moduleContent ) . toContain ( `import { LayoutModule } from '@angular/cdk/layout';` ) ;
27+ expect ( moduleContent ) . toContain ( `import { MatButtonModule } from '@angular/material/button';` ) ;
28+ expect ( moduleContent ) . toContain ( `import { MatIconModule } from '@angular/material/icon';` ) ;
29+ expect ( moduleContent ) . toContain ( `import { MatListModule } from '@angular/material/list';` ) ;
30+ expect ( moduleContent )
31+ . toContain ( `import { MatToolbarModule } from '@angular/material/toolbar';` ) ;
32+ expect ( moduleContent )
33+ . toContain ( `import { MatSidenavModule } from '@angular/material/sidenav';` ) ;
34+ }
35+
36+ it ( 'should create navigation files and add them to module' , async ( ) => {
1937 const app = await createTestApp ( runner ) ;
20- const tree = await runner . runSchematicAsync ( 'nav ' , baseOptions , app ) . toPromise ( ) ;
38+ const tree = await runner . runSchematicAsync ( 'navigation ' , baseOptions , app ) . toPromise ( ) ;
2139 const files = tree . files ;
2240
2341 expect ( files ) . toContain ( '/projects/material/src/app/foo/foo.component.css' ) ;
@@ -30,34 +48,24 @@ describe('material-nav-schematic', () => {
3048 expect ( moduleContent ) . toMatch ( / d e c l a r a t i o n s : \s * \[ [ ^ \] ] + ?, \r ? \n \s + F o o C o m p o n e n t \r ? \n / m) ;
3149 } ) ;
3250
33- it ( 'should add nav imports to module' , async ( ) => {
51+ it ( 'should add navigation imports to module' , async ( ) => {
3452 const app = await createTestApp ( runner ) ;
35- const tree = await runner . runSchematicAsync ( 'nav' , baseOptions , app ) . toPromise ( ) ;
36- const moduleContent = getFileContent ( tree , '/projects/material/src/app/app.module.ts' ) ;
37-
38- expect ( moduleContent ) . toContain ( 'LayoutModule' ) ;
39- expect ( moduleContent ) . toContain ( 'MatToolbarModule' ) ;
40- expect ( moduleContent ) . toContain ( 'MatButtonModule' ) ;
41- expect ( moduleContent ) . toContain ( 'MatSidenavModule' ) ;
42- expect ( moduleContent ) . toContain ( 'MatIconModule' ) ;
43- expect ( moduleContent ) . toContain ( 'MatListModule' ) ;
53+ const tree = await runner . runSchematicAsync ( 'navigation' , baseOptions , app ) . toPromise ( ) ;
54+ expectNavigationSchematicModuleImports ( tree ) ;
55+ } ) ;
4456
45- expect ( moduleContent ) . toContain ( `import { LayoutModule } from '@angular/cdk/layout';` ) ;
46- expect ( moduleContent ) . toContain ( `import { MatButtonModule } from '@angular/material/button';` ) ;
47- expect ( moduleContent ) . toContain ( `import { MatIconModule } from '@angular/material/icon';` ) ;
48- expect ( moduleContent ) . toContain ( `import { MatListModule } from '@angular/material/list';` ) ;
49- expect ( moduleContent )
50- . toContain ( `import { MatToolbarModule } from '@angular/material/toolbar';` ) ;
51- expect ( moduleContent )
52- . toContain ( `import { MatSidenavModule } from '@angular/material/sidenav';` ) ;
57+ it ( 'should support `nav` as schematic alias' , async ( ) => {
58+ const app = await createTestApp ( runner ) ;
59+ const tree = await runner . runSchematicAsync ( 'nav' , baseOptions , app ) . toPromise ( ) ;
60+ expectNavigationSchematicModuleImports ( tree ) ;
5361 } ) ;
5462
5563 it ( 'should throw if no name has been specified' , async ( ) => {
5664 const appTree = await createTestApp ( runner ) ;
5765 let message : string | null = null ;
5866
5967 try {
60- await runner . runSchematicAsync ( 'nav ' , { project : 'material' } , appTree ) . toPromise ( ) ;
68+ await runner . runSchematicAsync ( 'navigation ' , { project : 'material' } , appTree ) . toPromise ( ) ;
6169 } catch ( e ) {
6270 message = e . message ;
6371 }
@@ -67,39 +75,42 @@ describe('material-nav-schematic', () => {
6775
6876 describe ( 'style option' , ( ) => {
6977 it ( 'should respect the option value' , async ( ) => {
70- const tree = await runner
71- . runSchematicAsync (
72- 'nav' , { style : 'scss' , ...baseOptions } , await createTestApp ( runner ) )
73- . toPromise ( ) ;
78+ const tree =
79+ await runner
80+ . runSchematicAsync (
81+ 'navigation' , { style : 'scss' , ...baseOptions } , await createTestApp ( runner ) )
82+ . toPromise ( ) ;
7483
7584 expect ( tree . files ) . toContain ( '/projects/material/src/app/foo/foo.component.scss' ) ;
7685 } ) ;
7786
7887 it ( 'should fall back to the @schematics/angular:component option value' , async ( ) => {
79- const tree =
80- await runner
81- . runSchematicAsync ( 'nav ', baseOptions , await createTestApp ( runner , { style : 'less' } ) )
82- . toPromise ( ) ;
88+ const tree = await runner
89+ . runSchematicAsync (
90+ 'navigation ', baseOptions , await createTestApp ( runner , { style : 'less' } ) )
91+ . toPromise ( ) ;
8392
8493 expect ( tree . files ) . toContain ( '/projects/material/src/app/foo/foo.component.less' ) ;
8594 } ) ;
8695 } ) ;
8796
8897 describe ( 'inlineStyle option' , ( ) => {
8998 it ( 'should respect the option value' , async ( ) => {
90- const tree = await runner
91- . runSchematicAsync (
92- 'nav' , { inlineStyle : true , ...baseOptions } , await createTestApp ( runner ) )
93- . toPromise ( ) ;
99+ const tree =
100+ await runner
101+ . runSchematicAsync (
102+ 'navigation' , { inlineStyle : true , ...baseOptions } , await createTestApp ( runner ) )
103+ . toPromise ( ) ;
94104
95105 expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.css' ) ;
96106 } ) ;
97107
98108 it ( 'should fall back to the @schematics/angular:component option value' , async ( ) => {
99- const tree = await runner
100- . runSchematicAsync (
101- 'nav' , baseOptions , await createTestApp ( runner , { inlineStyle : true } ) )
102- . toPromise ( ) ;
109+ const tree =
110+ await runner
111+ . runSchematicAsync (
112+ 'navigation' , baseOptions , await createTestApp ( runner , { inlineStyle : true } ) )
113+ . toPromise ( ) ;
103114
104115 expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.css' ) ;
105116 } ) ;
@@ -110,36 +121,39 @@ describe('material-nav-schematic', () => {
110121 const tree =
111122 await runner
112123 . runSchematicAsync (
113- 'nav ' , { inlineTemplate : true , ...baseOptions } , await createTestApp ( runner ) )
124+ 'navigation ' , { inlineTemplate : true , ...baseOptions } , await createTestApp ( runner ) )
114125 . toPromise ( ) ;
115126
116127 expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.html' ) ;
117128 } ) ;
118129
119130 it ( 'should fall back to the @schematics/angular:component option value' , async ( ) => {
120- const tree = await runner
121- . runSchematicAsync (
122- 'nav' , baseOptions , await createTestApp ( runner , { inlineTemplate : true } ) )
123- . toPromise ( ) ;
131+ const tree =
132+ await runner
133+ . runSchematicAsync (
134+ 'navigation' , baseOptions , await createTestApp ( runner , { inlineTemplate : true } ) )
135+ . toPromise ( ) ;
124136
125137 expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.html' ) ;
126138 } ) ;
127139 } ) ;
128140
129141 describe ( 'skipTests option' , ( ) => {
130142 it ( 'should respect the option value' , async ( ) => {
131- const tree = await runner
132- . runSchematicAsync (
133- 'nav' , { skipTests : true , ...baseOptions } , await createTestApp ( runner ) )
134- . toPromise ( ) ;
143+ const tree =
144+ await runner
145+ . runSchematicAsync (
146+ 'navigation' , { skipTests : true , ...baseOptions } , await createTestApp ( runner ) )
147+ . toPromise ( ) ;
135148
136149 expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.spec.ts' ) ;
137150 } ) ;
138151
139152 it ( 'should fall back to the @schematics/angular:component option value' , async ( ) => {
140153 const tree =
141154 await runner
142- . runSchematicAsync ( 'nav' , baseOptions , await createTestApp ( runner , { skipTests : true } ) )
155+ . runSchematicAsync (
156+ 'navigation' , baseOptions , await createTestApp ( runner , { skipTests : true } ) )
143157 . toPromise ( ) ;
144158
145159 expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.spec.ts' ) ;
0 commit comments