@@ -102,6 +102,41 @@ describe('v9 HammerJS removal', () => {
102
102
export class TestModule {}` ) ;
103
103
} ) ;
104
104
105
+ it ( 'should remove references to HammerModule' , async ( ) => {
106
+ writeFile ( '/projects/cdk-testing/src/test.module.ts' , dedent `
107
+ import {NgModule} from '@angular/core';
108
+ import {HAMMER_GESTURE_CONFIG, HammerModule} from '@angular/platform-browser'; // some comment
109
+ import {GestureConfig} from '@angular/material/core';
110
+
111
+ @NgModule({
112
+ providers: [
113
+ {provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig},
114
+ OtherProvider,
115
+ ],
116
+ imports: [
117
+ HammerModule,
118
+ OtherModule
119
+ ],
120
+ })
121
+ export class TestModule {}
122
+ ` ) ;
123
+
124
+ await runMigration ( ) ;
125
+
126
+ expect ( tree . readContent ( '/projects/cdk-testing/src/test.module.ts' ) ) . toContain ( dedent `
127
+ import {NgModule} from '@angular/core';
128
+
129
+ @NgModule({
130
+ providers: [
131
+ OtherProvider,
132
+ ],
133
+ imports: [
134
+ OtherModule
135
+ ],
136
+ })
137
+ export class TestModule {}` ) ;
138
+ } ) ;
139
+
105
140
it ( 'should remove references to gesture config if imports are aliased' , async ( ) => {
106
141
writeFile ( '/projects/cdk-testing/src/test.module.ts' , dedent `
107
142
import {NgModule} from '@angular/core';
@@ -318,14 +353,15 @@ describe('v9 HammerJS removal', () => {
318
353
319
354
writeFile ( '/projects/cdk-testing/src/test.module.ts' , dedent `
320
355
import {NgModule} from '@angular/core';
321
- import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser';
356
+ import {HAMMER_GESTURE_CONFIG, HammerModule } from '@angular/platform-browser';
322
357
import {GestureConfig} from '@angular/material/core';
323
358
324
359
@NgModule({
325
360
providers: [
326
361
{provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig},
327
362
OtherProvider,
328
- ]
363
+ ],
364
+ imports: [HammerModule],
329
365
})
330
366
export class TestModule {}
331
367
` ) ;
@@ -340,7 +376,8 @@ describe('v9 HammerJS removal', () => {
340
376
@NgModule({
341
377
providers: [
342
378
OtherProvider,
343
- ]
379
+ ],
380
+ imports: [],
344
381
})
345
382
export class TestModule {}` ) ;
346
383
} ) ;
@@ -507,7 +544,7 @@ describe('v9 HammerJS removal', () => {
507
544
export class TestModule {}` ) ;
508
545
} ) ;
509
546
510
- it ( 'should add gesture config provider to app module' , async ( ) => {
547
+ it ( 'should set up Hammer gestures in app module' , async ( ) => {
511
548
writeFile ( '/projects/cdk-testing/src/app/app.component.html' , `
512
549
<span (pinch)="onPinch($event)"></span>
513
550
` ) ;
@@ -517,7 +554,7 @@ describe('v9 HammerJS removal', () => {
517
554
expect ( tree . readContent ( '/projects/cdk-testing/src/main.ts' ) ) . toContain ( `import 'hammerjs';` ) ;
518
555
expect ( tree . exists ( '/projects/cdk-testing/src/gesture-config.ts' ) ) . toBe ( true ) ;
519
556
expect ( tree . readContent ( '/projects/cdk-testing/src/app/app.module.ts' ) ) . toContain ( dedent `\
520
- import { BrowserModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
557
+ import { BrowserModule, HammerModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
521
558
import { NgModule } from '@angular/core';
522
559
523
560
import { AppComponent } from './app.component';
@@ -528,7 +565,8 @@ describe('v9 HammerJS removal', () => {
528
565
AppComponent
529
566
],
530
567
imports: [
531
- BrowserModule
568
+ BrowserModule,
569
+ HammerModule
532
570
],
533
571
providers: [{ provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig }],
534
572
bootstrap: [AppComponent]
@@ -565,7 +603,7 @@ describe('v9 HammerJS removal', () => {
565
603
expect ( tree . readContent ( '/projects/cdk-testing/src/main.ts' ) ) . toContain ( `import 'hammerjs';` ) ;
566
604
expect ( tree . exists ( '/projects/cdk-testing/src/gesture-config.ts' ) ) . toBe ( true ) ;
567
605
expect ( tree . readContent ( '/projects/cdk-testing/src/app/app.module.ts' ) ) . toContain ( dedent `\
568
- import { BrowserModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
606
+ import { BrowserModule, HammerModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
569
607
import { NgModule } from '@angular/core';
570
608
571
609
import { AppComponent } from './app.component';
@@ -576,7 +614,8 @@ describe('v9 HammerJS removal', () => {
576
614
AppComponent
577
615
],
578
616
imports: [
579
- BrowserModule
617
+ BrowserModule,
618
+ HammerModule
580
619
],
581
620
providers: [{ provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig }],
582
621
bootstrap: [AppComponent]
@@ -610,7 +649,7 @@ describe('v9 HammerJS removal', () => {
610
649
expect ( tree . readContent ( '/projects/cdk-testing/src/main.ts' ) ) . toContain ( `import 'hammerjs';` ) ;
611
650
expect ( tree . exists ( '/projects/cdk-testing/src/gesture-config.ts' ) ) . toBe ( true ) ;
612
651
expect ( tree . readContent ( '/projects/cdk-testing/src/app/app.module.ts' ) ) . toContain ( dedent `
613
- import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser';
652
+ import { HAMMER_GESTURE_CONFIG, HammerModule } from '@angular/platform-browser';
614
653
import {NgModule} from '@angular/core';
615
654
import { GestureConfig } from "../gesture-config";
616
655
@@ -621,6 +660,38 @@ describe('v9 HammerJS removal', () => {
621
660
useClass: GestureConfig
622
661
},
623
662
],
663
+ imports: [HammerModule],
664
+ })
665
+ export class AppModule {}` ) ;
666
+ } ) ;
667
+
668
+ it ( 'should not add HammerModule multiple times if already provided' , async ( ) => {
669
+ writeFile ( '/projects/cdk-testing/src/app/app.component.html' , `
670
+ <span (pinch)="onPinch($event)"></span>
671
+ ` ) ;
672
+
673
+ writeFile ( '/projects/cdk-testing/src/app/app.module.ts' , dedent `
674
+ import {HammerModule as myHammerModule} from '@angular/platform-browser';
675
+ import {NgModule} from '@angular/core';
676
+
677
+ @NgModule({
678
+ imports: [myHammerModule],
679
+ })
680
+ export class AppModule {}
681
+ ` ) ;
682
+
683
+ await runMigration ( ) ;
684
+
685
+ expect ( tree . readContent ( '/projects/cdk-testing/src/main.ts' ) ) . toContain ( `import 'hammerjs';` ) ;
686
+ expect ( tree . exists ( '/projects/cdk-testing/src/gesture-config.ts' ) ) . toBe ( true ) ;
687
+ expect ( tree . readContent ( '/projects/cdk-testing/src/app/app.module.ts' ) ) . toContain ( dedent `
688
+ import { HammerModule as myHammerModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
689
+ import {NgModule} from '@angular/core';
690
+ import { GestureConfig } from "../gesture-config";
691
+
692
+ @NgModule({
693
+ imports: [myHammerModule],
694
+ providers: [{ provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig }],
624
695
})
625
696
export class AppModule {}` ) ;
626
697
} ) ;
@@ -710,8 +781,8 @@ describe('v9 HammerJS removal', () => {
710
781
711
782
const { logOutput} = await runMigration ( ) ;
712
783
713
- expect ( logOutput ) . toContain (
714
- `Material gesture config is used while a custom gesture config is set up `) ;
784
+ expect ( logOutput ) . toContain ( `unable to perform the full migration for this target, but ` +
785
+ `removed all references to the deprecated Angular Material gesture config. `) ;
715
786
expect ( tree . readContent ( '/projects/cdk-testing/src/main.ts' ) ) . toContain ( 'hammerjs' ) ;
716
787
expect ( tree . readContent ( '/projects/cdk-testing/src/test.component.ts' ) ) . toContain ( dedent `
717
788
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser';
0 commit comments