Skip to content

Commit

Permalink
Add functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed Jan 22, 2025
1 parent d37c74d commit 16a7682
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const createExampleRootProfileProvider = (): RootProfileProvider => ({
isExperimental: true,
profile: {
getRenderAppWrapper,
getDefaultAdHocDataViews,
getCellRenderers: (prev) => (params) => ({
...prev(params),
'@timestamp': (props) => {
Expand Down Expand Up @@ -112,7 +113,7 @@ export const createExampleRootProfileProvider = (): RootProfileProvider => ({
export const createExampleSolutionViewRootProfileProvider = (): RootProfileProvider => ({
profileId: 'example-solution-view-root-profile',
isExperimental: true,
profile: { getRenderAppWrapper },
profile: { getRenderAppWrapper, getDefaultAdHocDataViews },
resolve: (params) => ({
isMatch: true,
context: { solutionType: params.solutionNavId as SolutionType },
Expand Down Expand Up @@ -151,3 +152,15 @@ const getRenderAppWrapper: RootProfileProvider['profile']['getRenderAppWrapper']
</PrevWrapper>
);
};

const getDefaultAdHocDataViews: RootProfileProvider['profile']['getDefaultAdHocDataViews'] =
(prev) => () =>
[
...prev(),
{
id: 'example-root-profile-ad-hoc-data-view',
name: 'Example profile data view',
title: 'my-example-*',
timeFieldName: '@timestamp',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import expect from '@kbn/expect';
import type { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const { common, discover, unifiedFieldList } = getPageObjects([
'common',
'discover',
'unifiedFieldList',
]);
const testSubjects = getService('testSubjects');
const dataViews = getService('dataViews');
const dataGrid = getService('dataGrid');
const toasts = getService('toasts');
const browser = getService('browser');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');

describe('extension getDefaultAdHocDataViews', () => {
after(async () => {
await kibanaServer.savedObjects.clean({ types: ['search'] });
});

it('should show the profile data view', async () => {
await common.navigateToActualUrl('discover', undefined, {
ensureCurrentUrl: false,
});
expect(await dataViews.getSelectedName()).not.to.be('Example profile data view');
await dataViews.switchTo('Example profile data view');
await discover.waitUntilSearchingHasFinished();
expect(await unifiedFieldList.getSidebarSectionFieldNames('available')).to.have.length(7);
expect(
await (await dataGrid.getCellElementByColumnName(0, '@timestamp')).getVisibleText()
).to.be('2024-06-10T16:30:00.000Z');
expect(
await (await dataGrid.getCellElementByColumnName(5, '@timestamp')).getVisibleText()
).to.be('2024-06-10T14:00:00.000Z');
});

it('should reload the profile data view on page refresh, and not show an error toast', async () => {
await browser.refresh();
await discover.waitUntilSearchingHasFinished();
expect(await toasts.getCount({ timeout: 2000 })).to.be(0);
expect(await dataViews.getSelectedName()).to.be('Example profile data view');
});

it('should create a copy of the profile data view when saving the Discover session', async () => {
await discover.saveSearch('Default profile data view session');
await discover.waitUntilSearchingHasFinished();
expect(await dataViews.getSelectedName()).to.be('Example profile data view (copy)');
expect(await unifiedFieldList.getSidebarSectionFieldNames('available')).to.have.length(7);
expect(
await (await dataGrid.getCellElementByColumnName(0, '@timestamp')).getVisibleText()
).to.be('2024-06-10T16:30:00.000Z');
expect(
await (await dataGrid.getCellElementByColumnName(5, '@timestamp')).getVisibleText()
).to.be('2024-06-10T14:00:00.000Z');
await dataViews.switchTo('Example profile data view');
await discover.waitUntilSearchingHasFinished();
expect(await unifiedFieldList.getSidebarSectionFieldNames('available')).to.have.length(7);
expect(
await (await dataGrid.getCellElementByColumnName(0, '@timestamp')).getVisibleText()
).to.be('2024-06-10T16:30:00.000Z');
expect(
await (await dataGrid.getCellElementByColumnName(5, '@timestamp')).getVisibleText()
).to.be('2024-06-10T14:00:00.000Z');
});

describe('fallback behaviour', function () {
after(async () => {
await esArchiver.load('test/functional/fixtures/es_archiver/discover/context_awareness');
await kibanaServer.importExport.load(
'test/functional/fixtures/kbn_archiver/discover/context_awareness'
);
});

it('should fall back to the profile data view when no other data views are available', async () => {
await kibanaServer.importExport.unload(
'test/functional/fixtures/kbn_archiver/discover/context_awareness'
);
await common.navigateToActualUrl('discover', undefined, {
ensureCurrentUrl: false,
});
expect(await dataViews.getSelectedName()).to.be('Example profile data view');
await discover.waitUntilSearchingHasFinished();
expect(await unifiedFieldList.getSidebarSectionFieldNames('available')).to.have.length(7);
expect(
await (await dataGrid.getCellElementByColumnName(0, '@timestamp')).getVisibleText()
).to.be('2024-06-10T16:30:00.000Z');
expect(
await (await dataGrid.getCellElementByColumnName(5, '@timestamp')).getVisibleText()
).to.be('2024-06-10T14:00:00.000Z');
});

it('should show the no data page when no ES data is available', async () => {
await esArchiver.unload('test/functional/fixtures/es_archiver/discover/context_awareness');
await common.navigateToActualUrl('discover', undefined, {
ensureCurrentUrl: false,
});
expect(await testSubjects.exists('kbnNoDataPage')).to.be(true);
});
});
});
}
1 change: 1 addition & 0 deletions test/functional/apps/discover/context_awareness/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ export default function ({ getService, getPageObjects, loadTestFile }: FtrProvid
loadTestFile(require.resolve('./extensions/_get_additional_cell_actions'));
loadTestFile(require.resolve('./extensions/_get_app_menu'));
loadTestFile(require.resolve('./extensions/_get_render_app_wrapper'));
loadTestFile(require.resolve('./extensions/_get_default_ad_hoc_data_views'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import type { FtrProviderContext } from '../../../../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const { common, discover, unifiedFieldList, svlCommonPage } = getPageObjects([
'common',
'discover',
'unifiedFieldList',
'svlCommonPage',
]);
const testSubjects = getService('testSubjects');
const dataViews = getService('dataViews');
const dataGrid = getService('dataGrid');
const toasts = getService('toasts');
const browser = getService('browser');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');

describe('extension getDefaultAdHocDataViews', () => {
before(async () => {
await svlCommonPage.loginAsAdmin();
});

after(async () => {
await kibanaServer.savedObjects.clean({ types: ['search'] });
});

it('should show the profile data view', async () => {
await common.navigateToActualUrl('discover', undefined, {
ensureCurrentUrl: false,
});
expect(await dataViews.getSelectedName()).not.to.be('Example profile data view');
await dataViews.switchTo('Example profile data view');
await discover.waitUntilSearchingHasFinished();
expect(await unifiedFieldList.getSidebarSectionFieldNames('available')).to.have.length(7);
expect(
await (await dataGrid.getCellElementByColumnName(0, '@timestamp')).getVisibleText()
).to.be('Jun 10, 2024 @ 16:30:00.000');
expect(
await (await dataGrid.getCellElementByColumnName(5, '@timestamp')).getVisibleText()
).to.be('Jun 10, 2024 @ 14:00:00.000');
});

it('should reload the profile data view on page refresh, and not show an error toast', async () => {
await browser.refresh();
await discover.waitUntilSearchingHasFinished();
expect(await toasts.getCount({ timeout: 2000 })).to.be(0);
expect(await dataViews.getSelectedName()).to.be('Example profile data view');
});

it('should create a copy of the profile data view when saving the Discover session', async () => {
await discover.saveSearch('Default profile data view session');
await discover.waitUntilSearchingHasFinished();
expect(await dataViews.getSelectedName()).to.be('Example profile data view (copy)');
expect(await unifiedFieldList.getSidebarSectionFieldNames('available')).to.have.length(7);
expect(
await (await dataGrid.getCellElementByColumnName(0, '@timestamp')).getVisibleText()
).to.be('Jun 10, 2024 @ 16:30:00.000');
expect(
await (await dataGrid.getCellElementByColumnName(5, '@timestamp')).getVisibleText()
).to.be('Jun 10, 2024 @ 14:00:00.000');
await dataViews.switchTo('Example profile data view');
await discover.waitUntilSearchingHasFinished();
expect(await unifiedFieldList.getSidebarSectionFieldNames('available')).to.have.length(7);
expect(
await (await dataGrid.getCellElementByColumnName(0, '@timestamp')).getVisibleText()
).to.be('Jun 10, 2024 @ 16:30:00.000');
expect(
await (await dataGrid.getCellElementByColumnName(5, '@timestamp')).getVisibleText()
).to.be('Jun 10, 2024 @ 14:00:00.000');
});

describe('fallback behaviour', function () {
// Search projects have a default data view, so these don't apply
this.tags(['skipSvlSearch']);

after(async () => {
await esArchiver.load('test/functional/fixtures/es_archiver/discover/context_awareness');
await kibanaServer.importExport.load(
'test/functional/fixtures/kbn_archiver/discover/context_awareness'
);
});

it('should fall back to the profile data view when no other data views are available', async () => {
await kibanaServer.importExport.unload(
'test/functional/fixtures/kbn_archiver/discover/context_awareness'
);
await common.navigateToActualUrl('discover', undefined, {
ensureCurrentUrl: false,
});
expect(await dataViews.getSelectedName()).to.be('Example profile data view');
await discover.waitUntilSearchingHasFinished();
expect(await unifiedFieldList.getSidebarSectionFieldNames('available')).to.have.length(7);
expect(
await (await dataGrid.getCellElementByColumnName(0, '@timestamp')).getVisibleText()
).to.be('Jun 10, 2024 @ 16:30:00.000');
expect(
await (await dataGrid.getCellElementByColumnName(5, '@timestamp')).getVisibleText()
).to.be('Jun 10, 2024 @ 14:00:00.000');
});

it('should show the no data page when no ES data is available', async () => {
await esArchiver.unload('test/functional/fixtures/es_archiver/discover/context_awareness');
await common.navigateToActualUrl('discover', undefined, {
ensureCurrentUrl: false,
});
expect(await testSubjects.exists('kbnNoDataPage')).to.be(true);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ export default function ({ getService, getPageObjects, loadTestFile }: FtrProvid
loadTestFile(require.resolve('./extensions/_get_additional_cell_actions'));
loadTestFile(require.resolve('./extensions/_get_app_menu'));
loadTestFile(require.resolve('./extensions/_get_render_app_wrapper'));
loadTestFile(require.resolve('./extensions/_get_default_ad_hoc_data_views'));
});
}

0 comments on commit 16a7682

Please sign in to comment.