From e45bd0d8adb2bcab633585ca997d091627b562d9 Mon Sep 17 00:00:00 2001 From: markuczy Date: Tue, 2 Apr 2024 13:05:19 +0200 Subject: [PATCH 1/5] feat: search testability enchanced --- .../page-header/page-header.component.html | 4 +- .../testing/group-by-count-diagram.harness.ts | 8 ++++ libs/angular-accelerator/testing/index.ts | 2 + .../testing/page-header.harness.ts | 28 +++++++++-- .../testing/search-header.harness.ts | 47 +++++++++++++++++++ libs/angular-testing/src/index.ts | 1 + .../src/lib/harnesses/list-item.harness.ts | 12 ++++- .../src/lib/harnesses/menu-item.harness.ts | 12 ++++- .../harnesses/primeng/p-breadcrumb.harness.ts | 12 +++++ .../harnesses/primeng/p-dropdown.harness.ts | 12 +++++ .../lib/harnesses/primeng/p-menu.harness.ts | 11 +++++ .../testing/index.ts | 1 - .../testing/search-header.harness.ts | 43 ----------------- 13 files changed, 141 insertions(+), 52 deletions(-) create mode 100644 libs/angular-accelerator/testing/group-by-count-diagram.harness.ts create mode 100644 libs/angular-accelerator/testing/search-header.harness.ts create mode 100644 libs/angular-testing/src/lib/harnesses/primeng/p-breadcrumb.harness.ts delete mode 100644 libs/portal-integration-angular/testing/search-header.harness.ts diff --git a/libs/angular-accelerator/src/lib/components/page-header/page-header.component.html b/libs/angular-accelerator/src/lib/components/page-header/page-header.component.html index cc3fb36d..e6ad0158 100644 --- a/libs/angular-accelerator/src/lib/components/page-header/page-header.component.html +++ b/libs/angular-accelerator/src/lib/components/page-header/page-header.component.html @@ -24,8 +24,8 @@
-

{{ header }}

-

{{ subheader }}

+

{{ header }}

+

{{ subheader }}

diff --git a/libs/angular-accelerator/testing/group-by-count-diagram.harness.ts b/libs/angular-accelerator/testing/group-by-count-diagram.harness.ts new file mode 100644 index 00000000..6062b253 --- /dev/null +++ b/libs/angular-accelerator/testing/group-by-count-diagram.harness.ts @@ -0,0 +1,8 @@ +import { ComponentHarness } from '@angular/cdk/testing' +import { DiagramHarness } from './diagram.harness' + +export class GroupByCountDiagramHarness extends ComponentHarness { + static hostSelector = 'ocx-group-by-count-diagram' + + getDiagram = this.locatorFor(DiagramHarness) +} \ No newline at end of file diff --git a/libs/angular-accelerator/testing/index.ts b/libs/angular-accelerator/testing/index.ts index 9fee1c87..65912d3e 100644 --- a/libs/angular-accelerator/testing/index.ts +++ b/libs/angular-accelerator/testing/index.ts @@ -7,10 +7,12 @@ export * from './data-view.harness' export * from './default-grid-item.harness' export * from './default-list-item.harness' export * from './diagram.harness' +export * from './group-by-count-diagram.harness' export * from './interactive-data-view.harness' export * from './more-actions-menu-button.harness' export * from './page-header.harness' export * from './search-config.harness' +export * from './search-header.harness' export * from '@angular/cdk/testing' export * from '@angular/cdk/testing/testbed' diff --git a/libs/angular-accelerator/testing/page-header.harness.ts b/libs/angular-accelerator/testing/page-header.harness.ts index 8c26aa2c..bc027034 100644 --- a/libs/angular-accelerator/testing/page-header.harness.ts +++ b/libs/angular-accelerator/testing/page-header.harness.ts @@ -1,17 +1,19 @@ import { ComponentHarness } from '@angular/cdk/testing' -import { PMenuHarness } from '@onecx/angular-testing' +import { ListItemHarness, MenuItemHarness, PBreadcrumbHarness, PMenuHarness } from '@onecx/angular-testing' export class PageHeaderHarness extends ComponentHarness { static hostSelector = 'ocx-page-header' getPageHeaderWrapperHarness = this.locatorForAll('[name="ocx-page-header-wrapper"]') + getBreadcrumb = this.locatorFor(PBreadcrumbHarness) + getMenu = this.locatorFor(PMenuHarness) async getInlineActionButtons() { return await this.locatorForAll('[name="ocx-page-header-inline-action-button"]')() } - async getOverflowActionButtons() { - return await this.locatorForAll('[name="ocx-page-header-overflow-action-button"]')() + async getOverflowActionButton() { + return await this.locatorFor('[name="ocx-page-header-overflow-action-button"]')() } async getElementByTitle(title: string) { @@ -35,8 +37,26 @@ export class PageHeaderHarness extends ComponentHarness { } async getOverFlowMenuItems() { - const menu = await this.locatorFor(PMenuHarness)() + const menu = await this.getMenu() const menuItems = await menu.getAllMenuItems() return menuItems ?? [] } + + async getOverFlowMenuItem(itemText: string): Promise { + const menu = await this.getMenu() + return await menu.getMenuItem(itemText) + } + + async getBreadcrumbItem(itemText: string): Promise { + const breadcrumb = await this.getBreadcrumb() + return await breadcrumb.getBreadcrumbItem(itemText) + } + + async getHeaderText(): Promise { + return await (await this.locatorForOptional('#page-header')())?.text() + } + + async getSubheaderText(): Promise { + return await (await this.locatorForOptional('#page-subheader')())?.text() + } } diff --git a/libs/angular-accelerator/testing/search-header.harness.ts b/libs/angular-accelerator/testing/search-header.harness.ts new file mode 100644 index 00000000..c55e98ce --- /dev/null +++ b/libs/angular-accelerator/testing/search-header.harness.ts @@ -0,0 +1,47 @@ +import { ComponentHarness } from '@angular/cdk/testing' +import { PButtonHarness, ButtonHarness } from '@onecx/angular-testing' +import { PageHeaderHarness } from './page-header.harness' +import { SearchConfigHarness } from './search-config.harness' +import { MoreActionsMenuButtonHarness } from './more-actions-menu-button.harness' + +export class SearchHeaderHarness extends ComponentHarness { + static hostSelector = 'ocx-search-header' + + getPageHeader = this.locatorFor(PageHeaderHarness) + getSearchConfig = this.locatorFor(SearchConfigHarness) + getSearchButton = this.locatorFor( + PButtonHarness.with({ + id: 'searchButton', + }) + ) + + getResetButton = this.locatorFor( + PButtonHarness.with({ + id: 'resetButton', + }) + ) + + getSimpleAdvancedButton = this.locatorForOptional( + PButtonHarness.with({ + id: 'simpleAdvancedButton', + }) + ) + + getMoreActionsMenuButton = this.locatorForOptional(MoreActionsMenuButtonHarness) + + async clickResetButton() { + await (await this.getResetButton()).click() + } + + async clickSearchButton() { + await (await this.getSearchButton()).click() + } + + async toggleSimpleAdvanced() { + if (await this.getSimpleAdvancedButton()) { + await (await this.getSimpleAdvancedButton())?.click() + } else { + console.warn('No SimpleAdvancedButton is being displayed to toggle, because no advanced form field is defined.') + } + } +} \ No newline at end of file diff --git a/libs/angular-testing/src/index.ts b/libs/angular-testing/src/index.ts index 72b8e8fc..bcda0e94 100644 --- a/libs/angular-testing/src/index.ts +++ b/libs/angular-testing/src/index.ts @@ -1,3 +1,4 @@ +export * from './lib/harnesses/primeng/p-breadcrumb.harness' export * from './lib/harnesses/primeng/p-button-directive.harness' export * from './lib/harnesses/primeng/p-button.harness' export * from './lib/harnesses/primeng/p-chart.harness' diff --git a/libs/angular-testing/src/lib/harnesses/list-item.harness.ts b/libs/angular-testing/src/lib/harnesses/list-item.harness.ts index e94bbcbc..3b070ca0 100644 --- a/libs/angular-testing/src/lib/harnesses/list-item.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/list-item.harness.ts @@ -1,8 +1,18 @@ -import { ComponentHarness } from '@angular/cdk/testing' +import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular/cdk/testing' + +export interface ListItemHarnessFilters extends BaseHarnessFilters { + text?: string +} export class ListItemHarness extends ComponentHarness { static hostSelector = 'li' + static with(options: ListItemHarnessFilters): HarnessPredicate { + return new HarnessPredicate(ListItemHarness, options).addOption('text', options.text, (harness, text) => + HarnessPredicate.stringMatches(harness.getText(), text) + ) + } + async getText() { return await (await this.host()).text() } diff --git a/libs/angular-testing/src/lib/harnesses/menu-item.harness.ts b/libs/angular-testing/src/lib/harnesses/menu-item.harness.ts index f22e8a2d..94b191c9 100644 --- a/libs/angular-testing/src/lib/harnesses/menu-item.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/menu-item.harness.ts @@ -1,8 +1,18 @@ -import { ComponentHarness } from '@angular/cdk/testing' +import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular/cdk/testing' + +export interface MenuItemHarnessFilters extends BaseHarnessFilters { + text?: string +} export class MenuItemHarness extends ComponentHarness { static hostSelector = 'li > a' + static with(options: MenuItemHarnessFilters): HarnessPredicate { + return new HarnessPredicate(MenuItemHarness, options).addOption('text', options.text, (harness, text) => + HarnessPredicate.stringMatches(harness.getText(), text) + ) + } + async getText() { return await (await this.host()).text() } diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-breadcrumb.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-breadcrumb.harness.ts new file mode 100644 index 00000000..b2f12a2b --- /dev/null +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-breadcrumb.harness.ts @@ -0,0 +1,12 @@ +import { ComponentHarness } from '@angular/cdk/testing' +import { ListItemHarness } from '../list-item.harness' + +export class PBreadcrumbHarness extends ComponentHarness { + static hostSelector = 'p-breadcrumb' + + getBreadcrumbItems = this.locatorForAll(ListItemHarness) + + async getBreadcrumbItem(itemText: string): Promise { + return await this.locatorForOptional(ListItemHarness.with({ text: itemText }))() + } +} diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-dropdown.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-dropdown.harness.ts index 37444542..0dc82ae0 100644 --- a/libs/angular-testing/src/lib/harnesses/primeng/p-dropdown.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-dropdown.harness.ts @@ -48,6 +48,10 @@ export class PDropdownHarness extends ContentContainerComponentHarness { return await dropdownItems } + async getDropdownItem(itemText: string): Promise { + return await this.locatorForOptional(ListItemHarness.with({ text: itemText }))() + } + async selectedDropdownItem(position: number) { const selectedColumnGroup = await Promise.all( (await this.getDropdownItems()).filter((listItem) => listItem.isSelected()) @@ -62,4 +66,12 @@ export class PDropdownHarness extends ContentContainerComponentHarness { async hasClearOption() { return (await this.locatorFor('div')()).hasClass('p-dropdown-clearable') } + + async clear() { + if (await this.hasClearOption()) { + return await (await this.locatorFor('.p-dropdown-clear-icon')()).click() + } else { + console.warn('Unable to clear dropdown, because it has no clear option') + } + } } diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-menu.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-menu.harness.ts index 4f7d2839..9d8e432d 100644 --- a/libs/angular-testing/src/lib/harnesses/primeng/p-menu.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-menu.harness.ts @@ -20,4 +20,15 @@ export class PMenuHarness extends ContentContainerComponentHarness { } return [] } + + async getMenuItem(itemText: string): Promise { + if (await this.isOpen()) { + return await ( + await this.getHarnessLoaderForPMenuOverlay() + )?.getHarnessOrNull(MenuItemHarness.with({ text: itemText })) + } else { + console.warn('Cannot get menu items because menu is closed.') + } + return undefined + } } diff --git a/libs/portal-integration-angular/testing/index.ts b/libs/portal-integration-angular/testing/index.ts index 244bf217..5fcca82e 100644 --- a/libs/portal-integration-angular/testing/index.ts +++ b/libs/portal-integration-angular/testing/index.ts @@ -4,7 +4,6 @@ export * from './content.harness' export * from './create-or-edit-search-config-dialog.harness' export * from './dialog-message-content.harness' export * from './lifecycle.harness' -export * from './search-header.harness' export * from '@angular/cdk/testing' export * from '@angular/cdk/testing/testbed' diff --git a/libs/portal-integration-angular/testing/search-header.harness.ts b/libs/portal-integration-angular/testing/search-header.harness.ts deleted file mode 100644 index d15ffbb9..00000000 --- a/libs/portal-integration-angular/testing/search-header.harness.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { ContentContainerComponentHarness } from '@angular/cdk/testing' -import { MoreActionsMenuButtonHarness } from '@onecx/angular-accelerator/testing' -import { ButtonHarness, PButtonHarness } from '@onecx/angular-testing' - -export class SearchHeaderHarness extends ContentContainerComponentHarness { - static hostSelector = 'ocx-search-header' - - getSearchButton = this.locatorFor( - PButtonHarness.with({ - id: 'searchButton', - }) - ) - - getResetButton = this.locatorFor( - PButtonHarness.with({ - id: 'resetButton', - }) - ) - - getSimpleAdvancedButton = this.locatorForOptional( - ButtonHarness.with({ - id: 'simpleAdvancedButton', - }) - ) - - getMoreActionsMenuButton = this.locatorForOptional(MoreActionsMenuButtonHarness) - - async search() { - await (await this.getSearchButton()).click() - } - - async reset() { - await (await this.getResetButton()).click() - } - - async toggleSimpleAdvanced() { - if (await this.getSimpleAdvancedButton()) { - await (await this.getSimpleAdvancedButton())?.click() - } else { - console.warn('No SimpleAdvancedButton is being displayed to toggle, because no advanced form field is defined.') - } - } -} From 16345b73452bdab909a2a3bafae291a295b11842 Mon Sep 17 00:00:00 2001 From: markuczy Date: Wed, 3 Apr 2024 12:58:36 +0200 Subject: [PATCH 2/5] feat: page header object details testability enchancements --- .../testing/page-header.harness.ts | 68 +++++++++++++++---- .../lib/harnesses/primeng/p-button.harness.ts | 24 ++++++- 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/libs/angular-accelerator/testing/page-header.harness.ts b/libs/angular-accelerator/testing/page-header.harness.ts index bc027034..463a0434 100644 --- a/libs/angular-accelerator/testing/page-header.harness.ts +++ b/libs/angular-accelerator/testing/page-header.harness.ts @@ -1,5 +1,11 @@ -import { ComponentHarness } from '@angular/cdk/testing' -import { ListItemHarness, MenuItemHarness, PBreadcrumbHarness, PMenuHarness } from '@onecx/angular-testing' +import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular/cdk/testing' +import { + ListItemHarness, + MenuItemHarness, + PBreadcrumbHarness, + PButtonHarness, + PMenuHarness, +} from '@onecx/angular-testing' export class PageHeaderHarness extends ComponentHarness { static hostSelector = 'ocx-page-header' @@ -8,10 +14,6 @@ export class PageHeaderHarness extends ComponentHarness { getBreadcrumb = this.locatorFor(PBreadcrumbHarness) getMenu = this.locatorFor(PMenuHarness) - async getInlineActionButtons() { - return await this.locatorForAll('[name="ocx-page-header-inline-action-button"]')() - } - async getOverflowActionButton() { return await this.locatorFor('[name="ocx-page-header-overflow-action-button"]')() } @@ -21,19 +23,29 @@ export class PageHeaderHarness extends ComponentHarness { } async getObjectInfos() { - return await this.locatorForAll('.object-info')() + return await this.locatorForAll(ObjectDetailItemHarness)() + } + + async getObjectInfoByLabel(objectInfolabel: string) { + return await this.locatorForOptional(ObjectDetailItemHarness.with({ label: objectInfolabel }))() } - async getObjectDetailLabels() { - return await this.locatorForAll('[name="object-detail-label"]')() + async getInlineActionButtons() { + const inlineActionButtons = await this.locatorForAll( + PButtonHarness.with({ name: 'ocx-page-header-inline-action-button' }) + )() + const inlineActionIconButtons = await this.locatorForAll( + PButtonHarness.with({ name: 'ocx-page-header-inline-action-icon-button' }) + )() + return inlineActionButtons.concat(inlineActionIconButtons) } - async getObjectDetailValues() { - return await this.locatorForAll('[name="object-detail-value"]')() + async getInlineActionButtonByLabel(buttonLabel: string) { + return await this.locatorForOptional(PButtonHarness.with({ label: buttonLabel }))() } - async getObjectDetailIcons() { - return await this.locatorForAll('[name="object-detail-icon"]')() + async getInlineActionButtonByIcon(buttonIcon: string) { + return await this.locatorForOptional(PButtonHarness.with({ icon: buttonIcon }))() } async getOverFlowMenuItems() { @@ -60,3 +72,33 @@ export class PageHeaderHarness extends ComponentHarness { return await (await this.locatorForOptional('#page-subheader')())?.text() } } + +interface ObjectDetailItemHarnessFilters extends BaseHarnessFilters { + label?: string +} + +class ObjectDetailItemHarness extends ComponentHarness { + static hostSelector = '.object-info' + + static with(options: ObjectDetailItemHarnessFilters): HarnessPredicate { + return new HarnessPredicate(ObjectDetailItemHarness, options).addOption('label', options.label, (harness, label) => + HarnessPredicate.stringMatches(harness.getLabel(), label) + ) + } + + getLabelElement = this.locatorFor('[name="object-detail-label"]') + getValueElement = this.locatorForOptional('[name="object-detail-value"]') + getIconElement = this.locatorForOptional('[name="object-detail-icon"]') + + async getLabel() { + return (await this.getLabelElement()).text() + } + + async getValue() { + return (await this.getValueElement())?.text() + } + + async getIcon() { + return (await this.getIconElement())?.getAttribute('class') + } +} diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-button.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-button.harness.ts index 517cbe7f..d938ac9c 100644 --- a/libs/angular-testing/src/lib/harnesses/primeng/p-button.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-button.harness.ts @@ -2,19 +2,37 @@ import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular export interface PButtonHarnessFilters extends BaseHarnessFilters { id?: string + name?: string + label?: string + icon?: string } + export class PButtonHarness extends ComponentHarness { static hostSelector = 'p-button' static with(options: PButtonHarnessFilters): HarnessPredicate { - return new HarnessPredicate(PButtonHarness, options).addOption('id', options.id, (harness, id) => - HarnessPredicate.stringMatches(harness.getId(), id) - ) + return new HarnessPredicate(PButtonHarness, options) + .addOption('id', options.id, (harness, id) => HarnessPredicate.stringMatches(harness.getId(), id)) + .addOption('name', options.name, (harness, name) => HarnessPredicate.stringMatches(harness.getName(), name)) + .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabel(), label)) + .addOption('icon', options.icon, (harness, icon) => HarnessPredicate.stringMatches(harness.getIcon(), icon)) } async getId(): Promise { return await (await this.host()).getAttribute('id') } + async getName(): Promise { + return await (await this.host()).getAttribute('name') + } + + async getLabel(): Promise { + return await (await this.host()).text() + } + + async getIcon(): Promise { + return await (await this.host()).getAttribute('ng-reflect-icon') + } + async click() { await (await this.locatorFor('button')()).click() } From c19eecf15a6b13bb1b3707e65acb6f4ad0afdf2f Mon Sep 17 00:00:00 2001 From: markuczy Date: Wed, 3 Apr 2024 13:05:00 +0200 Subject: [PATCH 3/5] refactor: lint --- .../testing/page-header.harness.ts | 8 +- .../testing/search-header.harness.ts | 78 +++++++++---------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/libs/angular-accelerator/testing/page-header.harness.ts b/libs/angular-accelerator/testing/page-header.harness.ts index 463a0434..0b89ca80 100644 --- a/libs/angular-accelerator/testing/page-header.harness.ts +++ b/libs/angular-accelerator/testing/page-header.harness.ts @@ -80,16 +80,16 @@ interface ObjectDetailItemHarnessFilters extends BaseHarnessFilters { class ObjectDetailItemHarness extends ComponentHarness { static hostSelector = '.object-info' + getLabelElement = this.locatorFor('[name="object-detail-label"]') + getValueElement = this.locatorForOptional('[name="object-detail-value"]') + getIconElement = this.locatorForOptional('[name="object-detail-icon"]') + static with(options: ObjectDetailItemHarnessFilters): HarnessPredicate { return new HarnessPredicate(ObjectDetailItemHarness, options).addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabel(), label) ) } - getLabelElement = this.locatorFor('[name="object-detail-label"]') - getValueElement = this.locatorForOptional('[name="object-detail-value"]') - getIconElement = this.locatorForOptional('[name="object-detail-icon"]') - async getLabel() { return (await this.getLabelElement()).text() } diff --git a/libs/angular-accelerator/testing/search-header.harness.ts b/libs/angular-accelerator/testing/search-header.harness.ts index c55e98ce..941634ad 100644 --- a/libs/angular-accelerator/testing/search-header.harness.ts +++ b/libs/angular-accelerator/testing/search-header.harness.ts @@ -1,47 +1,47 @@ import { ComponentHarness } from '@angular/cdk/testing' -import { PButtonHarness, ButtonHarness } from '@onecx/angular-testing' +import { PButtonHarness } from '@onecx/angular-testing' import { PageHeaderHarness } from './page-header.harness' import { SearchConfigHarness } from './search-config.harness' import { MoreActionsMenuButtonHarness } from './more-actions-menu-button.harness' export class SearchHeaderHarness extends ComponentHarness { - static hostSelector = 'ocx-search-header' - - getPageHeader = this.locatorFor(PageHeaderHarness) - getSearchConfig = this.locatorFor(SearchConfigHarness) - getSearchButton = this.locatorFor( - PButtonHarness.with({ - id: 'searchButton', - }) - ) - - getResetButton = this.locatorFor( - PButtonHarness.with({ - id: 'resetButton', - }) - ) - - getSimpleAdvancedButton = this.locatorForOptional( - PButtonHarness.with({ - id: 'simpleAdvancedButton', - }) - ) - - getMoreActionsMenuButton = this.locatorForOptional(MoreActionsMenuButtonHarness) - - async clickResetButton() { - await (await this.getResetButton()).click() - } + static hostSelector = 'ocx-search-header' - async clickSearchButton() { - await (await this.getSearchButton()).click() - } + getPageHeader = this.locatorFor(PageHeaderHarness) + getSearchConfig = this.locatorFor(SearchConfigHarness) + getSearchButton = this.locatorFor( + PButtonHarness.with({ + id: 'searchButton', + }) + ) + + getResetButton = this.locatorFor( + PButtonHarness.with({ + id: 'resetButton', + }) + ) + + getSimpleAdvancedButton = this.locatorForOptional( + PButtonHarness.with({ + id: 'simpleAdvancedButton', + }) + ) - async toggleSimpleAdvanced() { - if (await this.getSimpleAdvancedButton()) { - await (await this.getSimpleAdvancedButton())?.click() - } else { - console.warn('No SimpleAdvancedButton is being displayed to toggle, because no advanced form field is defined.') - } - } -} \ No newline at end of file + getMoreActionsMenuButton = this.locatorForOptional(MoreActionsMenuButtonHarness) + + async clickResetButton() { + await (await this.getResetButton()).click() + } + + async clickSearchButton() { + await (await this.getSearchButton()).click() + } + + async toggleSimpleAdvanced() { + if (await this.getSimpleAdvancedButton()) { + await (await this.getSimpleAdvancedButton())?.click() + } else { + console.warn('No SimpleAdvancedButton is being displayed to toggle, because no advanced form field is defined.') + } + } +} From de67a0e643ce13a8bb5f14bcc30a9f452db7c223 Mon Sep 17 00:00:00 2001 From: markuczy Date: Wed, 3 Apr 2024 14:06:34 +0200 Subject: [PATCH 4/5] fix: test fixes for new harnesses --- .../page-header/page-header.component.spec.ts | 86 ++++++++----------- .../testing/page-header.harness.ts | 18 ++-- 2 files changed, 47 insertions(+), 57 deletions(-) diff --git a/libs/angular-accelerator/src/lib/components/page-header/page-header.component.spec.ts b/libs/angular-accelerator/src/lib/components/page-header/page-header.component.spec.ts index ca122a8e..b5d7fa1e 100644 --- a/libs/angular-accelerator/src/lib/components/page-header/page-header.component.spec.ts +++ b/libs/angular-accelerator/src/lib/components/page-header/page-header.component.spec.ts @@ -42,7 +42,7 @@ const mockActions: Action[] = [ }, ] -describe('PageHeaderComponent', () => { +fdescribe('PageHeaderComponent', () => { const origAddEventListener = window.addEventListener const origPostMessage = window.postMessage @@ -115,13 +115,14 @@ describe('PageHeaderComponent', () => { it('should check permissions and render buttons accordingly', async () => { expect(await pageHeaderHarness.getInlineActionButtons()).toHaveLength(0) - expect(await pageHeaderHarness.getOverflowActionButtons()).toHaveLength(0) + expect(await pageHeaderHarness.getOverflowActionButton()).toBeNull() component.actions = mockActions expect(await pageHeaderHarness.getInlineActionButtons()).toHaveLength(1) expect(await pageHeaderHarness.getElementByTitle('My Test Action')).toBeTruthy() - expect(await pageHeaderHarness.getOverflowActionButtons()).toHaveLength(1) + await (await pageHeaderHarness.getOverflowActionButton())?.click() + expect(await pageHeaderHarness.getOverFlowMenuItems()).toHaveLength(2) expect(await pageHeaderHarness.getElementByTitle('More actions')).toBeTruthy() expect(userServiceSpy).toHaveBeenCalledTimes(3) }) @@ -132,13 +133,13 @@ describe('PageHeaderComponent', () => { userServiceSpy.mockReturnValue(false) expect(await pageHeaderHarness.getInlineActionButtons()).toHaveLength(0) - expect(await pageHeaderHarness.getOverflowActionButtons()).toHaveLength(0) + expect(await pageHeaderHarness.getOverflowActionButton()).toBeNull() component.actions = mockActions expect(await pageHeaderHarness.getInlineActionButtons()).toHaveLength(0) expect(await pageHeaderHarness.getElementByTitle('My Test Action')).toBeFalsy() - expect(await pageHeaderHarness.getOverflowActionButtons()).toHaveLength(0) + expect(await pageHeaderHarness.getOverFlowMenuItems()).toHaveLength(0) expect(await pageHeaderHarness.getElementByTitle('More actions')).toBeFalsy() expect(userServiceSpy).toHaveBeenCalledTimes(3) }) @@ -159,20 +160,15 @@ describe('PageHeaderComponent', () => { component.objectDetails = objectDetailsWithoutIcons expect((await pageHeaderHarness.getObjectInfos()).length).toEqual(2) - const objectDetailLabels = await pageHeaderHarness.getObjectDetailLabels() - const objectDetailValues = await pageHeaderHarness.getObjectDetailValues() - const objectDetailIcons = await pageHeaderHarness.getObjectDetailIcons() - expect(objectDetailLabels.length).toEqual(2) - expect(objectDetailValues.length).toEqual(2) - expect(objectDetailIcons.length).toEqual(0) - - objectDetailLabels.forEach(async (label, i) => { - expect(await label.text()).toEqual(objectDetailsWithoutIcons[i].label) - }) - objectDetailValues.forEach(async (value, i) => { - expect(await value.text()).toEqual(objectDetailsWithoutIcons[i].value) - }) + const firstDetail = await pageHeaderHarness.getObjectInfoByLabel('Venue') + expect(await firstDetail?.getLabel()).toEqual('Venue') + expect(await firstDetail?.getValue()).toEqual('AIE Munich') + expect(await firstDetail?.getIcon()).toBeUndefined() + const secondDetail = await pageHeaderHarness.getObjectInfoByLabel('Status') + expect(await secondDetail?.getLabel()).toEqual('Status') + expect(await secondDetail?.getValue()).toEqual('Confirmed') + expect(await secondDetail?.getIcon()).toBeUndefined() }) it('should render objectDetails with icons as object info in the page header', async () => { @@ -199,35 +195,31 @@ describe('PageHeaderComponent', () => { component.objectDetails = objectDetailsWithIcons expect((await pageHeaderHarness.getObjectInfos()).length).toEqual(4) - const objectDetailLabels = await pageHeaderHarness.getObjectDetailLabels() - const objectDetailValues = await pageHeaderHarness.getObjectDetailValues() - const objectDetailIcons = await pageHeaderHarness.getObjectDetailIcons() - expect(objectDetailLabels.length).toEqual(4) - expect(objectDetailValues.length).toEqual(3) - expect(objectDetailIcons.length).toEqual(2) - - objectDetailLabels.forEach(async (label, i) => { - expect(await label.text()).toEqual(objectDetailsWithIcons[i].label) - }) - - objectDetailValues.forEach(async (value, i) => { - if (objectDetailsWithIcons[i].value) { - expect(await value.text()).toEqual(objectDetailsWithIcons[i].value) - } - }) - - expect(await objectDetailIcons[0].getAttribute('class')).toEqual(objectDetailsWithIcons[1].icon) - expect(await objectDetailIcons[1].getAttribute('class')).toEqual(objectDetailsWithIcons[2].icon) + const firstDetail = await pageHeaderHarness.getObjectInfoByLabel('Venue') + expect(await firstDetail?.getLabel()).toEqual('Venue') + expect(await firstDetail?.getValue()).toEqual('AIE Munich') + expect(await firstDetail?.getIcon()).toBeUndefined() + const secondDetail = await pageHeaderHarness.getObjectInfoByLabel('Status') + expect(await secondDetail?.getLabel()).toEqual('Status') + expect(await secondDetail?.getValue()).toEqual('Confirmed') + expect(await secondDetail?.getIcon()).toEqual(PrimeIcons.CHECK) + const thirdDetail = await pageHeaderHarness.getObjectInfoByLabel('Done?') + expect(await thirdDetail?.getLabel()).toEqual('Done?') + expect(await thirdDetail?.getValue()).toEqual('') + expect(await thirdDetail?.getIcon()).toEqual(PrimeIcons.EXCLAMATION_CIRCLE) + const fourthDetail = await pageHeaderHarness.getObjectInfoByLabel('Empty') + expect(await fourthDetail?.getLabel()).toEqual('Empty') + expect(await fourthDetail?.getValue()).toBeUndefined() + expect(await fourthDetail?.getIcon()).toBeUndefined() }) it('should show overflow actions when menu overflow button clicked', async () => { component.actions = mockActions - const menuOverflowButtons = await pageHeaderHarness.getOverflowActionButtons() + const menuOverflowButton = await pageHeaderHarness.getOverflowActionButton() - expect(menuOverflowButtons).toBeTruthy() - expect(menuOverflowButtons.length).toBe(1) - await menuOverflowButtons[0].click() + expect(menuOverflowButton).toBeTruthy() + await menuOverflowButton?.click() const menuItems = await pageHeaderHarness.getOverFlowMenuItems() expect(menuItems.length).toBe(2) @@ -240,11 +232,10 @@ describe('PageHeaderComponent', () => { component.actions = mockActions - const menuOverflowButtons = await pageHeaderHarness.getOverflowActionButtons() + const menuOverflowButton = await pageHeaderHarness.getOverflowActionButton() - expect(menuOverflowButtons).toBeTruthy() - expect(menuOverflowButtons.length).toBe(1) - await menuOverflowButtons[0].click() + expect(menuOverflowButton).toBeTruthy() + await menuOverflowButton?.click() const menuItems = await pageHeaderHarness.getOverFlowMenuItems() expect(menuItems.length).toBe(2) @@ -259,10 +250,9 @@ describe('PageHeaderComponent', () => { component.actions = mockActions - const menuOverflowButton = await pageHeaderHarness.getOverflowActionButtons() + const menuOverflowButton = await pageHeaderHarness.getOverflowActionButton() expect(menuOverflowButton).toBeTruthy() - expect(menuOverflowButton.length).toBe(1) - menuOverflowButton[0].click() + await menuOverflowButton?.click() const overFlowMenuItems = await pageHeaderHarness.getOverFlowMenuItems() const disabledActionElement = overFlowMenuItems[1] diff --git a/libs/angular-accelerator/testing/page-header.harness.ts b/libs/angular-accelerator/testing/page-header.harness.ts index 0b89ca80..7d8bcd03 100644 --- a/libs/angular-accelerator/testing/page-header.harness.ts +++ b/libs/angular-accelerator/testing/page-header.harness.ts @@ -11,12 +11,8 @@ export class PageHeaderHarness extends ComponentHarness { static hostSelector = 'ocx-page-header' getPageHeaderWrapperHarness = this.locatorForAll('[name="ocx-page-header-wrapper"]') - getBreadcrumb = this.locatorFor(PBreadcrumbHarness) - getMenu = this.locatorFor(PMenuHarness) - - async getOverflowActionButton() { - return await this.locatorFor('[name="ocx-page-header-overflow-action-button"]')() - } + getBreadcrumb = this.locatorForOptional(PBreadcrumbHarness) + getMenu = this.locatorForOptional(PMenuHarness) async getElementByTitle(title: string) { return await this.locatorForOptional(`[title="${title}"]`)() @@ -48,20 +44,24 @@ export class PageHeaderHarness extends ComponentHarness { return await this.locatorForOptional(PButtonHarness.with({ icon: buttonIcon }))() } + async getOverflowActionButton() { + return await this.locatorForOptional('[name="ocx-page-header-overflow-action-button"]')() + } + async getOverFlowMenuItems() { const menu = await this.getMenu() - const menuItems = await menu.getAllMenuItems() + const menuItems = await menu?.getAllMenuItems() return menuItems ?? [] } async getOverFlowMenuItem(itemText: string): Promise { const menu = await this.getMenu() - return await menu.getMenuItem(itemText) + return await menu?.getMenuItem(itemText) } async getBreadcrumbItem(itemText: string): Promise { const breadcrumb = await this.getBreadcrumb() - return await breadcrumb.getBreadcrumbItem(itemText) + return await breadcrumb?.getBreadcrumbItem(itemText) } async getHeaderText(): Promise { From b3952b96361f86a2b575707b7e54db7cddb0715f Mon Sep 17 00:00:00 2001 From: markuczy Date: Wed, 3 Apr 2024 20:46:02 +0200 Subject: [PATCH 5/5] refactor: overflow action menu button renamed --- .../page-header/page-header.component.spec.ts | 14 +++++++------- .../testing/page-header.harness.ts | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/angular-accelerator/src/lib/components/page-header/page-header.component.spec.ts b/libs/angular-accelerator/src/lib/components/page-header/page-header.component.spec.ts index b5d7fa1e..f1498edc 100644 --- a/libs/angular-accelerator/src/lib/components/page-header/page-header.component.spec.ts +++ b/libs/angular-accelerator/src/lib/components/page-header/page-header.component.spec.ts @@ -42,7 +42,7 @@ const mockActions: Action[] = [ }, ] -fdescribe('PageHeaderComponent', () => { +describe('PageHeaderComponent', () => { const origAddEventListener = window.addEventListener const origPostMessage = window.postMessage @@ -115,13 +115,13 @@ fdescribe('PageHeaderComponent', () => { it('should check permissions and render buttons accordingly', async () => { expect(await pageHeaderHarness.getInlineActionButtons()).toHaveLength(0) - expect(await pageHeaderHarness.getOverflowActionButton()).toBeNull() + expect(await pageHeaderHarness.getOverflowActionMenuButton()).toBeNull() component.actions = mockActions expect(await pageHeaderHarness.getInlineActionButtons()).toHaveLength(1) expect(await pageHeaderHarness.getElementByTitle('My Test Action')).toBeTruthy() - await (await pageHeaderHarness.getOverflowActionButton())?.click() + await (await pageHeaderHarness.getOverflowActionMenuButton())?.click() expect(await pageHeaderHarness.getOverFlowMenuItems()).toHaveLength(2) expect(await pageHeaderHarness.getElementByTitle('More actions')).toBeTruthy() expect(userServiceSpy).toHaveBeenCalledTimes(3) @@ -133,7 +133,7 @@ fdescribe('PageHeaderComponent', () => { userServiceSpy.mockReturnValue(false) expect(await pageHeaderHarness.getInlineActionButtons()).toHaveLength(0) - expect(await pageHeaderHarness.getOverflowActionButton()).toBeNull() + expect(await pageHeaderHarness.getOverflowActionMenuButton()).toBeNull() component.actions = mockActions @@ -216,7 +216,7 @@ fdescribe('PageHeaderComponent', () => { it('should show overflow actions when menu overflow button clicked', async () => { component.actions = mockActions - const menuOverflowButton = await pageHeaderHarness.getOverflowActionButton() + const menuOverflowButton = await pageHeaderHarness.getOverflowActionMenuButton() expect(menuOverflowButton).toBeTruthy() await menuOverflowButton?.click() @@ -232,7 +232,7 @@ fdescribe('PageHeaderComponent', () => { component.actions = mockActions - const menuOverflowButton = await pageHeaderHarness.getOverflowActionButton() + const menuOverflowButton = await pageHeaderHarness.getOverflowActionMenuButton() expect(menuOverflowButton).toBeTruthy() await menuOverflowButton?.click() @@ -250,7 +250,7 @@ fdescribe('PageHeaderComponent', () => { component.actions = mockActions - const menuOverflowButton = await pageHeaderHarness.getOverflowActionButton() + const menuOverflowButton = await pageHeaderHarness.getOverflowActionMenuButton() expect(menuOverflowButton).toBeTruthy() await menuOverflowButton?.click() diff --git a/libs/angular-accelerator/testing/page-header.harness.ts b/libs/angular-accelerator/testing/page-header.harness.ts index 7d8bcd03..9938bb51 100644 --- a/libs/angular-accelerator/testing/page-header.harness.ts +++ b/libs/angular-accelerator/testing/page-header.harness.ts @@ -44,7 +44,7 @@ export class PageHeaderHarness extends ComponentHarness { return await this.locatorForOptional(PButtonHarness.with({ icon: buttonIcon }))() } - async getOverflowActionButton() { + async getOverflowActionMenuButton() { return await this.locatorForOptional('[name="ocx-page-header-overflow-action-button"]')() }