From 692df665ed7d6196e7667b98e20dfd8fad34af1c Mon Sep 17 00:00:00 2001 From: splincode Date: Fri, 27 Dec 2024 11:20:02 +0300 Subject: [PATCH] chore(schematics): valid migration for addon-table --- .../steps/constants/identifiers-to-replace.ts | 20 +++ .../schematic-migrate-pagination.spec.ts | 114 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-pagination.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 53b2ce1dc21a..2eac26d4eb7f 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 @@ -715,6 +715,16 @@ export const IDENTIFIERS_TO_REPLACE: ReplacementIdentifierMulti[] = [ from: {name: 'TuiChipModule', moduleSpecifier: '@taiga-ui/experimental'}, to: {name: 'TuiChip', moduleSpecifier: '@taiga-ui/kit'}, }, + { + from: { + name: 'TuiTablePagination', + moduleSpecifier: '@taiga-ui/addon-table', + }, + to: { + name: 'TuiTablePaginationEvent', + moduleSpecifier: '@taiga-ui/addon-table', + }, + }, { from: { name: 'TuiTablePaginationModule', @@ -725,6 +735,16 @@ export const IDENTIFIERS_TO_REPLACE: ReplacementIdentifierMulti[] = [ moduleSpecifier: '@taiga-ui/addon-table', }, }, + { + from: { + name: 'TuiTablePaginationComponent', + moduleSpecifier: '@taiga-ui/addon-table', + }, + to: { + name: 'TuiTablePagination', + moduleSpecifier: '@taiga-ui/addon-table', + }, + }, { from: {name: 'TuiCardModule', moduleSpecifier: '@taiga-ui/experimental'}, to: [ diff --git a/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-pagination.spec.ts b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-pagination.spec.ts new file mode 100644 index 000000000000..78993c859b53 --- /dev/null +++ b/projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-pagination.spec.ts @@ -0,0 +1,114 @@ +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 { TuiTablePaginationModule, TuiTablePaginationComponent, TuiTablePagination } from '@taiga-ui/addon-table'; + +@Component({ + standalone: true, + imports: [TuiTablePaginationModule], + template: \` + + \`, +}) +class Test { + @ViewChild(TuiTablePaginationComponent, {static: true}) + component!: TuiTablePaginationComponent; + + public page = 3; + public size = 10; + + protected update({page, size}: TuiTablePagination): void { + this.page = page; + this.size = size; + } +}`; + +const COMPONENT_AFTER = ` +import { TuiTablePaginationEvent, TuiTablePagination } from '@taiga-ui/addon-table'; + +@Component({ + standalone: true, + imports: [TuiTablePagination], + template: \` + + \`, +}) +class Test { + @ViewChild(TuiTablePagination, {static: true}) + component!: TuiTablePagination; + + public page = 3; + public size = 10; + + protected update({page, size}: TuiTablePaginationEvent): void { + this.page = page; + this.size = size; + } +}`.trim(); + +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 pagination references in ts files', 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').trim()).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"}}', + ); +}