@@ -87,7 +87,7 @@ describe('ng-add schematic', () => {
87
87
const workspace = await readWorkspace ( tree ) ;
88
88
const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
89
89
90
- expectProjectStyleFile ( project , '@angular /material/prebuilt-themes/azure-blue.css ' ) ;
90
+ expectProjectStyleFile ( project , 'projects /material/src/custom-theme.scss ' ) ;
91
91
} ) ;
92
92
93
93
it ( 'should support adding a custom theme' , async ( ) => {
@@ -96,7 +96,7 @@ describe('ng-add schematic', () => {
96
96
97
97
const tree = await runner . runSchematic (
98
98
'ng-add-setup-project' ,
99
- { ...baseOptions , theme : 'custom ' } ,
99
+ { ...baseOptions , theme : 'azure-blue ' } ,
100
100
appTree ,
101
101
) ;
102
102
const workspace = await readWorkspace ( tree ) ;
@@ -116,7 +116,7 @@ describe('ng-add schematic', () => {
116
116
117
117
const tree = await runner . runSchematic (
118
118
'ng-add-setup-project' ,
119
- { ...baseOptions , theme : 'custom ' } ,
119
+ { ...baseOptions , theme : 'azure-blue ' } ,
120
120
appTree ,
121
121
) ;
122
122
const workspace = await readWorkspace ( tree ) ;
@@ -213,108 +213,14 @@ describe('ng-add schematic', () => {
213
213
runner . runSchematic ( 'ng-add-setup-project' , baseOptions , appTree ) ,
214
214
) . toBeRejected ( ) ;
215
215
} ) ;
216
-
217
- it ( 'should warn if the "test" target has been changed' , async ( ) => {
218
- overwriteTargetBuilder ( appTree , 'test' , 'thirdparty-test-builder' ) ;
219
- await runner . runSchematic ( 'ng-add-setup-project' , baseOptions , appTree ) ;
220
-
221
- expect ( errorOutput . length ) . toBe ( 0 ) ;
222
- expect ( warnOutput . length ) . toBe ( 1 ) ;
223
- expect ( warnOutput [ 0 ] ) . toMatch (
224
- / n o t u s i n g t h e d e f a u l t b u i l d e r s .* c a n n o t a d d t h e c o n f i g u r e d t h e m e / ,
225
- ) ;
226
- } ) ;
227
216
} ) ;
228
217
229
218
describe ( 'theme files' , ( ) => {
230
- /** Path to the default prebuilt theme file that will be added when running ng-add. */
231
- const defaultPrebuiltThemePath = '@angular/material/prebuilt-themes/azure-blue.css' ;
232
-
233
- /** Writes a specific style file to the workspace in the given tree */
234
- function writeStyleFileToWorkspace ( tree : Tree , stylePath : string ) {
235
- tree . overwrite (
236
- '/angular.json' ,
237
- JSON . stringify (
238
- {
239
- version : 1 ,
240
- projects : {
241
- material : {
242
- projectType : 'application' ,
243
- root : 'projects/material' ,
244
- sourceRoot : 'projects/material/src' ,
245
- prefix : 'app' ,
246
- architect : {
247
- build : {
248
- builder : '@angular-devkit/build-angular:application' ,
249
- options : {
250
- outputPath : 'dist/material' ,
251
- index : 'projects/material/src/index.html' ,
252
- browser : 'projects/material/src/main.ts' ,
253
- styles : [ 'projects/material/src/styles.css' , stylePath ] ,
254
- } ,
255
- } ,
256
- } ,
257
- } ,
258
- } ,
259
- } ,
260
- null ,
261
- 2 ,
262
- ) ,
263
- ) ;
264
- }
265
-
266
- it ( 'should replace existing prebuilt theme files' , async ( ) => {
267
- const existingThemePath = '@angular/material/prebuilt-themes/purple-green.css' ;
268
- writeStyleFileToWorkspace ( appTree , existingThemePath ) ;
269
-
270
- const tree = await runner . runSchematic ( 'ng-add-setup-project' , baseOptions , appTree ) ;
271
- const workspace = await readWorkspace ( tree ) ;
272
- const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
273
- const styles = getProjectTargetOptions ( project , 'build' ) [ 'styles' ] ;
274
-
275
- expect ( styles )
276
- . not . withContext ( 'Expected the existing prebuilt theme file to be removed.' )
277
- . toContain ( existingThemePath ) ;
278
- expect ( styles )
279
- . withContext ( 'Expected the default prebuilt theme to be added.' )
280
- . toContain ( defaultPrebuiltThemePath ) ;
281
- } ) ;
282
-
283
- it ( 'should not replace existing custom theme files' , async ( ) => {
284
- writeStyleFileToWorkspace ( appTree , './projects/material/custom-theme.scss' ) ;
285
-
286
- const tree = await runner . runSchematic ( 'ng-add-setup-project' , baseOptions , appTree ) ;
287
- const workspace = await readWorkspace ( tree ) ;
288
- const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
289
- const styles = getProjectTargetOptions ( project , 'build' ) [ 'styles' ] ;
290
-
291
- expect ( styles )
292
- . not . withContext ( 'Expected the default prebuilt theme to be not configured.' )
293
- . toContain ( defaultPrebuiltThemePath ) ;
294
- expect ( errorOutput . length ) . toBe ( 1 ) ;
295
- expect ( errorOutput [ 0 ] ) . toMatch ( / C o u l d n o t a d d t h e s e l e c t e d t h e m e / ) ;
296
- } ) ;
297
-
298
- it ( 'should not add a theme file multiple times' , async ( ) => {
299
- writeStyleFileToWorkspace ( appTree , defaultPrebuiltThemePath ) ;
300
-
301
- const tree = await runner . runSchematic ( 'ng-add-setup-project' , baseOptions , appTree ) ;
302
- const workspace = await readWorkspace ( tree ) ;
303
- const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
304
- const styles = getProjectTargetOptions ( project , 'build' ) [ 'styles' ] ;
305
-
306
- expect ( styles )
307
- . withContext (
308
- 'Expected the "styles.css" file and default prebuilt theme to be ' + 'the only styles' ,
309
- )
310
- . toEqual ( [ 'projects/material/src/styles.css' , defaultPrebuiltThemePath ] ) ;
311
- } ) ;
312
-
313
219
it ( 'should not overwrite existing custom theme files' , async ( ) => {
314
220
appTree . create ( '/projects/material/custom-theme.scss' , 'custom-theme' ) ;
315
221
const tree = await runner . runSchematic (
316
222
'ng-add-setup-project' ,
317
- { ...baseOptions , theme : 'custom ' } ,
223
+ { ...baseOptions , theme : 'azure-blue ' } ,
318
224
appTree ,
319
225
) ;
320
226
expect ( tree . readContent ( '/projects/material/custom-theme.scss' ) )
@@ -323,117 +229,6 @@ describe('ng-add schematic', () => {
323
229
} ) ;
324
230
} ) ;
325
231
326
- it ( 'should add the global typography class if the body has no classes' , async ( ) => {
327
- const tree = await runner . runSchematic (
328
- 'ng-add-setup-project' ,
329
- {
330
- ...baseOptions ,
331
- typography : true ,
332
- } ,
333
- appTree ,
334
- ) ;
335
- const workspace = await readWorkspace ( tree ) ;
336
- const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
337
-
338
- const indexFiles = getProjectIndexFiles ( project ) ;
339
- expect ( indexFiles . length ) . toBe ( 1 ) ;
340
-
341
- indexFiles . forEach ( indexPath => {
342
- const buffer = tree . read ( indexPath ) ! ;
343
- expect ( buffer . toString ( ) ) . toContain ( '<body class="mat-typography">' ) ;
344
- } ) ;
345
- } ) ;
346
-
347
- it ( 'should add the global typography class if the body has existing classes' , async ( ) => {
348
- appTree . overwrite (
349
- 'projects/material/src/index.html' ,
350
- `
351
- <html>
352
- <head></head>
353
- <body class="one two"></body>
354
- </html>
355
- ` ,
356
- ) ;
357
-
358
- const tree = await runner . runSchematic (
359
- 'ng-add-setup-project' ,
360
- {
361
- ...baseOptions ,
362
- typography : true ,
363
- } ,
364
- appTree ,
365
- ) ;
366
- const workspace = await readWorkspace ( tree ) ;
367
- const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
368
- const indexFiles = getProjectIndexFiles ( project ) ;
369
- expect ( indexFiles . length ) . toBe ( 1 ) ;
370
-
371
- indexFiles . forEach ( indexPath => {
372
- const buffer = tree . read ( indexPath ) ! ;
373
- expect ( buffer . toString ( ) ) . toContain ( '<body class="one two mat-typography">' ) ;
374
- } ) ;
375
- } ) ;
376
-
377
- it ( 'should not add the global typography class if it exists already' , async ( ) => {
378
- appTree . overwrite (
379
- 'projects/material/src/index.html' ,
380
- `
381
- <html>
382
- <head></head>
383
- <body class="one mat-typography two"></body>
384
- </html>
385
- ` ,
386
- ) ;
387
-
388
- const tree = await runner . runSchematic (
389
- 'ng-add-setup-project' ,
390
- {
391
- ...baseOptions ,
392
- typography : true ,
393
- } ,
394
- appTree ,
395
- ) ;
396
- const workspace = await readWorkspace ( tree ) ;
397
- const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
398
- const indexFiles = getProjectIndexFiles ( project ) ;
399
- expect ( indexFiles . length ) . toBe ( 1 ) ;
400
-
401
- indexFiles . forEach ( indexPath => {
402
- const buffer = tree . read ( indexPath ) ! ;
403
- expect ( buffer . toString ( ) ) . toContain ( '<body class="one mat-typography two">' ) ;
404
- } ) ;
405
- } ) ;
406
-
407
- it ( 'should not add the global typography class if the user did not opt into it' , async ( ) => {
408
- appTree . overwrite (
409
- 'projects/material/src/index.html' ,
410
- `
411
- <html>
412
- <head></head>
413
- <body class="one two"></body>
414
- </html>
415
- ` ,
416
- ) ;
417
-
418
- const tree = await runner . runSchematic (
419
- 'ng-add-setup-project' ,
420
- {
421
- ...baseOptions ,
422
- typography : false ,
423
- } ,
424
- appTree ,
425
- ) ;
426
- const workspace = await readWorkspace ( tree ) ;
427
- const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
428
- const indexFiles = getProjectIndexFiles ( project ) ;
429
- expect ( indexFiles . length ) . toBe ( 1 ) ;
430
-
431
- indexFiles . forEach ( indexPath => {
432
- const buffer = tree . read ( indexPath ) ! ;
433
- expect ( buffer . toString ( ) ) . toContain ( '<body class="one two">' ) ;
434
- } ) ;
435
- } ) ;
436
-
437
232
describe ( 'using browser builder' , ( ) => {
438
233
beforeEach ( ( ) => {
439
234
const config = {
@@ -476,21 +271,7 @@ describe('ng-add schematic', () => {
476
271
const workspace = await readWorkspace ( tree ) ;
477
272
const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
478
273
479
- expectProjectStyleFile ( project , '@angular/material/prebuilt-themes/azure-blue.css' ) ;
480
- } ) ;
481
-
482
- it ( 'should add material app styles' , async ( ) => {
483
- const tree = await runner . runSchematic ( 'ng-add-setup-project' , baseOptions , appTree ) ;
484
- const workspace = await readWorkspace ( tree ) ;
485
- const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
486
-
487
- const defaultStylesPath = getProjectStyleFile ( project ) ! ;
488
- const htmlContent = tree . read ( defaultStylesPath ) ! . toString ( ) ;
489
-
490
- expect ( htmlContent ) . toContain ( 'html, body { height: 100%; }' ) ;
491
- expect ( htmlContent ) . toContain (
492
- 'body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }' ,
493
- ) ;
274
+ expectProjectStyleFile ( project , 'projects/material/src/custom-theme.scss' ) ;
494
275
} ) ;
495
276
} ) ;
496
277
@@ -536,21 +317,7 @@ describe('ng-add schematic', () => {
536
317
const workspace = await readWorkspace ( tree ) ;
537
318
const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
538
319
539
- expectProjectStyleFile ( project , '@angular/material/prebuilt-themes/azure-blue.css' ) ;
540
- } ) ;
541
-
542
- it ( 'should add material app styles' , async ( ) => {
543
- const tree = await runner . runSchematic ( 'ng-add-setup-project' , baseOptions , appTree ) ;
544
- const workspace = await readWorkspace ( tree ) ;
545
- const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
546
-
547
- const defaultStylesPath = getProjectStyleFile ( project ) ! ;
548
- const htmlContent = tree . read ( defaultStylesPath ) ! . toString ( ) ;
549
-
550
- expect ( htmlContent ) . toContain ( 'html, body { height: 100%; }' ) ;
551
- expect ( htmlContent ) . toContain (
552
- 'body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }' ,
553
- ) ;
320
+ expectProjectStyleFile ( project , 'projects/material/src/custom-theme.scss' ) ;
554
321
} ) ;
555
322
} ) ;
556
323
@@ -587,7 +354,7 @@ describe('ng-add schematic', () => {
587
354
const workspace = await readWorkspace ( tree ) ;
588
355
const project = getProjectFromWorkspace ( workspace , baseOptions . project ) ;
589
356
590
- expectProjectStyleFile ( project , '@angular /material/prebuilt-themes/azure-blue.css ' ) ;
357
+ expectProjectStyleFile ( project , 'projects /material/src/custom-theme.scss ' ) ;
591
358
} ) ;
592
359
} ) ;
593
360
} ) ;
0 commit comments