Skip to content

Commit 1f62724

Browse files
authored
fix(material/schematics): initialize slider template migrator (#25898)
1 parent a273032 commit 1f62724

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

src/material/schematics/ng-generate/mdc-migration/rules/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {TooltipStylesMigrator} from './components/tooltip/tooltip-styles';
3535
import {OptgroupStylesMigrator} from './components/optgroup/optgroup-styles';
3636
import {OptionStylesMigrator} from './components/option/option-styles';
3737
import {FormFieldTemplateMigrator} from './components/form-field/form-field-template';
38+
import {SliderTemplateMigrator} from './components/slider/slider-template';
3839

3940
/** Contains the migrators to migrate a single component. */
4041
export interface ComponentMigrator {
@@ -171,6 +172,7 @@ export const MIGRATORS: ComponentMigrator[] = [
171172
{
172173
component: 'slider',
173174
styles: new SliderStylesMigrator(),
175+
template: new SliderTemplateMigrator(),
174176
},
175177
{
176178
component: 'snack-bar',

0 commit comments

Comments
 (0)