diff --git a/packages/kbn-test/src/kbn_client/kbn_client_ui_settings.ts b/packages/kbn-test/src/kbn_client/kbn_client_ui_settings.ts index 8b9277fdab8b9..599184b30a461 100644 --- a/packages/kbn-test/src/kbn_client/kbn_client_ui_settings.ts +++ b/packages/kbn-test/src/kbn_client/kbn_client_ui_settings.ts @@ -10,7 +10,7 @@ import { ToolingLog } from '@kbn/tooling-log'; import { KbnClientRequester, pathWithSpace } from './kbn_client_requester'; -export type UiSettingValues = Record; +export type UiSettingValues = Record; interface UiSettingsApiResponse { settings: { [key: string]: { diff --git a/test/functional/apps/discover/group3/_default_columns.ts b/test/functional/apps/discover/group3/_default_columns.ts new file mode 100644 index 0000000000000..c467e31814f00 --- /dev/null +++ b/test/functional/apps/discover/group3/_default_columns.ts @@ -0,0 +1,145 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../ftr_provider_context'; + +export default function ({ getService, getPageObjects }: FtrProviderContext) { + const dataGrid = getService('dataGrid'); + const PageObjects = getPageObjects([ + 'common', + 'discover', + 'timePicker', + 'unifiedFieldList', + 'unifiedSearch', + 'header', + ]); + const esArchiver = getService('esArchiver'); + const kibanaServer = getService('kibanaServer'); + const security = getService('security'); + const defaultSettings = { + defaultIndex: 'logstash-*', + defaultColumns: ['message', 'extension', 'DestCountry'], + hideAnnouncements: true, + }; + + describe('discover default columns', function () { + before(async () => { + await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']); + await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional'); + await esArchiver.load('test/functional/fixtures/es_archiver/kibana_sample_data_logs_tsdb'); + await esArchiver.loadIfNeeded( + 'test/functional/fixtures/es_archiver/kibana_sample_data_flights' + ); + await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover'); + await kibanaServer.importExport.load( + 'test/functional/fixtures/kbn_archiver/kibana_sample_data_logs_tsdb' + ); + await kibanaServer.importExport.load( + 'test/functional/fixtures/kbn_archiver/kibana_sample_data_flights_index_pattern' + ); + }); + + after(async () => { + await kibanaServer.importExport.unload('test/functional/fixtures/kbn_archiver/discover'); + await esArchiver.unload('test/functional/fixtures/es_archiver/logstash_functional'); + await esArchiver.unload('test/functional/fixtures/es_archiver/kibana_sample_data_logs_tsdb'); + await esArchiver.unload('test/functional/fixtures/es_archiver/kibana_sample_data_flights'); + await kibanaServer.savedObjects.cleanStandardList(); + }); + + beforeEach(async function () { + await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings(); + await kibanaServer.uiSettings.update(defaultSettings); + await PageObjects.common.navigateToApp('discover'); + await PageObjects.discover.waitUntilSearchingHasFinished(); + }); + + it('should render default columns', async function () { + expect(await dataGrid.getHeaderFields()).to.eql([ + '@timestamp', + 'message', + 'extension', + 'DestCountry', + ]); + }); + + it('should render only available default columns after switching data views', async function () { + expect(await dataGrid.getHeaderFields()).to.eql([ + '@timestamp', + 'message', + 'extension', + 'DestCountry', + ]); + + await PageObjects.unifiedSearch.switchDataView( + 'discover-dataView-switch-link', + 'Kibana Sample Data Logs (TSDB)', + false + ); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.discover.expandTimeRangeAsSuggestedInNoResultsMessage(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + expect(await dataGrid.getHeaderFields()).to.eql(['timestamp', 'message', 'extension']); + + await PageObjects.unifiedSearch.switchDataView( + 'discover-dataView-switch-link', + 'kibana_sample_data_flights', + false + ); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.discover.expandTimeRangeAsSuggestedInNoResultsMessage(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + expect(await dataGrid.getHeaderFields()).to.eql(['timestamp', 'DestCountry']); + + await PageObjects.unifiedSearch.switchDataView( + 'discover-dataView-switch-link', + 'logstash-*', + false + ); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.discover.expandTimeRangeAsSuggestedInNoResultsMessage(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + expect(await dataGrid.getHeaderFields()).to.eql(['@timestamp', 'extension']); + }); + + it('should combine selected columns and default columns after switching data views', async function () { + await PageObjects.unifiedFieldList.clickFieldListItemAdd('bytes'); + await PageObjects.unifiedFieldList.clickFieldListItemRemove('DestCountry'); + await PageObjects.unifiedFieldList.clickFieldListItemRemove('message'); + await PageObjects.discover.waitUntilSearchingHasFinished(); + + expect(await dataGrid.getHeaderFields()).to.eql(['@timestamp', 'extension', 'bytes']); + + await PageObjects.unifiedSearch.switchDataView( + 'discover-dataView-switch-link', + 'Kibana Sample Data Logs (TSDB)', + false + ); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.discover.expandTimeRangeAsSuggestedInNoResultsMessage(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + expect(await dataGrid.getHeaderFields()).to.eql([ + 'timestamp', + 'extension', + 'bytes', + 'message', + ]); + + await PageObjects.unifiedSearch.switchDataView( + 'discover-dataView-switch-link', + 'logstash-*', + false + ); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await PageObjects.discover.expandTimeRangeAsSuggestedInNoResultsMessage(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + expect(await dataGrid.getHeaderFields()).to.eql(['@timestamp', 'extension', 'bytes']); + }); + }); +} diff --git a/test/functional/apps/discover/group3/index.ts b/test/functional/apps/discover/group3/index.ts index 4ac4572014a52..848bdc84def4d 100644 --- a/test/functional/apps/discover/group3/index.ts +++ b/test/functional/apps/discover/group3/index.ts @@ -20,6 +20,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) { await esArchiver.unload('test/functional/fixtures/es_archiver/logstash_functional'); }); + loadTestFile(require.resolve('./_default_columns')); loadTestFile(require.resolve('./_drag_drop')); loadTestFile(require.resolve('./_sidebar')); loadTestFile(require.resolve('./_request_counts'));