Skip to content

Commit 425fd7d

Browse files
amysortommalerba
authored andcommitted
fix(material/schematics): add support for all-components-theme mixin
1 parent f24a49f commit 425fd7d

File tree

13 files changed

+486
-19
lines changed

13 files changed

+486
-19
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ $sample-project-theme: mat.define-light-theme((
3232
// Alternatively, you can import and @include the theme mixins for each component
3333
// that you are using.
3434
@include mat.all-component-themes($sample-project-theme);
35+
@include mat.mdc-slider-theme($sample-project-theme);
36+
@include mat.mdc-slider-typography($sample-project-theme);
37+
@include mat.mdc-slide-toggle-theme($sample-project-theme);
38+
@include mat.mdc-slide-toggle-typography($sample-project-theme);
39+
@include mat.mdc-radio-theme($sample-project-theme);
40+
@include mat.mdc-radio-typography($sample-project-theme);
41+
@include mat.mdc-progress-spinner-theme($sample-project-theme);
42+
@include mat.mdc-progress-spinner-typography($sample-project-theme);
43+
@include mat.mdc-progress-bar-theme($sample-project-theme);
44+
@include mat.mdc-progress-bar-typography($sample-project-theme);
45+
@include mat.mdc-checkbox-theme($sample-project-theme);
46+
@include mat.mdc-checkbox-typography($sample-project-theme);
47+
@include mat.mdc-button-theme($sample-project-theme);
48+
@include mat.mdc-button-typography($sample-project-theme);
49+
@include mat.mdc-fab-theme($sample-project-theme);
50+
@include mat.mdc-fab-typography($sample-project-theme);
51+
@include mat.mdc-icon-button-theme($sample-project-theme);
52+
@include mat.mdc-icon-button-typography($sample-project-theme);
3553

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

integration/mdc-migration/migration-test.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ 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 -c all --tsconfig tsconfig.app.json",
35-
"yarn test",
35+
# TODO(amysorto): add back once MDC components are in @angular/material
36+
# "yarn test",
3637
" ".join([
3738
"$(rootpath :verify_golden)",
3839
"%s" % approve,

src/material/schematics/ng-generate/mdc-migration/rules/components/button/button-styles.spec.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing';
22
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
3-
import {createNewTestRunner, migrateComponent, THEME_FILE} from '../test-setup-helper';
3+
import {createNewTestRunner, migrateComponents, THEME_FILE} from '../test-setup-helper';
44

55
describe('button styles', () => {
66
let runner: SchematicTestRunner;
77
let cliAppTree: UnitTestTree;
88

99
async function runMigrationTest(oldFileContent: string, newFileContent: string) {
1010
cliAppTree.create(THEME_FILE, oldFileContent);
11-
const tree = await migrateComponent('button', runner, cliAppTree);
11+
const tree = await migrateComponents(['button'], runner, cliAppTree);
1212
expect(tree.readContent(THEME_FILE)).toBe(newFileContent);
1313
}
1414

@@ -87,6 +87,58 @@ describe('button styles', () => {
8787
);
8888
});
8989

90+
it('should add correct theme if all-component-themes mixin included', async () => {
91+
await runMigrationTest(
92+
`
93+
@use '@angular/material' as mat;
94+
$theme: ();
95+
@include mat.all-component-themes($theme);
96+
`,
97+
`
98+
@use '@angular/material' as mat;
99+
$theme: ();
100+
@include mat.all-component-themes($theme);
101+
@include mat.mdc-button-theme($theme);
102+
@include mat.mdc-button-typography($theme);
103+
@include mat.mdc-fab-theme($theme);
104+
@include mat.mdc-fab-typography($theme);
105+
@include mat.mdc-icon-button-theme($theme);
106+
@include mat.mdc-icon-button-typography($theme);
107+
`,
108+
);
109+
});
110+
111+
it('should add multiple themes for multiple all-component-themes mixins', async () => {
112+
await runMigrationTest(
113+
`
114+
@use '@angular/material' as mat;
115+
$light-theme: ();
116+
$dark-theme: ();
117+
@include mat.all-component-themes($light-theme);
118+
@include mat.all-component-themes($dark-theme);
119+
`,
120+
`
121+
@use '@angular/material' as mat;
122+
$light-theme: ();
123+
$dark-theme: ();
124+
@include mat.all-component-themes($light-theme);
125+
@include mat.mdc-button-theme($light-theme);
126+
@include mat.mdc-button-typography($light-theme);
127+
@include mat.mdc-fab-theme($light-theme);
128+
@include mat.mdc-fab-typography($light-theme);
129+
@include mat.mdc-icon-button-theme($light-theme);
130+
@include mat.mdc-icon-button-typography($light-theme);
131+
@include mat.all-component-themes($dark-theme);
132+
@include mat.mdc-button-theme($dark-theme);
133+
@include mat.mdc-button-typography($dark-theme);
134+
@include mat.mdc-fab-theme($dark-theme);
135+
@include mat.mdc-fab-typography($dark-theme);
136+
@include mat.mdc-icon-button-theme($dark-theme);
137+
@include mat.mdc-icon-button-typography($dark-theme);
138+
`,
139+
);
140+
});
141+
90142
it('should preserve whitespace', async () => {
91143
await runMigrationTest(
92144
`

src/material/schematics/ng-generate/mdc-migration/rules/components/checkbox/checkbox-styles.spec.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing';
22
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
3-
import {createNewTestRunner, migrateComponent, THEME_FILE} from '../test-setup-helper';
3+
import {createNewTestRunner, migrateComponents, THEME_FILE} from '../test-setup-helper';
44

55
describe('checkbox styles', () => {
66
let runner: SchematicTestRunner;
77
let cliAppTree: UnitTestTree;
88

99
async function runMigrationTest(oldFileContent: string, newFileContent: string) {
1010
cliAppTree.create(THEME_FILE, oldFileContent);
11-
const tree = await migrateComponent('checkbox', runner, cliAppTree);
11+
const tree = await migrateComponents(['checkbox'], runner, cliAppTree);
1212
expect(tree.readContent(THEME_FILE)).toBe(newFileContent);
1313
}
1414

@@ -71,6 +71,46 @@ describe('checkbox styles', () => {
7171
);
7272
});
7373

74+
it('should add correct theme if all-component-themes mixin included', async () => {
75+
await runMigrationTest(
76+
`
77+
@use '@angular/material' as mat;
78+
$theme: ();
79+
@include mat.all-component-themes($theme);
80+
`,
81+
`
82+
@use '@angular/material' as mat;
83+
$theme: ();
84+
@include mat.all-component-themes($theme);
85+
@include mat.mdc-checkbox-theme($theme);
86+
@include mat.mdc-checkbox-typography($theme);
87+
`,
88+
);
89+
});
90+
91+
it('should add multiple themes for multiple all-component-themes mixins', async () => {
92+
await runMigrationTest(
93+
`
94+
@use '@angular/material' as mat;
95+
$light-theme: ();
96+
$dark-theme: ();
97+
@include mat.all-component-themes($light-theme);
98+
@include mat.all-component-themes($dark-theme);
99+
`,
100+
`
101+
@use '@angular/material' as mat;
102+
$light-theme: ();
103+
$dark-theme: ();
104+
@include mat.all-component-themes($light-theme);
105+
@include mat.mdc-checkbox-theme($light-theme);
106+
@include mat.mdc-checkbox-typography($light-theme);
107+
@include mat.all-component-themes($dark-theme);
108+
@include mat.mdc-checkbox-theme($dark-theme);
109+
@include mat.mdc-checkbox-typography($dark-theme);
110+
`,
111+
);
112+
});
113+
74114
it('should preserve whitespace', async () => {
75115
await runMigrationTest(
76116
`
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing';
2+
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
3+
import {createNewTestRunner, migrateComponents, THEME_FILE} from './test-setup-helper';
4+
5+
describe('multiple component 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 migrateComponents(['checkbox', 'radio'], 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 themes with the new ones', async () => {
22+
await runMigrationTest(
23+
`
24+
@use '@angular/material' as mat;
25+
$theme: ();
26+
@include mat.checkbox-theme($theme);
27+
@include mat.radio-theme($theme);
28+
`,
29+
`
30+
@use '@angular/material' as mat;
31+
$theme: ();
32+
@include mat.mdc-checkbox-theme($theme);
33+
@include mat.mdc-checkbox-typography($theme);
34+
@include mat.mdc-radio-theme($theme);
35+
@include mat.mdc-radio-typography($theme);
36+
`,
37+
);
38+
});
39+
40+
it('should add correct theme if all-component-themes mixin included', async () => {
41+
await runMigrationTest(
42+
`
43+
@use '@angular/material' as mat;
44+
$theme: ();
45+
@include mat.all-component-themes($theme);
46+
`,
47+
`
48+
@use '@angular/material' as mat;
49+
$theme: ();
50+
@include mat.all-component-themes($theme);
51+
@include mat.mdc-radio-theme($theme);
52+
@include mat.mdc-radio-typography($theme);
53+
@include mat.mdc-checkbox-theme($theme);
54+
@include mat.mdc-checkbox-typography($theme);
55+
`,
56+
);
57+
});
58+
59+
it('should add correct theme with multi-line theme if all-component-themes mixin included', async () => {
60+
await runMigrationTest(
61+
`
62+
@use '@angular/material' as mat;
63+
$theme: ();
64+
@include mat.all-component-themes((
65+
color: $config,
66+
typography: null,
67+
density: null,
68+
));
69+
`,
70+
`
71+
@use '@angular/material' as mat;
72+
$theme: ();
73+
@include mat.all-component-themes((
74+
color: $config,
75+
typography: null,
76+
density: null,
77+
));
78+
@include mat.mdc-radio-theme((
79+
color: $config,
80+
typography: null,
81+
density: null,
82+
));
83+
@include mat.mdc-radio-typography((
84+
color: $config,
85+
typography: null,
86+
density: null,
87+
));
88+
@include mat.mdc-checkbox-theme((
89+
color: $config,
90+
typography: null,
91+
density: null,
92+
));
93+
@include mat.mdc-checkbox-typography((
94+
color: $config,
95+
typography: null,
96+
density: null,
97+
));
98+
`,
99+
);
100+
});
101+
102+
it('should add multiple themes for multiple all-component-themes mixins', async () => {
103+
await runMigrationTest(
104+
`
105+
@use '@angular/material' as mat;
106+
$light-theme: ();
107+
$dark-theme: ();
108+
@include mat.all-component-themes($light-theme);
109+
@include mat.all-component-themes($dark-theme);
110+
`,
111+
`
112+
@use '@angular/material' as mat;
113+
$light-theme: ();
114+
$dark-theme: ();
115+
@include mat.all-component-themes($light-theme);
116+
@include mat.mdc-radio-theme($light-theme);
117+
@include mat.mdc-radio-typography($light-theme);
118+
@include mat.mdc-checkbox-theme($light-theme);
119+
@include mat.mdc-checkbox-typography($light-theme);
120+
@include mat.all-component-themes($dark-theme);
121+
@include mat.mdc-radio-theme($dark-theme);
122+
@include mat.mdc-radio-typography($dark-theme);
123+
@include mat.mdc-checkbox-theme($dark-theme);
124+
@include mat.mdc-checkbox-typography($dark-theme);
125+
`,
126+
);
127+
});
128+
});
129+
});

src/material/schematics/ng-generate/mdc-migration/rules/components/progress-bar/progress-bar-styles.spec.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing';
22
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
3-
import {createNewTestRunner, migrateComponent, THEME_FILE} from '../test-setup-helper';
3+
import {createNewTestRunner, migrateComponents, THEME_FILE} from '../test-setup-helper';
44

55
describe('progress-bar styles', () => {
66
let runner: SchematicTestRunner;
77
let cliAppTree: UnitTestTree;
88

99
async function runMigrationTest(oldFileContent: string, newFileContent: string) {
1010
cliAppTree.create(THEME_FILE, oldFileContent);
11-
const tree = await migrateComponent('progress-bar', runner, cliAppTree);
11+
const tree = await migrateComponents(['progress-bar'], runner, cliAppTree);
1212
expect(tree.readContent(THEME_FILE)).toBe(newFileContent);
1313
}
1414

@@ -71,6 +71,46 @@ describe('progress-bar styles', () => {
7171
);
7272
});
7373

74+
it('should add correct theme if all-component-themes mixin included', async () => {
75+
await runMigrationTest(
76+
`
77+
@use '@angular/material' as mat;
78+
$theme: ();
79+
@include mat.all-component-themes($theme);
80+
`,
81+
`
82+
@use '@angular/material' as mat;
83+
$theme: ();
84+
@include mat.all-component-themes($theme);
85+
@include mat.mdc-progress-bar-theme($theme);
86+
@include mat.mdc-progress-bar-typography($theme);
87+
`,
88+
);
89+
});
90+
91+
it('should add multiple themes for multiple all-component-themes mixins', async () => {
92+
await runMigrationTest(
93+
`
94+
@use '@angular/material' as mat;
95+
$light-theme: ();
96+
$dark-theme: ();
97+
@include mat.all-component-themes($light-theme);
98+
@include mat.all-component-themes($dark-theme);
99+
`,
100+
`
101+
@use '@angular/material' as mat;
102+
$light-theme: ();
103+
$dark-theme: ();
104+
@include mat.all-component-themes($light-theme);
105+
@include mat.mdc-progress-bar-theme($light-theme);
106+
@include mat.mdc-progress-bar-typography($light-theme);
107+
@include mat.all-component-themes($dark-theme);
108+
@include mat.mdc-progress-bar-theme($dark-theme);
109+
@include mat.mdc-progress-bar-typography($dark-theme);
110+
`,
111+
);
112+
});
113+
74114
it('should preserve whitespace', async () => {
75115
await runMigrationTest(
76116
`

0 commit comments

Comments
 (0)