/
list-styles.spec.ts
274 lines (246 loc) · 6.94 KB
/
list-styles.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
import {createNewTestRunner, migrateComponents, THEME_FILE} from '../test-setup-helper';
describe('list styles', () => {
let runner: SchematicTestRunner;
let cliAppTree: UnitTestTree;
async function runMigrationTest(oldFileContent: string, newFileContent: string) {
cliAppTree.create(THEME_FILE, oldFileContent);
const tree = await migrateComponents(['list'], 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.list-theme($theme);
`,
`
@use '@angular/material' as mat;
$theme: ();
@include mat.mdc-list-theme($theme);
@include mat.mdc-list-typography($theme);
`,
);
});
it('should use the correct namespace', async () => {
await runMigrationTest(
`
@use '@angular/material' as arbitrary;
$theme: ();
@include arbitrary.list-theme($theme);
`,
`
@use '@angular/material' as arbitrary;
$theme: ();
@include arbitrary.mdc-list-theme($theme);
@include arbitrary.mdc-list-typography($theme);
`,
);
});
it('should handle updating multiple themes', async () => {
await runMigrationTest(
`
@use '@angular/material' as mat;
$light-theme: ();
$dark-theme: ();
@include mat.list-theme($light-theme);
@include mat.list-theme($dark-theme);
`,
`
@use '@angular/material' as mat;
$light-theme: ();
$dark-theme: ();
@include mat.mdc-list-theme($light-theme);
@include mat.mdc-list-typography($light-theme);
@include mat.mdc-list-theme($dark-theme);
@include mat.mdc-list-typography($dark-theme);
`,
);
});
it('should add correct theme if all-component-themes mixin included', async () => {
await runMigrationTest(
`
@use '@angular/material' as mat;
$theme: ();
@include mat.all-component-themes($theme);
`,
`
@use '@angular/material' as mat;
$theme: ();
@include mat.all-component-themes($theme);
@include mat.mdc-list-theme($theme);
@include mat.mdc-list-typography($theme);
`,
);
});
it('should add multiple themes for multiple all-component-themes mixins', async () => {
await runMigrationTest(
`
@use '@angular/material' as mat;
$light-theme: ();
$dark-theme: ();
@include mat.all-component-themes($light-theme);
@include mat.all-component-themes($dark-theme);
`,
`
@use '@angular/material' as mat;
$light-theme: ();
$dark-theme: ();
@include mat.all-component-themes($light-theme);
@include mat.mdc-list-theme($light-theme);
@include mat.mdc-list-typography($light-theme);
@include mat.all-component-themes($dark-theme);
@include mat.mdc-list-theme($dark-theme);
@include mat.mdc-list-typography($dark-theme);
`,
);
});
it('should preserve whitespace', async () => {
await runMigrationTest(
`
@use '@angular/material' as mat;
$theme: ();
@include mat.list-theme($theme);
`,
`
@use '@angular/material' as mat;
$theme: ();
@include mat.mdc-list-theme($theme);
@include mat.mdc-list-typography($theme);
`,
);
});
});
describe('selector migrations', () => {
it('should update the legacy mat-list classname', async () => {
await runMigrationTest(
`
.mat-list {
padding: 25px;
}
`,
`
.mat-mdc-list {
padding: 25px;
}
`,
);
});
it('should update multiple legacy classnames', async () => {
await runMigrationTest(
`
.mat-list {
padding: 25px;
}
.mat-subheader {
color: red;
}
`,
`
.mat-mdc-list {
padding: 25px;
}
.mat-mdc-subheader {
color: red;
}
`,
);
});
it('should update a legacy classname w/ multiple selectors', async () => {
await runMigrationTest(
`
.some-class.mat-list, .another-class {
padding: 25px;
}
`,
`
.some-class.mat-mdc-list, .another-class {
padding: 25px;
}
`,
);
});
it('should preserve the whitespace of multiple selectors', async () => {
await runMigrationTest(
`
.some-class,
.mat-list,
.another-class { padding: 25px; }
`,
`
.some-class,
.mat-mdc-list,
.another-class { padding: 25px; }
`,
);
});
it('should add comment for potentially deprecated selector', async () => {
await runMigrationTest(
`
.mat-list-item-content {
padding: 16px;
}
`,
`
/* TODO: The following rule targets internal classes of list that may no longer apply for the MDC version. */
.mat-list-item-content {
padding: 16px;
}
`,
);
});
it('should not add comment for legacy selector that also starts with deprecated prefix', async () => {
await runMigrationTest(
`
.mat-list-icon {
color: red;
}
`,
`
.mat-mdc-list-item-icon {
color: red;
}
`,
);
});
it('should add comment for potentially deprecated multi-line selector', async () => {
await runMigrationTest(
`
.some-class
.mat-list-item-content {
padding: 16px;
}
`,
`
/* TODO: The following rule targets internal classes of list that may no longer apply for the MDC version. */
.some-class
.mat-list-item-content {
padding: 16px;
}
`,
);
});
it('should update the legacy mat-list class and add comment for potentially deprecated selector', async () => {
await runMigrationTest(
`
.mat-list.some-class, .mat-list-item-content {
padding: 16px;
}
`,
`
/* TODO: The following rule targets internal classes of list that may no longer apply for the MDC version. */
.mat-mdc-list.some-class, .mat-list-item-content {
padding: 16px;
}
`,
);
});
});
});