import expect from '@kbn/expect' ; import { ProvidedType } from '@kbn/test' ; import { FtrProviderContext } from '../../ftr_provider_context' ; export type MlDashboardJobSelectionTable = ProvidedType < typeof MachineLearningDashboardJobSelectionTableProvider > ; export function MachineLearningDashboardJobSelectionTableProvider ( { getService , } ) { const retry = getService ( 'retry' ) ; const testSubjects = getService ( 'testSubjects' ) ; return { async assertJobSelectionTableExists ( ) { await retry . tryForTime ( 20 * 1000 , async ( ) => { await testSubjects . existOrFail ( 'mlCustomSelectionTable' , { timeout : 2000 } ) ; } ) ; } , async assertJobSelectionTableNotExists ( ) { await retry . tryForTime ( 5000 , async ( ) => { await testSubjects . missingOrFail ( 'mlCustomSelectionTable' ) ; } ) ; } , rowSelector ( jobId , subSelector ? ) { const row = `~mlCustomSelectionTable > ~row-${ jobId }` ; return ! subSelector ? row : `${ row } > ${ subSelector }` ; } , async assertRowExists ( jobId ) { await retry . tryForTime ( 5000 , async ( ) => { await testSubjects . existOrFail ( this . rowSelector ( jobId ) ) ; } ) ; } , async assertRowCheckboxExists ( jobId ) { await testSubjects . existOrFail ( this . rowSelector ( jobId , `${ jobId }-checkbox` ) ) ; } , async getRowCheckboxCheckedState ( jobId ) { const subj = this . rowSelector ( jobId , `${ jobId }-checkbox` ) ; const isSelected = await testSubjects . getAttribute ( subj , 'checked' ) ; return isSelected === 'true' ; } , async assertRowCheckboxCheckedState ( jobId , expectedCheckState ) { const actualCheckState = await this . getRowCheckboxCheckedState ( jobId ) ; expect ( actualCheckState ) . to . eql ( expectedCheckState , `Table row for job '${ jobId }' check state should be '${ expectedCheckState }' (got '${ actualCheckState }')` ) ; } , async setRowCheckboxState ( jobId , expectCheckedState ) { const subj = this . rowSelector ( jobId , `${ jobId }-checkbox` ) ; if ( ( await this . getRowCheckboxCheckedState ( jobId ) ) !== expectCheckedState ) { await retry . tryForTime ( 5 * 1000 , async ( ) => { await testSubjects . clickWhenNotDisabled ( subj ) ; await this . assertRowCheckboxCheckedState ( jobId , expectCheckedState ) ; } ) ; } } , async assertApplyJobSelectionEnabled ( ) { const subj = 'mlFlyoutJobSelectorButtonApply' ; await testSubjects . existOrFail ( subj ) ; await testSubjects . isEnabled ( subj ) ; } , async applyJobSelection ( ) { const subj = 'mlFlyoutJobSelectorButtonApply' ; await testSubjects . clickWhenNotDisabled ( subj ) ; await this . assertJobSelectionTableNotExists ( ) ; } , } ; }