Skip to content

Commit

Permalink
feat: extraction of harnesses to separate lib
Browse files Browse the repository at this point in the history
  • Loading branch information
markuczy committed Mar 11, 2024
1 parent d4b5434 commit fb3e7c7
Show file tree
Hide file tree
Showing 67 changed files with 332 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataTableComponent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion libs/angular-accelerator/testing/data-list-grid.harness.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
18 changes: 10 additions & 8 deletions libs/angular-accelerator/testing/data-table.harness.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -19,11 +21,11 @@ export class DataTableHarness extends ContentContainerComponentHarness {
async getHarnessesForCheckboxes(type: 'all' | 'checked' | 'unchecked'): Promise<PTableCheckboxHarness[]> {
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)
Expand All @@ -32,15 +34,15 @@ 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') {
return await this.locatorForOptional(`[name="action-column-${position}"]`)()
}

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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
5 changes: 2 additions & 3 deletions libs/angular-accelerator/testing/diagram.harness.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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() {
Expand Down
20 changes: 0 additions & 20 deletions libs/angular-accelerator/testing/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
62 changes: 31 additions & 31 deletions libs/angular-accelerator/testing/page-header.harness.ts
Original file line number Diff line number Diff line change
@@ -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 ?? []
}
}
async getOverFlowMenuItems() {
const menu = await this.locatorFor(PMenuHarness)()
const menuItems = await menu.getAllMenuItems()
return menuItems ?? []
}
}
2 changes: 1 addition & 1 deletion libs/angular-accelerator/testing/search-config.harness.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
46 changes: 46 additions & 0 deletions libs/angular-testing/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
7 changes: 7 additions & 0 deletions libs/angular-testing/README.md
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 22 additions & 0 deletions libs/angular-testing/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
export default {
displayName: 'angular-testing',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: '../../coverage/libs/angular-testing',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/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',
],
}
8 changes: 8 additions & 0 deletions libs/angular-testing/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/libs/angular-testing",
"lib": {
"entryFile": "src/index.ts"
}
}

12 changes: 12 additions & 0 deletions libs/angular-testing/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading

0 comments on commit fb3e7c7

Please sign in to comment.