Skip to content

Commit

Permalink
feat(testing): adds harness for dialog (#5785)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frequency21 authored Oct 30, 2023
1 parent 274d5fd commit eed5765
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
20 changes: 10 additions & 10 deletions projects/core/components/dialog/test/dialog.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -21,11 +23,7 @@ describe(`Dialog with TUI_DIALOG_OPTIONS`, () => {

let fixture: ComponentFixture<TestComponent>;
let tuiDialogService: TuiDialogService;
let pageObject: TuiPageObject<TestComponent>;

function getCloseButton(): DebugElement {
return pageObject.getByAutomationId(`tui-dialog__close`)!;
}
let loader: HarnessLoader;

configureTestSuite(() => {
TestBed.configureTestingModule({
Expand All @@ -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();
});
});
});
15 changes: 15 additions & 0 deletions projects/testing/core/dialog.harness.ts
Original file line number Diff line number Diff line change
@@ -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<TuiButtonHarness | null> {
return this.locatorForOptional(
TuiButtonHarness.with({
selector: `[automation-id=tui-dialog__close]`,
}),
)();
}
}
1 change: 1 addition & 0 deletions projects/testing/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit eed5765

Please sign in to comment.