Skip to content

Commit e9d5349

Browse files
committed
test(material/schematics): split up tests
Splits the tests for the `define-typography-config` migration into a separate file since they didn't make sense in the `multiple-components-styles.spec.ts`. (cherry picked from commit 9f006be)
1 parent 78ef2a8 commit e9d5349

File tree

2 files changed

+199
-180
lines changed

2 files changed

+199
-180
lines changed

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

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -201,185 +201,5 @@ describe('multiple component styles', () => {
201201
`,
202202
);
203203
});
204-
205-
it('should migrate an empty typography config call', async () => {
206-
await runMigrationTest(
207-
['checkbox', 'radio'],
208-
`
209-
@use '@angular/material' as mat;
210-
211-
$sample-project-theme: mat.define-light-theme((
212-
color: (
213-
primary: $sample-project-primary,
214-
accent: $sample-project-accent,
215-
warn: $sample-project-warn,
216-
),
217-
typography: mat.define-legacy-typography-config(),
218-
));
219-
`,
220-
`
221-
@use '@angular/material' as mat;
222-
223-
$sample-project-theme: mat.define-light-theme((
224-
color: (
225-
primary: $sample-project-primary,
226-
accent: $sample-project-accent,
227-
warn: $sample-project-warn,
228-
),
229-
typography: mat.define-typography-config(),
230-
));
231-
`,
232-
);
233-
});
234-
235-
it('should migrate a typography config with positional arguments', async () => {
236-
await runMigrationTest(
237-
['checkbox', 'radio'],
238-
`
239-
@use '@angular/material' as mat;
240-
241-
$sample-project-theme: mat.define-light-theme((
242-
color: (
243-
primary: $sample-project-primary,
244-
accent: $sample-project-accent,
245-
warn: $sample-project-warn,
246-
),
247-
typography: mat.define-legacy-typography-config($font-family, $display-4, $display-3),
248-
));
249-
`,
250-
`
251-
@use '@angular/material' as mat;
252-
253-
$sample-project-theme: mat.define-light-theme((
254-
color: (
255-
primary: $sample-project-primary,
256-
accent: $sample-project-accent,
257-
warn: $sample-project-warn,
258-
),
259-
typography: mat.define-typography-config($font-family, $display-4, $display-3),
260-
));
261-
`,
262-
);
263-
});
264-
265-
it('should migrate a typography config with named arguments', async () => {
266-
await runMigrationTest(
267-
['checkbox', 'radio'],
268-
`
269-
@use '@angular/material' as mat;
270-
271-
$sample-project-theme: mat.define-light-theme((
272-
color: (
273-
primary: $sample-project-primary,
274-
accent: $sample-project-accent,
275-
warn: $sample-project-warn,
276-
),
277-
typography: mat.define-legacy-typography-config(
278-
$font-family: $font-family,
279-
$display-4: $display-4,
280-
$display-3: $display-3,
281-
$display-2: $display-2,
282-
$display-1: $display-1,
283-
$headline: $headline,
284-
$title: $title,
285-
$subheading-2: $subheading-2,
286-
$subheading-1: $subheading-1,
287-
$body-2: $body-2,
288-
$body-1: $body-1,
289-
$caption: $caption,
290-
$button: $button,
291-
$input: $input,
292-
),
293-
));
294-
`,
295-
`
296-
@use '@angular/material' as mat;
297-
298-
$sample-project-theme: mat.define-light-theme((
299-
color: (
300-
primary: $sample-project-primary,
301-
accent: $sample-project-accent,
302-
warn: $sample-project-warn,
303-
),
304-
typography: mat.define-typography-config(
305-
$font-family: $font-family,
306-
$headline-1: $display-4,
307-
$headline-2: $display-3,
308-
$headline-3: $display-2,
309-
$headline-4: $display-1,
310-
$headline-5: $headline,
311-
$headline-6: $title,
312-
$subtitle-1: $subheading-2,
313-
$body-1: $subheading-1,
314-
$subtitle-2: $body-2,
315-
$body-2: $body-1,
316-
$caption: $caption,
317-
$button: $button,
318-
$input: $input,
319-
),
320-
));
321-
`,
322-
);
323-
});
324-
325-
it('should migrate multiple typography configs with named arguments within the same file', async () => {
326-
await runMigrationTest(
327-
['checkbox', 'radio'],
328-
`
329-
@use '@angular/material' as mat;
330-
331-
$sample-project-theme: mat.define-light-theme((
332-
color: (
333-
primary: $sample-project-primary,
334-
accent: $sample-project-accent,
335-
warn: $sample-project-warn,
336-
),
337-
typography: mat.define-legacy-typography-config(
338-
$display-4: $display-4,
339-
$title: $title,
340-
),
341-
));
342-
343-
$other-sample-project-theme: mat.define-light-theme((
344-
color: (
345-
primary: $sample-project-primary,
346-
accent: $sample-project-accent,
347-
warn: $sample-project-warn,
348-
),
349-
typography: mat.define-legacy-typography-config(
350-
$display-2: $display-2,
351-
$subheading-2: $subheading-2,
352-
),
353-
));
354-
`,
355-
`
356-
@use '@angular/material' as mat;
357-
358-
$sample-project-theme: mat.define-light-theme((
359-
color: (
360-
primary: $sample-project-primary,
361-
accent: $sample-project-accent,
362-
warn: $sample-project-warn,
363-
),
364-
typography: mat.define-typography-config(
365-
$headline-1: $display-4,
366-
$headline-6: $title,
367-
),
368-
));
369-
370-
$other-sample-project-theme: mat.define-light-theme((
371-
color: (
372-
primary: $sample-project-primary,
373-
accent: $sample-project-accent,
374-
warn: $sample-project-warn,
375-
),
376-
typography: mat.define-typography-config(
377-
$headline-3: $display-2,
378-
$subtitle-1: $subheading-2,
379-
),
380-
));
381-
`,
382-
);
383-
});
384204
});
385205
});
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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('typography migrations', () => {
6+
let runner: SchematicTestRunner;
7+
let cliAppTree: UnitTestTree;
8+
9+
async function runMigrationTest(file: string, oldFileContent: string, newFileContent: string) {
10+
cliAppTree.create(file, oldFileContent);
11+
const tree = await migrateComponents([], runner, cliAppTree);
12+
expect(tree.readContent(file)).toBe(newFileContent);
13+
}
14+
15+
beforeEach(async () => {
16+
runner = createNewTestRunner();
17+
cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner));
18+
});
19+
20+
it('should migrate an empty typography config call', async () => {
21+
await runMigrationTest(
22+
THEME_FILE,
23+
`
24+
@use '@angular/material' as mat;
25+
26+
$sample-project-theme: mat.define-light-theme((
27+
color: (
28+
primary: $sample-project-primary,
29+
accent: $sample-project-accent,
30+
warn: $sample-project-warn,
31+
),
32+
typography: mat.define-legacy-typography-config(),
33+
));
34+
`,
35+
`
36+
@use '@angular/material' as mat;
37+
38+
$sample-project-theme: mat.define-light-theme((
39+
color: (
40+
primary: $sample-project-primary,
41+
accent: $sample-project-accent,
42+
warn: $sample-project-warn,
43+
),
44+
typography: mat.define-typography-config(),
45+
));
46+
`,
47+
);
48+
});
49+
50+
it('should migrate a typography config with positional arguments', async () => {
51+
await runMigrationTest(
52+
THEME_FILE,
53+
`
54+
@use '@angular/material' as mat;
55+
56+
$sample-project-theme: mat.define-light-theme((
57+
color: (
58+
primary: $sample-project-primary,
59+
accent: $sample-project-accent,
60+
warn: $sample-project-warn,
61+
),
62+
typography: mat.define-legacy-typography-config($font-family, $display-4, $display-3),
63+
));
64+
`,
65+
`
66+
@use '@angular/material' as mat;
67+
68+
$sample-project-theme: mat.define-light-theme((
69+
color: (
70+
primary: $sample-project-primary,
71+
accent: $sample-project-accent,
72+
warn: $sample-project-warn,
73+
),
74+
typography: mat.define-typography-config($font-family, $display-4, $display-3),
75+
));
76+
`,
77+
);
78+
});
79+
80+
it('should migrate a typography config with named arguments', async () => {
81+
await runMigrationTest(
82+
THEME_FILE,
83+
`
84+
@use '@angular/material' as mat;
85+
86+
$sample-project-theme: mat.define-light-theme((
87+
color: (
88+
primary: $sample-project-primary,
89+
accent: $sample-project-accent,
90+
warn: $sample-project-warn,
91+
),
92+
typography: mat.define-legacy-typography-config(
93+
$font-family: $font-family,
94+
$display-4: $display-4,
95+
$display-3: $display-3,
96+
$display-2: $display-2,
97+
$display-1: $display-1,
98+
$headline: $headline,
99+
$title: $title,
100+
$subheading-2: $subheading-2,
101+
$subheading-1: $subheading-1,
102+
$body-2: $body-2,
103+
$body-1: $body-1,
104+
$caption: $caption,
105+
$button: $button,
106+
$input: $input,
107+
),
108+
));
109+
`,
110+
`
111+
@use '@angular/material' as mat;
112+
113+
$sample-project-theme: mat.define-light-theme((
114+
color: (
115+
primary: $sample-project-primary,
116+
accent: $sample-project-accent,
117+
warn: $sample-project-warn,
118+
),
119+
typography: mat.define-typography-config(
120+
$font-family: $font-family,
121+
$headline-1: $display-4,
122+
$headline-2: $display-3,
123+
$headline-3: $display-2,
124+
$headline-4: $display-1,
125+
$headline-5: $headline,
126+
$headline-6: $title,
127+
$subtitle-1: $subheading-2,
128+
$body-1: $subheading-1,
129+
$subtitle-2: $body-2,
130+
$body-2: $body-1,
131+
$caption: $caption,
132+
$button: $button,
133+
$input: $input,
134+
),
135+
));
136+
`,
137+
);
138+
});
139+
140+
it('should migrate multiple typography configs with named arguments within the same file', async () => {
141+
await runMigrationTest(
142+
THEME_FILE,
143+
`
144+
@use '@angular/material' as mat;
145+
146+
$sample-project-theme: mat.define-light-theme((
147+
color: (
148+
primary: $sample-project-primary,
149+
accent: $sample-project-accent,
150+
warn: $sample-project-warn,
151+
),
152+
typography: mat.define-legacy-typography-config(
153+
$display-4: $display-4,
154+
$title: $title,
155+
),
156+
));
157+
158+
$other-sample-project-theme: mat.define-light-theme((
159+
color: (
160+
primary: $sample-project-primary,
161+
accent: $sample-project-accent,
162+
warn: $sample-project-warn,
163+
),
164+
typography: mat.define-legacy-typography-config(
165+
$display-2: $display-2,
166+
$subheading-2: $subheading-2,
167+
),
168+
));
169+
`,
170+
`
171+
@use '@angular/material' as mat;
172+
173+
$sample-project-theme: mat.define-light-theme((
174+
color: (
175+
primary: $sample-project-primary,
176+
accent: $sample-project-accent,
177+
warn: $sample-project-warn,
178+
),
179+
typography: mat.define-typography-config(
180+
$headline-1: $display-4,
181+
$headline-6: $title,
182+
),
183+
));
184+
185+
$other-sample-project-theme: mat.define-light-theme((
186+
color: (
187+
primary: $sample-project-primary,
188+
accent: $sample-project-accent,
189+
warn: $sample-project-warn,
190+
),
191+
typography: mat.define-typography-config(
192+
$headline-3: $display-2,
193+
$subtitle-1: $subheading-2,
194+
),
195+
));
196+
`,
197+
);
198+
});
199+
});

0 commit comments

Comments
 (0)