From c3cc31dad7d38915f8b358114fdec8963d04ebb4 Mon Sep 17 00:00:00 2001 From: Yann Thomas LE MOIGNE Date: Thu, 6 Jul 2023 22:19:45 +0200 Subject: [PATCH] fix(schematics/card): Migrated to appearance=outlined wich is not the MDC standard The schematics change standard raised to outlined. I have deleted the rules in schematics. Fixes https://github.com/angular/components/issues/27004 --- .../components/card/card-template.spec.ts | 142 ------------------ .../rules/components/card/card-template.ts | 31 ---- .../ng-generate/mdc-migration/rules/index.ts | 2 - .../ts-migration/runtime-migrator.spec.ts | 8 +- 4 files changed, 4 insertions(+), 179 deletions(-) delete mode 100644 src/material/schematics/ng-generate/mdc-migration/rules/components/card/card-template.spec.ts delete mode 100644 src/material/schematics/ng-generate/mdc-migration/rules/components/card/card-template.ts diff --git a/src/material/schematics/ng-generate/mdc-migration/rules/components/card/card-template.spec.ts b/src/material/schematics/ng-generate/mdc-migration/rules/components/card/card-template.spec.ts deleted file mode 100644 index 5e2311e2ce59..000000000000 --- a/src/material/schematics/ng-generate/mdc-migration/rules/components/card/card-template.spec.ts +++ /dev/null @@ -1,142 +0,0 @@ -import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing'; -import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; -import { - APP_MODULE_FILE, - createNewTestRunner, - migrateComponents, - TEMPLATE_FILE, -} from '../test-setup-helper'; - -describe('card template migrator', () => { - let runner: SchematicTestRunner; - let cliAppTree: UnitTestTree; - - async function runMigrationTest(oldFileContent: string, newFileContent: string) { - cliAppTree.overwrite(TEMPLATE_FILE, oldFileContent); - const tree = await migrateComponents(['card'], 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('', ''); - }); - - it('should update single', async () => { - await runMigrationTest('', ''); - }); - - it('should update multiple same-line unnested', async () => { - await runMigrationTest( - '', - '', - ); - }); - - it('should update multiple same-line nested', async () => { - await runMigrationTest( - '', - '', - ); - }); - - it('should update multiple same-line nested and unnested', async () => { - await runMigrationTest( - '', - '', - ); - }); - - it('should update multiple multi-line unnested', async () => { - await runMigrationTest( - ` - - - `, - ` - - - `, - ); - }); - - it('should update multiple multi-line nested', async () => { - await runMigrationTest( - ` - - - - `, - ` - - - - `, - ); - }); - - it('should update multiple multi-line nested and unnested', async () => { - await runMigrationTest( - ` - - - - - `, - ` - - - - - `, - ); - }); - - it('should match indentation', async () => { - await runMigrationTest( - ` - - `, - ` - - `, - ); - }); - - it('should migrate inline templates', async () => { - const oldContent = ` - import {Component} from '@angular/core'; - - @Component({ - template: '' - }) - export class MyComp {} - `; - - const newContent = ` - import {Component} from '@angular/core'; - - @Component({ - template: '' - }) - export class MyComp {} - `; - - cliAppTree.overwrite(APP_MODULE_FILE, oldContent); - const tree = await migrateComponents(['card'], runner, cliAppTree); - expect(tree.readContent(APP_MODULE_FILE)).toBe(newContent); - }); -}); diff --git a/src/material/schematics/ng-generate/mdc-migration/rules/components/card/card-template.ts b/src/material/schematics/ng-generate/mdc-migration/rules/components/card/card-template.ts deleted file mode 100644 index f99c22420e19..000000000000 --- a/src/material/schematics/ng-generate/mdc-migration/rules/components/card/card-template.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @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 CardTemplateMigrator extends TemplateMigrator { - getUpdates(ast: compiler.ParsedTemplate): Update[] { - const updates: Update[] = []; - - visitElements(ast.nodes, (node: compiler.TmplAstElement) => { - if (node.name !== 'mat-card') { - return; - } - - updates.push({ - offset: node.startSourceSpan.start.offset, - updateFn: html => updateAttribute(html, node, 'appearance', () => 'outlined'), - }); - }); - - 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 374b025b594c..4eb27d1728cd 100644 --- a/src/material/schematics/ng-generate/mdc-migration/rules/index.ts +++ b/src/material/schematics/ng-generate/mdc-migration/rules/index.ts @@ -12,7 +12,6 @@ import {TemplateMigrator} from './template-migrator'; import {AutocompleteStylesMigrator} from './components/autocomplete/autocomplete-styles'; import {ButtonStylesMigrator} from './components/button/button-styles'; import {CardStylesMigrator} from './components/card/card-styles'; -import {CardTemplateMigrator} from './components/card/card-template'; import {CheckboxStylesMigrator} from './components/checkbox/checkbox-styles'; import {ChipsStylesMigrator} from './components/chips/chips-styles'; import {ChipsTemplateMigrator} from './components/chips/chips-template'; @@ -107,7 +106,6 @@ export const MIGRATORS: ComponentMigrator[] = [ { component: 'card', styles: new CardStylesMigrator(), - template: new CardTemplateMigrator(), }, { component: 'checkbox', diff --git a/src/material/schematics/ng-generate/mdc-migration/rules/ts-migration/runtime-migrator.spec.ts b/src/material/schematics/ng-generate/mdc-migration/rules/ts-migration/runtime-migrator.spec.ts index 2c0e724b057d..dc2b7ce35e4b 100644 --- a/src/material/schematics/ng-generate/mdc-migration/rules/ts-migration/runtime-migrator.spec.ts +++ b/src/material/schematics/ng-generate/mdc-migration/rules/ts-migration/runtime-migrator.spec.ts @@ -521,7 +521,7 @@ describe('runtime code migration', () => { ` @Component({ selector: 'card-example', - template: 'Learn More', + template: 'Learn More', }) class CardExample {} `, @@ -545,7 +545,7 @@ describe('runtime code migration', () => { ` @Component({ selector: 'card-example', - template: \` + template: \` Learn More \`, @@ -568,7 +568,7 @@ describe('runtime code migration', () => { ` @Component({ selector: 'card-example', - template: 'Learn More', + template: 'Learn More', styles: ['.mat-mdc-card { padding-right: 4px; }'], }) class CardExample {} @@ -599,7 +599,7 @@ describe('runtime code migration', () => { standalone: true, selector: 'card-example', imports: [MatCardModule], - template: 'Learn More', + template: 'Learn More', styles: ['.mat-mdc-card { padding-right: 4px; }'], }) class CardExample {}