From 37c92d10f232c29075644e2dee66e2c12f147282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Thu, 9 Jan 2025 14:37:17 +0300 Subject: [PATCH] chore(schematics): valid migration for error pipe module (#10096) --- .../steps/constants/identifiers-to-replace.ts | 5 +- .../v4/tests/schematic-migrate-error.spec.ts | 104 ++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-error.spec.ts 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 476854bee19f..f724da9f27bc 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 @@ -354,7 +354,10 @@ export const IDENTIFIERS_TO_REPLACE: ReplacementIdentifierMulti[] = [ }, { from: {name: 'TuiFieldErrorPipeModule', moduleSpecifier: '@taiga-ui/kit'}, - to: {name: 'TuiFieldErrorPipe', moduleSpecifier: '@taiga-ui/kit'}, + to: [ + {name: 'TuiFieldErrorPipe', moduleSpecifier: '@taiga-ui/kit'}, + {name: 'TuiFieldErrorContentPipe', moduleSpecifier: '@taiga-ui/kit'}, + ], }, { from: {name: 'TuiThumbnailCardModule', moduleSpecifier: '@taiga-ui/experimental'}, diff --git a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-error.spec.ts b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-error.spec.ts new file mode 100644 index 000000000000..d861d63db6d5 --- /dev/null +++ b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-error.spec.ts @@ -0,0 +1,104 @@ +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 { TuiInputModule, TuiFieldErrorPipeModule } from "@taiga-ui/kit"; + +@Component({ + standalone: true, + templateUrl: './test.template.html', + imports: [ TuiInputModule, TuiFieldErrorPipeModule] +}) +export class Test { +}`; + +const COMPONENT_AFTER = `import { TuiInputModule } from "@taiga-ui/legacy"; + +import { TuiFieldErrorPipe, TuiFieldErrorContentPipe } from "@taiga-ui/kit"; + +@Component({ + standalone: true, + templateUrl: './test.template.html', + imports: [ TuiInputModule, TuiFieldErrorPipe, TuiFieldErrorContentPipe] +}) +export class Test { +}`; + +const TEMPLATE_BEFORE = ` + + Tooltip host + +`; + +const TEMPLATE_AFTER = ` + + Tooltip host + +`; + +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 error pipe in template', async () => { + const tree = await runner.runSchematic( + 'updateToV4', + {'skip-logs': process.env['TUI_CI'] === 'true'} as Partial, + host, + ); + + expect(tree.readContent('test/app/test.template.html')).toEqual(TEMPLATE_AFTER); + expect(tree.readContent('test/app/test.component.ts')).toEqual(COMPONENT_AFTER); + }); + + afterEach(() => { + resetActiveProject(); + }); +}); + +function createMainFiles(): void { + createSourceFile('test/app/test.component.ts', COMPONENT_BEFORE); + createSourceFile('test/app/test.template.html', TEMPLATE_BEFORE); + createAngularJson(); + createSourceFile( + 'package.json', + '{"dependencies": {"@angular/core": "~13.0.0", "@taiga-ui/addon-commerce": "~3.42.0"}}', + ); +}