import expect from '@kbn/expect' ; import { FtrService } from '../ftr_provider_context' ; export class SpaceSelectorPageObject extends FtrService { private readonly retry = this . ctx . getService ( 'retry' ) ; private readonly log = this . ctx . getService ( 'log' ) ; private readonly testSubjects = this . ctx . getService ( 'testSubjects' ) ; private readonly browser = this . ctx . getService ( 'browser' ) ; private readonly find = this . ctx . getService ( 'find' ) ; private readonly common = this . ctx . getPageObject ( 'common' ) ; async initTests ( ) { this . log . debug ( 'SpaceSelectorPage:initTests' ) ; } async clickSpaceCard ( spaceId ) { await this . common . sleep ( 10000 ) ; return await this . retry . try ( async ( ) => { this . log . info ( `SpaceSelectorPage:clickSpaceCard(${ spaceId })` ) ; await this . testSubjects . click ( `space-card-${ spaceId }` ) ; await this . common . sleep ( 1000 ) ; } ) ; } async expectHomePage ( spaceId ) { return await this . expectRoute ( spaceId , `/app/home#/` ) ; } async expectRoute ( spaceId , route ) { return await this . retry . try ( async ( ) => { this . log . debug ( `expectRoute(${ spaceId }, ${ route })` ) ; await this . find . byCssSelector ( '[data-test-subj="kibanaChrome"] nav:not(.ng-hide) ' , 20000 ) ; const url = await this . browser . getCurrentUrl ( ) ; if ( spaceId === 'default' ) { expect ( url ) . to . contain ( route ) ; } else { expect ( url ) . to . contain ( `/s/${ spaceId }${ route }` ) ; } } ) ; } async openSpacesNav ( ) { this . log . debug ( 'openSpacesNav()' ) ; return await this . testSubjects . click ( 'spacesNavSelector' ) ; } async clickManageSpaces ( ) { await this . testSubjects . click ( 'manageSpaces' ) ; } async clickCreateSpace ( ) { await this . testSubjects . click ( 'createSpace' ) ; } async clickEnterSpaceName ( ) { await this . testSubjects . click ( 'addSpaceName' ) ; } async addSpaceName ( spaceName ) { await this . testSubjects . setValue ( 'addSpaceName' , spaceName ) ; } async clickCustomizeSpaceAvatar ( spaceId ) { await this . testSubjects . click ( `space-avatar-${ spaceId }` ) ; } async clickSpaceInitials ( ) { await this . testSubjects . click ( 'spaceLetterInitial' ) ; } async addSpaceInitials ( spaceInitials ) { await this . testSubjects . setValue ( 'spaceLetterInitial' , spaceInitials ) ; } async clickColorPicker ( ) { await this . testSubjects . click ( 'euiColorPickerAnchor' ) ; } async setColorinPicker ( hexValue ) { await this . testSubjects . setValue ( 'euiColorPickerAnchor' , hexValue ) ; } async clickShowFeatures ( ) { await this . testSubjects . click ( 'show-hide-section-link' ) ; } async clickChangeAllPriv ( ) { await this . testSubjects . click ( 'changeAllPrivilegesButton' ) ; } async clickSaveSpaceCreation ( ) { await this . testSubjects . click ( 'save-space-button' ) ; } async clickSpaceEditButton ( spaceName ) { await this . testSubjects . click ( `${ spaceName }-editSpace` ) ; } async clickGoToRolesPage ( ) { await this . testSubjects . click ( 'rolesManagementPage' ) ; } async clickCancelSpaceCreation ( ) { await this . testSubjects . click ( 'cancel-space-button' ) ; } async clickOnCustomizeURL ( ) { await this . testSubjects . click ( 'CustomizeOrReset' ) ; } async clickOnSpaceURLDisplay ( ) { await this . testSubjects . click ( 'spaceURLDisplay' ) ; } async setSpaceURL ( spaceURL ) { await this . testSubjects . setValue ( 'spaceURLDisplay' , spaceURL ) ; } async clickHideAllFeatures ( ) { await this . testSubjects . click ( 'spc-toggle-all-features-hide' ) ; } async clickShowAllFeatures ( ) { await this . testSubjects . click ( 'spc-toggle-all-features-show' ) ; } async openFeatureCategory ( categoryName ) { const category = await this . find . byCssSelector ( `button[aria-controls=featureCategory_${ categoryName }]` ) ; const isCategoryExpanded = ( await category . getAttribute ( 'aria-expanded' ) ) === 'true' ; if ( ! isCategoryExpanded ) { await category . click ( ) ; } } async closeFeatureCategory ( categoryName ) { const category = await this . find . byCssSelector ( `button[aria-controls=featureCategory_${ categoryName }]` ) ; const isCategoryExpanded = ( await category . getAttribute ( 'aria-expanded' ) ) === 'true' ; if ( isCategoryExpanded ) { await category . click ( ) ; } } async toggleFeatureCategoryVisibility ( categoryName ) { await this . testSubjects . click ( `featureCategoryButton_${ categoryName }` ) ; } async clickOnDescriptionOfSpace ( ) { await this . testSubjects . click ( 'descriptionSpaceText' ) ; } async setOnDescriptionOfSpace ( descriptionSpace ) { await this . testSubjects . setValue ( 'descriptionSpaceText' , descriptionSpace ) ; } async clickOnDeleteSpaceButton ( spaceName ) { await this . testSubjects . click ( `${ spaceName }-deleteSpace` ) ; } async cancelDeletingSpace ( ) { await this . testSubjects . click ( 'confirmModalCancelButton' ) ; } async confirmDeletingSpace ( ) { await this . testSubjects . click ( 'confirmModalConfirmButton' ) ; } async clickOnSpaceb ( ) { await this . testSubjects . click ( 'space-avatar-space_b' ) ; } async goToSpecificSpace ( spaceName ) { await this . testSubjects . click ( `${ spaceName }-gotoSpace` ) ; } async clickSpaceAvatar ( spaceId ) { return await this . retry . try ( async ( ) => { this . log . info ( `SpaceSelectorPage:clickSpaceAvatar(${ spaceId })` ) ; await this . testSubjects . click ( `space-avatar-${ spaceId }` ) ; await this . common . sleep ( 1000 ) ; } ) ; } async expectSearchBoxInSpacesSelector ( ) { expect ( await this . find . existsByCssSelector ( 'div[role="dialog"] input[type="search"]' ) ) . to . be ( true ) ; } async setSearchBoxInSpacesSelector ( searchText ) { const searchBox = await this . find . byCssSelector ( 'div[role="dialog"] input[type="search"]' ) ; searchBox . clearValue ( ) ; searchBox . type ( searchText ) ; await this . common . sleep ( 1000 ) ; } async expectToFindThatManySpace ( numberOfExpectedSpace ) { const spacesFound = await this . find . allByCssSelector ( 'div[role="dialog"] a.euiContextMenuItem' ) ; expect ( spacesFound . length ) . to . be ( numberOfExpectedSpace ) ; } async expectNoSpacesFound ( ) { const msgElem = await this . find . byCssSelector ( 'div[role="dialog"] .euiContextMenuPanel .euiText' ) ; expect ( await msgElem . getVisibleText ( ) ) . to . be ( 'no spaces found' ) ; } }