Skip to content

Commit a12f268

Browse files
amysortommalerba
authored andcommitted
feat(material/schematics): add progress spinner styles migrator and tests
1 parent d8f1cce commit a12f268

File tree

4 files changed

+148
-2
lines changed

4 files changed

+148
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 {ClassNameChange, StyleMigrator} from '../../style-migrator';
10+
11+
export class ProgressSpinnerStylesMigrator extends StyleMigrator {
12+
component = 'progress-spinner';
13+
14+
// There are no other progress spinner selectors available aside from the
15+
// specified changes below
16+
deprecatedPrefix = null;
17+
18+
mixinChanges = [
19+
{
20+
old: 'progress-spinner-theme',
21+
new: ['mdc-progress-spinner-theme', 'mdc-progress-spinner-typography'],
22+
},
23+
];
24+
25+
classChanges: ClassNameChange[] = [
26+
{old: '.mat-progress-spinner', new: '.mat-mdc-progress-spinner'},
27+
{old: '.mat-spinner', new: '.mat-mdc-progress-spinner'},
28+
];
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing';
2+
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
3+
import {createNewTestRunner, migrateComponent, THEME_FILE} from '../test-setup-helper';
4+
5+
describe('progress-spinner styles', () => {
6+
let runner: SchematicTestRunner;
7+
let cliAppTree: UnitTestTree;
8+
9+
async function runMigrationTest(oldFileContent: string, newFileContent: string) {
10+
cliAppTree.create(THEME_FILE, oldFileContent);
11+
const tree = await migrateComponent('progress-spinner', runner, cliAppTree);
12+
expect(tree.readContent(THEME_FILE)).toBe(newFileContent);
13+
}
14+
15+
beforeEach(async () => {
16+
runner = createNewTestRunner();
17+
cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner));
18+
});
19+
20+
describe('mixin migrations', () => {
21+
it('should replace the old theme with the new ones', async () => {
22+
await runMigrationTest(
23+
`
24+
@use '@angular/material' as mat;
25+
$theme: ();
26+
@include mat.progress-spinner-theme($theme);
27+
`,
28+
`
29+
@use '@angular/material' as mat;
30+
$theme: ();
31+
@include mat.mdc-progress-spinner-theme($theme);
32+
@include mat.mdc-progress-spinner-typography($theme);
33+
`,
34+
);
35+
});
36+
37+
it('should use the correct namespace', async () => {
38+
await runMigrationTest(
39+
`
40+
@use '@angular/material' as arbitrary;
41+
$theme: ();
42+
@include arbitrary.progress-spinner-theme($theme);
43+
`,
44+
`
45+
@use '@angular/material' as arbitrary;
46+
$theme: ();
47+
@include arbitrary.mdc-progress-spinner-theme($theme);
48+
@include arbitrary.mdc-progress-spinner-typography($theme);
49+
`,
50+
);
51+
});
52+
53+
it('should handle updating multiple themes', async () => {
54+
await runMigrationTest(
55+
`
56+
@use '@angular/material' as mat;
57+
$light-theme: ();
58+
$dark-theme: ();
59+
@include mat.progress-spinner-theme($light-theme);
60+
@include mat.progress-spinner-theme($dark-theme);
61+
`,
62+
`
63+
@use '@angular/material' as mat;
64+
$light-theme: ();
65+
$dark-theme: ();
66+
@include mat.mdc-progress-spinner-theme($light-theme);
67+
@include mat.mdc-progress-spinner-typography($light-theme);
68+
@include mat.mdc-progress-spinner-theme($dark-theme);
69+
@include mat.mdc-progress-spinner-typography($dark-theme);
70+
`,
71+
);
72+
});
73+
74+
it('should preserve whitespace', async () => {
75+
await runMigrationTest(
76+
`
77+
@use '@angular/material' as mat;
78+
$theme: ();
79+
80+
81+
@include mat.progress-spinner-theme($theme);
82+
83+
84+
`,
85+
`
86+
@use '@angular/material' as mat;
87+
$theme: ();
88+
89+
90+
@include mat.mdc-progress-spinner-theme($theme);
91+
@include mat.mdc-progress-spinner-typography($theme);
92+
93+
94+
`,
95+
);
96+
});
97+
});
98+
99+
describe('selector migrations', () => {
100+
it('should update the legacy mat-progress-spinner classname', async () => {
101+
await runMigrationTest(
102+
`
103+
.mat-progress-spinner {
104+
margin: 4px;
105+
}
106+
`,
107+
`
108+
.mat-mdc-progress-spinner {
109+
margin: 4px;
110+
}
111+
`,
112+
);
113+
});
114+
});
115+
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {ButtonStylesMigrator} from './components/button/button-styles';
1010
import {CheckboxStylesMigrator} from './components/checkbox/checkbox-styles';
1111
import {ProgressBarStylesMigrator} from './components/progress-bar/progress-bar-styles';
12+
import {ProgressSpinnerStylesMigrator} from './components/progress-spinner/progress-spinner-styles';
1213
import {RadioStylesMigrator} from './components/radio/radio-styles';
1314
import {SlideToggleStylesMigrator} from './components/slide-toggle/slide-toggle-styles';
1415
import {SliderStylesMigrator} from './components/slider/slider-styles';
@@ -18,6 +19,7 @@ export const MIGRATORS: StyleMigrator[] = [
1819
new ButtonStylesMigrator(),
1920
new CheckboxStylesMigrator(),
2021
new ProgressBarStylesMigrator(),
22+
new ProgressSpinnerStylesMigrator(),
2123
new RadioStylesMigrator(),
2224
new SlideToggleStylesMigrator(),
2325
new SliderStylesMigrator(),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export abstract class StyleMigrator {
4040
abstract mixinChanges: MixinChange[];
4141

4242
/** The prefix of classes that are specific to the old components */
43-
abstract deprecatedPrefix: string;
43+
abstract deprecatedPrefix: string | null;
4444

4545
/**
4646
* Returns whether the given at-include at-rule is a use of a legacy mixin for this component.
@@ -125,7 +125,7 @@ export abstract class StyleMigrator {
125125
* @returns `true` if the given Rule uses a selector with the deprecated prefix.
126126
*/
127127
isDeprecatedSelector(rule: postcss.Rule): boolean {
128-
return rule.selector.includes(this.deprecatedPrefix);
128+
return this.deprecatedPrefix ? rule.selector.includes(this.deprecatedPrefix) : false;
129129
}
130130

131131
/**

0 commit comments

Comments
 (0)