diff --git a/src/material/schematics/ng-generate/mdc-migration/rules/components/slider/slider-template.spec.ts b/src/material/schematics/ng-generate/mdc-migration/rules/components/slider/slider-template.spec.ts new file mode 100644 index 000000000000..7640e6d6a418 --- /dev/null +++ b/src/material/schematics/ng-generate/mdc-migration/rules/components/slider/slider-template.spec.ts @@ -0,0 +1,23 @@ +import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing'; +import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; +import {createNewTestRunner, migrateComponents, TEMPLATE_FILE} from '../test-setup-helper'; + +describe('slider template migrator', () => { + let runner: SchematicTestRunner; + let cliAppTree: UnitTestTree; + + async function runMigrationTest(oldFileContent: string, newFileContent: string) { + cliAppTree.overwrite(TEMPLATE_FILE, oldFileContent); + const tree = await migrateComponents(['slider'], runner, cliAppTree); + expect(tree.readContent(TEMPLATE_FILE)).toBe(newFileContent); + } + + beforeEach(async () => { + runner = createNewTestRunner(); + cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner)); + }); + + it('should not update other elements', async () => { + await runMigrationTest('', ''); + }); +}); diff --git a/src/material/schematics/ng-generate/mdc-migration/rules/components/slider/slider-template.ts b/src/material/schematics/ng-generate/mdc-migration/rules/components/slider/slider-template.ts new file mode 100644 index 000000000000..73f9013f0c56 --- /dev/null +++ b/src/material/schematics/ng-generate/mdc-migration/rules/components/slider/slider-template.ts @@ -0,0 +1,28 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import * as compiler from '@angular/compiler'; +import {TemplateMigrator} from '../../template-migrator'; +import {visitElements} from '../../tree-traversal'; +import {Update} from '../../../../../migration-utilities'; + +export class SliderTemplateMigrator extends TemplateMigrator { + getUpdates(ast: compiler.ParsedTemplate): Update[] { + const updates: Update[] = []; + + visitElements(ast.nodes, (node: compiler.TmplAstElement) => { + if (node.name === 'mat-slider') { + updates.push({ + offset: node.sourceSpan.start.offset, + updateFn: (html: string) => html, + }); + } + }); + return updates; + } +} diff --git a/src/material/schematics/ng-generate/mdc-migration/rules/index.ts b/src/material/schematics/ng-generate/mdc-migration/rules/index.ts index ee1ee5fc1c61..cb421900a3fb 100644 --- a/src/material/schematics/ng-generate/mdc-migration/rules/index.ts +++ b/src/material/schematics/ng-generate/mdc-migration/rules/index.ts @@ -35,6 +35,7 @@ import {TooltipStylesMigrator} from './components/tooltip/tooltip-styles'; import {OptgroupStylesMigrator} from './components/optgroup/optgroup-styles'; import {OptionStylesMigrator} from './components/option/option-styles'; import {FormFieldTemplateMigrator} from './components/form-field/form-field-template'; +import {SliderTemplateMigrator} from './components/slider/slider-template'; /** Contains the migrators to migrate a single component. */ export interface ComponentMigrator { @@ -171,6 +172,7 @@ export const MIGRATORS: ComponentMigrator[] = [ { component: 'slider', styles: new SliderStylesMigrator(), + template: new SliderTemplateMigrator(), }, { component: 'snack-bar',