From 582625f622678178cc432a501960acb4be657e64 Mon Sep 17 00:00:00 2001 From: Nikita Barsukov Date: Thu, 30 May 2024 15:37:42 +0300 Subject: [PATCH] refactor(testing): improve flexibility of `TuiNativeInputPO` (#7574) --- .../input-range/test/input-range.component.spec.ts | 12 ++++++++---- projects/testing/utils/native-input.page-object.ts | 10 ++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/projects/legacy/components/input-range/test/input-range.component.spec.ts b/projects/legacy/components/input-range/test/input-range.component.spec.ts index c948cf38d83a..58586a8dc48c 100644 --- a/projects/legacy/components/input-range/test/input-range.component.spec.ts +++ b/projects/legacy/components/input-range/test/input-range.component.spec.ts @@ -440,13 +440,17 @@ describe('InputRange', () => { inputPOLeft = new TuiNativeInputPO( fixture, - testContext.nativeInputAutoId, - leftInputWrapper, + pageObject.getByAutomationId( + testContext.nativeInputAutoId, + leftInputWrapper, + )!, ); inputPORight = new TuiNativeInputPO( fixture, - testContext.nativeInputAutoId, - rightInputWrapper, + pageObject.getByAutomationId( + testContext.nativeInputAutoId, + rightInputWrapper, + )!, ); } }); diff --git a/projects/testing/utils/native-input.page-object.ts b/projects/testing/utils/native-input.page-object.ts index 1ad34a3b2f7a..a0c26f3de6ec 100644 --- a/projects/testing/utils/native-input.page-object.ts +++ b/projects/testing/utils/native-input.page-object.ts @@ -10,17 +10,15 @@ export class TuiNativeInputPO { constructor( private readonly fixture: ComponentFixture, - private readonly automationId: string, - private readonly hostDebugElement?: DebugElement, + private readonly automationIdOrElement: DebugElement | string, ) { this.pageObject = new TuiPageObject(fixture); } public get nativeElement(): HTMLInputElement | HTMLTextAreaElement | null { - return ( - this.pageObject.getByAutomationId(this.automationId, this.hostDebugElement) - ?.nativeElement ?? null - ); + return typeof this.automationIdOrElement === 'string' + ? this.pageObject.getByAutomationId(this.automationIdOrElement)?.nativeElement + : this.automationIdOrElement.nativeElement; } public get value(): string {