-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(material/schematics): fix various issues with mdc-migration (#25772)
* fix(material/schematics): add missing material/core transforms * test(material/schematics): fix integration test diff output * fix(material/schematics): delete legacy mixin when migrating if new mixin is already present * fix(material/schematics): handle form-field appearance * test(material/schematics): fix test errors in mdc migration sample app * test(material/schematics): verify golden builds and doesn't contain 'legacy'
- Loading branch information
Showing
27 changed files
with
367 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ion/sample-project/src/app/components/progress-spinner/progress-spinner.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...c-migration/sample-project/src/app/components/slide-toggle/slide-toggle.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ion/mdc-migration/sample-project/src/app/components/snack-bar/snack-bar.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
integration/mdc-migration/sample-project/src/app/components/table/table.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
integration/mdc-migration/sample-project/src/app/components/tabs/tabs.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ematics/ng-generate/mdc-migration/rules/components/form-field/form-field-template.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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('form-field template migrator', () => { | ||
let runner: SchematicTestRunner; | ||
let cliAppTree: UnitTestTree; | ||
|
||
async function runMigrationTest(oldFileContent: string, newFileContent: string) { | ||
cliAppTree.overwrite(TEMPLATE_FILE, oldFileContent); | ||
const tree = await migrateComponents(['form-field'], runner, cliAppTree); | ||
expect(tree.readContent(TEMPLATE_FILE)).toBe(newFileContent); | ||
} | ||
|
||
beforeEach(async () => { | ||
runner = createNewTestRunner(); | ||
cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner)); | ||
}); | ||
|
||
it('should not update other elements appearance', async () => { | ||
await runMigrationTest( | ||
'<mat-card appearance="raised"></mat-card>', | ||
'<mat-card appearance="raised"></mat-card>', | ||
); | ||
}); | ||
|
||
it('should not update default appearance', async () => { | ||
await runMigrationTest( | ||
'<mat-form-field></mat-form-field>', | ||
'<mat-form-field></mat-form-field>', | ||
); | ||
}); | ||
|
||
it('should not update outline appearance', async () => { | ||
await runMigrationTest( | ||
'<mat-form-field appearance="outline"></mat-form-field>', | ||
'<mat-form-field appearance="outline"></mat-form-field>', | ||
); | ||
}); | ||
|
||
it('should not update fill appearance', async () => { | ||
await runMigrationTest( | ||
'<mat-form-field appearance="fill"></mat-form-field>', | ||
'<mat-form-field appearance="fill"></mat-form-field>', | ||
); | ||
}); | ||
|
||
it('should update standard appearance', async () => { | ||
await runMigrationTest( | ||
'<mat-form-field appearance="standard"></mat-form-field>', | ||
'<mat-form-field></mat-form-field>', | ||
); | ||
}); | ||
|
||
it('should update legacy appearance', async () => { | ||
await runMigrationTest( | ||
'<mat-form-field appearance="legacy"></mat-form-field>', | ||
'<mat-form-field></mat-form-field>', | ||
); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...l/schematics/ng-generate/mdc-migration/rules/components/form-field/form-field-template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @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 {updateAttribute, visitElements} from '../../tree-traversal'; | ||
import {Update} from '../../../../../migration-utilities'; | ||
|
||
export class FormFieldTemplateMigrator extends TemplateMigrator { | ||
getUpdates(ast: compiler.ParsedTemplate): Update[] { | ||
const updates: Update[] = []; | ||
|
||
visitElements(ast.nodes, (node: compiler.TmplAstElement) => { | ||
if (node.name !== 'mat-form-field') { | ||
return; | ||
} | ||
|
||
updates.push({ | ||
offset: node.startSourceSpan.start.offset, | ||
updateFn: html => | ||
updateAttribute(html, node, 'appearance', old => | ||
['legacy', 'standard'].includes(old || '') ? null : old, | ||
), | ||
}); | ||
}); | ||
|
||
return updates; | ||
} | ||
} |
Oops, something went wrong.