diff --git a/projects/core/components/dialog/test/dialog.component.spec.ts b/projects/core/components/dialog/test/dialog.component.spec.ts index b2a9d5b7ad17..6056c38d25b0 100644 --- a/projects/core/components/dialog/test/dialog.component.spec.ts +++ b/projects/core/components/dialog/test/dialog.component.spec.ts @@ -1,8 +1,10 @@ -import {Component, DebugElement} from '@angular/core'; +import {HarnessLoader} from '@angular/cdk/testing'; +import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; +import {Component} from '@angular/core'; import {ComponentFixture, TestBed} from '@angular/core/testing'; import {NoopAnimationsModule} from '@angular/platform-browser/animations'; import {TuiIdService} from '@taiga-ui/cdk'; -import {configureTestSuite, TuiPageObject} from '@taiga-ui/testing'; +import {configureTestSuite, TuiDialogHarness} from '@taiga-ui/testing'; import {TuiRootModule} from '../../root/root.module'; import {TuiDialogModule} from '../dialog.module'; @@ -21,11 +23,7 @@ describe(`Dialog with TUI_DIALOG_OPTIONS`, () => { let fixture: ComponentFixture; let tuiDialogService: TuiDialogService; - let pageObject: TuiPageObject; - - function getCloseButton(): DebugElement { - return pageObject.getByAutomationId(`tui-dialog__close`)!; - } + let loader: HarnessLoader; configureTestSuite(() => { TestBed.configureTestingModule({ @@ -43,16 +41,18 @@ describe(`Dialog with TUI_DIALOG_OPTIONS`, () => { beforeEach(() => { fixture = TestBed.createComponent(TestComponent); + loader = TestbedHarnessEnvironment.loader(fixture); tuiDialogService = TestBed.inject(TuiDialogService); - pageObject = new TuiPageObject(fixture); }); describe(`close button`, () => { - it(`when closeable = false is absent`, () => { + it(`when closeable = false is absent`, async () => { tuiDialogService.open(`Test`).subscribe(); fixture.detectChanges(); - expect(getCloseButton()).toBeNull(); + const dialog = await loader.getHarness(TuiDialogHarness); + + expect(await dialog.getCloseButton()).toBeNull(); }); }); }); diff --git a/projects/testing/core/dialog.harness.ts b/projects/testing/core/dialog.harness.ts new file mode 100644 index 000000000000..49a9ea93422e --- /dev/null +++ b/projects/testing/core/dialog.harness.ts @@ -0,0 +1,15 @@ +import {TuiContentContainerComponentHarness} from '@taiga-ui/testing/utils'; + +import {TuiButtonHarness} from './button.harness'; + +export class TuiDialogHarness extends TuiContentContainerComponentHarness { + static hostSelector = `tui-dialog`; + + async getCloseButton(): Promise { + return this.locatorForOptional( + TuiButtonHarness.with({ + selector: `[automation-id=tui-dialog__close]`, + }), + )(); + } +} diff --git a/projects/testing/core/index.ts b/projects/testing/core/index.ts index a54255f71198..e6dca28ea348 100644 --- a/projects/testing/core/index.ts +++ b/projects/testing/core/index.ts @@ -6,6 +6,7 @@ export * from './badge.harness'; export * from './button.harness'; export * from './calendar.harness'; export * from './card.harness'; +export * from './dialog.harness'; export * from './hosted-dropdown.harness'; export * from './island.harness'; export * from './loader.harness';