@@ -166,6 +166,233 @@ describe("migrateComponents", () => {
166
166
` ) ,
167
167
) ;
168
168
} ) ;
169
+
170
+ describe ( "hyperlinks" , ( ) => {
171
+ it ( "should detect and import routerLink used in the template" , async ( ) => {
172
+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
173
+ const component = `
174
+ import { Component } from "@angular/core";
175
+
176
+ @Component({
177
+ selector: 'my-component',
178
+ template: '<a routerLink="/home">Home</a>',
179
+ standalone: true
180
+ })
181
+ export class MyComponent { }
182
+ ` ;
183
+
184
+ const componentSourceFile = project . createSourceFile (
185
+ "foo.component.ts" ,
186
+ dedent ( component ) ,
187
+ ) ;
188
+
189
+ await migrateComponents ( project , { dryRun : false } ) ;
190
+
191
+ expect ( dedent ( componentSourceFile . getText ( ) ) ) . toBe (
192
+ dedent ( `
193
+ import { Component } from "@angular/core";
194
+ import { IonRouterLinkWithHref } from "@ionic/angular/standalone";
195
+
196
+ @Component({
197
+ selector: 'my-component',
198
+ template: '<a routerLink="/home">Home</a>',
199
+ standalone: true,
200
+ imports: [IonRouterLinkWithHref]
201
+ })
202
+ export class MyComponent { }
203
+ ` )
204
+ ) ;
205
+ } ) ;
206
+
207
+ it ( "should detect and import routerAction used in the template" , async ( ) => {
208
+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
209
+ const component = `
210
+ import { Component } from "@angular/core";
211
+
212
+ @Component({
213
+ selector: 'my-component',
214
+ template: '<a routerAction="push">Home</a>',
215
+ standalone: true
216
+ })
217
+ export class MyComponent { }
218
+ ` ;
219
+
220
+ const componentSourceFile = project . createSourceFile (
221
+ "foo.component.ts" ,
222
+ dedent ( component ) ,
223
+ ) ;
224
+
225
+ await migrateComponents ( project , { dryRun : false } ) ;
226
+
227
+ expect ( dedent ( componentSourceFile . getText ( ) ) ) . toBe (
228
+ dedent ( `
229
+ import { Component } from "@angular/core";
230
+ import { IonRouterLinkWithHref } from "@ionic/angular/standalone";
231
+
232
+ @Component({
233
+ selector: 'my-component',
234
+ template: '<a routerAction="push">Home</a>',
235
+ standalone: true,
236
+ imports: [IonRouterLinkWithHref]
237
+ })
238
+ export class MyComponent { }
239
+ ` )
240
+ ) ;
241
+ } ) ;
242
+
243
+ it ( "should detect and import routerDirection used in the template" , async ( ) => {
244
+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
245
+ const component = `
246
+ import { Component } from "@angular/core";
247
+
248
+ @Component({
249
+ selector: 'my-component',
250
+ template: '<a routerDirection="forward">Home</a>',
251
+ standalone: true
252
+ })
253
+ export class MyComponent { }
254
+ ` ;
255
+
256
+ const componentSourceFile = project . createSourceFile (
257
+ "foo.component.ts" ,
258
+ dedent ( component ) ,
259
+ ) ;
260
+
261
+ await migrateComponents ( project , { dryRun : false } ) ;
262
+
263
+ expect ( dedent ( componentSourceFile . getText ( ) ) ) . toBe (
264
+ dedent ( `
265
+ import { Component } from "@angular/core";
266
+ import { IonRouterLinkWithHref } from "@ionic/angular/standalone";
267
+
268
+ @Component({
269
+ selector: 'my-component',
270
+ template: '<a routerDirection="forward">Home</a>',
271
+ standalone: true,
272
+ imports: [IonRouterLinkWithHref]
273
+ })
274
+ export class MyComponent { }
275
+ ` )
276
+ ) ;
277
+ } ) ;
278
+ } ) ;
279
+
280
+ describe ( "Ionic components" , ( ) => {
281
+ it ( "should detect and import routerLink used in the template" , async ( ) => {
282
+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
283
+ const component = `
284
+ import { Component } from "@angular/core";
285
+ import { IonicModule } from "@ionic/angular";
286
+
287
+ @Component({
288
+ selector: 'my-component',
289
+ template: '<ion-button routerLink="/home">Home</ion-button>',
290
+ standalone: true,
291
+ imports: [IonicModule]
292
+ })
293
+ export class MyComponent { }
294
+ ` ;
295
+
296
+ const componentSourceFile = project . createSourceFile (
297
+ "foo.component.ts" ,
298
+ dedent ( component ) ,
299
+ ) ;
300
+
301
+ await migrateComponents ( project , { dryRun : false } ) ;
302
+
303
+ expect ( dedent ( componentSourceFile . getText ( ) ) ) . toBe (
304
+ dedent ( `
305
+ import { Component } from "@angular/core";
306
+ import { IonRouterLink, IonButton } from "@ionic/angular/standalone";
307
+
308
+ @Component({
309
+ selector: 'my-component',
310
+ template: '<ion-button routerLink="/home">Home</ion-button>',
311
+ standalone: true,
312
+ imports: [IonRouterLink, IonButton]
313
+ })
314
+ export class MyComponent { }
315
+ ` )
316
+ ) ;
317
+ } ) ;
318
+
319
+ it ( "should detect and import routerAction used in the template" , async ( ) => {
320
+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
321
+ const component = `
322
+ import { Component } from "@angular/core";
323
+ import { IonicModule } from "@ionic/angular";
324
+
325
+ @Component({
326
+ selector: 'my-component',
327
+ template: '<ion-button routerAction="push">Home</ion-button>',
328
+ standalone: true,
329
+ imports: [IonicModule]
330
+ })
331
+ export class MyComponent { }
332
+ ` ;
333
+
334
+ const componentSourceFile = project . createSourceFile (
335
+ "foo.component.ts" ,
336
+ dedent ( component ) ,
337
+ ) ;
338
+
339
+ await migrateComponents ( project , { dryRun : false } ) ;
340
+
341
+ expect ( dedent ( componentSourceFile . getText ( ) ) ) . toBe (
342
+ dedent ( `
343
+ import { Component } from "@angular/core";
344
+ import { IonRouterLink, IonButton } from "@ionic/angular/standalone";
345
+
346
+ @Component({
347
+ selector: 'my-component',
348
+ template: '<ion-button routerAction="push">Home</ion-button>',
349
+ standalone: true,
350
+ imports: [IonRouterLink, IonButton]
351
+ })
352
+ export class MyComponent { }
353
+ ` )
354
+ ) ;
355
+ } ) ;
356
+
357
+ it ( "should detect and import routerDirection used in the template" , async ( ) => {
358
+ const project = new Project ( { useInMemoryFileSystem : true } ) ;
359
+ const component = `
360
+ import { Component } from "@angular/core";
361
+ import { IonicModule } from "@ionic/angular";
362
+
363
+ @Component({
364
+ selector: 'my-component',
365
+ template: '<ion-button routerDirection="forward">Home</ion-button>',
366
+ standalone: true,
367
+ imports: [IonicModule]
368
+ })
369
+ export class MyComponent { }
370
+ ` ;
371
+
372
+ const componentSourceFile = project . createSourceFile (
373
+ "foo.component.ts" ,
374
+ dedent ( component ) ,
375
+ ) ;
376
+
377
+ await migrateComponents ( project , { dryRun : false } ) ;
378
+
379
+ expect ( dedent ( componentSourceFile . getText ( ) ) ) . toBe (
380
+ dedent ( `
381
+ import { Component } from "@angular/core";
382
+ import { IonRouterLink, IonButton } from "@ionic/angular/standalone";
383
+
384
+ @Component({
385
+ selector: 'my-component',
386
+ template: '<ion-button routerDirection="forward">Home</ion-button>',
387
+ standalone: true,
388
+ imports: [IonRouterLink, IonButton]
389
+ })
390
+ export class MyComponent { }
391
+ ` )
392
+ ) ;
393
+ } ) ;
394
+ } )
395
+
169
396
} ) ;
170
397
171
398
describe ( "single component angular modules" , ( ) => {
0 commit comments