Skip to content

Commit ffd19e4

Browse files
committed
test(material/schematics): Add test for CSS token renames
1 parent bb9ef4d commit ffd19e4

File tree

5 files changed

+97
-6
lines changed

5 files changed

+97
-6
lines changed

src/cdk/schematics/ng-update/migrations/css-tokens.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ export class CssTokensMigration extends Migration<UpgradeData> {
6767
}
6868

6969
private _visitStringLiteralLike(node: ts.StringLiteralLike) {
70-
if (node.parent && node.parent.kind !== ts.SyntaxKind.CallExpression) {
71-
return;
72-
}
73-
7470
const textContent = node.getText();
7571
const filePath = this.fileSystem.resolve(node.getSourceFile().fileName);
7672

src/material/checkbox/checkbox.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@
196196
// user of this. Therefore we add the pointer cursor on top of MDC's styles.
197197
label {
198198
cursor: pointer;
199+
}
199200

201+
.mat-internal-form-field {
200202
@include token-utils.use-tokens(
201203
tokens-mat-checkbox.$prefix,
202204
tokens-mat-checkbox.get-token-slots()

src/material/radio/radio.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
}
5555
}
5656

57-
.mdc-radio + label {
57+
.mat-internal-form-field {
5858
@include token-utils.use-tokens(
5959
tokens-mat-radio.$prefix,
6060
tokens-mat-radio.get-token-slots()
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import {createTestCaseSetup} from '@angular/cdk/schematics/testing';
2+
import {MIGRATION_PATH} from '../../paths';
3+
4+
describe('V18 token renames', () => {
5+
async function setup(fileName: string, originalSource: string): Promise<string> {
6+
const filePath = `projects/cdk-testing/src/${fileName}`;
7+
const {runFixers, writeFile, appTree} = await createTestCaseSetup(
8+
'migration-v18',
9+
MIGRATION_PATH,
10+
[],
11+
);
12+
13+
if (fileName.endsWith('.html')) {
14+
writeFile(
15+
'projects/cdk-testing/src/comp.ts',
16+
[
17+
`import {Component} from '@angular/core';`,
18+
`@Component({selector: 'comp', templateUrl: '${fileName}'})`,
19+
`export class Comp {}`,
20+
].join('\n'),
21+
);
22+
} else if (fileName.endsWith('.css') && fileName !== 'theme.css') {
23+
writeFile(
24+
'projects/cdk-testing/src/comp.ts',
25+
[
26+
`import {Component} from '@angular/core';`,
27+
`@Component({selector: 'comp', template: '', styleUrl: '${fileName}'})`,
28+
`export class Comp {}`,
29+
].join('\n'),
30+
);
31+
}
32+
33+
writeFile(filePath, originalSource);
34+
await runFixers();
35+
return appTree.readContent(filePath);
36+
}
37+
38+
it('should migrate mdc-form-field tokens in theme css', async () => {
39+
const result = await setup(
40+
'theme.scss',
41+
[
42+
`body {`,
43+
` --mdc-form-field-label-text-color: red;`,
44+
` --mdc-form-field-label-text-font: Roboto;`,
45+
` --mdc-form-field-label-text-size: 16px;`,
46+
` --mdc-form-field-label-text-weight: bold;`,
47+
` --mdc-form-field-label-text-tracking: 0;`,
48+
` --mdc-form-field-label-text-line-height: 1.2;`,
49+
` --mdc-form-field-label-text-color-custom: green;`,
50+
`}`,
51+
].join('\n'),
52+
);
53+
54+
expect(result.split('\n')).toEqual([
55+
`body {`,
56+
` --mat-checkbox-label-text-color: red;`,
57+
` --mat-checkbox-label-text-font: Roboto;`,
58+
` --mat-checkbox-label-text-size: 16px;`,
59+
` --mat-checkbox-label-text-weight: bold;`,
60+
` --mat-checkbox-label-text-tracking: 0;`,
61+
` --mat-checkbox-label-text-line-height: 1.2;`,
62+
` --mdc-form-field-label-text-color-custom: green;`,
63+
`}`,
64+
]);
65+
});
66+
67+
it('should migrate mdc-form-field tokens in component css', async () => {
68+
const result = await setup(
69+
'some-comp.css',
70+
`:host {color: var(--mdc-form-field-label-text-color);}`,
71+
);
72+
73+
expect(result).toBe(`:host {color: var(--mat-checkbox-label-text-color);}`);
74+
});
75+
76+
it('should migrate mdc-form-field tokens in ts', async () => {
77+
const result = await setup(
78+
'some-comp.ts',
79+
`const TEXT_COLOR_PROP = '--mdc-form-field-label-text-color';`,
80+
);
81+
82+
expect(result).toBe(`const TEXT_COLOR_PROP = '--mat-checkbox-label-text-color';`);
83+
});
84+
85+
it('should migrate mdc-form-field tokens in html', async () => {
86+
const result = await setup(
87+
'some-comp.html',
88+
`<div style="--mdc-form-field-label-text-color: red;"><ng-content /></div>`,
89+
);
90+
91+
expect(result).toBe(`<div style="--mat-checkbox-label-text-color: red;"><ng-content /></div>`);
92+
});
93+
});

src/material/slide-toggle/slide-toggle.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// Add the MDC switch static styles.
1616
@include mdc-switch.static-styles-without-ripple();
1717

18-
.mdc-switch + label {
18+
.mat-mdc-slide-toggle .mat-internal-form-field {
1919
@include token-utils.use-tokens(
2020
tokens-mat-switch.$prefix,
2121
tokens-mat-switch.get-token-slots()

0 commit comments

Comments
 (0)