Skip to content

Commit a0ec4be

Browse files
authored
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'
1 parent a231e9b commit a0ec4be

27 files changed

+367
-80
lines changed

integration/mdc-migration/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ migration_test(
4040
"sample-project/**/*",
4141
]),
4242
approve = False,
43+
verify = [
44+
"! grep" +
45+
" --include=*.{ts,css,scss,html}" +
46+
" --exclude-dir={node_modules,.angular,.yarn_cache_folder}" +
47+
" -ir legacy" +
48+
" || { echo \"Error: golden project contains 'legacy'.\" >&2; exit 1; }",
49+
"yarn build",
50+
# TODO(mmalerba): add back once slider tests pass.
51+
# "yarn test",
52+
],
4353
)
4454

4555
migration_test(

integration/mdc-migration/golden/angular.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{
3737
"type": "initial",
3838
"maximumWarning": "500kb",
39-
"maximumError": "1mb"
39+
"maximumError": "2mb"
4040
},
4141
{
4242
"type": "anyComponentStyle",

integration/mdc-migration/golden/src/app/app.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {MatSnackBarModule} from '@angular/material/snack-bar';
2525
import {MatTableModule} from '@angular/material/table';
2626
import {MatTabsModule} from '@angular/material/tabs';
2727
import {MatTooltipModule} from '@angular/material/tooltip';
28+
import {MatOptionModule, VERSION} from '@angular/material/core';
2829
import {AutocompleteComponent} from './components/autocomplete/autocomplete.component';
2930
import {ButtonComponent} from './components/button/button.component';
3031
import {CardComponent} from './components/card/card.component';
@@ -94,9 +95,12 @@ import {TooltipComponent} from './components/tooltip/tooltip.component';
9495
MatTableModule,
9596
MatTabsModule,
9697
MatTooltipModule,
98+
MatOptionModule,
9799
ReactiveFormsModule,
98100
],
99101
providers: [],
100102
bootstrap: [AppComponent],
101103
})
102-
export class AppModule {}
104+
export class AppModule {
105+
version = VERSION;
106+
}

integration/mdc-migration/golden/src/app/components/form-field/form-field.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ <h2>Form field example</h2>
22
<mat-form-field hintLabel="Max 10 characters" appearance="fill">
33
<mat-label>Enter some input</mat-label>
44
<input matInput #input maxlength="10" placeholder="Ex. Nougat">
5-
<mat-hint align="end">{{input.value?.length || 0}}/10</mat-hint>
5+
<mat-hint align="end">{{input.value.length}}/10</mat-hint>
66
</mat-form-field>
7+
<mat-form-field appearance="outline"><input matInput></mat-form-field>
8+
<mat-form-field><input matInput></mat-form-field>
9+
<mat-form-field><input matInput></mat-form-field>

integration/mdc-migration/golden/src/styles.scss

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// Include the common styles for Angular Material. We include this here so that you only
88
// have to load a single css file for Angular Material in your app.
99
// Be sure that you only ever include this mixin once!
10-
@include mat.all-component-typographies();
11-
@include mat.legacy-core();
10+
@include mat.all-component-typographies(mat.define-typography-config());
11+
@include mat.core();
1212

1313
// Define the palettes for your theme using the Material Design palettes available in palette.scss
1414
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
@@ -26,9 +26,11 @@ $sample-project-theme: mat.define-light-theme((
2626
primary: $sample-project-primary,
2727
accent: $sample-project-accent,
2828
warn: $sample-project-warn,
29-
)
29+
),
30+
typography: mat.define-typography-config(),
3031
));
3132

33+
@include mat.core-theme($sample-project-theme);
3234
@include mat.autocomplete-theme($sample-project-theme);
3335
@include mat.button-theme($sample-project-theme);
3436
@include mat.fab-theme($sample-project-theme);
@@ -45,13 +47,14 @@ $sample-project-theme: mat.define-light-theme((
4547
@include mat.progress-bar-theme($sample-project-theme);
4648
@include mat.progress-spinner-theme($sample-project-theme);
4749
@include mat.radio-theme($sample-project-theme);
48-
@include mat.legacy-select-theme($sample-project-theme);
4950
@include mat.slide-toggle-theme($sample-project-theme);
5051
@include mat.slider-theme($sample-project-theme);
5152
@include mat.snack-bar-theme($sample-project-theme);
5253
@include mat.table-theme($sample-project-theme);
5354
@include mat.tabs-theme($sample-project-theme);
5455
@include mat.tooltip-theme($sample-project-theme);
56+
@include mat.option-theme($sample-project-theme);
57+
@include mat.optgroup-theme($sample-project-theme);
5558

5659
/* You can add global styles to this file, and also import other style files */
5760

integration/mdc-migration/migration-test.bzl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ IGNORED_FILES = [
2121
"yarn.lock",
2222
]
2323

24-
def migration_test(name, srcs, approve):
24+
def migration_test(name, srcs, approve, verify = []):
2525
node_integration_test(
2626
name = name,
2727
srcs = srcs,
@@ -32,15 +32,13 @@ def migration_test(name, srcs, approve):
3232
# TODO(devversion): determine if a solution/workaround could live in the test runner.
3333
"yarn install --cache-folder .yarn_cache_folder/",
3434
"yarn ng generate @angular/material:mdc-migration --components all",
35-
# TODO(amysorto): add back once MDC components are in @angular/material
36-
# "yarn test",
3735
" ".join([
3836
"$(rootpath :verify_golden)",
3937
"%s" % approve,
4038
"../golden",
4139
"integration/mdc-migration/golden",
4240
] + IGNORED_FILES),
43-
],
41+
] + verify,
4442
data = [
4543
":golden_project",
4644
":test_project",

integration/mdc-migration/sample-project/angular.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{
3737
"type": "initial",
3838
"maximumWarning": "500kb",
39-
"maximumError": "1mb"
39+
"maximumError": "2mb"
4040
},
4141
{
4242
"type": "anyComponentStyle",

integration/mdc-migration/sample-project/src/app/app.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {MatLegacySnackBarModule as MatSnackBarModule} from '@angular/material/le
2525
import {MatLegacyTableModule as MatTableModule} from '@angular/material/legacy-table';
2626
import {MatLegacyTabsModule as MatTabsModule} from '@angular/material/legacy-tabs';
2727
import {MatLegacyTooltipModule as MatTooltipModule} from '@angular/material/legacy-tooltip';
28+
import {MatLegacyOptionModule, LEGACY_VERSION} from '@angular/material/legacy-core';
2829
import {AutocompleteComponent} from './components/autocomplete/autocomplete.component';
2930
import {ButtonComponent} from './components/button/button.component';
3031
import {CardComponent} from './components/card/card.component';
@@ -94,9 +95,12 @@ import {TooltipComponent} from './components/tooltip/tooltip.component';
9495
MatTableModule,
9596
MatTabsModule,
9697
MatTooltipModule,
98+
MatLegacyOptionModule,
9799
ReactiveFormsModule,
98100
],
99101
providers: [],
100102
bootstrap: [AppComponent],
101103
})
102-
export class AppModule {}
104+
export class AppModule {
105+
version = LEGACY_VERSION;
106+
}

integration/mdc-migration/sample-project/src/app/components/form-field/form-field.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ <h2>Form field example</h2>
22
<mat-form-field hintLabel="Max 10 characters" appearance="fill">
33
<mat-label>Enter some input</mat-label>
44
<input matInput #input maxlength="10" placeholder="Ex. Nougat">
5-
<mat-hint align="end">{{input.value?.length || 0}}/10</mat-hint>
5+
<mat-hint align="end">{{input.value.length}}/10</mat-hint>
66
</mat-form-field>
7+
<mat-form-field appearance="outline"><input matInput></mat-form-field>
8+
<mat-form-field appearance="standard"><input matInput></mat-form-field>
9+
<mat-form-field appearance="legacy"><input matInput></mat-form-field>

integration/mdc-migration/sample-project/src/app/components/progress-spinner/progress-spinner.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ComponentFixture, TestBed} from '@angular/core/testing';
22
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
3-
import {MatProgressSpinnerModule} from '@angular/material/legacy-progress-spinner';
3+
import {MatLegacyProgressSpinnerModule as MatProgressSpinnerModule} from '@angular/material/legacy-progress-spinner';
44
import {ProgressSpinnerComponent} from './progress-spinner.component';
55

66
describe('ProgressSpinnerComponent', () => {

0 commit comments

Comments
 (0)