From 28d30a0410cc7c4ee189638ad2fac8a421bb3b00 Mon Sep 17 00:00:00 2001 From: markuczy Date: Thu, 23 May 2024 08:42:31 +0200 Subject: [PATCH 1/3] feat: menu harnesses enchanced --- libs/angular-testing/src/index.ts | 9 +++++- .../harnesses/menu-item-with-icon.harness.ts | 12 ++++++++ .../primeng/p-accordion-tab.harness.ts | 11 ++++++++ .../harnesses/primeng/p-accordion.harness.ts | 8 ++++++ .../harnesses/primeng/p-menu-item.harness.ts | 23 +++++++++++++++ .../harnesses/primeng/p-menubar.harness.ts | 8 ++++++ .../primeng/p-panelmenu-item.harness.ts | 28 +++++++++++++++++++ .../harnesses/primeng/p-panelmenu.harness.ts | 8 ++++++ 8 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 libs/angular-testing/src/lib/harnesses/menu-item-with-icon.harness.ts create mode 100644 libs/angular-testing/src/lib/harnesses/primeng/p-accordion-tab.harness.ts create mode 100644 libs/angular-testing/src/lib/harnesses/primeng/p-accordion.harness.ts create mode 100644 libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts create mode 100644 libs/angular-testing/src/lib/harnesses/primeng/p-menubar.harness.ts create mode 100644 libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts create mode 100644 libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu.harness.ts diff --git a/libs/angular-testing/src/index.ts b/libs/angular-testing/src/index.ts index 1a2b7edf..377f1270 100644 --- a/libs/angular-testing/src/index.ts +++ b/libs/angular-testing/src/index.ts @@ -1,3 +1,5 @@ +export * from './lib/harnesses/primeng/p-accordion.harness' +export * from './lib/harnesses/primeng/p-accordion-tab.harness' 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' @@ -5,13 +7,17 @@ export * from './lib/harnesses/primeng/p-chart.harness' export * from './lib/harnesses/primeng/p-checkbox.harness' export * from './lib/harnesses/primeng/p-dialog.harness' export * from './lib/harnesses/primeng/p-dropdown.harness' +export * from './lib/harnesses/primeng/p-menu-item.harness' export * from './lib/harnesses/primeng/p-menu.harness' +export * from './lib/harnesses/primeng/p-menubar.harness' export * from './lib/harnesses/primeng/p-multiSelect.harness' export * from './lib/harnesses/primeng/p-multiSelectListItem.harness' +export * from './lib/harnesses/primeng/p-panelmenu-item.harness' +export * from './lib/harnesses/primeng/p-panelmenu.harness' +export * from './lib/harnesses/primeng/p-paginator.harness' export * from './lib/harnesses/primeng/p-password.harness' export * from './lib/harnesses/primeng/p-picklist.harness' export * from './lib/harnesses/primeng/p-selectButton.harness' -export * from './lib/harnesses/primeng/p-paginator.harness' export * from './lib/harnesses/utils/primeicon.utils' @@ -20,6 +26,7 @@ export * from './lib/harnesses/div.harness' export * from './lib/harnesses/input.harness' export * from './lib/harnesses/list-item.harness' export * from './lib/harnesses/menu-item.harness' +export * from './lib/harnesses/menu-item-with-icon.harness' export * from './lib/harnesses/p-tableCheckbox.harness' export * from './lib/harnesses/p.harness' export * from './lib/harnesses/span.harness' diff --git a/libs/angular-testing/src/lib/harnesses/menu-item-with-icon.harness.ts b/libs/angular-testing/src/lib/harnesses/menu-item-with-icon.harness.ts new file mode 100644 index 00000000..a281e0c9 --- /dev/null +++ b/libs/angular-testing/src/lib/harnesses/menu-item-with-icon.harness.ts @@ -0,0 +1,12 @@ +import { MenuItemHarness } from './menu-item.harness' + +export class MenuItemWithIconHarness extends MenuItemHarness { + async hasIcon(icon: string): Promise { + const classList = await (await this.locatorForOptional('i')())?.getAttribute('class') + return classList?.includes(icon) + } + + async isExternal(): Promise { + return (await (await this.host()).getAttribute('ng-reflect-router-link')) === null + } +} diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-accordion-tab.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-accordion-tab.harness.ts new file mode 100644 index 00000000..11f2931c --- /dev/null +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-accordion-tab.harness.ts @@ -0,0 +1,11 @@ +import { ComponentHarness } from '@angular/cdk/testing' + +export class PAccordionTabHarness extends ComponentHarness { + static hostSelector = 'p-accordiontab' + + getButton = this.locatorFor('a.p-accordion-header-link') + + async expand() { + await (await this.getButton()).click() + } +} diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-accordion.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-accordion.harness.ts new file mode 100644 index 00000000..bf899291 --- /dev/null +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-accordion.harness.ts @@ -0,0 +1,8 @@ +import { ComponentHarness } from '@angular/cdk/testing' +import { PAccordionTabHarness } from './p-accordion-tab.harness' + +export class PAccordionHarness extends ComponentHarness { + static hostSelector = 'p-accordion' + + getAllAccordionTabs = this.locatorForAll(PAccordionTabHarness) +} diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts new file mode 100644 index 00000000..679d4290 --- /dev/null +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts @@ -0,0 +1,23 @@ +import { ComponentHarness } from '@angular/cdk/testing' +import { SpanHarness } from '../span.harness' + +export class PMenuItemHarness extends ComponentHarness { + static hostSelector = 'li.p-menuitem' + + getAnchor = this.locatorFor('a') + getChildren = this.locatorForAll(PMenuItemHarness) + getIconSpan = this.locatorForOptional(SpanHarness.with({ class: 'p-menuitem-icon' })) + + async getText() { + return await (await this.getAnchor()).text() + } + + async hasIcon(icon: string): Promise { + const classList = await (await (await this.getIconSpan())?.host())?.getAttribute('class') + return classList?.includes(icon) + } + + async isExternal(): Promise { + return (await (await this.getAnchor()).getAttribute('ng-reflect-router-link')) === null + } +} diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-menubar.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-menubar.harness.ts new file mode 100644 index 00000000..c535e803 --- /dev/null +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-menubar.harness.ts @@ -0,0 +1,8 @@ +import { ComponentHarness } from '@angular/cdk/testing' +import { PMenuItemHarness } from './p-menu-item.harness' + +export class PMenuBarHarness extends ComponentHarness { + static hostSelector = 'p-menubar' + + getAllMenuItems = this.locatorForAll(PMenuItemHarness) +} diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts new file mode 100644 index 00000000..cc269dfd --- /dev/null +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts @@ -0,0 +1,28 @@ +import { ComponentHarness } from '@angular/cdk/testing' +import { SpanHarness } from '../span.harness' +import { PMenuItemHarness } from './p-menu-item.harness' + +export class PanelMenuItemHarness extends ComponentHarness { + static hostSelector = 'div.p-panelmenu-panel' + + getAnchor = this.locatorFor('a') + getChildren = this.locatorForAll(PMenuItemHarness) + getIconSpan = this.locatorForOptional(SpanHarness.with({ class: 'p-menuitem-icon' })) + + async getText() { + return await (await this.getAnchor()).text() + } + + async hasIcon(icon: string): Promise { + const classList = await (await (await this.getIconSpan())?.host())?.getAttribute('class') + return classList?.includes(icon) + } + + async isExternal(): Promise { + return (await (await this.getAnchor()).getAttribute('ng-reflect-router-link')) === null + } + + async click() { + await (await this.getAnchor()).click() + } +} diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu.harness.ts new file mode 100644 index 00000000..9b550451 --- /dev/null +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu.harness.ts @@ -0,0 +1,8 @@ +import { ComponentHarness } from '@angular/cdk/testing' +import { PanelMenuItemHarness } from './p-panelmenu-item.harness' + +export class PPanelMenuHarness extends ComponentHarness { + static hostSelector = 'p-panelmenu' + + getAllPanels = this.locatorForAll(PanelMenuItemHarness) +} From ace5f0ff7f2860bd736967908e01297a8eafb2b4 Mon Sep 17 00:00:00 2001 From: markuczy Date: Mon, 27 May 2024 10:54:14 +0200 Subject: [PATCH 2/3] feat: removed external check from harnesses --- .../src/lib/harnesses/menu-item-with-icon.harness.ts | 4 ---- .../src/lib/harnesses/primeng/p-menu-item.harness.ts | 4 ---- .../src/lib/harnesses/primeng/p-panelmenu-item.harness.ts | 4 ---- 3 files changed, 12 deletions(-) diff --git a/libs/angular-testing/src/lib/harnesses/menu-item-with-icon.harness.ts b/libs/angular-testing/src/lib/harnesses/menu-item-with-icon.harness.ts index a281e0c9..3aed3648 100644 --- a/libs/angular-testing/src/lib/harnesses/menu-item-with-icon.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/menu-item-with-icon.harness.ts @@ -5,8 +5,4 @@ export class MenuItemWithIconHarness extends MenuItemHarness { const classList = await (await this.locatorForOptional('i')())?.getAttribute('class') return classList?.includes(icon) } - - async isExternal(): Promise { - return (await (await this.host()).getAttribute('ng-reflect-router-link')) === null - } } diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts index 679d4290..0e8db396 100644 --- a/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts @@ -16,8 +16,4 @@ export class PMenuItemHarness extends ComponentHarness { const classList = await (await (await this.getIconSpan())?.host())?.getAttribute('class') return classList?.includes(icon) } - - async isExternal(): Promise { - return (await (await this.getAnchor()).getAttribute('ng-reflect-router-link')) === null - } } diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts index cc269dfd..fb3aa720 100644 --- a/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts @@ -18,10 +18,6 @@ export class PanelMenuItemHarness extends ComponentHarness { return classList?.includes(icon) } - async isExternal(): Promise { - return (await (await this.getAnchor()).getAttribute('ng-reflect-router-link')) === null - } - async click() { await (await this.getAnchor()).click() } From 9d0e58bd1e4ceb128ef3fec25178133444064ef4 Mon Sep 17 00:00:00 2001 From: markuczy Date: Mon, 27 May 2024 11:50:01 +0200 Subject: [PATCH 3/3] feat: further menu harness enchancements --- .../src/lib/harnesses/menu-item.harness.ts | 6 +++++- .../src/lib/harnesses/primeng/p-menu-item.harness.ts | 10 +++++++++- .../src/lib/harnesses/primeng/p-menu.harness.ts | 2 +- .../lib/harnesses/primeng/p-panelmenu-item.harness.ts | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) 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 94b191c9..bd86d4f3 100644 --- a/libs/angular-testing/src/lib/harnesses/menu-item.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/menu-item.harness.ts @@ -13,11 +13,15 @@ export class MenuItemHarness extends ComponentHarness { ) } - async getText() { + async getText(): Promise { return await (await this.host()).text() } async selectItem() { await (await this.host()).click() } + + async getLink(): Promise { + return await (await this.host()).getAttribute('href') + } } diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts index 0e8db396..5355dcf2 100644 --- a/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-menu-item.harness.ts @@ -8,7 +8,7 @@ export class PMenuItemHarness extends ComponentHarness { getChildren = this.locatorForAll(PMenuItemHarness) getIconSpan = this.locatorForOptional(SpanHarness.with({ class: 'p-menuitem-icon' })) - async getText() { + async getText(): Promise { return await (await this.getAnchor()).text() } @@ -16,4 +16,12 @@ export class PMenuItemHarness extends ComponentHarness { const classList = await (await (await this.getIconSpan())?.host())?.getAttribute('class') return classList?.includes(icon) } + + async click() { + return await (await this.getAnchor()).click() + } + + async getLink(): Promise { + return await (await this.getAnchor()).getAttribute('href') + } } 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 9d8e432d..3afcdd1b 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 @@ -12,7 +12,7 @@ export class PMenuHarness extends ContentContainerComponentHarness { return !!(await this.getHarnessLoaderForPMenuOverlay()) } - async getAllMenuItems() { + async getAllMenuItems(): Promise { if (await this.isOpen()) { return await (await this.getHarnessLoaderForPMenuOverlay())?.getAllHarnesses(MenuItemHarness) } else { diff --git a/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts index fb3aa720..ded18462 100644 --- a/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts +++ b/libs/angular-testing/src/lib/harnesses/primeng/p-panelmenu-item.harness.ts @@ -9,7 +9,7 @@ export class PanelMenuItemHarness extends ComponentHarness { getChildren = this.locatorForAll(PMenuItemHarness) getIconSpan = this.locatorForOptional(SpanHarness.with({ class: 'p-menuitem-icon' })) - async getText() { + async getText(): Promise { return await (await this.getAnchor()).text() } @@ -21,4 +21,8 @@ export class PanelMenuItemHarness extends ComponentHarness { async click() { await (await this.getAnchor()).click() } + + async getLink(): Promise { + return await (await this.getAnchor()).getAttribute('href') + } }