1
- import { SchematicTestRunner } from '@angular-devkit/schematics/testing' ;
1
+ import { SchematicTestRunner , UnitTestTree } from '@angular-devkit/schematics/testing' ;
2
2
import { createTestApp , getFileContent } from '@angular/cdk/schematics/testing' ;
3
3
4
4
import { Schema } from './schema' ;
5
5
6
- describe ( 'material-nav -schematic' , ( ) => {
6
+ describe ( 'material-navigation -schematic' , ( ) => {
7
7
let runner : SchematicTestRunner ;
8
8
9
9
const baseOptions : Schema = {
@@ -15,9 +15,27 @@ describe('material-nav-schematic', () => {
15
15
runner = new SchematicTestRunner ( 'schematics' , require . resolve ( '../../collection.json' ) ) ;
16
16
} ) ;
17
17
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 ( ) => {
19
37
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 ( ) ;
21
39
const files = tree . files ;
22
40
23
41
expect ( files ) . toContain ( '/projects/material/src/app/foo/foo.component.css' ) ;
@@ -30,34 +48,24 @@ describe('material-nav-schematic', () => {
30
48
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) ;
31
49
} ) ;
32
50
33
- it ( 'should add nav imports to module' , async ( ) => {
51
+ it ( 'should add navigation imports to module' , async ( ) => {
34
52
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
+ } ) ;
44
56
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 ) ;
53
61
} ) ;
54
62
55
63
it ( 'should throw if no name has been specified' , async ( ) => {
56
64
const appTree = await createTestApp ( runner ) ;
57
65
let message : string | null = null ;
58
66
59
67
try {
60
- await runner . runSchematicAsync ( 'nav ' , { project : 'material' } , appTree ) . toPromise ( ) ;
68
+ await runner . runSchematicAsync ( 'navigation ' , { project : 'material' } , appTree ) . toPromise ( ) ;
61
69
} catch ( e ) {
62
70
message = e . message ;
63
71
}
@@ -67,39 +75,42 @@ describe('material-nav-schematic', () => {
67
75
68
76
describe ( 'style option' , ( ) => {
69
77
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 ( ) ;
74
83
75
84
expect ( tree . files ) . toContain ( '/projects/material/src/app/foo/foo.component.scss' ) ;
76
85
} ) ;
77
86
78
87
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 ( ) ;
83
92
84
93
expect ( tree . files ) . toContain ( '/projects/material/src/app/foo/foo.component.less' ) ;
85
94
} ) ;
86
95
} ) ;
87
96
88
97
describe ( 'inlineStyle option' , ( ) => {
89
98
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 ( ) ;
94
104
95
105
expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.css' ) ;
96
106
} ) ;
97
107
98
108
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 ( ) ;
103
114
104
115
expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.css' ) ;
105
116
} ) ;
@@ -110,36 +121,39 @@ describe('material-nav-schematic', () => {
110
121
const tree =
111
122
await runner
112
123
. runSchematicAsync (
113
- 'nav ' , { inlineTemplate : true , ...baseOptions } , await createTestApp ( runner ) )
124
+ 'navigation ' , { inlineTemplate : true , ...baseOptions } , await createTestApp ( runner ) )
114
125
. toPromise ( ) ;
115
126
116
127
expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.html' ) ;
117
128
} ) ;
118
129
119
130
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 ( ) ;
124
136
125
137
expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.html' ) ;
126
138
} ) ;
127
139
} ) ;
128
140
129
141
describe ( 'skipTests option' , ( ) => {
130
142
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 ( ) ;
135
148
136
149
expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.spec.ts' ) ;
137
150
} ) ;
138
151
139
152
it ( 'should fall back to the @schematics/angular:component option value' , async ( ) => {
140
153
const tree =
141
154
await runner
142
- . runSchematicAsync ( 'nav' , baseOptions , await createTestApp ( runner , { skipTests : true } ) )
155
+ . runSchematicAsync (
156
+ 'navigation' , baseOptions , await createTestApp ( runner , { skipTests : true } ) )
143
157
. toPromise ( ) ;
144
158
145
159
expect ( tree . files ) . not . toContain ( '/projects/material/src/app/foo/foo.component.spec.ts' ) ;
0 commit comments