Skip to content

refactor: rename nav schematic to navigation #18364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion guides/schematics.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ a toolbar with the app name and a responsive side nav based on Material
breakpoints.

```
ng generate @angular/material:nav <component-name>
ng generate @angular/material:navigation <component-name>
```

#### Table schematic
Expand Down
8 changes: 4 additions & 4 deletions src/material/schematics/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"aliases": ["material-table"]
},
// Creates toolbar and navigation components
"nav": {
"navigation": {
"description": "Create a component with a responsive sidenav for navigation",
"factory": "./ng-generate/nav/index",
"schema": "./ng-generate/nav/schema.json",
"aliases": ["material-nav", "materialNav"]
"factory": "./ng-generate/navigation/index",
"schema": "./ng-generate/navigation/schema.json",
"aliases": ["material-nav", "materialNav", "nav"]
},
// Create a file tree component
"tree": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
import {createTestApp, getFileContent} from '@angular/cdk/schematics/testing';

import {Schema} from './schema';

describe('material-nav-schematic', () => {
describe('material-navigation-schematic', () => {
let runner: SchematicTestRunner;

const baseOptions: Schema = {
Expand All @@ -15,9 +15,27 @@ describe('material-nav-schematic', () => {
runner = new SchematicTestRunner('schematics', require.resolve('../../collection.json'));
});

it('should create nav files and add them to module', async () => {
function expectNavigationSchematicModuleImports(tree: UnitTestTree) {
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
expect(moduleContent).toMatch(/LayoutModule,\s+/);
expect(moduleContent).toMatch(/MatToolbarModule,\s+/);
expect(moduleContent).toMatch(/MatButtonModule,\s+/);
expect(moduleContent).toMatch(/MatSidenavModule,\s+/);
expect(moduleContent).toMatch(/MatIconModule,\s+/);
expect(moduleContent).toMatch(/MatListModule\s+],/);
expect(moduleContent).toContain(`import { LayoutModule } from '@angular/cdk/layout';`);
expect(moduleContent).toContain(`import { MatButtonModule } from '@angular/material/button';`);
expect(moduleContent).toContain(`import { MatIconModule } from '@angular/material/icon';`);
expect(moduleContent).toContain(`import { MatListModule } from '@angular/material/list';`);
expect(moduleContent)
.toContain(`import { MatToolbarModule } from '@angular/material/toolbar';`);
expect(moduleContent)
.toContain(`import { MatSidenavModule } from '@angular/material/sidenav';`);
}

it('should create navigation files and add them to module', async () => {
const app = await createTestApp(runner);
const tree = await runner.runSchematicAsync('nav', baseOptions, app).toPromise();
const tree = await runner.runSchematicAsync('navigation', baseOptions, app).toPromise();
const files = tree.files;

expect(files).toContain('/projects/material/src/app/foo/foo.component.css');
Expand All @@ -30,34 +48,24 @@ describe('material-nav-schematic', () => {
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooComponent\r?\n/m);
});

it('should add nav imports to module', async () => {
it('should add navigation imports to module', async () => {
const app = await createTestApp(runner);
const tree = await runner.runSchematicAsync('nav', baseOptions, app).toPromise();
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');

expect(moduleContent).toContain('LayoutModule');
expect(moduleContent).toContain('MatToolbarModule');
expect(moduleContent).toContain('MatButtonModule');
expect(moduleContent).toContain('MatSidenavModule');
expect(moduleContent).toContain('MatIconModule');
expect(moduleContent).toContain('MatListModule');
const tree = await runner.runSchematicAsync('navigation', baseOptions, app).toPromise();
expectNavigationSchematicModuleImports(tree);
});

expect(moduleContent).toContain(`import { LayoutModule } from '@angular/cdk/layout';`);
expect(moduleContent).toContain(`import { MatButtonModule } from '@angular/material/button';`);
expect(moduleContent).toContain(`import { MatIconModule } from '@angular/material/icon';`);
expect(moduleContent).toContain(`import { MatListModule } from '@angular/material/list';`);
expect(moduleContent)
.toContain(`import { MatToolbarModule } from '@angular/material/toolbar';`);
expect(moduleContent)
.toContain(`import { MatSidenavModule } from '@angular/material/sidenav';`);
it('should support `nav` as schematic alias', async () => {
const app = await createTestApp(runner);
const tree = await runner.runSchematicAsync('nav', baseOptions, app).toPromise();
expectNavigationSchematicModuleImports(tree);
});

it('should throw if no name has been specified', async () => {
const appTree = await createTestApp(runner);
let message: string|null = null;

try {
await runner.runSchematicAsync('nav', {project: 'material'}, appTree).toPromise();
await runner.runSchematicAsync('navigation', {project: 'material'}, appTree).toPromise();
} catch (e) {
message = e.message;
}
Expand All @@ -67,39 +75,42 @@ describe('material-nav-schematic', () => {

describe('style option', () => {
it('should respect the option value', async () => {
const tree = await runner
.runSchematicAsync(
'nav', {style: 'scss', ...baseOptions}, await createTestApp(runner))
.toPromise();
const tree =
await runner
.runSchematicAsync(
'navigation', {style: 'scss', ...baseOptions}, await createTestApp(runner))
.toPromise();

expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
});

it('should fall back to the @schematics/angular:component option value', async () => {
const tree =
await runner
.runSchematicAsync('nav', baseOptions, await createTestApp(runner, {style: 'less'}))
.toPromise();
const tree = await runner
.runSchematicAsync(
'navigation', baseOptions, await createTestApp(runner, {style: 'less'}))
.toPromise();

expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.less');
});
});

describe('inlineStyle option', () => {
it('should respect the option value', async () => {
const tree = await runner
.runSchematicAsync(
'nav', {inlineStyle: true, ...baseOptions}, await createTestApp(runner))
.toPromise();
const tree =
await runner
.runSchematicAsync(
'navigation', {inlineStyle: true, ...baseOptions}, await createTestApp(runner))
.toPromise();

expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
});

it('should fall back to the @schematics/angular:component option value', async () => {
const tree = await runner
.runSchematicAsync(
'nav', baseOptions, await createTestApp(runner, {inlineStyle: true}))
.toPromise();
const tree =
await runner
.runSchematicAsync(
'navigation', baseOptions, await createTestApp(runner, {inlineStyle: true}))
.toPromise();

expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
});
Expand All @@ -110,36 +121,39 @@ describe('material-nav-schematic', () => {
const tree =
await runner
.runSchematicAsync(
'nav', {inlineTemplate: true, ...baseOptions}, await createTestApp(runner))
'navigation', {inlineTemplate: true, ...baseOptions}, await createTestApp(runner))
.toPromise();

expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
});

it('should fall back to the @schematics/angular:component option value', async () => {
const tree = await runner
.runSchematicAsync(
'nav', baseOptions, await createTestApp(runner, {inlineTemplate: true}))
.toPromise();
const tree =
await runner
.runSchematicAsync(
'navigation', baseOptions, await createTestApp(runner, {inlineTemplate: true}))
.toPromise();

expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
});
});

describe('skipTests option', () => {
it('should respect the option value', async () => {
const tree = await runner
.runSchematicAsync(
'nav', {skipTests: true, ...baseOptions}, await createTestApp(runner))
.toPromise();
const tree =
await runner
.runSchematicAsync(
'navigation', {skipTests: true, ...baseOptions}, await createTestApp(runner))
.toPromise();

expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
});

it('should fall back to the @schematics/angular:component option value', async () => {
const tree =
await runner
.runSchematicAsync('nav', baseOptions, await createTestApp(runner, {skipTests: true}))
.runSchematicAsync(
'navigation', baseOptions, await createTestApp(runner, {skipTests: true}))
.toPromise();

expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/schema",
"id": "SchematicsMaterialNav",
"title": "Material Nav Options Schema",
"id": "SchematicsMaterialNavigation",
"title": "Material Navigation Options Schema",
"type": "object",
"properties": {
"path": {
Expand Down