|
| 1 | +import * as path from 'path'; |
| 2 | + |
| 3 | +import { EmptyTree } from '@angular-devkit/schematics'; |
| 4 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 5 | + |
| 6 | +const version = '13.0.0'; |
| 7 | + |
| 8 | +describe(`Update to ${version}`, () => { |
| 9 | + let appTree: UnitTestTree; |
| 10 | + const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json')); |
| 11 | + const configJson = { |
| 12 | + defaultProject: 'testProj', |
| 13 | + projects: { |
| 14 | + testProj: { |
| 15 | + sourceRoot: '/testSrc' |
| 16 | + } |
| 17 | + }, |
| 18 | + schematics: { |
| 19 | + '@schematics/angular:component': { |
| 20 | + prefix: 'appPrefix' |
| 21 | + } |
| 22 | + } |
| 23 | + }; |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + appTree = new UnitTestTree(new EmptyTree()); |
| 27 | + appTree.create('/angular.json', JSON.stringify(configJson)); |
| 28 | + }); |
| 29 | + |
| 30 | + const migrationName = 'migration-22'; |
| 31 | + const lineBreaksAndSpaceRegex = /\s/g; |
| 32 | + |
| 33 | + it('should rename CarouselAnimationType to HorizontalAnimationType', async () => { |
| 34 | + appTree.create( |
| 35 | + '/testSrc/appPrefix/component/test.component.ts', |
| 36 | + `import { Component, ViewChild } from '@angular/core'; |
| 37 | + import { CarouselAnimationType } from 'igniteui-angular'; |
| 38 | +
|
| 39 | + @Component({ |
| 40 | + selector: 'animationType', |
| 41 | + templateUrl: './test.component.html', |
| 42 | + styleUrls: ['./test.component.scss'] |
| 43 | + }) |
| 44 | + export class AnimationType { |
| 45 | + public animationType: CarouselAnimationType = CarouselAnimationType.slide; |
| 46 | + } |
| 47 | + `); |
| 48 | + const tree = await schematicRunner |
| 49 | + .runSchematicAsync(migrationName, {}, appTree) |
| 50 | + .toPromise(); |
| 51 | + |
| 52 | + const expectedContent = `import { Component, ViewChild } from '@angular/core'; |
| 53 | + import { HorizontalAnimationType } from 'igniteui-angular'; |
| 54 | +
|
| 55 | + @Component({ |
| 56 | + selector: 'animationType', |
| 57 | + templateUrl: './test.component.html', |
| 58 | + styleUrls: ['./test.component.scss'] |
| 59 | + }) |
| 60 | + export class AnimationType { |
| 61 | + public animationType: HorizontalAnimationType = HorizontalAnimationType.slide; |
| 62 | + } |
| 63 | + `; |
| 64 | + |
| 65 | + expect( |
| 66 | + tree.readContent( |
| 67 | + '/testSrc/appPrefix/component/test.component.ts' |
| 68 | + ) |
| 69 | + ).toEqual(expectedContent); |
| 70 | + }); |
| 71 | + |
| 72 | + /* eslint-disable arrow-parens */ |
| 73 | + it('Should properly rename columns property to columnsCollection', async () => { |
| 74 | + appTree.create('/testSrc/appPrefix/component/test.component.ts', |
| 75 | + ` |
| 76 | + import { IgxGridComponent } from 'igniteui-angular'; |
| 77 | + export class MyClass { |
| 78 | + @ViewChild(IgxGridComponent, { read: IgxGridComponent }) |
| 79 | + public grid1: IgxGridComponent; |
| 80 | +
|
| 81 | + public ngAfterViewInit() { |
| 82 | + const columns = grid1.columns; |
| 83 | + } |
| 84 | + } |
| 85 | + `); |
| 86 | + |
| 87 | + const tree = await schematicRunner |
| 88 | + .runSchematicAsync(migrationName, {}, appTree) |
| 89 | + .toPromise(); |
| 90 | + |
| 91 | + expect( |
| 92 | + tree.readContent('/testSrc/appPrefix/component/test.component.ts') |
| 93 | + ).toEqual( |
| 94 | + ` |
| 95 | + import { IgxGridComponent } from 'igniteui-angular'; |
| 96 | + export class MyClass { |
| 97 | + @ViewChild(IgxGridComponent, { read: IgxGridComponent }) |
| 98 | + public grid1: IgxGridComponent; |
| 99 | +
|
| 100 | + public ngAfterViewInit() { |
| 101 | + const columns = grid1.columnsCollection; |
| 102 | + } |
| 103 | + } |
| 104 | + ` |
| 105 | + ); |
| 106 | + }); |
| 107 | + |
| 108 | + it('Should properly rename columns property to columnsCollection - treeGrid', async () => { |
| 109 | + appTree.create('/testSrc/appPrefix/component/test.component.ts', |
| 110 | + ` |
| 111 | + import { IgxTreeGridComponent } from 'igniteui-angular'; |
| 112 | + export class MyClass { |
| 113 | + @ViewChild(IgxTreeGridComponent, { read: IgxTreeGridComponent }) |
| 114 | + public tGrid1: IgxTreeGridComponent; |
| 115 | +
|
| 116 | + public ngAfterViewInit() { |
| 117 | + const columns = this.tGrid1.columns; |
| 118 | + } |
| 119 | +
|
| 120 | + public soSth() { |
| 121 | + const editableColumns = this.tGrid1.columns.filter(c => e.editable); |
| 122 | + } |
| 123 | + } |
| 124 | + `); |
| 125 | + |
| 126 | + const tree = await schematicRunner |
| 127 | + .runSchematicAsync(migrationName, {}, appTree) |
| 128 | + .toPromise(); |
| 129 | + |
| 130 | + expect( |
| 131 | + tree.readContent('/testSrc/appPrefix/component/test.component.ts') |
| 132 | + ).toEqual( |
| 133 | + ` |
| 134 | + import { IgxTreeGridComponent } from 'igniteui-angular'; |
| 135 | + export class MyClass { |
| 136 | + @ViewChild(IgxTreeGridComponent, { read: IgxTreeGridComponent }) |
| 137 | + public tGrid1: IgxTreeGridComponent; |
| 138 | +
|
| 139 | + public ngAfterViewInit() { |
| 140 | + const columns = this.tGrid1.columnsCollection; |
| 141 | + } |
| 142 | +
|
| 143 | + public soSth() { |
| 144 | + const editableColumns = this.tGrid1.columnsCollection.filter(c => e.editable); |
| 145 | + } |
| 146 | + } |
| 147 | + ` |
| 148 | + ); |
| 149 | + }); |
| 150 | + |
| 151 | + it('should remove paging and paginationTemplate property and define a igx-paginator component with custom content', async () => { |
| 152 | + appTree.create( |
| 153 | + '/testSrc/appPrefix/component/test.component.html', ` |
| 154 | +<div class="columnHidingContainer"> |
| 155 | + <div *ngFor="let col of grid.columns"> |
| 156 | + {{col.field}} |
| 157 | + </div> |
| 158 | +</div> |
| 159 | +<div class="gridContainer"> |
| 160 | + <igx-grid igxPreventDocumentScroll #grid [data]="data" [autoGenerate]="false" width="100%" height="560px" columnWidth="200px" |
| 161 | + [allowFiltering]="true"> |
| 162 | + <igx-column [field]="'ID'" dataType="string" [sortable]="true"></igx-column> |
| 163 | + <igx-column [field]="'ContactName'" dataType="string" [sortable]="true" [disableHiding]="true"></igx-column> |
| 164 | + <igx-column [field]="'ContactTitle'" dataType="string" [sortable]="true" [disableHiding]="true"></igx-column> |
| 165 | + <igx-column [field]="'City'" dataType="string" [sortable]="true"></igx-column> |
| 166 | + <igx-column [field]="'CompanyName'" dataType="string" [sortable]="true"></igx-column> |
| 167 | + </igx-grid> |
| 168 | +</div>`); |
| 169 | + const tree = await schematicRunner.runSchematicAsync(migrationName, {}, appTree) |
| 170 | + .toPromise(); |
| 171 | + |
| 172 | + expect(tree.readContent('/testSrc/appPrefix/component/test.component.html').replace(lineBreaksAndSpaceRegex, '')) |
| 173 | + .toEqual(` |
| 174 | +<div class="columnHidingContainer"> |
| 175 | + <div *ngFor="let col of grid.columnsCollection"> |
| 176 | + {{col.field}} |
| 177 | + </div> |
| 178 | +</div> |
| 179 | +<div class="gridContainer"> |
| 180 | + <igx-grid igxPreventDocumentScroll #grid [data]="data" [autoGenerate]="false" width="100%" height="560px" columnWidth="200px" |
| 181 | + [allowFiltering]="true"> |
| 182 | + <igx-column [field]="'ID'" dataType="string" [sortable]="true"></igx-column> |
| 183 | + <igx-column [field]="'ContactName'" dataType="string" [sortable]="true" [disableHiding]="true"></igx-column> |
| 184 | + <igx-column [field]="'ContactTitle'" dataType="string" [sortable]="true" [disableHiding]="true"></igx-column> |
| 185 | + <igx-column [field]="'City'" dataType="string" [sortable]="true"></igx-column> |
| 186 | + <igx-column [field]="'CompanyName'" dataType="string" [sortable]="true"></igx-column> |
| 187 | + </igx-grid> |
| 188 | +</div> |
| 189 | +`.replace(lineBreaksAndSpaceRegex, '')); |
| 190 | + }); |
| 191 | +}); |
0 commit comments