File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
src/material/schematics/ng-generate/mdc-migration/rules Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { createTestApp , patchDevkitTreeToExposeTypeScript } from '@angular/cdk/schematics/testing' ;
2
+ import { SchematicTestRunner , UnitTestTree } from '@angular-devkit/schematics/testing' ;
3
+ import { createNewTestRunner , migrateComponents , TEMPLATE_FILE } from '../test-setup-helper' ;
4
+
5
+ describe ( 'slider template migrator' , ( ) => {
6
+ let runner : SchematicTestRunner ;
7
+ let cliAppTree : UnitTestTree ;
8
+
9
+ async function runMigrationTest ( oldFileContent : string , newFileContent : string ) {
10
+ cliAppTree . overwrite ( TEMPLATE_FILE , oldFileContent ) ;
11
+ const tree = await migrateComponents ( [ 'slider' ] , runner , cliAppTree ) ;
12
+ expect ( tree . readContent ( TEMPLATE_FILE ) ) . toBe ( newFileContent ) ;
13
+ }
14
+
15
+ beforeEach ( async ( ) => {
16
+ runner = createNewTestRunner ( ) ;
17
+ cliAppTree = patchDevkitTreeToExposeTypeScript ( await createTestApp ( runner ) ) ;
18
+ } ) ;
19
+
20
+ it ( 'should not update other elements' , async ( ) => {
21
+ await runMigrationTest ( '<mat-button></mat-button>' , '<mat-button></mat-button>' ) ;
22
+ } ) ;
23
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+
9
+ import * as compiler from '@angular/compiler' ;
10
+ import { TemplateMigrator } from '../../template-migrator' ;
11
+ import { visitElements } from '../../tree-traversal' ;
12
+ import { Update } from '../../../../../migration-utilities' ;
13
+
14
+ export class SliderTemplateMigrator extends TemplateMigrator {
15
+ getUpdates ( ast : compiler . ParsedTemplate ) : Update [ ] {
16
+ const updates : Update [ ] = [ ] ;
17
+
18
+ visitElements ( ast . nodes , ( node : compiler . TmplAstElement ) => {
19
+ if ( node . name === 'mat-slider' ) {
20
+ updates . push ( {
21
+ offset : node . sourceSpan . start . offset ,
22
+ updateFn : ( html : string ) => html ,
23
+ } ) ;
24
+ }
25
+ } ) ;
26
+ return updates ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import {TooltipStylesMigrator} from './components/tooltip/tooltip-styles';
35
35
import { OptgroupStylesMigrator } from './components/optgroup/optgroup-styles' ;
36
36
import { OptionStylesMigrator } from './components/option/option-styles' ;
37
37
import { FormFieldTemplateMigrator } from './components/form-field/form-field-template' ;
38
+ import { SliderTemplateMigrator } from './components/slider/slider-template' ;
38
39
39
40
/** Contains the migrators to migrate a single component. */
40
41
export interface ComponentMigrator {
@@ -171,6 +172,7 @@ export const MIGRATORS: ComponentMigrator[] = [
171
172
{
172
173
component : 'slider' ,
173
174
styles : new SliderStylesMigrator ( ) ,
175
+ template : new SliderTemplateMigrator ( ) ,
174
176
} ,
175
177
{
176
178
component : 'snack-bar' ,
You can’t perform that action at this time.
0 commit comments