Skip to content

Commit

Permalink
feat: menu harnesses enhancements (onecx#260)
Browse files Browse the repository at this point in the history
* feat: menu harnesses enchanced

* feat: removed external check from harnesses

* feat: further menu harness enchancements
  • Loading branch information
markuczy authored and anninowak committed Jun 4, 2024
1 parent 20134d1 commit 325a7b3
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 3 deletions.
9 changes: 8 additions & 1 deletion libs/angular-testing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
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'
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'

Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { MenuItemHarness } from './menu-item.harness'

export class MenuItemWithIconHarness extends MenuItemHarness {
async hasIcon(icon: string): Promise<boolean | undefined> {
const classList = await (await this.locatorForOptional('i')())?.getAttribute('class')
return classList?.includes(icon)
}
}
6 changes: 5 additions & 1 deletion libs/angular-testing/src/lib/harnesses/menu-item.harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ export class MenuItemHarness extends ComponentHarness {
)
}

async getText() {
async getText(): Promise<string> {
return await (await this.host()).text()
}

async selectItem() {
await (await this.host()).click()
}

async getLink(): Promise<string | null> {
return await (await this.host()).getAttribute('href')
}
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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(): Promise<string> {
return await (await this.getAnchor()).text()
}

async hasIcon(icon: string): Promise<boolean | undefined> {
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<string | null> {
return await (await this.getAnchor()).getAttribute('href')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class PMenuHarness extends ContentContainerComponentHarness {
return !!(await this.getHarnessLoaderForPMenuOverlay())
}

async getAllMenuItems() {
async getAllMenuItems(): Promise<MenuItemHarness[] | undefined> {
if (await this.isOpen()) {
return await (await this.getHarnessLoaderForPMenuOverlay())?.getAllHarnesses(MenuItemHarness)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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(): Promise<string> {
return await (await this.getAnchor()).text()
}

async hasIcon(icon: string): Promise<boolean | undefined> {
const classList = await (await (await this.getIconSpan())?.host())?.getAttribute('class')
return classList?.includes(icon)
}

async click() {
await (await this.getAnchor()).click()
}

async getLink(): Promise<string | null> {
return await (await this.getAnchor()).getAttribute('href')
}
}
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 325a7b3

Please sign in to comment.