From fb3e7c793bc7247584186df45f658bd5c11da1fd Mon Sep 17 00:00:00 2001 From: markuczy Date: Mon, 11 Mar 2024 09:09:26 +0100 Subject: [PATCH] feat: extraction of harnesses to separate lib --- .../data-table/data-table.component.spec.ts | 3 +- .../interactive-data-view.component.spec.ts | 16 ++--- .../testing/column-group-selection.harness.ts | 2 +- .../custom-group-column-selector.harness.ts | 3 +- .../testing/data-layout-selection.harness.ts | 3 +- .../testing/data-list-grid.harness.ts | 2 +- .../testing/data-table.harness.ts | 18 +++--- .../testing/default-grid-item.harness.ts | 2 +- .../testing/default-list-item.harness.ts | 3 +- .../testing/diagram.harness.ts | 5 +- libs/angular-accelerator/testing/index.ts | 20 ------ .../testing/interactive-data-view.harness.ts | 4 +- .../more-actions-menu-button.harness.ts | 2 +- .../testing/page-header.harness.ts | 62 +++++++++---------- .../testing/search-config.harness.ts | 2 +- libs/angular-testing/.eslintrc.json | 46 ++++++++++++++ libs/angular-testing/README.md | 7 +++ libs/angular-testing/jest.config.ts | 22 +++++++ libs/angular-testing/ng-package.json | 8 +++ libs/angular-testing/package.json | 12 ++++ libs/angular-testing/project.json | 55 ++++++++++++++++ libs/angular-testing/src/index.ts | 28 +++++++++ .../src/lib/harnesses}/button.harness.ts | 0 .../src/lib/harnesses}/div.harness.ts | 0 .../src/lib/harnesses}/input.harness.ts | 0 .../src/lib/harnesses}/list-item.harness.ts | 0 .../src/lib/harnesses}/menu-item.harness.ts | 0 .../lib/harnesses}/p-tableCheckbox.harness.ts | 0 .../src/lib/harnesses}/p.harness.ts | 0 .../primeng/p-button-directive.harness.ts | 0 .../harnesses}/primeng/p-button.harness.ts | 0 .../lib/harnesses}/primeng/p-chart.harness.ts | 0 .../harnesses}/primeng/p-checkbox.harness.ts | 0 .../harnesses}/primeng/p-dialog.harness.ts | 0 .../harnesses}/primeng/p-dropdown.harness.ts | 0 .../lib/harnesses}/primeng/p-menu.harness.ts | 0 .../primeng/p-multiSelect.harness.ts | 0 .../primeng/p-multiSelectListItem.harness.ts | 0 .../harnesses}/primeng/p-paginator.harness.ts | 0 .../harnesses}/primeng/p-picklist.harness.ts | 0 .../primeng/p-selectButton.harness.ts | 0 .../src/lib/harnesses}/span.harness.ts | 0 .../harnesses}/table-header-column.harness.ts | 0 .../src/lib/harnesses}/table-row.harness.ts | 0 .../lib/harnesses}/utils/primeicon.utils.ts | 0 libs/angular-testing/src/test-setup.ts | 8 +++ libs/angular-testing/tsconfig.json | 31 ++++++++++ libs/angular-testing/tsconfig.lib.json | 14 +++++ libs/angular-testing/tsconfig.lib.prod.json | 13 ++++ libs/angular-testing/tsconfig.spec.json | 11 ++++ .../button-dialog.component.spec.ts | 3 +- ...dit-search-config-dialog.component.spec.ts | 3 +- .../services/portal-dialog.service.spec.ts | 3 +- .../testing/button-dialog.harness.ts | 2 +- .../testing/button.harness.ts | 40 ------------ .../testing/content-container.harness.ts | 2 +- .../testing/content.harness.ts | 3 +- ...te-or-edit-search-config-dialog.harness.ts | 3 +- .../testing/div.harness.ts | 40 ------------ .../testing/index.ts | 9 --- .../testing/menu-item.harness.ts | 13 ---- .../more-actions-menu-button.harness.ts | 2 +- .../testing/primeng/p-button.harness.ts | 21 ------- .../testing/primeng/p-calendar.harness.ts | 60 ------------------ .../testing/primeng/p-menu.harness.ts | 23 ------- .../testing/search-header.harness.ts | 3 +- tsconfig.base.json | 1 + 67 files changed, 332 insertions(+), 301 deletions(-) create mode 100644 libs/angular-testing/.eslintrc.json create mode 100644 libs/angular-testing/README.md create mode 100644 libs/angular-testing/jest.config.ts create mode 100644 libs/angular-testing/ng-package.json create mode 100644 libs/angular-testing/package.json create mode 100644 libs/angular-testing/project.json create mode 100644 libs/angular-testing/src/index.ts rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/button.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/div.harness.ts (100%) rename libs/{portal-integration-angular/testing => angular-testing/src/lib/harnesses}/input.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/list-item.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/menu-item.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/p-tableCheckbox.harness.ts (100%) rename libs/{portal-integration-angular/testing => angular-testing/src/lib/harnesses}/p.harness.ts (100%) rename libs/{portal-integration-angular/testing => angular-testing/src/lib/harnesses}/primeng/p-button-directive.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-button.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-chart.harness.ts (100%) rename libs/{portal-integration-angular/testing => angular-testing/src/lib/harnesses}/primeng/p-checkbox.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-dialog.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-dropdown.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-menu.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-multiSelect.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-multiSelectListItem.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-paginator.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-picklist.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/primeng/p-selectButton.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/span.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/table-header-column.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/table-row.harness.ts (100%) rename libs/{angular-accelerator/testing => angular-testing/src/lib/harnesses}/utils/primeicon.utils.ts (100%) create mode 100644 libs/angular-testing/src/test-setup.ts create mode 100644 libs/angular-testing/tsconfig.json create mode 100644 libs/angular-testing/tsconfig.lib.json create mode 100644 libs/angular-testing/tsconfig.lib.prod.json create mode 100644 libs/angular-testing/tsconfig.spec.json delete mode 100644 libs/portal-integration-angular/testing/button.harness.ts delete mode 100644 libs/portal-integration-angular/testing/div.harness.ts delete mode 100644 libs/portal-integration-angular/testing/menu-item.harness.ts delete mode 100644 libs/portal-integration-angular/testing/primeng/p-button.harness.ts delete mode 100644 libs/portal-integration-angular/testing/primeng/p-calendar.harness.ts delete mode 100644 libs/portal-integration-angular/testing/primeng/p-menu.harness.ts diff --git a/libs/angular-accelerator/src/lib/core/components/data-table/data-table.component.spec.ts b/libs/angular-accelerator/src/lib/core/components/data-table/data-table.component.spec.ts index 642df8eb..24aabb0d 100644 --- a/libs/angular-accelerator/src/lib/core/components/data-table/data-table.component.spec.ts +++ b/libs/angular-accelerator/src/lib/core/components/data-table/data-table.component.spec.ts @@ -7,7 +7,8 @@ import { TranslateTestingModule } from 'ngx-translate-testing' import { ColumnType } from '../../../model/column-type.model' import { AngularAcceleratorModule } from '../../angular-accelerator.module' import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' -import { DataTableHarness, PTableCheckboxHarness } from '../../../../../testing' +import { DataTableHarness } from '../../../../../testing' +import { PTableCheckboxHarness } from '@onecx/angular-testing' describe('DataTableComponent', () => { let fixture: ComponentFixture diff --git a/libs/angular-accelerator/src/lib/core/components/interactive-data-view/interactive-data-view.component.spec.ts b/libs/angular-accelerator/src/lib/core/components/interactive-data-view/interactive-data-view.component.spec.ts index 0b234d19..895cb820 100644 --- a/libs/angular-accelerator/src/lib/core/components/interactive-data-view/interactive-data-view.component.spec.ts +++ b/libs/angular-accelerator/src/lib/core/components/interactive-data-view/interactive-data-view.component.spec.ts @@ -18,20 +18,22 @@ import { ColumnGroupSelectionHarness, CustomGroupColumnSelectorHarness, DataLayoutSelectionHarness, - PDropdownHarness, - PButtonHarness, DataTableHarness, DataListGridHarness, - TableHeaderColumnHarness, - TableRowHarness, - ListItemHarness, DefaultGridItemHarness, DefaultListItemHarness, + InteractiveDataViewHarness, +} from '../../../../../testing' +import { + PDropdownHarness, + PButtonHarness, PPicklistHarness, ButtonHarness, PMultiSelectListItemHarness, - InteractiveDataViewHarness, -} from '../../../../../testing' + TableHeaderColumnHarness, + TableRowHarness, + ListItemHarness, +} from '@onecx/angular-testing' import { RouterTestingModule } from '@angular/router/testing' import { TranslateTestingModule } from 'ngx-translate-testing' import { NoopAnimationsModule } from '@angular/platform-browser/animations' diff --git a/libs/angular-accelerator/testing/column-group-selection.harness.ts b/libs/angular-accelerator/testing/column-group-selection.harness.ts index ab484c0a..638e8461 100644 --- a/libs/angular-accelerator/testing/column-group-selection.harness.ts +++ b/libs/angular-accelerator/testing/column-group-selection.harness.ts @@ -1,5 +1,5 @@ import { ComponentHarness } from '@angular/cdk/testing' -import { PDropdownHarness } from './primeng/p-dropdown.harness' +import { PDropdownHarness } from '@onecx/angular-testing' export class ColumnGroupSelectionHarness extends ComponentHarness { static hostSelector = 'ocx-column-group-selection' diff --git a/libs/angular-accelerator/testing/custom-group-column-selector.harness.ts b/libs/angular-accelerator/testing/custom-group-column-selector.harness.ts index 73b4de93..35df7b8d 100644 --- a/libs/angular-accelerator/testing/custom-group-column-selector.harness.ts +++ b/libs/angular-accelerator/testing/custom-group-column-selector.harness.ts @@ -1,6 +1,5 @@ import { ContentContainerComponentHarness } from '@angular/cdk/testing' -import { PDialogHarness, PPicklistHarness } from '.' -import { PButtonHarness } from './primeng/p-button.harness' +import { PDialogHarness, PPicklistHarness, PButtonHarness } from '@onecx/angular-testing' export class CustomGroupColumnSelectorHarness extends ContentContainerComponentHarness { static hostSelector = 'ocx-custom-group-column-selector' diff --git a/libs/angular-accelerator/testing/data-layout-selection.harness.ts b/libs/angular-accelerator/testing/data-layout-selection.harness.ts index 3e7da442..11c3fd22 100644 --- a/libs/angular-accelerator/testing/data-layout-selection.harness.ts +++ b/libs/angular-accelerator/testing/data-layout-selection.harness.ts @@ -1,7 +1,6 @@ import { ContentContainerComponentHarness, TestElement } from '@angular/cdk/testing' -import { PSelectButtonHarness } from './primeng/p-selectButton.harness' +import { PSelectButtonHarness, PrimeIcon } from '@onecx/angular-testing' import { PrimeIcons } from 'primeng/api' -import { PrimeIcon } from './utils/primeicon.utils' export class DataLayoutSelectionHarness extends ContentContainerComponentHarness { static hostSelector = 'ocx-data-layout-selection' diff --git a/libs/angular-accelerator/testing/data-list-grid.harness.ts b/libs/angular-accelerator/testing/data-list-grid.harness.ts index 86e0be0e..4ea6de1d 100644 --- a/libs/angular-accelerator/testing/data-list-grid.harness.ts +++ b/libs/angular-accelerator/testing/data-list-grid.harness.ts @@ -1,7 +1,7 @@ import { ContentContainerComponentHarness } from '@angular/cdk/testing' +import { PPaginatorHarness } from '@onecx/angular-testing' import { DefaultGridItemHarness } from './default-grid-item.harness' import { DefaultListItemHarness } from './default-list-item.harness' -import { PPaginatorHarness } from './primeng/p-paginator.harness' export class DataListGridHarness extends ContentContainerComponentHarness { static hostSelector = 'ocx-data-list-grid' diff --git a/libs/angular-accelerator/testing/data-table.harness.ts b/libs/angular-accelerator/testing/data-table.harness.ts index dbf9b196..ee70883e 100644 --- a/libs/angular-accelerator/testing/data-table.harness.ts +++ b/libs/angular-accelerator/testing/data-table.harness.ts @@ -1,8 +1,10 @@ import { ContentContainerComponentHarness, TestElement } from '@angular/cdk/testing' -import { TableHeaderColumnHarness } from './table-header-column.harness' -import { TableRowHarness } from './table-row.harness' -import { PPaginatorHarness } from './primeng/p-paginator.harness' -import { PTableCheckboxHarness } from './p-tableCheckbox.harness' +import { + TableHeaderColumnHarness, + TableRowHarness, + PPaginatorHarness, + PTableCheckboxHarness, +} from '@onecx/angular-testing' export class DataTableHarness extends ContentContainerComponentHarness { static hostSelector = 'ocx-data-table' @@ -19,11 +21,11 @@ export class DataTableHarness extends ContentContainerComponentHarness { async getHarnessesForCheckboxes(type: 'all' | 'checked' | 'unchecked'): Promise { let checkBoxHarnesses: PTableCheckboxHarness[] if (type === 'checked') { - checkBoxHarnesses = await this.getAllHarnesses(PTableCheckboxHarness.with({isSelected: true})) + checkBoxHarnesses = await this.getAllHarnesses(PTableCheckboxHarness.with({ isSelected: true })) return checkBoxHarnesses } if (type === 'unchecked') { - checkBoxHarnesses = await this.getAllHarnesses(PTableCheckboxHarness.with({isSelected: false})) + checkBoxHarnesses = await this.getAllHarnesses(PTableCheckboxHarness.with({ isSelected: false })) return checkBoxHarnesses } else { checkBoxHarnesses = await this.getAllHarnesses(PTableCheckboxHarness) @@ -32,7 +34,7 @@ export class DataTableHarness extends ContentContainerComponentHarness { } async getActionColumnHeader(position: 'left' | 'right') { - return await this.locatorForOptional(`[name="action-column-header-${position}"]`)() + return await this.locatorForOptional(`[name="action-column-header-${position}"]`)() } async getActionColumn(position: 'left' | 'right') { @@ -40,7 +42,7 @@ export class DataTableHarness extends ContentContainerComponentHarness { } async columnIsFrozen(column: TestElement | null) { - if(column == null) { + if (column == null) { throw new Error('Given column is null') } return await column.hasClass('p-frozen-column') diff --git a/libs/angular-accelerator/testing/default-grid-item.harness.ts b/libs/angular-accelerator/testing/default-grid-item.harness.ts index 61a0784d..10481591 100644 --- a/libs/angular-accelerator/testing/default-grid-item.harness.ts +++ b/libs/angular-accelerator/testing/default-grid-item.harness.ts @@ -1,5 +1,5 @@ import { ComponentHarness } from '@angular/cdk/testing' -import { DivHarness } from './div.harness' +import { DivHarness } from '@onecx/angular-testing' import { MoreActionsMenuButtonHarness } from './more-actions-menu-button.harness' export class DefaultGridItemHarness extends ComponentHarness { diff --git a/libs/angular-accelerator/testing/default-list-item.harness.ts b/libs/angular-accelerator/testing/default-list-item.harness.ts index d4956af5..3e011086 100644 --- a/libs/angular-accelerator/testing/default-list-item.harness.ts +++ b/libs/angular-accelerator/testing/default-list-item.harness.ts @@ -1,6 +1,5 @@ import { ComponentHarness } from '@angular/cdk/testing' -import { ButtonHarness } from './button.harness' -import { DivHarness } from './div.harness' +import { ButtonHarness, DivHarness } from '@onecx/angular-testing' export class DefaultListItemHarness extends ComponentHarness { static hostSelector = '.data-list-items' diff --git a/libs/angular-accelerator/testing/diagram.harness.ts b/libs/angular-accelerator/testing/diagram.harness.ts index 8dfe3d22..fe1a70dc 100644 --- a/libs/angular-accelerator/testing/diagram.harness.ts +++ b/libs/angular-accelerator/testing/diagram.harness.ts @@ -1,6 +1,5 @@ import { ComponentHarness } from '@angular/cdk/testing' -import { PChartHarness } from './primeng/p-chart.harness' -import { PSelectButtonHarness } from './primeng/p-selectButton.harness' +import { PChartHarness, PSelectButtonHarness } from '@onecx/angular-testing' export class DiagramHarness extends ComponentHarness { static hostSelector = 'ocx-diagram' @@ -16,7 +15,7 @@ export class DiagramHarness extends ComponentHarness { } async getDiagramTypeSelectButton() { - return (await this.locatorForOptional('p-selectButton[name="diagram-type-select-button"]')()) + return await this.locatorForOptional('p-selectButton[name="diagram-type-select-button"]')() } async getAllSelectionButtons() { diff --git a/libs/angular-accelerator/testing/index.ts b/libs/angular-accelerator/testing/index.ts index 7895eb1a..22cd889d 100644 --- a/libs/angular-accelerator/testing/index.ts +++ b/libs/angular-accelerator/testing/index.ts @@ -1,14 +1,3 @@ -export * from './primeng/p-button.harness' -export * from './primeng/p-dialog.harness' -export * from './primeng/p-dropdown.harness' -export * from './primeng/p-menu.harness' -export * from './primeng/p-multiSelect.harness' -export * from './primeng/p-multiSelectListItem.harness' -export * from './primeng/p-picklist.harness' -export * from './primeng/p-selectButton.harness' -export * from './primeng/p-paginator.harness' - -export * from './button.harness' export * from './column-group-selection.harness' export * from './custom-group-column-selector.harness' export * from './data-layout-selection.harness' @@ -17,20 +6,11 @@ export * from './data-table.harness' export * from './data-view.harness' export * from './default-grid-item.harness' export * from './default-list-item.harness' -export * from './div.harness' export * from './interactive-data-view.harness' -export * from './list-item.harness' -export * from './menu-item.harness' export * from './more-actions-menu-button.harness' -export * from './table-header-column.harness' -export * from './table-row.harness' export * from './diagram.harness' export * from './search-config.harness' -export * from './span.harness' export * from './page-header.harness' -export * from './p-tableCheckbox.harness' - -export * from './utils/primeicon.utils' export * from '@angular/cdk/testing' export * from '@angular/cdk/testing/testbed' diff --git a/libs/angular-accelerator/testing/interactive-data-view.harness.ts b/libs/angular-accelerator/testing/interactive-data-view.harness.ts index e977c832..f17cce6e 100644 --- a/libs/angular-accelerator/testing/interactive-data-view.harness.ts +++ b/libs/angular-accelerator/testing/interactive-data-view.harness.ts @@ -1,9 +1,9 @@ import { ContentContainerComponentHarness } from '@angular/cdk/testing' +import { PButtonHarness } from '@onecx/angular-testing' +import { PDropdownHarness } from '@onecx/angular-testing' import { CustomGroupColumnSelectorHarness } from '.' import { DataLayoutSelectionHarness } from './data-layout-selection.harness' import { DataViewHarness } from './data-view.harness' -import { PButtonHarness } from './primeng/p-button.harness' -import { PDropdownHarness } from './primeng/p-dropdown.harness' export class InteractiveDataViewHarness extends ContentContainerComponentHarness { static hostSelector = 'ocx-interactive-data-view' diff --git a/libs/angular-accelerator/testing/more-actions-menu-button.harness.ts b/libs/angular-accelerator/testing/more-actions-menu-button.harness.ts index d11f815a..c234dec2 100644 --- a/libs/angular-accelerator/testing/more-actions-menu-button.harness.ts +++ b/libs/angular-accelerator/testing/more-actions-menu-button.harness.ts @@ -1,5 +1,5 @@ import { ContentContainerComponentHarness, HarnessLoader } from '@angular/cdk/testing' -import { MenuItemHarness } from './menu-item.harness' +import { MenuItemHarness } from '@onecx/angular-testing' export class MoreActionsMenuButtonHarness extends ContentContainerComponentHarness { static hostSelector = '.more-actions-menu-button' diff --git a/libs/angular-accelerator/testing/page-header.harness.ts b/libs/angular-accelerator/testing/page-header.harness.ts index 709ffbc8..8c26aa2c 100644 --- a/libs/angular-accelerator/testing/page-header.harness.ts +++ b/libs/angular-accelerator/testing/page-header.harness.ts @@ -1,42 +1,42 @@ -import { ComponentHarness } from "@angular/cdk/testing"; -import { PMenuHarness } from "./primeng/p-menu.harness"; +import { ComponentHarness } from '@angular/cdk/testing' +import { PMenuHarness } from '@onecx/angular-testing' export class PageHeaderHarness extends ComponentHarness { - static hostSelector = 'ocx-page-header' + static hostSelector = 'ocx-page-header' - getPageHeaderWrapperHarness = this.locatorForAll('[name="ocx-page-header-wrapper"]') + getPageHeaderWrapperHarness = this.locatorForAll('[name="ocx-page-header-wrapper"]') - async getInlineActionButtons() { - return await this.locatorForAll('[name="ocx-page-header-inline-action-button"]')() - } + 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 getOverflowActionButtons() { + return await this.locatorForAll('[name="ocx-page-header-overflow-action-button"]')() + } - async getElementByTitle(title: string) { - return await this.locatorForOptional(`[title="${title}"]`)() - } + async getElementByTitle(title: string) { + return await this.locatorForOptional(`[title="${title}"]`)() + } - async getObjectInfos() { - return await this.locatorForAll('.object-info')() - } + async getObjectInfos() { + return await this.locatorForAll('.object-info')() + } - async getObjectDetailLabels() { - return await this.locatorForAll('[name="object-detail-label"]')() - } + async getObjectDetailLabels() { + return await this.locatorForAll('[name="object-detail-label"]')() + } - async getObjectDetailValues() { - return await this.locatorForAll('[name="object-detail-value"]')() - } + async getObjectDetailValues() { + return await this.locatorForAll('[name="object-detail-value"]')() + } - async getObjectDetailIcons() { - return await this.locatorForAll('[name="object-detail-icon"]')() - } + async getObjectDetailIcons() { + return await this.locatorForAll('[name="object-detail-icon"]')() + } - async getOverFlowMenuItems() { - const menu = await this.locatorFor(PMenuHarness)() - const menuItems = await menu.getAllMenuItems() - return menuItems ?? [] - } -} \ No newline at end of file + async getOverFlowMenuItems() { + const menu = await this.locatorFor(PMenuHarness)() + const menuItems = await menu.getAllMenuItems() + return menuItems ?? [] + } +} diff --git a/libs/angular-accelerator/testing/search-config.harness.ts b/libs/angular-accelerator/testing/search-config.harness.ts index ce413e59..1820f6cd 100644 --- a/libs/angular-accelerator/testing/search-config.harness.ts +++ b/libs/angular-accelerator/testing/search-config.harness.ts @@ -1,5 +1,5 @@ -import { PDropdownHarness } from './primeng/p-dropdown.harness' import { ContentContainerComponentHarness } from '@angular/cdk/testing' +import { PDropdownHarness } from '@onecx/angular-testing' export class SearchConfigHarness extends ContentContainerComponentHarness { static hostSelector = 'ocx-search-config' diff --git a/libs/angular-testing/.eslintrc.json b/libs/angular-testing/.eslintrc.json new file mode 100644 index 00000000..d4c0a6b0 --- /dev/null +++ b/libs/angular-testing/.eslintrc.json @@ -0,0 +1,46 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts"], + "extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"], + "rules": { + "@angular-eslint/directive-selector": [ + "error", + { + "type": "attribute", + "prefix": "ocx", + "style": "camelCase" + } + ], + "@angular-eslint/component-selector": [ + "error", + { + "type": "element", + "prefix": "ocx", + "style": "kebab-case" + } + ], + "no-restricted-syntax": [ + "off", + { + "selector": "CallExpression[callee.object.name=\"console\"][callee.property.name=/^(debug|info|time|timeEnd|trace)$/]" + } + ] + } + }, + { + "files": ["*.html"], + "extends": ["plugin:@nx/angular-template"], + "rules": {} + }, + { + "files": ["*.json"], + "parser": "jsonc-eslint-parser", + "rules": { + "@nx/dependency-checks": "error" + } + } + ] +} diff --git a/libs/angular-testing/README.md b/libs/angular-testing/README.md new file mode 100644 index 00000000..03b33ae6 --- /dev/null +++ b/libs/angular-testing/README.md @@ -0,0 +1,7 @@ +# angular-testing + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test angular-testing` to execute the unit tests. diff --git a/libs/angular-testing/jest.config.ts b/libs/angular-testing/jest.config.ts new file mode 100644 index 00000000..648b49dd --- /dev/null +++ b/libs/angular-testing/jest.config.ts @@ -0,0 +1,22 @@ +/* eslint-disable */ +export default { + displayName: 'angular-testing', + preset: '../../jest.preset.js', + setupFilesAfterEnv: ['/src/test-setup.ts'], + coverageDirectory: '../../coverage/libs/angular-testing', + transform: { + '^.+\\.(ts|mjs|js|html)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + }, + ], + }, + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], + snapshotSerializers: [ + 'jest-preset-angular/build/serializers/no-ng-attributes', + 'jest-preset-angular/build/serializers/ng-snapshot', + 'jest-preset-angular/build/serializers/html-comment', + ], +} diff --git a/libs/angular-testing/ng-package.json b/libs/angular-testing/ng-package.json new file mode 100644 index 00000000..5bb22778 --- /dev/null +++ b/libs/angular-testing/ng-package.json @@ -0,0 +1,8 @@ +{ + "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", + "dest": "../../dist/libs/angular-testing", + "lib": { + "entryFile": "src/index.ts" + } + } + \ No newline at end of file diff --git a/libs/angular-testing/package.json b/libs/angular-testing/package.json new file mode 100644 index 00000000..4ccc1684 --- /dev/null +++ b/libs/angular-testing/package.json @@ -0,0 +1,12 @@ +{ + "name": "@onecx/angular-testing", + "version": "4.9.0", + "peerDependencies": { + "@angular/cdk": "^15.2.7", + "primeng": "^15.2.1" + }, + "dependencies": {}, + "publishConfig": { + "access": "public" + } +} \ No newline at end of file diff --git a/libs/angular-testing/project.json b/libs/angular-testing/project.json new file mode 100644 index 00000000..50dcbe3d --- /dev/null +++ b/libs/angular-testing/project.json @@ -0,0 +1,55 @@ +{ + "name": "angular-testing", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/angular-testing/src", + "prefix": "onecx", + "tags": [], + "projectType": "library", + "targets": { + "build": { + "executor": "@nx/angular:package", + "outputs": [ + "{workspaceRoot}/dist/{projectRoot}" + ], + "options": { + "project": "libs/angular-testing/ng-package.json" + }, + "configurations": { + "production": { + "tsConfig": "libs/angular-testing/tsconfig.lib.prod.json" + }, + "development": { + "tsConfig": "libs/angular-testing/tsconfig.lib.json" + } + }, + "defaultConfiguration": "production" + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/angular-testing/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + }, + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["libs/angular-testing/**/*.ts", "libs/angular-testing/**/*.html"] + } + }, + "release": { + "executor": "nx-release:build-update-publish", + "options": { + "libName": "angular-testing" + } + } + } +} diff --git a/libs/angular-testing/src/index.ts b/libs/angular-testing/src/index.ts new file mode 100644 index 00000000..897aad99 --- /dev/null +++ b/libs/angular-testing/src/index.ts @@ -0,0 +1,28 @@ +export * from './lib/harnesses/primeng/p-button.harness' +export * from './lib/harnesses/primeng/p-button-directive.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.harness' +export * from './lib/harnesses/primeng/p-multiSelect.harness' +export * from './lib/harnesses/primeng/p-multiSelectListItem.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/button.harness' +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/table-header-column.harness' +export * from './lib/harnesses/table-row.harness' +export * from './lib/harnesses/span.harness' +export * from './lib/harnesses/p.harness' +export * from './lib/harnesses/p-tableCheckbox.harness' + +export * from './lib/harnesses/utils/primeicon.utils' + +export * from '@angular/cdk/testing' +export * from '@angular/cdk/testing/testbed' diff --git a/libs/angular-accelerator/testing/button.harness.ts b/libs/angular-testing/src/lib/harnesses/button.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/button.harness.ts rename to libs/angular-testing/src/lib/harnesses/button.harness.ts diff --git a/libs/angular-accelerator/testing/div.harness.ts b/libs/angular-testing/src/lib/harnesses/div.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/div.harness.ts rename to libs/angular-testing/src/lib/harnesses/div.harness.ts diff --git a/libs/portal-integration-angular/testing/input.harness.ts b/libs/angular-testing/src/lib/harnesses/input.harness.ts similarity index 100% rename from libs/portal-integration-angular/testing/input.harness.ts rename to libs/angular-testing/src/lib/harnesses/input.harness.ts diff --git a/libs/angular-accelerator/testing/list-item.harness.ts b/libs/angular-testing/src/lib/harnesses/list-item.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/list-item.harness.ts rename to libs/angular-testing/src/lib/harnesses/list-item.harness.ts diff --git a/libs/angular-accelerator/testing/menu-item.harness.ts b/libs/angular-testing/src/lib/harnesses/menu-item.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/menu-item.harness.ts rename to libs/angular-testing/src/lib/harnesses/menu-item.harness.ts diff --git a/libs/angular-accelerator/testing/p-tableCheckbox.harness.ts b/libs/angular-testing/src/lib/harnesses/p-tableCheckbox.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/p-tableCheckbox.harness.ts rename to libs/angular-testing/src/lib/harnesses/p-tableCheckbox.harness.ts diff --git a/libs/portal-integration-angular/testing/p.harness.ts b/libs/angular-testing/src/lib/harnesses/p.harness.ts similarity index 100% rename from libs/portal-integration-angular/testing/p.harness.ts rename to libs/angular-testing/src/lib/harnesses/p.harness.ts diff --git a/libs/portal-integration-angular/testing/primeng/p-button-directive.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-button-directive.harness.ts similarity index 100% rename from libs/portal-integration-angular/testing/primeng/p-button-directive.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-button-directive.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-button.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-button.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-button.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-button.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-chart.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-chart.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-chart.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-chart.harness.ts diff --git a/libs/portal-integration-angular/testing/primeng/p-checkbox.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-checkbox.harness.ts similarity index 100% rename from libs/portal-integration-angular/testing/primeng/p-checkbox.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-checkbox.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-dialog.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-dialog.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-dialog.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-dialog.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-dropdown.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-dropdown.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-dropdown.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-dropdown.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-menu.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-menu.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-menu.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-menu.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-multiSelect.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-multiSelect.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-multiSelect.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-multiSelect.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-multiSelectListItem.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-multiSelectListItem.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-multiSelectListItem.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-multiSelectListItem.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-paginator.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-paginator.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-paginator.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-paginator.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-picklist.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-picklist.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-picklist.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-picklist.harness.ts diff --git a/libs/angular-accelerator/testing/primeng/p-selectButton.harness.ts b/libs/angular-testing/src/lib/harnesses/primeng/p-selectButton.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/primeng/p-selectButton.harness.ts rename to libs/angular-testing/src/lib/harnesses/primeng/p-selectButton.harness.ts diff --git a/libs/angular-accelerator/testing/span.harness.ts b/libs/angular-testing/src/lib/harnesses/span.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/span.harness.ts rename to libs/angular-testing/src/lib/harnesses/span.harness.ts diff --git a/libs/angular-accelerator/testing/table-header-column.harness.ts b/libs/angular-testing/src/lib/harnesses/table-header-column.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/table-header-column.harness.ts rename to libs/angular-testing/src/lib/harnesses/table-header-column.harness.ts diff --git a/libs/angular-accelerator/testing/table-row.harness.ts b/libs/angular-testing/src/lib/harnesses/table-row.harness.ts similarity index 100% rename from libs/angular-accelerator/testing/table-row.harness.ts rename to libs/angular-testing/src/lib/harnesses/table-row.harness.ts diff --git a/libs/angular-accelerator/testing/utils/primeicon.utils.ts b/libs/angular-testing/src/lib/harnesses/utils/primeicon.utils.ts similarity index 100% rename from libs/angular-accelerator/testing/utils/primeicon.utils.ts rename to libs/angular-testing/src/lib/harnesses/utils/primeicon.utils.ts diff --git a/libs/angular-testing/src/test-setup.ts b/libs/angular-testing/src/test-setup.ts new file mode 100644 index 00000000..a5e675ac --- /dev/null +++ b/libs/angular-testing/src/test-setup.ts @@ -0,0 +1,8 @@ +// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment +globalThis.ngJest = { + testEnvironmentOptions: { + errorOnUnknownElements: true, + errorOnUnknownProperties: true, + }, +} +import 'jest-preset-angular/setup-jest' diff --git a/libs/angular-testing/tsconfig.json b/libs/angular-testing/tsconfig.json new file mode 100644 index 00000000..cd40c79f --- /dev/null +++ b/libs/angular-testing/tsconfig.json @@ -0,0 +1,31 @@ +{ + "compilerOptions": { + "target": "es2022", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "esModuleInterop": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.lib.prod.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../tsconfig.base.json", + "angularCompilerOptions": { + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/libs/angular-testing/tsconfig.lib.json b/libs/angular-testing/tsconfig.lib.json new file mode 100644 index 00000000..b9561ca9 --- /dev/null +++ b/libs/angular-testing/tsconfig.lib.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "declaration": true, + "declarationMap": true, + "inlineSources": true, + "types": [], + "target": "es2022", + "useDefineForClassFields": false + }, + "exclude": ["**/*.spec.ts", "src/test-setup.ts", "jest.config.ts", "**/*.test.ts", "**/*.stories.ts", "jest.config.ts"], + "include": ["**/*.ts"] +} diff --git a/libs/angular-testing/tsconfig.lib.prod.json b/libs/angular-testing/tsconfig.lib.prod.json new file mode 100644 index 00000000..3a838333 --- /dev/null +++ b/libs/angular-testing/tsconfig.lib.prod.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.lib.json", + "compilerOptions": { + "declarationMap": false, + "target": "es2022", + "useDefineForClassFields": false + }, + "angularCompilerOptions": { + "compilationMode": "partial" + }, + "exclude": ["jest.config.ts"] + } + \ No newline at end of file diff --git a/libs/angular-testing/tsconfig.spec.json b/libs/angular-testing/tsconfig.spec.json new file mode 100644 index 00000000..4251c922 --- /dev/null +++ b/libs/angular-testing/tsconfig.spec.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "target": "es2016", + "types": ["jest", "node"] + }, + "files": ["src/test-setup.ts"], + "include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"] +} 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 47995ce2..27627036 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,7 +7,8 @@ import { ButtonModule } from 'primeng/button' import { ButtonDialogComponent } from './button-dialog.component' import { MockAuthModule } from '../../../mock-auth/mock-auth.module' -import { ButtonDialogHarness, DivHarness } from '../../../../../testing' +import { ButtonDialogHarness } from '../../../../../testing' +import { DivHarness } from '@onecx/angular-testing' import { ButtonDialogConfig } from '../../../model/button-dialog' import { PrimeIcons } from 'primeng/api' diff --git a/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.spec.ts b/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.spec.ts index 077467fe..d8f20446 100644 --- a/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.spec.ts +++ b/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.spec.ts @@ -6,7 +6,8 @@ import { TranslateTestingModule } from 'ngx-translate-testing' import { HttpClientTestingModule } from '@angular/common/http/testing' import { TranslateService } from '@ngx-translate/core' import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' -import { PCheckboxHarness, CreateOrEditSearchConfigDialogHarness } from '../../../../../testing' +import { CreateOrEditSearchConfigDialogHarness } from '../../../../../testing' +import { PCheckboxHarness } from '@onecx/angular-testing' import { DialogState } from '../../../services/portal-dialog.service' import { ReactiveFormsModule } from '@angular/forms' import { InputTextModule } from 'primeng/inputtext' 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 1831233f..d41ca248 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 @@ -19,7 +19,8 @@ import { DialogState, PortalDialogService, } from './portal-dialog.service' -import { DivHarness, InputHarness, ButtonDialogHarness } from '../../../testing/index' +import { DivHarness, InputHarness } from '@onecx/angular-testing' +import { ButtonDialogHarness } from '../../../testing/index' import { PrimeIcons } from 'primeng/api' @Component({ diff --git a/libs/portal-integration-angular/testing/button-dialog.harness.ts b/libs/portal-integration-angular/testing/button-dialog.harness.ts index 0a208e05..c1497cd3 100644 --- a/libs/portal-integration-angular/testing/button-dialog.harness.ts +++ b/libs/portal-integration-angular/testing/button-dialog.harness.ts @@ -1,5 +1,5 @@ import { ContentContainerComponentHarness } from '@angular/cdk/testing' -import { PButtonDirectiveHarness } from './primeng/p-button-directive.harness' +import { PButtonDirectiveHarness } from '@onecx/angular-testing' import { DialogMessageContentHarness } from './dialog-message-content.harness' export class ButtonDialogHarness extends ContentContainerComponentHarness { diff --git a/libs/portal-integration-angular/testing/button.harness.ts b/libs/portal-integration-angular/testing/button.harness.ts deleted file mode 100644 index 016dabf4..00000000 --- a/libs/portal-integration-angular/testing/button.harness.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular/cdk/testing' - -export interface ButtonHarnessFilters extends BaseHarnessFilters { - id?: string - icon?: string - class?: string -} - -export class ButtonHarness extends ComponentHarness { - static hostSelector = 'button' - - static with(options: ButtonHarnessFilters): HarnessPredicate { - return new HarnessPredicate(ButtonHarness, options) - .addOption('id', options.id, (harness, id) => HarnessPredicate.stringMatches(harness.getId(), id)) - .addOption('icon', options.icon, (harness, icon) => HarnessPredicate.stringMatches(harness.getIcon(), icon)) - .addOption('class', options.class, (harness, c) => HarnessPredicate.stringMatches(harness.getByClass(c), c)) - } - - async getId(): Promise { - return await (await this.host()).getAttribute('id') - } - async getIcon(): Promise { - return await (await this.host()).getAttribute('icon') - } - async getByClass(c: string): Promise { - return (await (await this.host()).hasClass(c)) ? c : '' - } - - async click() { - if (!(await this.isDisabled())) { - await (await this.host()).click() - } else { - console.warn('Button cannot be clicked, because it is disabled!') - } - } - - async isDisabled(): Promise { - return await (await this.host()).getProperty('disabled') - } -} diff --git a/libs/portal-integration-angular/testing/content-container.harness.ts b/libs/portal-integration-angular/testing/content-container.harness.ts index e7046da7..6adfd04f 100644 --- a/libs/portal-integration-angular/testing/content-container.harness.ts +++ b/libs/portal-integration-angular/testing/content-container.harness.ts @@ -1,5 +1,5 @@ import { ComponentHarness } from '@angular/cdk/testing' -import { DivHarness } from './div.harness' +import { DivHarness } from '@onecx/angular-testing' export class OcxContentContainerHarness extends ComponentHarness { static hostSelector = 'ocx-content-container' diff --git a/libs/portal-integration-angular/testing/content.harness.ts b/libs/portal-integration-angular/testing/content.harness.ts index 03a05f20..688bea52 100644 --- a/libs/portal-integration-angular/testing/content.harness.ts +++ b/libs/portal-integration-angular/testing/content.harness.ts @@ -1,6 +1,5 @@ import { ComponentHarness } from '@angular/cdk/testing' -import { DivHarness } from './div.harness' -import { PHarness } from './p.harness' +import { DivHarness, PHarness } from '@onecx/angular-testing' export class OcxContentHarness extends ComponentHarness { static hostSelector = 'ocx-content' diff --git a/libs/portal-integration-angular/testing/create-or-edit-search-config-dialog.harness.ts b/libs/portal-integration-angular/testing/create-or-edit-search-config-dialog.harness.ts index d056751b..1de86db7 100644 --- a/libs/portal-integration-angular/testing/create-or-edit-search-config-dialog.harness.ts +++ b/libs/portal-integration-angular/testing/create-or-edit-search-config-dialog.harness.ts @@ -1,6 +1,5 @@ import { ContentContainerComponentHarness } from '@angular/cdk/testing' -import { PCheckboxHarness } from './primeng/p-checkbox.harness' -import { InputHarness } from './input.harness' +import { PCheckboxHarness, InputHarness } from '@onecx/angular-testing' export class CreateOrEditSearchConfigDialogHarness extends ContentContainerComponentHarness { static hostSelector = 'ocx-create-or-edit-search-config-dialog' diff --git a/libs/portal-integration-angular/testing/div.harness.ts b/libs/portal-integration-angular/testing/div.harness.ts deleted file mode 100644 index 6cf90005..00000000 --- a/libs/portal-integration-angular/testing/div.harness.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular/cdk/testing' - -export interface DivHarnessFilters extends BaseHarnessFilters { - class?: string -} - -export class DivHarness extends ComponentHarness { - static hostSelector = 'div' - - static with(options: DivHarnessFilters): HarnessPredicate { - return new HarnessPredicate(DivHarness, options).addOption('class', options.class, (harness, c) => - HarnessPredicate.stringMatches(harness.getByClass(c), c) - ) - } - - async getByClass(c: string): Promise { - return (await (await this.host()).hasClass(c)) ? c : '' - } - - async checkHasClass(value: string) { - return await (await this.host()).hasClass(value) - } - - async getText(): Promise { - return await (await this.host()).text() - } - - async getClassList() { - const host = await this.host() - const attributeString = await host.getAttribute('class') - if (attributeString) { - return attributeString.trim().split(' ') - } - return [] - } - - async click(): Promise { - await (await this.host()).click() - } -} diff --git a/libs/portal-integration-angular/testing/index.ts b/libs/portal-integration-angular/testing/index.ts index 7635a61a..450d3e94 100644 --- a/libs/portal-integration-angular/testing/index.ts +++ b/libs/portal-integration-angular/testing/index.ts @@ -1,13 +1,4 @@ -export * from './primeng/p-button.harness' -export * from './primeng/p-calendar.harness' -export * from './primeng/p-menu.harness' -export * from './primeng/p-checkbox.harness' - export * from './button-dialog.harness' -export * from './button.harness' -export * from './div.harness' -export * from './input.harness' -export * from './menu-item.harness' export * from './more-actions-menu-button.harness' export * from './search-header.harness' export * from './create-or-edit-search-config-dialog.harness' diff --git a/libs/portal-integration-angular/testing/menu-item.harness.ts b/libs/portal-integration-angular/testing/menu-item.harness.ts deleted file mode 100644 index f22e8a2d..00000000 --- a/libs/portal-integration-angular/testing/menu-item.harness.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ComponentHarness } from '@angular/cdk/testing' - -export class MenuItemHarness extends ComponentHarness { - static hostSelector = 'li > a' - - async getText() { - return await (await this.host()).text() - } - - async selectItem() { - await (await this.host()).click() - } -} diff --git a/libs/portal-integration-angular/testing/more-actions-menu-button.harness.ts b/libs/portal-integration-angular/testing/more-actions-menu-button.harness.ts index d11f815a..c234dec2 100644 --- a/libs/portal-integration-angular/testing/more-actions-menu-button.harness.ts +++ b/libs/portal-integration-angular/testing/more-actions-menu-button.harness.ts @@ -1,5 +1,5 @@ import { ContentContainerComponentHarness, HarnessLoader } from '@angular/cdk/testing' -import { MenuItemHarness } from './menu-item.harness' +import { MenuItemHarness } from '@onecx/angular-testing' export class MoreActionsMenuButtonHarness extends ContentContainerComponentHarness { static hostSelector = '.more-actions-menu-button' diff --git a/libs/portal-integration-angular/testing/primeng/p-button.harness.ts b/libs/portal-integration-angular/testing/primeng/p-button.harness.ts deleted file mode 100644 index 517cbe7f..00000000 --- a/libs/portal-integration-angular/testing/primeng/p-button.harness.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular/cdk/testing' - -export interface PButtonHarnessFilters extends BaseHarnessFilters { - id?: 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) - ) - } - async getId(): Promise { - return await (await this.host()).getAttribute('id') - } - - async click() { - await (await this.locatorFor('button')()).click() - } -} diff --git a/libs/portal-integration-angular/testing/primeng/p-calendar.harness.ts b/libs/portal-integration-angular/testing/primeng/p-calendar.harness.ts deleted file mode 100644 index cac5ad7e..00000000 --- a/libs/portal-integration-angular/testing/primeng/p-calendar.harness.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { - BaseHarnessFilters, - ContentContainerComponentHarness, - HarnessLoader, - HarnessPredicate, - TestKey, -} from '@angular/cdk/testing' -import { InputHarness } from '../input.harness' - -export interface PCalendarHarnessFilters extends BaseHarnessFilters { - id?: string -} - -export class PCalendarHarness extends ContentContainerComponentHarness { - static hostSelector = 'p-calendar' - - getCalendarInput = this.locatorFor(InputHarness) - - static with(options: PCalendarHarnessFilters): HarnessPredicate { - return new HarnessPredicate(PCalendarHarness, options).addOption('id', options.id, (harness, id) => - HarnessPredicate.stringMatches(harness.getId(), id) - ) - } - - async getId(): Promise { - return await (await this.host()).getAttribute('id') - } - - async getHarnessLoaderForPDatepicker(): Promise { - return this.documentRootLocatorFactory().harnessLoaderForOptional('.p-datepicker') - } - - async isOpen(): Promise { - return !!(await this.getHarnessLoaderForPDatepicker()) - } - - async open(): Promise { - if (!(await this.isOpen())) { - await (await this.getCalendarInput()).click() - } else { - console.warn('Unable to open calendar, because it is already open.') - } - } - - async close(): Promise { - if (await this.isOpen()) { - await (await (await this.getCalendarInput()).getTestElement()).sendKeys(TestKey.ESCAPE) - } else { - console.warn('Unable to close calendar, because it is not open.') - } - } - - async setValue(value: string | Date) { - await (await this.getCalendarInput()).setValue(value) - } - - async getValue(): Promise { - return await (await this.getCalendarInput()).getValue() - } -} diff --git a/libs/portal-integration-angular/testing/primeng/p-menu.harness.ts b/libs/portal-integration-angular/testing/primeng/p-menu.harness.ts deleted file mode 100644 index 4f7d2839..00000000 --- a/libs/portal-integration-angular/testing/primeng/p-menu.harness.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ContentContainerComponentHarness, HarnessLoader } from '@angular/cdk/testing' -import { MenuItemHarness } from '../menu-item.harness' - -export class PMenuHarness extends ContentContainerComponentHarness { - static hostSelector = 'p-menu' - - async getHarnessLoaderForPMenuOverlay(): Promise { - return this.documentRootLocatorFactory().harnessLoaderForOptional('.p-menu-overlay') - } - - async isOpen(): Promise { - return !!(await this.getHarnessLoaderForPMenuOverlay()) - } - - async getAllMenuItems() { - if (await this.isOpen()) { - return await (await this.getHarnessLoaderForPMenuOverlay())?.getAllHarnesses(MenuItemHarness) - } else { - console.warn('Cannot get menu items because menu is closed.') - } - return [] - } -} diff --git a/libs/portal-integration-angular/testing/search-header.harness.ts b/libs/portal-integration-angular/testing/search-header.harness.ts index 226d6ae3..6d046586 100644 --- a/libs/portal-integration-angular/testing/search-header.harness.ts +++ b/libs/portal-integration-angular/testing/search-header.harness.ts @@ -1,7 +1,6 @@ import { ContentContainerComponentHarness } from '@angular/cdk/testing' -import { ButtonHarness } from './button.harness' import { MoreActionsMenuButtonHarness } from './more-actions-menu-button.harness' -import { PButtonHarness } from './primeng/p-button.harness' +import { ButtonHarness, PButtonHarness } from '@onecx/angular-testing' export class SearchHeaderHarness extends ContentContainerComponentHarness { static hostSelector = 'ocx-search-header' diff --git a/tsconfig.base.json b/tsconfig.base.json index d4eab69b..ac8f5e48 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -17,6 +17,7 @@ "paths": { "@onecx/accelerator": ["libs/accelerator/src/index.ts"], "@onecx/angular-accelerator": ["libs/angular-accelerator/src/index.ts"], + "@onecx/angular-testing": ["libs/angular-testing/src/index.ts"], "@onecx/integration-interface": ["libs/integration-interface/src/index.ts"], "@onecx/keycloak-auth": ["libs/keycloak-auth/src/index.ts"], "@onecx/portal-integration-angular": ["libs/portal-integration-angular/src/index.ts"],