|
| 1 | +import * as path from 'path'; |
| 2 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 3 | +import { setupTestTree } from '../common/setup.spec'; |
| 4 | + |
| 5 | +describe('Migration 20.0.6 - 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-48'; |
| 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 | + }); |
| 46 | + }); |
| 47 | + |
| 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.'"; |
| 53 | + |
| 54 | + appTree.create(makeTemplate(`${component}-referenceInTsFile`), input); |
| 55 | + |
| 56 | + const tree = await runner.runSchematic(migrationName, {}, appTree); |
| 57 | + const output = tree.readContent(makeTemplate(`${component}-referenceInTsFile`)); |
| 58 | + |
| 59 | + expect(output).toContain('[filteringOptions]'); |
| 60 | + expect(output).toContain(warnMsg); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 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); |
| 67 | + |
| 68 | + const tree = await runner.runSchematic(migrationName, {}, appTree); |
| 69 | + const output = tree.readContent(makeTemplate('combo-has-disableFiltering')); |
| 70 | + |
| 71 | + const occurrences = (output.match(/\[disableFiltering\]/g) || []).length; |
| 72 | + |
| 73 | + expect(occurrences).toBe(1); |
| 74 | + expect(output).not.toContain('filterable'); |
| 75 | + }); |
| 76 | + |
| 77 | + // TS file tests |
| 78 | + |
| 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.'"; |
| 83 | + |
| 84 | + appTree.create(makeScript('tsWarnOnDirectAssignment'), input); |
| 85 | + |
| 86 | + const tree = await runner.runSchematic(migrationName, {}, appTree); |
| 87 | + const output = tree.readContent(makeScript('tsWarnOnDirectAssignment')); |
| 88 | + |
| 89 | + expect(output).toContain(expectedComment); |
| 90 | + expect(output).toContain('this.igxCombo.filteringOptions.filterable = false;'); |
| 91 | + }); |
| 92 | + |
| 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 | + }); |
| 106 | +}); |
0 commit comments