import { ChainablePromiseArray , ChainablePromiseElement , ElementArray } from 'webdriverio' ; import { ToastTypes } from '../../src/renderer/app/models/toasts.model' ; class Utils { public async setElementValue ( element , value ) { await element . click ( ) ; await element . setValue ( value ) ; } public async assertHasClass ( element , className , reverse = false ) { const classes = await element . getAttribute ( 'class' ) ; if ( reverse ) { expect ( classes ) . not . toContain ( className ) ; } else { expect ( classes ) . toContain ( className ) ; } } public async assertElementText ( element , text ) { expect ( await element . getText ( ) ) . toEqual ( text ) ; } public async assertElementTextContain ( element , text ) { expect ( await element . getText ( ) ) . toContain ( text ) ; } public async countElements ( elements , expected ) { expect ( ( await elements ) . length ) . toEqual ( expected ) ; } public async openDropdown ( dropdownId ) { await $ ( `#${ dropdownId }-dropdown` ) . click ( ) ; } public async selectDropdownItem ( dropdownId , itemIndex ) { await $ ( `#${ dropdownId }-dropdown-menu .dropdown-menu-content button:nth-of-type(${ itemIndex })` ) . click ( ) ; } public async setDropdownInputValue ( dropdownId , value ) { await $ ( `#${ dropdownId }-dropdown-menu .form-control` ) . setValue ( value ) ; } public async assertDropdownItemsNumber ( dropdownId , expectedNumber ) { await this . countElements ( $$ ( `#${ dropdownId }-dropdown-menu .dropdown-menu-content button` ) , expectedNumber ) ; } public async assertDropdownItemText ( dropdownId , itemIndex , expectedText ) { await this . assertElementText ( $ ( `#${ dropdownId }-dropdown-menu .dropdown-menu-content button:nth-of-type(${ itemIndex })` ) , expectedText ) ; } public async assertDropdownToggleText ( dropdownId , expectedText ) { await this . assertElementText ( $ ( `#${ dropdownId }-dropdown .dropdown-toggle` ) , expectedText ) ; } public async waitForAutosave ( ) { await browser . pause ( 1500 ) ; } public async checkToastDisplayed ( toastType , text ) { const toastSelector = `.toast.toast-${ toastType }:last-of-type` ; await $ ( toastSelector ) . waitForExist ( ) ; if ( text ) { await this . assertElementTextContain ( $ ( `${ toastSelector } .toast-body` ) , text ) ; } } public async closeToast ( ) { await $ ( '.toast:last-of-type' ) . click ( ) ; } public makeString ( length ) { let result = '' ; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ; const charactersLength = characters . length ; for ( let i = 0 ; i < length ; i ++ ) { result += characters . charAt ( Math . floor ( Math . random ( ) * charactersLength ) ) ; } return result ; } } export default new Utils ( ) ;