diff --git a/libs/portal-integration-angular/src/lib/core/components/button-dialog/button-dialog.component.spec.ts b/libs/portal-integration-angular/src/lib/core/components/button-dialog/button-dialog.component.spec.ts index d8f99150..aac6a935 100644 --- a/libs/portal-integration-angular/src/lib/core/components/button-dialog/button-dialog.component.spec.ts +++ b/libs/portal-integration-angular/src/lib/core/components/button-dialog/button-dialog.component.spec.ts @@ -7,12 +7,12 @@ import { ButtonModule } from 'primeng/button' import { ButtonDialogComponent } from './button-dialog.component' import { MockAuthModule } from '../../../mock-auth/mock-auth.module' -import { ButtonDialogHarness } from '../../../../../testing' +import { ButtonDialogHarness, DivHarness } from '../../../../../testing' import { ButtonDialogConfig } from '../../../model/button-dialog' @Component({ template: ` -
HostComponentContent
+
HostComponentContent
`, }) class TestBaseHostComponent {} @@ -31,7 +31,7 @@ const config: ButtonDialogConfig = { @Component({ template: ` -
HostComponentContent
+
HostComponentContent
`, }) class TestHostWithConfigComponent { @@ -40,7 +40,7 @@ class TestHostWithConfigComponent { @Component({ template: ` -
HostComponentContent
+
HostComponentContent
`, }) class TestHostWithResultSubComponent { @@ -301,7 +301,9 @@ describe('ButtonDialogComponent', () => { harnessLoader = await TestbedHarnessEnvironment.loader(fixtureWithHost) buttonDialogHarness = await harnessLoader.getHarness(ButtonDialogHarness) - expect(await buttonDialogHarness.getTextFor('#host')).toBe('HostComponentContent') + const contentDiv = await buttonDialogHarness.getHarness(DivHarness.with({ class: 'host' })) + expect(contentDiv).toBeDefined() + expect(await contentDiv.getText()).toBe('HostComponentContent') }) it('should use passed config', async () => { diff --git a/libs/portal-integration-angular/src/lib/core/components/button-dialog/dialog-message-content/dialog-message-content.component.html b/libs/portal-integration-angular/src/lib/core/components/button-dialog/dialog-message-content/dialog-message-content.component.html index 9364f3b7..066a540a 100644 --- a/libs/portal-integration-angular/src/lib/core/components/button-dialog/dialog-message-content/dialog-message-content.component.html +++ b/libs/portal-integration-angular/src/lib/core/components/button-dialog/dialog-message-content/dialog-message-content.component.html @@ -1,4 +1,4 @@ -
+

{{message | translate:messageParameters}} diff --git a/libs/portal-integration-angular/src/lib/services/portal-dialog.service.spec.ts b/libs/portal-integration-angular/src/lib/services/portal-dialog.service.spec.ts index c97feec1..959dc15d 100644 --- a/libs/portal-integration-angular/src/lib/services/portal-dialog.service.spec.ts +++ b/libs/portal-integration-angular/src/lib/services/portal-dialog.service.spec.ts @@ -57,7 +57,7 @@ class BaseTestComponent { } @Component({ - template: `

{{ header }}

`, + template: `
{{ header }}
`, }) class TestWithInputsComponent { @Input() header = 'header' @@ -279,8 +279,8 @@ describe('PortalDialogService', () => { fixture.componentInstance.show('title', 'MESSAGE', 'button1', 'button2') const dialogHarness = await rootLoader.getHarness(ButtonDialogHarness) - const message = await dialogHarness.getTextFor('#dialogMessage') - expect(message).toEqual(translations['MESSAGE']) + const dialogMessageContentHarness = await dialogHarness.getDialogMessageContent() + expect(await dialogMessageContentHarness?.getMessageContent()).toEqual(translations['MESSAGE']) }) it('should display dialog with translated message with parameters', async () => { @@ -294,7 +294,8 @@ describe('PortalDialogService', () => { ) const dialogHarness = await rootLoader.getHarness(ButtonDialogHarness) - const message = await dialogHarness.getTextFor('#dialogMessage') + const dialogMessageContentHarness = await dialogHarness.getDialogMessageContent() + const message = await dialogMessageContentHarness?.getMessageContent() expect(message).toEqual('myMessage myMsgParam') }) @@ -355,9 +356,10 @@ describe('PortalDialogService', () => { fixture.componentInstance.show('title', { message: 'MESSAGE', icon: 'pi pi-times' }, 'button1', 'button2') const dialogHarness = await rootLoader.getHarness(ButtonDialogHarness) - const message = await dialogHarness.getTextFor('#dialogMessage') + const dialogMessageContentHarness = await dialogHarness.getDialogMessageContent() + const message = await dialogMessageContentHarness?.getMessageContent() expect(message).toEqual(translations['MESSAGE']) - const icon = await dialogHarness.getAttributeFor('i', 'class') + const icon = await dialogMessageContentHarness?.getIconValue() expect(icon).toContain('pi pi-times') }) @@ -372,9 +374,10 @@ describe('PortalDialogService', () => { ) const dialogHarness = await rootLoader.getHarness(ButtonDialogHarness) - const message = await dialogHarness.getTextFor('#dialogMessage') + const dialogMessageContentHarness = await dialogHarness.getDialogMessageContent() + const message = await dialogMessageContentHarness?.getMessageContent() expect(message).toEqual('myMessage dialogMessageParam') - const icon = await dialogHarness.getAttributeFor('i', 'class') + const icon = await dialogMessageContentHarness?.getIconValue() expect(icon).toContain('pi pi-times') }) @@ -384,7 +387,8 @@ describe('PortalDialogService', () => { fixture.componentInstance.show('title', { type: TestWithInputsComponent }, 'button1', 'button2') const dialogHarness = await rootLoader.getHarness(ButtonDialogHarness) - const headerValue = await dialogHarness.getTextFor('#testHeader') + const headerDiv = await dialogHarness.getHarness(DivHarness.with({ class: 'testHeader' })) + const headerValue = await headerDiv.getText() expect(headerValue).toEqual('header') }) @@ -404,7 +408,8 @@ describe('PortalDialogService', () => { ) const dialogHarness = await rootLoader.getHarness(ButtonDialogHarness) - const headerValue = await dialogHarness.getTextFor('#testHeader') + const headerDiv = await dialogHarness.getHarness(DivHarness.with({ class: 'testHeader' })) + const headerValue = await headerDiv.getText() expect(headerValue).toEqual('myCustomHeader') }) diff --git a/libs/portal-integration-angular/testing/button-dialog.harness.ts b/libs/portal-integration-angular/testing/button-dialog.harness.ts index 77989120..0a208e05 100644 --- a/libs/portal-integration-angular/testing/button-dialog.harness.ts +++ b/libs/portal-integration-angular/testing/button-dialog.harness.ts @@ -1,11 +1,13 @@ import { ContentContainerComponentHarness } from '@angular/cdk/testing' import { PButtonDirectiveHarness } from './primeng/p-button-directive.harness' +import { DialogMessageContentHarness } from './dialog-message-content.harness' export class ButtonDialogHarness extends ContentContainerComponentHarness { static hostSelector = 'ocx-button-dialog' getPrimaryButton = this.locatorFor(PButtonDirectiveHarness.with({ id: 'buttonDialogPrimaryButton' })) getSecondaryButton = this.locatorForOptional(PButtonDirectiveHarness.with({ id: 'buttonDialogSecondaryButton' })) + getDialogMessageContent = this.locatorForOptional(DialogMessageContentHarness) async clickPrimaryButton() { await (await this.getPrimaryButton()).click() @@ -31,16 +33,6 @@ export class ButtonDialogHarness extends ContentContainerComponentHarness { return await (await this.getSecondaryButton())?.getIcon() } - async getTextFor(selector: string): Promise { - const element = await this.locatorForOptional(selector) - return await (await element())?.text() - } - - async getAttributeFor(selector: string, attribute: string): Promise { - const element = await this.locatorForOptional(selector) - return await (await element())?.getAttribute(attribute) - } - async getPrimaryButtonDisabled(): Promise { return await (await this.getPrimaryButton()).getDisabled() } diff --git a/libs/portal-integration-angular/testing/dialog-message-content.harness.ts b/libs/portal-integration-angular/testing/dialog-message-content.harness.ts new file mode 100644 index 00000000..894b5580 --- /dev/null +++ b/libs/portal-integration-angular/testing/dialog-message-content.harness.ts @@ -0,0 +1,16 @@ +import { ComponentHarness } from '@angular/cdk/testing' + +export class DialogMessageContentHarness extends ComponentHarness { + static hostSelector = '.dialogMessageContent' + + private getMessageSpan = this.locatorFor('#dialogMessage') + private getIcon = this.locatorForOptional('i') + + async getMessageContent(): Promise { + return await (await this.getMessageSpan()).text() + } + + async getIconValue(): Promise { + return await (await this.getIcon())?.getAttribute('class') + } +}