import { ElementFinder , by , browser } from 'protractor' ; import { isPresentAndDisplayed , Utils } from '../../../utilities/utils' ; import { BrowserActions , TestElement } from '@alfresco/adf-testing' ; export class GenericFilter { private filterName : string ; constructor ( filterName ) { this . filterName = filterName ; } private readonly selectors = { root : 'adf-search-filter-chips' , chip : '.mat-chip' , chipDialog : '.mat-menu-content .adf-search-filter-menu-card' } ; get chip ( ) : ElementFinder { return browser . element ( by . cssContainingText ( this . selectors . chip , this . filterName ) ) ; } get filterDialogOpened ( ) : ElementFinder { return browser . element ( by . cssContainingText ( this . selectors . chipDialog , this . filterName ) ) ; } async getChipTitle ( ) { return browser . element ( by . cssContainingText ( `${ this . selectors . root } ${ this . selectors . chip }` , this . filterName ) ) . getAttribute ( 'title' ) ; } async clickApplyButton ( ) { await TestElement . byId ( 'apply-filter-button' ) . click ( ) ; } async clickResetButton ( ) { await TestElement . byId ( 'cancel-filter-button' ) . click ( ) ; } async isDisplayed ( ) { return isPresentAndDisplayed ( this . chip ) ; } async isDialogPresent ( ) { return isPresentAndDisplayed ( this . filterDialogOpened ) ; } async openDialog ( ) { if ( ! ( await this . isDialogPresent ( ) ) ) { await this . chip . click ( ) ; await BrowserActions . waitUntilActionMenuIsVisible ( ) ; } } async closeDialog ( ) { if ( await this . isDialogPresent ( ) ) { await Utils . pressEscape ( ) ; await BrowserActions . waitUntilActionMenuIsNotVisible ( ) ; } } }