@@ -3,106 +3,101 @@ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/te
33import { setupTestTree } from '../common/setup.spec' ;
44
55describe ( 'Migration 19.2.15 - Replace filteringOptions.filterable' , ( ) => {
6- let appTree : UnitTestTree ;
7- const runner = new SchematicTestRunner (
8- 'ig-migrate' ,
9- path . join ( __dirname , '../migration-collection.json' )
10- ) ;
11- const migrationName = 'migration-46' ;
12- const makeTemplate = ( name : string ) => `/testSrc/appPrefix/component/${ name } .component.html` ;
13- const makeScript = ( name : string ) => `/testSrc/appPrefix/component/${ name } .component.ts` ;
14- const components = [ 'igx-simple-combo' , 'igx-combo' ] ;
15-
16-
17-
18- beforeEach ( ( ) => {
19- appTree = setupTestTree ( ) ;
20- } ) ;
21-
22- it ( 'should replace simple inline filteringOptions.filterable true with default behavior of the simple combo' , async ( ) => {
23- components . forEach ( async component => {
24- const input = `<${ component } [filteringOptions]="{ filterable: true }"></${ component } >` ;
25- appTree . create ( makeTemplate ( `${ component } -inline-true` ) , input ) ;
26-
27- const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
28- const output = tree . readContent ( makeTemplate ( `${ component } -inline-true` ) ) ;
29-
30- expect ( output ) . not . toContain ( '[disableFiltering]' ) ;
31- expect ( output ) . not . toContain ( 'filterable' ) ;
32- } ) ;
33- } ) ;
34-
35- it ( 'should handle mixed object literal correctly' , async ( ) => {
36- components . forEach ( async component => {
37- const input = `<${ component } [filteringOptions]="{ filterable: false, caseSensitive: true }"></${ component } >` ;
38- appTree . create ( makeTemplate ( `${ component } -inline2` ) , input ) ;
39-
40- const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
41- const output = tree . readContent ( makeTemplate ( `${ component } -inline2` ) ) ;
42-
43- expect ( output ) . toContain ( `[disableFiltering]="true"` ) ;
44- expect ( output ) . toContain ( `[filteringOptions]="{ caseSensitive: true }"` ) ;
45- } ) ;
6+ let appTree : UnitTestTree ;
7+ const runner = new SchematicTestRunner (
8+ 'ig-migrate' ,
9+ path . join ( __dirname , '../migration-collection.json' )
10+ ) ;
11+ const migrationName = 'migration-46' ;
12+ const makeTemplate = ( name : string ) => `/testSrc/appPrefix/component/${ name } .component.html` ;
13+ const makeScript = ( name : string ) => `/testSrc/appPrefix/component/${ name } .component.ts` ;
14+ const components = [ 'igx-simple-combo' , 'igx-combo' ] ;
15+
16+ const warnMsg =
17+ "Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable. Since it has been deprecated." ;
18+
19+ beforeEach ( ( ) => {
20+ appTree = setupTestTree ( ) ;
21+ } ) ;
22+
23+ it ( 'should replace simple inline filteringOptions.filterable true with default behavior of the simple combo' , async ( ) => {
24+ components . forEach ( async component => {
25+ const input = `<${ component } [filteringOptions]="{ filterable: true }"></${ component } >` ;
26+ appTree . create ( makeTemplate ( `${ component } -inline-true` ) , input ) ;
27+
28+ const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
29+ const output = tree . readContent ( makeTemplate ( `${ component } -inline-true` ) ) ;
30+
31+ expect ( output ) . not . toContain ( '[disableFiltering]' ) ;
32+ expect ( output ) . not . toContain ( 'filterable' ) ;
33+ } ) ;
34+ } ) ;
35+
36+ it ( 'should handle mixed object literal correctly' , async ( ) => {
37+ components . forEach ( async component => {
38+ const input = `<${ component } [filteringOptions]="{ filterable: false, caseSensitive: true }"></${ component } >` ;
39+ appTree . create ( makeTemplate ( `${ component } -inline2` ) , input ) ;
40+
41+ const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
42+ const output = tree . readContent ( makeTemplate ( `${ component } -inline2` ) ) ;
43+
44+ expect ( output ) . toContain ( `[disableFiltering]="true"` ) ;
45+ expect ( output ) . toContain ( `[filteringOptions]="{ caseSensitive: true }"` ) ;
46+ expect ( output ) . not . toContain ( 'filterable' ) ;
4647 } ) ;
48+ } ) ;
4749
48- it ( 'should warn on variable reference' , async ( ) => {
49- components . forEach ( async component => {
50- const input = `<${ component } [filteringOptions]="filterOpts""></${ component } >` ;
51- const warnMsg = "Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable." +
52- "Since it has been deprecated.'" ;
50+ it ( 'should warn on variable reference' , async ( ) => {
51+ for ( const component of components ) {
52+ const input = `<${ component } [filteringOptions]="filterOpts"></${ component } >` ;
5353
54- appTree . create ( makeTemplate ( `${ component } -referenceInTsFile` ) , input ) ;
54+ appTree . create ( makeTemplate ( `${ component } -referenceInTsFile` ) , input ) ;
5555
56- const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
57- const output = tree . readContent ( makeTemplate ( `${ component } -referenceInTsFile` ) ) ;
56+ const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
57+ const output = tree . readContent ( makeTemplate ( `${ component } -referenceInTsFile` ) ) ;
5858
59- expect ( output ) . toContain ( '[filteringOptions]' ) ;
60- expect ( output ) . toContain ( warnMsg ) ;
61- } ) ;
62- } ) ;
59+ expect ( output ) . toContain ( '[filteringOptions]' ) ;
60+ expect ( output ) . toContain ( warnMsg ) ;
61+ }
62+ } ) ;
6363
64- it ( 'should skip adding new [disableFiltering] if already present on igx-combo' , async ( ) => {
65- const input = `<igx-combo [disableFiltering]="true" [filteringOptions]="{ filterable: false }"></igx-combo>` ;
66- appTree . create ( makeTemplate ( 'combo-has-disableFiltering' ) , input ) ;
64+ it ( 'should skip adding new [disableFiltering] if already present on igx-combo' , async ( ) => {
65+ const input = `<igx-combo [disableFiltering]="true" [filteringOptions]="{ filterable: false }"></igx-combo>` ;
66+ appTree . create ( makeTemplate ( 'combo-has-disableFiltering' ) , input ) ;
6767
68- const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
69- const output = tree . readContent ( makeTemplate ( 'combo-has-disableFiltering' ) ) ;
68+ const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
69+ const output = tree . readContent ( makeTemplate ( 'combo-has-disableFiltering' ) ) ;
7070
71- const occurrences = ( output . match ( / \[ d i s a b l e F i l t e r i n g \] / g) || [ ] ) . length ;
71+ const occurrences = ( output . match ( / \[ d i s a b l e F i l t e r i n g \] / g) || [ ] ) . length ;
7272
73- expect ( occurrences ) . toBe ( 1 ) ;
74- expect ( output ) . not . toContain ( 'filterable' ) ;
75- } ) ;
73+ expect ( occurrences ) . toBe ( 1 ) ;
74+ expect ( output ) . not . toContain ( 'filterable' ) ;
75+ } ) ;
7676
77- // TS file tests
77+ // TS file tests
7878
79- it ( 'should insert warning comment before `.filteringOptions.filterable = ...` assignment' , async ( ) => {
80- const input = `this.igxCombo.filteringOptions.filterable = false;` ;
81- const expectedComment = "// Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable." +
82- "Since it has been deprecated.'" ;
79+ it ( 'should insert warning comment before `.filteringOptions.filterable = ...` assignment' , async ( ) => {
80+ const input = `this.igxCombo.filteringOptions.filterable = false;` ;
81+ const expectedComment = `// ${ warnMsg } ` ;
8382
84- appTree . create ( makeScript ( 'tsWarnOnDirectAssignment' ) , input ) ;
83+ appTree . create ( makeScript ( 'tsWarnOnDirectAssignment' ) , input ) ;
8584
86- const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
87- const output = tree . readContent ( makeScript ( 'tsWarnOnDirectAssignment' ) ) ;
85+ const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
86+ const output = tree . readContent ( makeScript ( 'tsWarnOnDirectAssignment' ) ) ;
8887
89- expect ( output ) . toContain ( expectedComment ) ;
90- expect ( output ) . toContain ( 'this.igxCombo.filteringOptions.filterable = false;' ) ;
91- } ) ;
88+ expect ( output ) . toContain ( expectedComment ) ;
89+ expect ( output ) . toContain ( 'this.igxCombo.filteringOptions.filterable = false;' ) ;
90+ } ) ;
9291
93- it ( 'should insert warning comment before `.filteringOptions = { ... }` assignment' , async ( ) => {
94- const input = `this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };` ;
95- const expectedComment = "// Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable." +
96- "Since it has been deprecated.'" ;
97-
98- appTree . create ( makeScript ( 'tsWarnOnObjectAssignment' ) , input ) ;
99-
100- const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
101- const output = tree . readContent ( makeScript ( 'tsWarnOnObjectAssignment' ) ) ;
102-
103- expect ( output ) . toContain ( expectedComment ) ;
104- expect ( output ) . toContain ( 'this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };' ) ;
105- } ) ;
92+ it ( 'should insert warning comment before `.filteringOptions = { ... }` assignment' , async ( ) => {
93+ const input = `this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };` ;
94+ const expectedComment = `// ${ warnMsg } ` ;
95+ appTree . create ( makeScript ( 'tsWarnOnObjectAssignment' ) , input ) ;
10696
97+ const tree = await runner . runSchematic ( migrationName , { } , appTree ) ;
98+ const output = tree . readContent ( makeScript ( 'tsWarnOnObjectAssignment' ) ) ;
10799
100+ expect ( output ) . toContain ( expectedComment ) ;
101+ expect ( output ) . toContain ( 'this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };' ) ;
102+ } ) ;
108103} ) ;
0 commit comments