Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(material/schematics): add progress spinner styles migrator and t…
…ests
- Loading branch information
Showing
4 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...cs/ng-generate/mdc-migration/rules/components/progress-spinner/progress-spinner-styles.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,29 @@ | ||
/** | ||
* @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 {ClassNameChange, StyleMigrator} from '../../style-migrator'; | ||
|
||
export class ProgressSpinnerStylesMigrator extends StyleMigrator { | ||
component = 'progress-spinner'; | ||
|
||
// There are no other progress spinner selectors available aside from the | ||
// specified changes below | ||
deprecatedPrefix = null; | ||
|
||
mixinChanges = [ | ||
{ | ||
old: 'progress-spinner-theme', | ||
new: ['mdc-progress-spinner-theme', 'mdc-progress-spinner-typography'], | ||
}, | ||
]; | ||
|
||
classChanges: ClassNameChange[] = [ | ||
{old: '.mat-progress-spinner', new: '.mat-mdc-progress-spinner'}, | ||
{old: '.mat-spinner', new: '.mat-mdc-progress-spinner'}, | ||
]; | ||
} |
115 changes: 115 additions & 0 deletions
115
...tics/ng-generate/mdc-migration/rules/components/progress-spinner/progress-spinner.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,115 @@ | ||
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing'; | ||
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; | ||
import {createNewTestRunner, migrateComponent, THEME_FILE} from '../test-setup-helper'; | ||
|
||
describe('progress-spinner styles', () => { | ||
let runner: SchematicTestRunner; | ||
let cliAppTree: UnitTestTree; | ||
|
||
async function runMigrationTest(oldFileContent: string, newFileContent: string) { | ||
cliAppTree.create(THEME_FILE, oldFileContent); | ||
const tree = await migrateComponent('progress-spinner', runner, cliAppTree); | ||
expect(tree.readContent(THEME_FILE)).toBe(newFileContent); | ||
} | ||
|
||
beforeEach(async () => { | ||
runner = createNewTestRunner(); | ||
cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner)); | ||
}); | ||
|
||
describe('mixin migrations', () => { | ||
it('should replace the old theme with the new ones', async () => { | ||
await runMigrationTest( | ||
` | ||
@use '@angular/material' as mat; | ||
$theme: (); | ||
@include mat.progress-spinner-theme($theme); | ||
`, | ||
` | ||
@use '@angular/material' as mat; | ||
$theme: (); | ||
@include mat.mdc-progress-spinner-theme($theme); | ||
@include mat.mdc-progress-spinner-typography($theme); | ||
`, | ||
); | ||
}); | ||
|
||
it('should use the correct namespace', async () => { | ||
await runMigrationTest( | ||
` | ||
@use '@angular/material' as arbitrary; | ||
$theme: (); | ||
@include arbitrary.progress-spinner-theme($theme); | ||
`, | ||
` | ||
@use '@angular/material' as arbitrary; | ||
$theme: (); | ||
@include arbitrary.mdc-progress-spinner-theme($theme); | ||
@include arbitrary.mdc-progress-spinner-typography($theme); | ||
`, | ||
); | ||
}); | ||
|
||
it('should handle updating multiple themes', async () => { | ||
await runMigrationTest( | ||
` | ||
@use '@angular/material' as mat; | ||
$light-theme: (); | ||
$dark-theme: (); | ||
@include mat.progress-spinner-theme($light-theme); | ||
@include mat.progress-spinner-theme($dark-theme); | ||
`, | ||
` | ||
@use '@angular/material' as mat; | ||
$light-theme: (); | ||
$dark-theme: (); | ||
@include mat.mdc-progress-spinner-theme($light-theme); | ||
@include mat.mdc-progress-spinner-typography($light-theme); | ||
@include mat.mdc-progress-spinner-theme($dark-theme); | ||
@include mat.mdc-progress-spinner-typography($dark-theme); | ||
`, | ||
); | ||
}); | ||
|
||
it('should preserve whitespace', async () => { | ||
await runMigrationTest( | ||
` | ||
@use '@angular/material' as mat; | ||
$theme: (); | ||
@include mat.progress-spinner-theme($theme); | ||
`, | ||
` | ||
@use '@angular/material' as mat; | ||
$theme: (); | ||
@include mat.mdc-progress-spinner-theme($theme); | ||
@include mat.mdc-progress-spinner-typography($theme); | ||
`, | ||
); | ||
}); | ||
}); | ||
|
||
describe('selector migrations', () => { | ||
it('should update the legacy mat-progress-spinner classname', async () => { | ||
await runMigrationTest( | ||
` | ||
.mat-progress-spinner { | ||
margin: 4px; | ||
} | ||
`, | ||
` | ||
.mat-mdc-progress-spinner { | ||
margin: 4px; | ||
} | ||
`, | ||
); | ||
}); | ||
}); | ||
}); |
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