igniteui-angular-sovn
Version:
Ignite UI for Angular is a dependency-free Angular toolkit for building modern web apps
109 lines (99 loc) • 4.16 kB
text/typescript
import * as path from 'path';
import { EmptyTree } from '@angular-devkit/schematics';
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { workspaces } from '@angular-devkit/core';
import * as addNormalize from '../../schematics/ng-add/add-normalize';
describe('Update 7.2.0', () => {
let appTree: UnitTestTree;
const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json'));
const configJson = {
version: 1,
projects: {
testProj: {
root: '/',
sourceRoot: '/testSrc'
}
},
schematics: {
'@schematics/angular:component': {
prefix: 'appPrefix'
}
}
};
beforeEach(() => {
appTree = new UnitTestTree(new EmptyTree());
appTree.create('/angular.json', JSON.stringify(configJson));
});
it(`should replace **ONLY** 'isSelected' and 'isFocused'`, async () => {
appTree.create(
'/testSrc/appPrefix/component/custom.component.html',
`<igx-drop-down
<igx-drop-down-item
isSelected="something"
isFocused="isSelected"
>1
</igx-drop-down-item>
<igx-drop-down-item
[]="something2"
[]="isFocused == 2"
>2
</igx-drop-down-item>
<igx-drop-down-item
[ isSelected ]="something3"
[ isFocused ]=" isFocused === '7'"
>3
</igx-drop-down-item>
<igx-drop-down-item
[]="something3"
[]="isFocused === '7'"
myCustomDirective [myCustomItem_isSelected]="true"
>4
</igx-drop-down-item>
</igx-drop-down>`);
const tree = await schematicRunner.runSchematicAsync('migration-08', {}, appTree)
.toPromise();
expect(tree.readContent('/testSrc/appPrefix/component/custom.component.html'))
.toEqual(
`<igx-drop-down
<igx-drop-down-item
selected="something"
focused="isSelected"
>1
</igx-drop-down-item>
<igx-drop-down-item
[]="something2"
[]="isFocused == 2"
>2
</igx-drop-down-item>
<igx-drop-down-item
[ selected ]="something3"
[ focused ]=" isFocused === '7'"
>3
</igx-drop-down-item>
<igx-drop-down-item
[]="something3"
[]="isFocused === '7'"
myCustomDirective [myCustomItem_isSelected]="true"
>4
</igx-drop-down-item>
</igx-drop-down>`);
});
it(`should add minireset css package and import`, async () => {
appTree.create('/testSrc/styles.scss', '');
appTree.create('package.json', '{}');
spyOn(addNormalize, 'addResetCss').and.callThrough();
const tree = await schematicRunner.runSchematicAsync('migration-08', {}, appTree)
.toPromise();
expect(addNormalize.addResetCss).toHaveBeenCalledWith(
jasmine.objectContaining<workspaces.WorkspaceDefinition>({
extensions: jasmine.anything(),
projects: jasmine.anything()
}), appTree);
expect(tree.readContent('/testSrc/styles.scss')).toContain(addNormalize.scssImport);
expect(JSON.parse(tree.readContent('package.json'))).toEqual({
dependencies: { 'minireset.css': '~0.0.4' }
});
expect(schematicRunner.tasks).toContain(new NodePackageInstallTask().toConfiguration());
});
});