Skip to content

Commit 447ca71

Browse files
authored
refactor: rename nav schematic to navigation (#18364)
Our docs often describe the `nav` schematic as `navigation` schematics, and it's not quite clear what the actual schematic name is. To avoid this confusion, we just name it `navigation`, but keep support for the old `nav` abbreviation.
1 parent 2fc488c commit 447ca71

File tree

10 files changed

+70
-56
lines changed

10 files changed

+70
-56
lines changed

guides/schematics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ a toolbar with the app name and a responsive side nav based on Material
7272
breakpoints.
7373

7474
```
75-
ng generate @angular/material:nav <component-name>
75+
ng generate @angular/material:navigation <component-name>
7676
```
7777

7878
#### Table schematic

src/material/schematics/collection.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
"aliases": ["material-table"]
3131
},
3232
// Creates toolbar and navigation components
33-
"nav": {
33+
"navigation": {
3434
"description": "Create a component with a responsive sidenav for navigation",
35-
"factory": "./ng-generate/nav/index",
36-
"schema": "./ng-generate/nav/schema.json",
37-
"aliases": ["material-nav", "materialNav"]
35+
"factory": "./ng-generate/navigation/index",
36+
"schema": "./ng-generate/navigation/schema.json",
37+
"aliases": ["material-nav", "materialNav", "nav"]
3838
},
3939
// Create a file tree component
4040
"tree": {

src/material/schematics/ng-generate/nav/index.spec.ts renamed to src/material/schematics/ng-generate/navigation/index.spec.ts

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
1+
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
22
import {createTestApp, getFileContent} from '@angular/cdk/schematics/testing';
33

44
import {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(/LayoutModule,\s+/);
21+
expect(moduleContent).toMatch(/MatToolbarModule,\s+/);
22+
expect(moduleContent).toMatch(/MatButtonModule,\s+/);
23+
expect(moduleContent).toMatch(/MatSidenavModule,\s+/);
24+
expect(moduleContent).toMatch(/MatIconModule,\s+/);
25+
expect(moduleContent).toMatch(/MatListModule\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(/declarations:\s*\[[^\]]+?,\r?\n\s+FooComponent\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');

src/material/schematics/ng-generate/nav/schema.json renamed to src/material/schematics/ng-generate/navigation/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "http://json-schema.org/schema",
3-
"id": "SchematicsMaterialNav",
4-
"title": "Material Nav Options Schema",
3+
"id": "SchematicsMaterialNavigation",
4+
"title": "Material Navigation Options Schema",
55
"type": "object",
66
"properties": {
77
"path": {

0 commit comments

Comments
 (0)