diff --git a/libs/portal-integration-angular/assets/i18n/de.json b/libs/portal-integration-angular/assets/i18n/de.json index 6700ddf1..49f81244 100644 --- a/libs/portal-integration-angular/assets/i18n/de.json +++ b/libs/portal-integration-angular/assets/i18n/de.json @@ -16,6 +16,11 @@ "RIGHT": "Rechts" } }, + "OCX_SEARCH_CONFIG": { + "PLACEHOLDER": "Bitte geben Sie den Namen der Suchkonfiguration an.", + "SAVE_COLUMNS_OPTION": "Möchten Sie die angezeigten Spalten speichern?", + "SAVE_INPUT_FIELDS_OPTION": "Möchten Sie die Werte aus den Suchfeldern speichern?" + }, "OCX_LIST_GRID_SORT": { "DROPDOWN": { "PLACEHOLDER": "Sortierung auswählen", diff --git a/libs/portal-integration-angular/assets/i18n/en.json b/libs/portal-integration-angular/assets/i18n/en.json index 357b85a7..1ec7f442 100644 --- a/libs/portal-integration-angular/assets/i18n/en.json +++ b/libs/portal-integration-angular/assets/i18n/en.json @@ -16,6 +16,11 @@ "RIGHT": "Right" } }, + "OCX_SEARCH_CONFIG": { + "PLACEHOLDER": "Please enter the name of the search configuration", + "SAVE_COLUMNS_OPTION": "Do you want to save the shown columns?", + "SAVE_INPUT_FIELDS_OPTION": "Do you want to save the input values from the input fields?" + }, "OCX_LIST_GRID_SORT": { "DROPDOWN": { "PLACEHOLDER": "Select sorting", diff --git a/libs/portal-integration-angular/src/index.ts b/libs/portal-integration-angular/src/index.ts index bde66c78..e4189909 100644 --- a/libs/portal-integration-angular/src/index.ts +++ b/libs/portal-integration-angular/src/index.ts @@ -56,6 +56,7 @@ export * from './lib/core/components/search-config/search-config.component' export * from './lib/core/components/loading-indicator/loading-indicator.component' export * from './lib/core/components/content-container/content-container.component' export * from './lib/core/components/content/content.component' +export * from './lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component' // services export * from './lib/services/app.menu.service' diff --git a/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.html b/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.html new file mode 100644 index 00000000..e8b4d141 --- /dev/null +++ b/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.html @@ -0,0 +1,27 @@ +
+
+ +
+ +
+ + + +
+ +
+ + +
+
diff --git a/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.scss b/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.scss new file mode 100644 index 00000000..a530b42b --- /dev/null +++ b/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.scss @@ -0,0 +1,14 @@ +.searchConfigDialog { + display: flex; + flex-direction: column; + gap: 1em; + margin-bottom: 1em; +} + +:host ::ng-deep .p-inputtext { + width: 100%; +} + +:host ::ng-deep .p-checkbox { + margin-right: 1em; +} 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 new file mode 100644 index 00000000..077467fe --- /dev/null +++ b/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.spec.ts @@ -0,0 +1,147 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing' +import { CreateOrEditSearchConfigDialogComponent } from './create-or-edit-search-config-dialog.component' +import { CheckboxModule } from 'primeng/checkbox' +import { MockAuthModule } from '../../../mock-auth/mock-auth.module' +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 { DialogState } from '../../../services/portal-dialog.service' +import { ReactiveFormsModule } from '@angular/forms' +import { InputTextModule } from 'primeng/inputtext' + +describe('CreateOrEditSearchConfigDialogComponent', () => { + let component: CreateOrEditSearchConfigDialogComponent + let fixture: ComponentFixture + let translateService: TranslateService + let dialogHarness: CreateOrEditSearchConfigDialogHarness + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [CreateOrEditSearchConfigDialogComponent], + imports: [ + CheckboxModule, + MockAuthModule, + TranslateTestingModule.withTranslations({ + en: require('./../../../../../assets/i18n/en.json'), + de: require('./../../../../../assets/i18n/de.json'), + }), + HttpClientTestingModule, + ReactiveFormsModule, + InputTextModule, + ], + }).compileComponents() + + fixture = TestBed.createComponent(CreateOrEditSearchConfigDialogComponent) + component = fixture.componentInstance + + translateService = TestBed.inject(TranslateService) + translateService.setDefaultLang('en') + translateService.use('en') + + fixture.detectChanges() + dialogHarness = await TestbedHarnessEnvironment.harnessForFixture(fixture, CreateOrEditSearchConfigDialogHarness) + }) + + it('should create the component', () => { + expect(component).toBeTruthy() + }) + + it('should load the CreateOrEditSearchConfigDialogHarness', async () => { + expect(dialogHarness).toBeTruthy() + }) + + it('should set the DialogResult of the saveInputValuesId checkbox to true when the saveInputValuesId checkbox is checked', async () => { + const saveInputValuesCheckbox = await dialogHarness.getHarness( + PCheckboxHarness.with({ inputid: 'saveInputValuesId' }) + ) + await saveInputValuesCheckbox.click() + const _state: DialogState = { button: 'primary', result: undefined } + component.ocxDialogButtonClicked(_state) + const dialogResult = { + searchConfigName: '', + saveInputValues: true, + saveColumns: false, + } + expect(component.dialogResult).toEqual(dialogResult) + }) + + it('should set the DialogResult of the saveColumnsId checkbox initially false', async () => { + const _state: DialogState = { button: 'primary', result: undefined } + await component.ocxDialogButtonClicked(_state) + const dialogResult = { + searchConfigName: '', + saveInputValues: false, + saveColumns: false, + } + expect(component.dialogResult).toEqual(dialogResult) + }) + + it('should set the DialogResult of the searchConfig input Field to the entered value', async () => { + await (await dialogHarness.getSearchConfigInputHarness()).setValue('search Config') + const _state: DialogState = { button: 'primary', result: undefined } + await component.ocxDialogButtonClicked(_state) + const dialogResult = { + searchConfigName: 'search Config', + saveInputValues: false, + saveColumns: false, + } + expect(component.dialogResult).toEqual(dialogResult) + }) + + it('should set the saveColumnsId checkbox initially to unchecked', async () => { + const saveInputValuesCheckbox = await dialogHarness.getSaveColumnsCheckboxHarness() + const checked = await saveInputValuesCheckbox.isChecked() + expect(checked).toBeFalsy() + }) + + it('should set the saveInputValues checkbox initially to unchecked', async () => { + const saveInputValuesCheckbox = await dialogHarness.getSaveInputValuesCheckboxHarness() + const checked = await saveInputValuesCheckbox.isChecked() + expect(checked).toBeFalsy() + }) + + it('should set the saveInputValues checkbox to true when it is clicked', async () => { + const saveInputValuesCheckbox = await dialogHarness.getSaveInputValuesCheckboxHarness() + await saveInputValuesCheckbox.click() + const checked = await saveInputValuesCheckbox.isChecked() + expect(checked).toBeTruthy() + }) + + it('should emit true when the searchConfig name is not an empty string and the saveColumnsCheckBox is clicked', async () => { + let done: () => void + const finished = new Promise((resolve) => (done = resolve)) + let enabled = false + component.primaryButtonEnabled.subscribe((v) => { + enabled = v + done() + }) + + const searchConfigInputHarness = await dialogHarness.getSearchConfigInputHarness() + searchConfigInputHarness.setValue('test') + const saveInputValuesCheckbox = await dialogHarness.getSaveColumnsCheckboxHarness() + await saveInputValuesCheckbox.click() + + await finished + expect(enabled).toEqual(true) + }) + + it('emit true when the searchConfig Name is not an empty string and the saveInputValuesCheckbox is clicked', async () => { + let done: () => void + const finished = new Promise((resolve) => (done = resolve)) + let enabled = false + component.primaryButtonEnabled.subscribe((v) => { + enabled = v + done() + }) + + const searchConfigInputHarness = await dialogHarness.getSearchConfigInputHarness() + searchConfigInputHarness.setValue('test') + const saveInputValuesCheckbox = await dialogHarness.getSaveInputValuesCheckboxHarness() + await saveInputValuesCheckbox.click() + + await finished + expect(enabled).toEqual(true) + }) +}) diff --git a/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.ts b/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.ts new file mode 100644 index 00000000..b0205c84 --- /dev/null +++ b/libs/portal-integration-angular/src/lib/core/components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component.ts @@ -0,0 +1,59 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core' +import { FormControl, FormGroup } from '@angular/forms' +import { + DialogButtonClicked, + DialogPrimaryButtonDisabled, + DialogResult, + DialogState, +} from '../../../services/portal-dialog.service' +import { Observable, map } from 'rxjs' + +export type CreateOrEditSearchDialogContent = { + searchConfigName: string + saveInputValues: boolean + saveColumns: boolean +} +@Component({ + selector: 'ocx-create-or-edit-search-config-dialog', + templateUrl: './create-or-edit-search-config-dialog.component.html', + styleUrls: ['./create-or-edit-search-config-dialog.component.scss'], +}) +export class CreateOrEditSearchConfigDialogComponent + implements + DialogPrimaryButtonDisabled, + DialogResult, + DialogButtonClicked +{ + @Input() searchConfigName: string | undefined + @Input() saveInputValues: boolean | undefined + @Input() saveColumns: boolean | undefined + placeHolderKey = 'OCX_SEARCH_CONFIG.PLACEHOLDER' + @Output() primaryButtonEnabled: EventEmitter = new EventEmitter() + searchConfigFormGroup: FormGroup = new FormGroup({ + searchConfigName: new FormControl(''), + saveInputValues: new FormControl(false), + saveColumns: new FormControl(false), + }) + dialogResult: CreateOrEditSearchDialogContent = { searchConfigName: '', saveInputValues: false, saveColumns: false } + constructor() { + this.searchConfigFormGroup.valueChanges + .pipe( + map( + (dialogFormValues: CreateOrEditSearchDialogContent) => + !!dialogFormValues.searchConfigName && (dialogFormValues.saveInputValues || dialogFormValues.saveColumns) + ) + ) + .subscribe(this.primaryButtonEnabled) + } + + ocxDialogButtonClicked( + _state: DialogState + ): boolean | Observable | Promise | undefined { + this.dialogResult = { + searchConfigName: this.searchConfigFormGroup?.get('searchConfigName')?.value, + saveInputValues: this.searchConfigFormGroup?.get('saveInputValues')?.value, + saveColumns: this.searchConfigFormGroup?.get('saveColumns')?.value, + } + return true + } +} diff --git a/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts b/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts index a36073b9..65cbb6e8 100644 --- a/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts +++ b/libs/portal-integration-angular/src/lib/core/components/interactive-data-view/interactive-data-view.component.ts @@ -59,6 +59,7 @@ export class InteractiveDataViewComponent implements OnInit { @Input() tablePaginator = true @Input() page = 0 @Input() selectedRows: Row[] = [] + @Input() displayedColumns: DataTableColumn[] = [] @ContentChild('tableCell') tableCell: TemplateRef | undefined @ContentChild('tableDateCell') tableDateCell: TemplateRef | undefined @ContentChild('tableRelativeDateCell') tableRelativeDateCell: TemplateRef | undefined @@ -78,8 +79,8 @@ export class InteractiveDataViewComponent implements OnInit { @Output() dataViewLayoutChange = new EventEmitter<'grid' | 'list' | 'table'>() @Output() displayedColumnsChange = new EventEmitter() @Output() selectionChanged: EventEmitter = new EventEmitter() + @Output() pageChanged: EventEmitter = new EventEmitter() - displayedColumns: DataTableColumn[] = [] selectedGroupKey = '' isDeleteItemObserved: boolean | undefined isViewItemObserved: boolean | undefined diff --git a/libs/portal-integration-angular/src/lib/core/components/search-config/search-config.component.spec.ts b/libs/portal-integration-angular/src/lib/core/components/search-config/search-config.component.spec.ts index 229285ea..50de2329 100644 --- a/libs/portal-integration-angular/src/lib/core/components/search-config/search-config.component.spec.ts +++ b/libs/portal-integration-angular/src/lib/core/components/search-config/search-config.component.spec.ts @@ -30,7 +30,7 @@ describe('SearchConfigComponent', () => { }, ] - const searchConfigsEntries: SearchConfig[] = [ + const searchConfigs: SearchConfig[] = [ { id: '01', name: 'Basic search config', @@ -82,7 +82,7 @@ describe('SearchConfigComponent', () => { fixture = TestBed.createComponent(SearchConfigComponent) component = fixture.componentInstance - component.searchConfigs = searchConfigsEntries + component.searchConfigs = searchConfigs translateService = TestBed.inject(TranslateService) translateService.setDefaultLang('en') translateService.use('en') @@ -110,7 +110,7 @@ describe('SearchConfigComponent', () => { const searchConfigHarness = await TestbedHarnessEnvironment.harnessForFixture(fixture, SearchConfigHarness) const dropdown = await searchConfigHarness.getSearchConfigDropdown() const items = await dropdown?.getDropdownItems() - expect(items?.length).toEqual(searchConfigsEntries.length) + expect(items?.length).toEqual(searchConfigs.length) }) it('should display no dropdown if the search config is empty', async () => { @@ -124,14 +124,14 @@ describe('SearchConfigComponent', () => { const searchConfigHarness = await TestbedHarnessEnvironment.harnessForFixture(fixture, SearchConfigHarness) const dropdown = await searchConfigHarness.getSearchConfigDropdown() const selectedDropdownItem = await dropdown?.selectedDropdownItemText(0) - expect(selectedDropdownItem).toEqual(searchConfigsEntries[0].name) + expect(selectedDropdownItem).toEqual(searchConfigs[0].name) }) it('should display the values in the fields after selecting the fist hard coded search config', async () => { const searchConfigHarness = await TestbedHarnessEnvironment.harnessForFixture(fixture, SearchConfigHarness) const dropdown = await searchConfigHarness.getSearchConfigDropdown() const selectedDropdownItem = await dropdown?.selectedDropdownItemText(1) - expect(selectedDropdownItem).toEqual(searchConfigsEntries[1].name) + expect(selectedDropdownItem).toEqual(searchConfigs[1].name) }) it('should display the values in the fields correctly after selecting the fist search config and then selecting the second search config', async () => { @@ -139,7 +139,7 @@ describe('SearchConfigComponent', () => { const dropdown = await searchConfigHarness.getSearchConfigDropdown() let selectedDropdownItem = await dropdown?.selectedDropdownItemText(0) selectedDropdownItem = await dropdown?.selectedDropdownItemText(1) - expect(selectedDropdownItem).toEqual(searchConfigsEntries[1].name) + expect(selectedDropdownItem).toEqual(searchConfigs[1].name) }) it('should have the option to remove the selection', async () => { diff --git a/libs/portal-integration-angular/src/lib/core/components/search-config/search-config.component.ts b/libs/portal-integration-angular/src/lib/core/components/search-config/search-config.component.ts index 671b63dc..884af52c 100644 --- a/libs/portal-integration-angular/src/lib/core/components/search-config/search-config.component.ts +++ b/libs/portal-integration-angular/src/lib/core/components/search-config/search-config.component.ts @@ -14,7 +14,7 @@ export class SearchConfigComponent implements OnInit { @Input() placeholderKey = 'OCX_SEARCH_HEADER.OCX_SEARCH_CONFIG.DROPDOWN_DEFAULT' @Output() - selectedSearchConfig: EventEmitter = new EventEmitter() + selectedSearchConfigChanged: EventEmitter = new EventEmitter() formGroup: FormGroup | undefined ngOnInit(): void { @@ -23,7 +23,7 @@ export class SearchConfigComponent implements OnInit { }) } - onSearchConfigChange(event: SearchConfig[]) { - this.selectedSearchConfig?.emit(event) + onSearchConfigChange(searchConfig: SearchConfig) { + this.selectedSearchConfigChanged?.emit(searchConfig) } } diff --git a/libs/portal-integration-angular/src/lib/core/components/search-header/search-header.component.html b/libs/portal-integration-angular/src/lib/core/components/search-header/search-header.component.html index 98f0abbb..5b0ce2c0 100644 --- a/libs/portal-integration-angular/src/lib/core/components/search-header/search-header.component.html +++ b/libs/portal-integration-angular/src/lib/core/components/search-header/search-header.component.html @@ -4,7 +4,8 @@ [actions]="headerActions" > - + +
diff --git a/libs/portal-integration-angular/src/lib/core/components/search-header/search-header.component.ts b/libs/portal-integration-angular/src/lib/core/components/search-header/search-header.component.ts index 0680ddd0..9d2d445d 100644 --- a/libs/portal-integration-angular/src/lib/core/components/search-header/search-header.component.ts +++ b/libs/portal-integration-angular/src/lib/core/components/search-header/search-header.component.ts @@ -24,8 +24,9 @@ import { SearchConfig } from '../../../model/search-config' styleUrls: ['./search-header.component.scss'], }) export class SearchHeaderComponent implements AfterViewInit { - @Input() searchConfigsEntries: SearchConfig[] | undefined + @Input() searchConfigs: SearchConfig[] | undefined @Input() headline = '' + @Input() viewMode: 'basic' | 'advanced' = 'basic' @Input() manualBreadcrumbs = false _actions: Action[] = [] @Input() @@ -39,7 +40,8 @@ export class SearchHeaderComponent implements AfterViewInit { @Output() searched: EventEmitter = new EventEmitter() @Output() resetted: EventEmitter = new EventEmitter() - @Output() selectedSearchConfig: EventEmitter = new EventEmitter() + @Output() selectedSearchConfigChanged: EventEmitter = new EventEmitter() + @Output() viewModeChanged: EventEmitter = new EventEmitter() @ContentChild('additionalToolbarContent') additionalToolbarContent: TemplateRef | undefined @@ -49,7 +51,6 @@ export class SearchHeaderComponent implements AfterViewInit { @ViewChild('searchParameterFields') searchParameterFields: ElementRef | undefined - viewMode: 'basic' | 'advanced' = 'basic' hasAdvanced = false headerActions: Action[] = [] @@ -59,6 +60,7 @@ export class SearchHeaderComponent implements AfterViewInit { toggleViewMode() { this.viewMode = this.viewMode === 'basic' ? 'advanced' : 'basic' + this.viewModeChanged?.emit(this.viewMode) this.updateHeaderActions() setTimeout(() => this.addKeyUpEventListener()) } @@ -103,7 +105,7 @@ export class SearchHeaderComponent implements AfterViewInit { } } - confirmSearchConfig(event: any) { - this.selectedSearchConfig?.emit(event) + confirmSearchConfig(searchConfig: SearchConfig) { + this.selectedSearchConfigChanged?.emit(searchConfig) } } diff --git a/libs/portal-integration-angular/src/lib/core/portal-core.module.ts b/libs/portal-integration-angular/src/lib/core/portal-core.module.ts index 98e64f1c..393b6a49 100644 --- a/libs/portal-integration-angular/src/lib/core/portal-core.module.ts +++ b/libs/portal-integration-angular/src/lib/core/portal-core.module.ts @@ -86,6 +86,7 @@ import { UserProfileAPIService } from '../services/userprofile-api.service' import { createTranslateLoader } from './utils/create-translate-loader.utils' import { MessageService } from 'primeng/api' import { TranslationCacheService } from '../services/translation-cache.service' +import { CreateOrEditSearchConfigDialogComponent } from './components/create-or-edit-search-config-dialog/create-or-edit-search-config-dialog.component' export class PortalMissingTranslationHandler implements MissingTranslationHandler { handle(params: MissingTranslationHandlerParams) { @@ -167,6 +168,7 @@ export class PortalMissingTranslationHandler implements MissingTranslationHandle OcxContentComponent, OcxContentContainerComponent, SearchConfigComponent, + CreateOrEditSearchConfigDialogComponent, ], providers: [ { @@ -237,6 +239,7 @@ export class PortalMissingTranslationHandler implements MissingTranslationHandle OcxContentComponent, OcxContentContainerComponent, SearchConfigComponent, + CreateOrEditSearchConfigDialogComponent, ], schemas: [CUSTOM_ELEMENTS_SCHEMA], entryComponents: [ColumnTogglerComponent], diff --git a/libs/portal-integration-angular/src/lib/core/primeng.module.ts b/libs/portal-integration-angular/src/lib/core/primeng.module.ts index ade47c52..ec99f0a7 100644 --- a/libs/portal-integration-angular/src/lib/core/primeng.module.ts +++ b/libs/portal-integration-angular/src/lib/core/primeng.module.ts @@ -22,6 +22,7 @@ import { DialogModule } from 'primeng/dialog' import { InputSwitchModule } from 'primeng/inputswitch' import { DataViewModule } from 'primeng/dataview' import { ChartModule } from 'primeng/chart' +import { CheckboxModule } from 'primeng/checkbox' @NgModule({ imports: [ @@ -49,6 +50,7 @@ import { ChartModule } from 'primeng/chart' DataViewModule, ChartModule, MessageModule, + CheckboxModule, ], exports: [ BadgeModule, @@ -75,6 +77,7 @@ import { ChartModule } from 'primeng/chart' DataViewModule, ChartModule, MessageModule, + CheckboxModule, ], }) export class PrimeNgModule {} 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 new file mode 100644 index 00000000..d056751b --- /dev/null +++ b/libs/portal-integration-angular/testing/create-or-edit-search-config-dialog.harness.ts @@ -0,0 +1,19 @@ +import { ContentContainerComponentHarness } from '@angular/cdk/testing' +import { PCheckboxHarness } from './primeng/p-checkbox.harness' +import { InputHarness } from './input.harness' + +export class CreateOrEditSearchConfigDialogHarness extends ContentContainerComponentHarness { + static hostSelector = 'ocx-create-or-edit-search-config-dialog' + + getSaveInputValuesCheckboxHarness() { + return this.getHarness(PCheckboxHarness.with({ inputid: 'saveInputValuesId' })) + } + + getSaveColumnsCheckboxHarness() { + return this.getHarness(PCheckboxHarness.with({ inputid: 'saveColumnsId' })) + } + + getSearchConfigInputHarness() { + return this.getHarness(InputHarness.with({ id: 'searchConfigName' })) + } +} diff --git a/libs/portal-integration-angular/testing/div.harness.ts b/libs/portal-integration-angular/testing/div.harness.ts index 39669eae..6cf90005 100644 --- a/libs/portal-integration-angular/testing/div.harness.ts +++ b/libs/portal-integration-angular/testing/div.harness.ts @@ -27,10 +27,14 @@ export class DivHarness extends ComponentHarness { async getClassList() { const host = await this.host() - const attributeString = await host.getAttribute("class"); - if(attributeString) { - return attributeString.trim().split(" ") + 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 4ff94656..d2744661 100644 --- a/libs/portal-integration-angular/testing/index.ts +++ b/libs/portal-integration-angular/testing/index.ts @@ -8,6 +8,7 @@ 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 './primeng/p-checkbox.harness' export * from './button-dialog.harness' export * from './button.harness' @@ -33,6 +34,7 @@ export * from './search-config.harness' export * from './span.harness' export * from './page-header.harness' export * from './p-tableCheckbox.harness' +export * from './create-or-edit-search-config-dialog.harness' export * from '@angular/cdk/testing' export * from '@angular/cdk/testing/testbed' diff --git a/libs/portal-integration-angular/testing/input.harness.ts b/libs/portal-integration-angular/testing/input.harness.ts index 32cab9d5..834eb479 100644 --- a/libs/portal-integration-angular/testing/input.harness.ts +++ b/libs/portal-integration-angular/testing/input.harness.ts @@ -20,6 +20,9 @@ export class InputHarness extends ComponentHarness { async getValue(): Promise { return await (await this.host()).getProperty('value') } + async getChecked(): Promise { + return await (await this.host()).getProperty('checked') + } async setValue(value: string | Date): Promise { if (value instanceof Date) { @@ -33,6 +36,10 @@ export class InputHarness extends ComponentHarness { })} ${value.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}` ) } else { + await (await this.host()).clear() + if (value) { + await (await this.host()).sendKeys(value) + } await (await this.host()).setInputValue(value) } } diff --git a/libs/portal-integration-angular/testing/primeng/p-checkbox.harness.ts b/libs/portal-integration-angular/testing/primeng/p-checkbox.harness.ts new file mode 100644 index 00000000..5d435ac4 --- /dev/null +++ b/libs/portal-integration-angular/testing/primeng/p-checkbox.harness.ts @@ -0,0 +1,35 @@ +import { BaseHarnessFilters, ComponentHarness, HarnessPredicate } from '@angular/cdk/testing' +import { DivHarness } from '../div.harness' +import { InputHarness } from '../input.harness' + +export interface PCheckBoxHarnessFilters extends BaseHarnessFilters { + inputid?: string +} +export class PCheckboxHarness extends ComponentHarness { + static hostSelector = 'p-checkbox' + + getCheckBoxDiv = this.locatorForOptional(DivHarness.with({ class: 'p-checkbox-box' })) + + static with(options: PCheckBoxHarnessFilters): HarnessPredicate { + return new HarnessPredicate(PCheckboxHarness, options).addOption('inputid', options.inputid, (harness, inputid) => + HarnessPredicate.stringMatches(harness.getId(), inputid) + ) + } + + async isChecked(): Promise { + return (await this.locatorFor(InputHarness)()).getChecked() + } + + async getId(): Promise { + return await (await this.host()).getAttribute('inputId') + } + + async isHidden(): Promise { + const attr = await (await this.host()).getAttribute('hidden') + return Boolean(attr) + } + + async click(): Promise { + await (await this.getCheckBoxDiv())?.click() + } +}