import expect from '@kbn/expect' ; import { mapValues } from 'lodash' ; import { FtrProviderContext } from '../../common/ftr_provider_context' ; import { UICapabilitiesService } from '../../common/services/ui_capabilities' ; import { SpaceScenarios } from '../scenarios' ; export default function catalogueTests ( { getService } ) { const uiCapabilitiesService = getService ( 'uiCapabilities' ) ; const esFeatureExceptions = [ 'security' , 'index_lifecycle_management' , 'snapshot_restore' , 'rollup_jobs' , 'reporting' , 'transform' , 'watcher' , ] ; const uiCapabilitiesExceptions = [ 'enterpriseSearch' , 'appSearch' , 'workplaceSearch' , ] ; describe ( 'catalogue' , ( ) => { SpaceScenarios . forEach ( ( scenario ) => { it ( `${ scenario . name }` , async ( ) => { const uiCapabilities = await uiCapabilitiesService . get ( { spaceId : scenario . id } ) ; switch ( scenario . id ) { case 'everything_space' : { expect ( uiCapabilities . success ) . to . be ( true ) ; expect ( uiCapabilities . value ) . to . have . property ( 'catalogue' ) ; const expected = mapValues ( uiCapabilities . value ! . catalogue , ( enabled , catalogueId ) => ! uiCapabilitiesExceptions . includes ( catalogueId ) ) ; expect ( uiCapabilities . value ! . catalogue ) . to . eql ( expected ) ; break ; } case 'nothing_space' : { expect ( uiCapabilities . success ) . to . be ( true ) ; expect ( uiCapabilities . value ) . to . have . property ( 'catalogue' ) ; const expected = mapValues ( uiCapabilities . value ! . catalogue , ( enabled , catalogueId ) => esFeatureExceptions . includes ( catalogueId ) || catalogueId === 'spaces' ) ; expect ( uiCapabilities . value ! . catalogue ) . to . eql ( expected ) ; break ; } case 'foo_disabled_space' : { expect ( uiCapabilities . success ) . to . be ( true ) ; expect ( uiCapabilities . value ) . to . have . property ( 'catalogue' ) ; const expected = mapValues ( uiCapabilities . value ! . catalogue , ( enabled , catalogueId ) => ! uiCapabilitiesExceptions . includes ( catalogueId ) && catalogueId !== 'foo' ) ; expect ( uiCapabilities . value ! . catalogue ) . to . eql ( expected ) ; break ; } default : throw new UnreachableError ( scenario ) ; } } ) ; } ) ; } ) ; }