import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../ftr_provider_context' ; import { MlDataVisualizerTable } from './data_visualizer_table' ; export function MachineLearningDataVisualizerIndexPatternManagementProvider ( { getService } , dataVisualizerTable ) { const testSubjects = getService ( 'testSubjects' ) ; const retry = getService ( 'retry' ) ; const fieldEditor = getService ( 'fieldEditor' ) ; const comboBox = getService ( 'comboBox' ) ; return { async assertIndexPatternManagementButtonExists ( ) { await testSubjects . existOrFail ( 'dataVisualizerIndexPatternManagementButton' ) ; } , async assertIndexPatternManagementMenuExists ( ) { await testSubjects . existOrFail ( 'dataVisualizerIndexPatternManagementMenu' ) ; } , async assertIndexPatternFieldEditorExists ( ) { await testSubjects . existOrFail ( 'indexPatternFieldEditorForm' ) ; } , async assertIndexPatternFieldEditorNotExist ( ) { await testSubjects . missingOrFail ( 'indexPatternFieldEditorForm' ) ; } , async clickIndexPatternManagementButton ( ) { await retry . tryForTime ( 5000 , async ( ) => { await testSubjects . clickWhenNotDisabled ( 'dataVisualizerIndexPatternManagementButton' ) ; await this . assertIndexPatternManagementMenuExists ( ) ; } ) ; } , async clickAddIndexPatternFieldAction ( ) { await retry . tryForTime ( 5000 , async ( ) => { await this . assertIndexPatternManagementMenuExists ( ) ; await testSubjects . clickWhenNotDisabled ( 'dataVisualizerAddIndexPatternFieldAction' ) ; await this . assertIndexPatternFieldEditorExists ( ) ; } ) ; } , async clickManageIndexPatternAction ( ) { await retry . tryForTime ( 5000 , async ( ) => { await this . assertIndexPatternManagementMenuExists ( ) ; await testSubjects . clickWhenNotDisabled ( 'dataVisualizerManageIndexPatternAction' ) ; await testSubjects . existOrFail ( 'editIndexPattern' ) ; } ) ; } , async assertIndexPatternFieldEditorFieldType ( expectedIdentifier ) { await retry . tryForTime ( 2000 , async ( ) => { const comboBoxSelectedOptions = await comboBox . getComboBoxSelectedOptions ( 'typeField > comboBoxInput' ) ; expect ( comboBoxSelectedOptions ) . to . eql ( expectedIdentifier === '' ? [ ] : [ expectedIdentifier ] , `Expected type field to be '${ expectedIdentifier }' (got '${ comboBoxSelectedOptions }')` ) ; } ) ; } , async setIndexPatternFieldEditorFieldType ( type ) { await comboBox . set ( 'typeField > comboBoxInput' , type ) ; await this . assertIndexPatternFieldEditorFieldType ( type ) ; } , async addRuntimeField ( name , script , fieldType ) { await retry . tryForTime ( 5000 , async ( ) => { await this . clickIndexPatternManagementButton ( ) ; await this . clickAddIndexPatternFieldAction ( ) ; await this . assertIndexPatternFieldEditorExists ( ) ; await fieldEditor . setName ( name ) ; await fieldEditor . enableValue ( ) ; await fieldEditor . typeScript ( script ) ; await this . setIndexPatternFieldEditorFieldType ( fieldType ) ; await fieldEditor . save ( ) ; await this . assertIndexPatternFieldEditorNotExist ( ) ; } ) ; } , async renameField ( originalName , newName ) { await retry . tryForTime ( 5000 , async ( ) => { await dataVisualizerTable . clickEditIndexPatternFieldButton ( originalName ) ; await this . assertIndexPatternFieldEditorExists ( ) ; await fieldEditor . enableCustomLabel ( ) ; await fieldEditor . setCustomLabel ( newName ) ; await fieldEditor . save ( ) ; await this . assertIndexPatternFieldEditorNotExist ( ) ; } ) ; } , async confirmDeleteField ( ) { await testSubjects . existOrFail ( 'deleteModalConfirmText' ) ; await testSubjects . setValue ( 'deleteModalConfirmText' , 'remove' ) ; await testSubjects . click ( 'confirmModalConfirmButton' ) ; await testSubjects . missingOrFail ( 'deleteModalConfirmText' ) ; } , async deleteField ( fieldName ) { await retry . tryForTime ( 5000 , async ( ) => { await dataVisualizerTable . clickActionMenuDeleteIndexPatternFieldButton ( fieldName ) ; await this . confirmDeleteField ( ) ; await dataVisualizerTable . assertRowNotExists ( fieldName ) ; } ) ; } , } ; }