@@ -6,6 +6,7 @@ import * as fs from 'fs';
66import * as path from 'path' ;
77import { ClassChanges , BindingChanges , SelectorChanges , ThemePropertyChanges , ImportsChanges } from './schema' ;
88import { UpdateChanges } from './UpdateChanges' ;
9+ import * as tsUtils from './tsUtils' ;
910
1011describe ( 'UpdateChanges' , ( ) => {
1112 let appTree : UnitTestTree ;
@@ -226,7 +227,8 @@ describe('UpdateChanges', () => {
226227 } ) ;
227228 spyOn < any > ( fs , 'readFileSync' ) . and . callFake ( ( ) => JSON . stringify ( classJson ) ) ;
228229
229- const fileContent = `import { igxClass } from ""; export class Test { prop: igxClass; prop2: igxClass2; }` ;
230+ const fileContent =
231+ `import { igxClass, igxClass2 } from "igniteui-angular"; export class Test { prop: igxClass; prop2: igxClass2; }` ;
230232 appTree . create ( 'test.component.ts' , fileContent ) ;
231233
232234 const update = new UnitUpdateChanges ( __dirname , appTree ) ;
@@ -236,7 +238,7 @@ describe('UpdateChanges', () => {
236238
237239 update . applyChanges ( ) ;
238240 expect ( appTree . readContent ( 'test.component.ts' ) ) . toEqual (
239- `import { igxReplace } from ""; export class Test { prop: igxReplace; prop2: igxSecond; }` ) ;
241+ `import { igxReplace, igxSecond } from "igniteui-angular "; export class Test { prop: igxReplace; prop2: igxSecond; }` ) ;
240242
241243 done ( ) ;
242244 } ) ;
@@ -268,13 +270,13 @@ describe('UpdateChanges', () => {
268270
269271 const fileContent =
270272 `import { Component, Injectable, ViewChild } from "@angular/core";` +
271- `import { IgxGridComponent } from "../../lib/grid/grid.component ";` +
272- `import { IgxColumnComponent, IgxProvided, STRING_FILTERS} from "../../lib/main ";\r\n` +
273+ `import { IgxGridComponent } from "igniteui-angular ";` +
274+ `import { IgxColumnComponent, IgxProvided, STRING_FILTERS} from "igniteui-angular ";\r\n` +
273275 `import {` +
274276 ` IgxCsvExporterService,` +
275277 ` IgxExcelExporterOptions,` +
276278 ` IgxExporterOptionsBase` +
277- `} from "../../lib/services/index ";\r\n` +
279+ `} from "igniteui-angular ";\r\n` +
278280 `@Component({` +
279281 ` providers: [IgxProvided, RemoteService]` +
280282 `})` +
@@ -306,13 +308,13 @@ describe('UpdateChanges', () => {
306308 update . applyChanges ( ) ;
307309 expect ( appTree . readContent ( 'test.component.ts' ) ) . toEqual (
308310 `import { Component, Injectable, ViewChild } from "@angular/core";` +
309- `import { IgxGridReplace } from "../../lib/grid/grid.component ";` +
310- `import { IgxColumnReplace, IgxProvidedReplace, REPLACED_CONST} from "../../lib/main ";\r\n` +
311+ `import { IgxGridReplace } from "igniteui-angular ";` +
312+ `import { IgxColumnReplace, IgxProvidedReplace, REPLACED_CONST} from "igniteui-angular ";\r\n` +
311313 `import {` +
312314 ` Injected,` +
313315 ` IgxNewable,` +
314316 ` ReturnType` +
315- `} from "../../lib/services/index ";\r\n` +
317+ `} from "igniteui-angular ";\r\n` +
316318 `@Component({` +
317319 ` providers: [IgxProvidedReplace, RemoteService]` +
318320 `})` +
@@ -338,6 +340,93 @@ describe('UpdateChanges', () => {
338340 done ( ) ;
339341 } ) ;
340342
343+ it ( 'should correctly ignore types not from igniteui-angular' , ( ) => {
344+ const classJson : ClassChanges = {
345+ changes : [
346+ { name : 'Name' , replaceWith : 'NameName' } ,
347+ { name : 'Another' , replaceWith : 'Other' } ,
348+ ]
349+ } ;
350+ const jsonPath = path . join ( __dirname , 'changes' , 'classes.json' ) ;
351+ spyOn ( fs , 'existsSync' ) . and . callFake ( ( filePath : string ) => {
352+ if ( filePath === jsonPath ) {
353+ return true ;
354+ }
355+ return false ;
356+ } ) ;
357+ spyOn < any > ( fs , 'readFileSync' ) . and . callFake ( ( ) => JSON . stringify ( classJson ) ) ;
358+
359+ const fileContent =
360+ `import { Name } from ""; import { Another } from "@space/package"; export class Test { prop: Name; prop2: Another; }` ;
361+ appTree . create ( 'test.component.ts' , fileContent ) ;
362+
363+ const update = new UnitUpdateChanges ( __dirname , appTree ) ;
364+ expect ( update . getClassChanges ( ) ) . toEqual ( classJson ) ;
365+
366+ spyOn ( tsUtils , 'getRenamePositions' ) . and . callThrough ( ) ;
367+
368+ update . applyChanges ( ) ;
369+ expect ( tsUtils . getRenamePositions ) . toHaveBeenCalledWith ( '/test.component.ts' , 'Name' , jasmine . anything ( ) ) ;
370+ expect ( tsUtils . getRenamePositions ) . toHaveBeenCalledWith ( '/test.component.ts' , 'Another' , jasmine . anything ( ) ) ;
371+ expect ( appTree . readContent ( 'test.component.ts' ) ) . toEqual ( fileContent ) ;
372+ } ) ;
373+
374+ it ( 'should correctly rename aliased imports and handle collision from other packages' , ( ) => {
375+ const classJson : ClassChanges = {
376+ changes : [
377+ { name : 'Type' , replaceWith : 'IgxType' } ,
378+ { name : 'Size' , replaceWith : 'IgxSize' } ,
379+ { name : 'IgxService' , replaceWith : 'IgxService1' } ,
380+ { name : 'IgxDiffService' , replaceWith : 'IgxNewDiffService' } ,
381+ { name : 'Calendar' , replaceWith : 'CalendarActual' }
382+ ]
383+ } ;
384+ const jsonPath = path . join ( __dirname , 'changes' , 'classes.json' ) ;
385+ spyOn ( fs , 'existsSync' ) . and . callFake ( ( filePath : string ) => {
386+ if ( filePath === jsonPath ) {
387+ return true ;
388+ }
389+ return false ;
390+ } ) ;
391+ spyOn < any > ( fs , 'readFileSync' ) . and . callFake ( ( ) => JSON . stringify ( classJson ) ) ;
392+
393+ const fileContent =
394+ `import { Size, Type as someThg } from "igniteui-angular";
395+ import { IgxService, IgxDiffService as eDiffService, Calendar as Calendar } from 'igniteui-angular';
396+ import { Type } from "@angular/core";
397+ export class Test {
398+ prop: Type;
399+ prop1: someThg;
400+ prop2: Size = { prop: "Size" };
401+ secondary: eDiffService;
402+ cal: Calendar;
403+
404+ constructor (public router: Router, private _iconService: IgxService) {}
405+ }` ;
406+ appTree . create ( 'test.component.ts' , fileContent ) ;
407+
408+ const update = new UnitUpdateChanges ( __dirname , appTree ) ;
409+ expect ( fs . existsSync ) . toHaveBeenCalledWith ( jsonPath ) ;
410+ expect ( fs . readFileSync ) . toHaveBeenCalledWith ( jsonPath , 'utf-8' ) ;
411+ expect ( update . getClassChanges ( ) ) . toEqual ( classJson ) ;
412+
413+ update . applyChanges ( ) ;
414+ expect ( appTree . readContent ( 'test.component.ts' ) ) . toEqual (
415+ `import { IgxSize, IgxType as someThg } from "igniteui-angular";
416+ import { IgxService1, IgxNewDiffService as eDiffService, CalendarActual as Calendar } from 'igniteui-angular';
417+ import { Type } from "@angular/core";
418+ export class Test {
419+ prop: Type;
420+ prop1: someThg;
421+ prop2: IgxSize = { prop: "Size" };
422+ secondary: eDiffService;
423+ cal: Calendar;
424+
425+ constructor (public router: Router, private _iconService: IgxService1) {}
426+ }`
427+ ) ;
428+ } ) ;
429+
341430 it ( 'should move property value between element tags' , done => {
342431 const inputJson : BindingChanges = {
343432 changes : [
0 commit comments