diff --git a/src/legacy/core_plugins/visualizations/public/np_ready/public/vis.ts b/src/legacy/core_plugins/visualizations/public/np_ready/public/vis.ts index 0ba936c9f6567..91b6a2368f5ef 100644 --- a/src/legacy/core_plugins/visualizations/public/np_ready/public/vis.ts +++ b/src/legacy/core_plugins/visualizations/public/np_ready/public/vis.ts @@ -132,8 +132,10 @@ export class Vis { this.data.savedSearchId = state.data.savedSearchId; } if (state.data && state.data.aggs) { - let configStates = state.data.aggs; - configStates = this.initializeDefaultsFromSchemas(configStates, this.type.schemas.all || []); + const configStates = this.initializeDefaultsFromSchemas( + cloneDeep(state.data.aggs), + this.type.schemas.all || [] + ); if (!this.data.indexPattern) { if (state.data.aggs.length) { throw new Error('trying to initialize aggs without index pattern'); diff --git a/test/functional/apps/discover/_field_visualize.ts b/test/functional/apps/discover/_field_visualize.ts new file mode 100644 index 0000000000000..4a72d5bb34716 --- /dev/null +++ b/test/functional/apps/discover/_field_visualize.ts @@ -0,0 +1,80 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function({ getService, getPageObjects }: FtrProviderContext) { + const esArchiver = getService('esArchiver'); + const inspector = getService('inspector'); + const kibanaServer = getService('kibanaServer'); + const log = getService('log'); + const PageObjects = getPageObjects(['common', 'discover', 'header', 'timePicker']); + const defaultSettings = { + defaultIndex: 'logstash-*', + }; + + describe('discover field visualize button', () => { + before(async function() { + log.debug('load kibana index with default index pattern'); + await esArchiver.load('discover'); + + // and load a set of makelogs data + await esArchiver.loadIfNeeded('logstash_functional'); + await kibanaServer.uiSettings.replace(defaultSettings); + }); + + beforeEach(async () => { + log.debug('go to discover'); + await PageObjects.common.navigateToApp('discover'); + await PageObjects.timePicker.setDefaultAbsoluteRange(); + }); + + it('should visualize a field in area chart', async () => { + await PageObjects.discover.clickFieldListItem('phpmemory'); + log.debug('visualize a phpmemory field'); + await PageObjects.discover.clickFieldListItemVisualize('phpmemory'); + await PageObjects.header.waitUntilLoadingHasFinished(); + const expectedTableData = [ + ['0', '10'], + ['58,320', '2'], + ['171,080', '2'], + ['3,240', '1'], + ['3,520', '1'], + ['3,880', '1'], + ['4,120', '1'], + ['4,640', '1'], + ['4,760', '1'], + ['5,680', '1'], + ['7,160', '1'], + ['7,400', '1'], + ['8,400', '1'], + ['8,800', '1'], + ['8,960', '1'], + ['9,400', '1'], + ['10,280', '1'], + ['10,840', '1'], + ['13,080', '1'], + ['13,360', '1'], + ]; + await inspector.open(); + await inspector.expectTableData(expectedTableData); + await inspector.close(); + }); + }); +} diff --git a/test/functional/apps/discover/index.js b/test/functional/apps/discover/index.js index 64a5a61335365..582c979a194f4 100644 --- a/test/functional/apps/discover/index.js +++ b/test/functional/apps/discover/index.js @@ -35,6 +35,7 @@ export default function({ getService, loadTestFile }) { loadTestFile(require.resolve('./_saved_queries')); loadTestFile(require.resolve('./_discover')); loadTestFile(require.resolve('./_discover_histogram')); + loadTestFile(require.resolve('./_field_visualize')); loadTestFile(require.resolve('./_filter_editor')); loadTestFile(require.resolve('./_errors')); loadTestFile(require.resolve('./_field_data'));