-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: drop
TuiInteractiveStateT
(#7290)
- Loading branch information
Showing
18 changed files
with
154 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
projects/cdk/schematics/ng-update/v4/steps/constants/enums.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type {ReplacementEnum} from '../../../interfaces/replacement-enum'; | ||
|
||
export const ENUMS_TO_REPLACE: ReplacementEnum[] = [ | ||
{ | ||
name: 'TuiInteractiveState', | ||
replaceValues: { | ||
Disabled: 'disabled', | ||
Active: 'active', | ||
Hover: 'hover', | ||
Readonly: 'readonly', | ||
}, | ||
keepAsType: true, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
projects/cdk/schematics/ng-update/v4/tests/schematic-migrate-enums.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
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'; | ||
|
||
const collectionPath = join(__dirname, '../../../migration.json'); | ||
|
||
const COMPONENT_BEFORE = ` | ||
import { TuiInteractiveState, TuiInteractiveStateT } from '@taiga-ui/core'; | ||
export class MyComponent { | ||
public getItemState(item: TuiDay): TuiInteractiveStateT | null { | ||
const {disabledItemHandler, pressedItem, hoveredItem} = this; | ||
if (disabledItemHandler(item)) { | ||
return TuiInteractiveState.Disabled; | ||
} | ||
if (pressedItem?.daySame(item)) { | ||
return TuiInteractiveState.Active; | ||
} | ||
if (hoveredItem?.daySame(item)) { | ||
return TuiInteractiveState.Hover; | ||
} | ||
return null; | ||
} | ||
} | ||
`.trim(); | ||
|
||
const COMPONENT_AFTER = ` | ||
import { TuiInteractiveState } from '@taiga-ui/core'; | ||
export class MyComponent { | ||
public getItemState(item: TuiDay): TuiInteractiveState | null { | ||
const {disabledItemHandler, pressedItem, hoveredItem} = this; | ||
if (disabledItemHandler(item)) { | ||
return 'disabled'; | ||
} | ||
if (pressedItem?.daySame(item)) { | ||
return 'active'; | ||
} | ||
if (hoveredItem?.daySame(item)) { | ||
return 'hover'; | ||
} | ||
return null; | ||
} | ||
} | ||
`.trim(); | ||
|
||
describe('ng-update enums', () => { | ||
let host: UnitTestTree; | ||
let runner: SchematicTestRunner; | ||
|
||
beforeEach(() => { | ||
host = new UnitTestTree(new HostTree()); | ||
runner = new SchematicTestRunner('schematics', collectionPath); | ||
|
||
setActiveProject(createProject(host)); | ||
|
||
createMainFiles(); | ||
|
||
saveActiveProject(); | ||
}); | ||
|
||
it('migrate', async () => { | ||
const tree = await runner.runSchematic( | ||
'updateToV4', | ||
{'skip-logs': process.env['TUI_CI'] === 'true'} as Partial<TuiSchema>, | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './appearance'; | ||
export * from './dropdown-animation'; | ||
export * from './interactive-state'; | ||
export * from './range-state'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type TuiInteractiveState = 'active' | 'disabled' | 'hover' | 'readonly'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.