Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 80 additions & 83 deletions projects/igniteui-angular/migrations/update-20_0_6/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,104 +3,101 @@ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/te
import { setupTestTree } from '../common/setup.spec';

describe('Migration 20.0.6 - Replace filteringOptions.filterable', () => {
let appTree: UnitTestTree;
const runner = new SchematicTestRunner(
'ig-migrate',
path.join(__dirname, '../migration-collection.json')
);
const migrationName = 'migration-48';
const makeTemplate = (name: string) => `/testSrc/appPrefix/component/${name}.component.html`;
const makeScript = (name: string) => `/testSrc/appPrefix/component/${name}.component.ts`;
const components = ['igx-simple-combo', 'igx-combo'];



beforeEach(() => {
appTree = setupTestTree();
});

it('should replace simple inline filteringOptions.filterable true with default behavior of the simple combo', async () => {
components.forEach(async component =>{
const input = `<${component} [filteringOptions]="{ filterable: true }"></${component}>`;
appTree.create(makeTemplate(`${component}-inline-true`), input);

const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeTemplate(`${component}-inline-true`));

expect(output).not.toContain('[disableFiltering]');
expect(output).not.toContain('filterable');
});
});

it('should handle mixed object literal correctly', async () => {
components.forEach(async component =>{
const input = `<${component} [filteringOptions]="{ filterable: false, caseSensitive: true }"></${component}>`;
appTree.create(makeTemplate(`${component}-inline2`), input);

const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeTemplate(`${component}-inline2`));

expect(output).toContain(`[disableFiltering]="true"`);
expect(output).toContain(`[filteringOptions]="{ caseSensitive: true }"`);
});
let appTree: UnitTestTree;
const runner = new SchematicTestRunner(
'ig-migrate',
path.join(__dirname, '../migration-collection.json')
);
const migrationName = 'migration-48';
const makeTemplate = (name: string) => `/testSrc/appPrefix/component/${name}.component.html`;
const makeScript = (name: string) => `/testSrc/appPrefix/component/${name}.component.ts`;
const components = ['igx-simple-combo', 'igx-combo'];

const warnMsg =
"Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable. Since it has been deprecated.";

beforeEach(() => {
appTree = setupTestTree();
});

it('should replace simple inline filteringOptions.filterable true with default behavior of the simple combo', async () => {
components.forEach(async component =>{
const input = `<${component} [filteringOptions]="{ filterable: true }"></${component}>`;
appTree.create(makeTemplate(`${component}-inline-true`), input);

const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeTemplate(`${component}-inline-true`));

expect(output).not.toContain('[disableFiltering]');
expect(output).not.toContain('filterable');
});
});

it('should handle mixed object literal correctly', async () => {
components.forEach(async component =>{
const input = `<${component} [filteringOptions]="{ filterable: false, caseSensitive: true }"></${component}>`;
appTree.create(makeTemplate(`${component}-inline2`), input);

const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeTemplate(`${component}-inline2`));

expect(output).toContain(`[disableFiltering]="true"`);
expect(output).toContain(`[filteringOptions]="{ caseSensitive: true }"`);
expect(output).not.toContain('filterable');
});
});

it('should warn on variable reference', async () => {
components.forEach(async component =>{
const input = `<${component} [filteringOptions]="filterOpts""></${component}>`;
const warnMsg = "Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable." +
"Since it has been deprecated.'";

appTree.create(makeTemplate(`${component}-referenceInTsFile`), input);
it('should warn on variable reference', async () => {
for (const component of components) {
const input = `<${component} [filteringOptions]="filterOpts"></${component}>`;

const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeTemplate(`${component}-referenceInTsFile`));
appTree.create(makeTemplate(`${component}-referenceInTsFile`), input);

expect(output).toContain('[filteringOptions]');
expect(output).toContain(warnMsg);
});
});
const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeTemplate(`${component}-referenceInTsFile`));

it('should skip adding new [disableFiltering] if already present on igx-combo', async () => {
const input = `<igx-combo [disableFiltering]="true" [filteringOptions]="{ filterable: false }"></igx-combo>`;
appTree.create(makeTemplate('combo-has-disableFiltering'), input);
expect(output).toContain('[filteringOptions]');
expect(output).toContain(warnMsg);
}
});

const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeTemplate('combo-has-disableFiltering'));
it('should skip adding new [disableFiltering] if already present on igx-combo', async () => {
const input = `<igx-combo [disableFiltering]="true" [filteringOptions]="{ filterable: false }"></igx-combo>`;
appTree.create(makeTemplate('combo-has-disableFiltering'), input);

const occurrences = (output.match(/\[disableFiltering\]/g) || []).length;
const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeTemplate('combo-has-disableFiltering'));

expect(occurrences).toBe(1);
expect(output).not.toContain('filterable');
});
const occurrences = (output.match(/\[disableFiltering\]/g) || []).length;

// TS file tests
expect(occurrences).toBe(1);
expect(output).not.toContain('filterable');
});

it('should insert warning comment before `.filteringOptions.filterable = ...` assignment', async () => {
const input = `this.igxCombo.filteringOptions.filterable = false;`;
const expectedComment = "// Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable." +
"Since it has been deprecated.'";
// TS file tests

appTree.create(makeScript('tsWarnOnDirectAssignment'), input);
it('should insert warning comment before `.filteringOptions.filterable = ...` assignment', async () => {
const input = `this.igxCombo.filteringOptions.filterable = false;`;
const expectedComment = `// ${warnMsg}`;

const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeScript('tsWarnOnDirectAssignment'));
appTree.create(makeScript('tsWarnOnDirectAssignment'), input);

expect(output).toContain(expectedComment);
expect(output).toContain('this.igxCombo.filteringOptions.filterable = false;');
});
const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeScript('tsWarnOnDirectAssignment'));

it('should insert warning comment before `.filteringOptions = { ... }` assignment', async () => {
const input = `this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };`;
const expectedComment = "// Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable." +
"Since it has been deprecated.'";
expect(output).toContain(expectedComment);
expect(output).toContain('this.igxCombo.filteringOptions.filterable = false;');
});

appTree.create(makeScript('tsWarnOnObjectAssignment'), input);
it('should insert warning comment before `.filteringOptions = { ... }` assignment', async () => {
const input = `this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };`;
const expectedComment = `// ${warnMsg}`;
appTree.create(makeScript('tsWarnOnObjectAssignment'), input);

const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeScript('tsWarnOnObjectAssignment'));
const tree = await runner.runSchematic(migrationName, {}, appTree);
const output = tree.readContent(makeScript('tsWarnOnObjectAssignment'));

expect(output).toContain(expectedComment);
expect(output).toContain('this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };');
});
expect(output).toContain(expectedComment);
expect(output).toContain('this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };');
});
});
Loading
Loading