diff --git a/projects/cdk/schematics/ng-update/v4/steps/constants/identifiers-to-replace.ts b/projects/cdk/schematics/ng-update/v4/steps/constants/identifiers-to-replace.ts index 2eac26d4eb7f..26fea89e8131 100644 --- a/projects/cdk/schematics/ng-update/v4/steps/constants/identifiers-to-replace.ts +++ b/projects/cdk/schematics/ng-update/v4/steps/constants/identifiers-to-replace.ts @@ -294,6 +294,26 @@ export const IDENTIFIERS_TO_REPLACE: ReplacementIdentifierMulti[] = [ from: {name: 'TuiTreeModule', moduleSpecifier: '@taiga-ui/kit'}, to: {name: 'TuiTree', moduleSpecifier: '@taiga-ui/kit', spreadInModule: true}, }, + { + from: {name: 'TuiTreeItemComponent', moduleSpecifier: '@taiga-ui/kit'}, + to: {name: 'TuiTreeItem', moduleSpecifier: '@taiga-ui/kit'}, + }, + { + from: {name: 'TuiTreeItemContentComponent', moduleSpecifier: '@taiga-ui/kit'}, + to: {name: 'TuiTreeItemContent', moduleSpecifier: '@taiga-ui/kit'}, + }, + { + from: {name: 'TuiTreeChildrenDirective', moduleSpecifier: '@taiga-ui/kit'}, + to: {name: 'TuiTreeChildren', moduleSpecifier: '@taiga-ui/kit'}, + }, + { + from: {name: 'TuiTreeItemControllerDirective', moduleSpecifier: '@taiga-ui/kit'}, + to: {name: 'TuiTreeItemController', moduleSpecifier: '@taiga-ui/kit'}, + }, + { + from: {name: 'TuiTreeNodeDirective', moduleSpecifier: '@taiga-ui/kit'}, + to: {name: 'TuiTreeNode', moduleSpecifier: '@taiga-ui/kit'}, + }, { from: { name: 'TuiDataListDropdownManagerModule', diff --git a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-tree.spec.ts b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-tree.spec.ts new file mode 100644 index 000000000000..f0286b06beb4 --- /dev/null +++ b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-tree.spec.ts @@ -0,0 +1,101 @@ +import {join} from 'node:path'; + +import {HostTree} from '@angular-devkit/schematics'; +import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; +import type {TuiSchema} from '@taiga-ui/cdk/schematics/ng-add/schema'; +import { + createProject, + createSourceFile, + resetActiveProject, + saveActiveProject, + setActiveProject, +} from 'ng-morph'; + +import {createAngularJson} from '../../../utils/create-angular-json'; + +const collectionPath = join(__dirname, '../../../migration.json'); + +const COMPONENT_BEFORE = ` +import { TuiTreeModule, TuiTreeComponent, + TuiTreeItemComponent, + TuiTreeItemContentComponent, + TuiTreeChildrenDirective, + TuiTreeItemControllerDirective, + TuiTreeControllerDirective, + TuiTreeNodeDirective } from "@taiga-ui/kit"; + +@Component({ + standalone: true, + template: '', + imports: [TuiTreeModule] +}) +export class Test { + protected readonly list = [ + TuiTreeComponent, + TuiTreeItemComponent, + TuiTreeItemContentComponent, + TuiTreeChildrenDirective, + TuiTreeItemControllerDirective, + TuiTreeControllerDirective, + TuiTreeNodeDirective, + ]; +}`; + +const COMPONENT_AFTER = ` +import { TuiTreeComponent, TuiTreeControllerDirective, TuiTree, TuiTreeItem, TuiTreeItemContent, TuiTreeChildren, TuiTreeItemController, TuiTreeNode } from "@taiga-ui/kit"; + +@Component({ + standalone: true, + template: '', + imports: [TuiTree] +}) +export class Test { + protected readonly list = [ + TuiTreeComponent, + TuiTreeItem, + TuiTreeItemContent, + TuiTreeChildren, + TuiTreeItemController, + TuiTreeControllerDirective, + TuiTreeNode, + ]; +}`; + +describe('ng-update', () => { + let host: UnitTestTree; + let runner: SchematicTestRunner; + + beforeEach(() => { + host = new UnitTestTree(new HostTree()); + runner = new SchematicTestRunner('schematics', collectionPath); + + setActiveProject(createProject(host)); + + createMainFiles(); + + saveActiveProject(); + }); + + it('should migrate tree references', async () => { + const tree = await runner.runSchematic( + 'updateToV4', + {'skip-logs': process.env['TUI_CI'] === 'true'} as Partial, + host, + ); + + expect(tree.readContent('test/app/test.component.ts')).toEqual(COMPONENT_AFTER); + }); + + afterEach(() => { + resetActiveProject(); + }); +}); + +function createMainFiles(): void { + createSourceFile('test/app/test.component.ts', COMPONENT_BEFORE); + createAngularJson(); + createSourceFile( + 'package.json', + '{"dependencies": {"@angular/core": "~13.0.0", "@taiga-ui/addon-commerce": "~3.42.0"}}', + ); +}