import { ElementFinder , by , browser } from 'protractor' ; import { BrowserActions } from '@alfresco/adf-testing' ; import { Menu } from '../menu/menu' ; import { Component } from '../component' ; import { Utils } from '../../utilities/utils' ; export class Toolbar extends Component { menu = new Menu ( ) ; buttons = this . allByCss ( 'button' ) ; shareButton = this . byCss ( `.mat-icon-button[title='Share']` ) ; shareEditButton = this . byCss ( `.mat-icon-button[title='Shared Link Settings']` ) ; viewButton = this . byCss ( `.mat-icon-button[title='View']` ) ; downloadButton = this . byCss ( `.mat-icon-button[title='Download']` ) ; editFolderButton = this . byId ( 'app.toolbar.editFolder' ) ; viewDetailsButton = this . byCss ( `.mat-icon-button[title='View Details']` ) ; printButton = this . byCss ( `.mat-icon-button[title='Print']` ) ; fullScreenButton = this . byCss ( `.mat-icon-button[title='Activate full-screen mode']` ) ; joinButton = this . byCss ( `.mat-icon-button[title='Join']` ) ; leaveButton = this . byCss ( `.mat-icon-button[title='Leave Library']` ) ; permanentlyDeleteButton = this . byCss ( `.mat-icon-button[title='Permanently Delete']` ) ; restoreButton = this . byCss ( `.mat-icon-button[title='Restore']` ) ; constructor ( ancestor ? ) { super ( '.adf-toolbar' , ancestor ) ; } async isEmpty ( ) { const count = await this . buttons . count ( ) ; return count === 0 ; } async getButtons ( ) { return this . buttons . map ( async ( elem ) => { return elem . getAttribute ( 'title' ) ; } ) ; } async isButtonPresent ( title ) { const element = this . byCss ( `button[title="${ title }"]` ) ; return element . isPresent ( ) ; } getButtonByTitleAttribute ( title ) { return this . byCss ( `button[title="${ title }"]` ) ; } getButtonById ( id ) { return this . component . element ( by . id ( id ) ) ; } async openMoreMenu ( ) { await this . isButtonPresent ( 'More Actions' ) ; const moreMenu = this . getButtonByTitleAttribute ( 'More Actions' ) ; await BrowserActions . click ( moreMenu ) ; await this . menu . waitForMenuToOpen ( ) ; await browser . sleep ( 500 ) ; } async closeMoreMenu ( ) { await Utils . pressEscape ( ) ; } async getButtonTooltip ( button ) { return button . getAttribute ( 'title' ) ; } async clickButton ( title ) { await BrowserActions . click ( this . getButtonByTitleAttribute ( title ) ) ; } async isPrintPresent ( ) { return browser . isElementPresent ( this . printButton ) ; } async clickMoreActionsFavorite ( ) { await this . openMoreMenu ( ) ; await this . menu . clickMenuItem ( 'Favorite' ) ; } async clickMoreActionsRemoveFavorite ( ) { await this . openMoreMenu ( ) ; await this . menu . clickMenuItem ( 'Remove Favorite' ) ; } async clickMoreActionsDelete ( ) { await this . openMoreMenu ( ) ; await this . menu . clickMenuItem ( 'Delete' ) ; } async clickMoreActionsManageVersions ( ) { await this . openMoreMenu ( ) ; await this . menu . clickMenuItem ( 'Manage Versions' ) ; } async clickMoreActionsMove ( ) { await this . openMoreMenu ( ) ; await this . menu . clickMenuItem ( 'Move' ) ; } async clickMoreActionsCopy ( ) { await this . openMoreMenu ( ) ; await this . menu . copyAction . click ( ) ; } async clickMoreActionsEditOffline ( ) { await this . openMoreMenu ( ) ; await this . menu . clickMenuItem ( 'Edit Offline' ) ; } async clickMoreActionsCancelEditing ( ) { await this . openMoreMenu ( ) ; await this . menu . clickMenuItem ( 'Cancel Editing' ) ; } async clickMoreActionsUploadNewVersion ( ) { await this . openMoreMenu ( ) ; await this . menu . clickMenuItem ( 'Upload New Version' ) ; } }