@@ -385,6 +385,78 @@ describe('runtime code migration', () => {
385
385
) ;
386
386
} ) ;
387
387
388
+ it ( 'should not replace imports from non selected components' , async ( ) => {
389
+ declareLibrarySymbols ( 'legacy-button' , 'export declare class MatLegacyButtonModule {};' ) ;
390
+ declareLibrarySymbols ( 'legacy-checkbox' , 'export declare class MatLegacyCheckboxModule {};' ) ;
391
+
392
+ await runMigrationTest (
393
+ `
394
+ import {NgModule} from '@angular/core';
395
+ import {MatLegacyButtonModule} from '@angular/material/legacy-button';
396
+ import {MatLegacyCheckboxModule} from '@angular/material/legacy-checkbox';
397
+
398
+ @NgModule({imports: [MatLegacyButtonModule, MatLegacyCheckboxModule]})
399
+ export class AppModule {}
400
+ ` ,
401
+ `
402
+ import {NgModule} from '@angular/core';
403
+ import {MatButtonModule} from '@angular/material/button';
404
+ import {MatLegacyCheckboxModule} from '@angular/material/legacy-checkbox';
405
+
406
+ @NgModule({imports: [MatButtonModule, MatLegacyCheckboxModule]})
407
+ export class AppModule {}
408
+ ` ,
409
+ ) ;
410
+ } ) ;
411
+
412
+ it ( 'should migrate legacy-core symbols when option or optgroup is choosen for migration' , async ( ) => {
413
+ declareLibrarySymbols ( 'legacy-select' , 'export declare class MatLegacySelectModule {};' ) ;
414
+
415
+ async function runMigrationSelectTest ( oldFileContent : string , newFileContent : string ) {
416
+ cliAppTree . overwrite ( APP_MODULE_FILE , oldFileContent ) ;
417
+ const tree = await migrateComponents ( [ 'select' ] , runner , cliAppTree ) ;
418
+ expect ( tree . readContent ( APP_MODULE_FILE ) ) . toBe ( newFileContent ) ;
419
+ }
420
+
421
+ await runMigrationSelectTest (
422
+ `
423
+ import {NgModule} from '@angular/core';
424
+ import {MatLegacySelectModule as MatSelectModule} from '@angular/material/legacy-select';
425
+ import {MatLegacyOptionModule as MatOptionModule, LEGACY_VERSION as VERSION} from '@angular/material/legacy-core';
426
+
427
+ @NgModule({imports: [MatSelectModule, MatOptionModule]})
428
+ export class AppModule {}
429
+ ` ,
430
+ `
431
+ import {NgModule} from '@angular/core';
432
+ import {MatSelectModule} from '@angular/material/select';
433
+ import {MatOptionModule, VERSION} from '@angular/material/core';
434
+
435
+ @NgModule({imports: [MatSelectModule, MatOptionModule]})
436
+ export class AppModule {}
437
+ ` ,
438
+ ) ;
439
+ } ) ;
440
+
441
+ it ( 'should not migrate legacy-core symbols when option or optgroup are not choosen for migration' , async ( ) => {
442
+ await runMigrationTest (
443
+ `
444
+ import {NgModule} from '@angular/core';
445
+ import {MatLegacyOptionModule as MatOptionModule, LEGACY_VERSION as VERSION} from '@angular/material/legacy-core';
446
+
447
+ @NgModule({imports: [MatOptionModule]})
448
+ export class AppModule {}
449
+ ` ,
450
+ `
451
+ import {NgModule} from '@angular/core';
452
+ import {MatLegacyOptionModule as MatOptionModule, LEGACY_VERSION as VERSION} from '@angular/material/legacy-core';
453
+
454
+ @NgModule({imports: [MatOptionModule]})
455
+ export class AppModule {}
456
+ ` ,
457
+ ) ;
458
+ } ) ;
459
+
388
460
it ( 'should migrate styles for a component' , async ( ) => {
389
461
await runMigrationTest (
390
462
`
0 commit comments