Skip to content

Commit

Permalink
Adding saved_objects_page in OSS (#69900)
Browse files Browse the repository at this point in the history
* add savedObjects own PO

* fix usage

* simplify functions

* fix test

* fix title parsing

* add missing await

* improve parsing

* wait for table is loaded

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
dmlemeshko and elasticmachine authored Jun 26, 2020
1 parent 7440eea commit 6ebf56b
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 312 deletions.
12 changes: 9 additions & 3 deletions test/functional/apps/dashboard/time_zones.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ export default function ({ getService, getPageObjects }) {
const pieChart = getService('pieChart');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const PageObjects = getPageObjects(['dashboard', 'timePicker', 'settings', 'common']);
const PageObjects = getPageObjects([
'dashboard',
'timePicker',
'settings',
'common',
'savedObjects',
]);

describe('dashboard time zones', function () {
this.tags('includeFirefox');
Expand All @@ -36,10 +42,10 @@ export default function ({ getService, getPageObjects }) {
});
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSavedObjects();
await PageObjects.settings.importFile(
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', 'timezonetest_6_2_4.json')
);
await PageObjects.settings.checkImportSucceeded();
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.preserveCrossAppState();
await PageObjects.dashboard.loadSavedDashboard('time zone test');
Expand Down
199 changes: 92 additions & 107 deletions test/functional/apps/management/_import_objects.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/functional/apps/management/_mgmt_import_saved_objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import path from 'path';

export default function ({ getService, getPageObjects }) {
const esArchiver = getService('esArchiver');
const PageObjects = getPageObjects(['common', 'settings', 'header']);
const PageObjects = getPageObjects(['common', 'settings', 'header', 'savedObjects']);

//in 6.4.0 bug the Saved Search conflict would be resolved and get imported but the visualization
//that referenced the saved search was not imported.( https://github.com/elastic/kibana/issues/22238)
Expand All @@ -40,19 +40,19 @@ export default function ({ getService, getPageObjects }) {

it('should import saved objects mgmt', async function () {
await PageObjects.settings.clickKibanaSavedObjects();
await PageObjects.settings.importFile(
await PageObjects.savedObjects.importFile(
path.join(__dirname, 'exports', 'mgmt_import_objects.json')
);
await PageObjects.settings.associateIndexPattern(
'4c3f3c30-ac94-11e8-a651-614b2788174a',
'logstash-*'
);
await PageObjects.settings.clickConfirmChanges();
await PageObjects.settings.clickImportDone();
await PageObjects.settings.waitUntilSavedObjectsTableIsNotLoading();
await PageObjects.savedObjects.clickConfirmChanges();
await PageObjects.savedObjects.clickImportDone();
await PageObjects.savedObjects.waitTableIsLoaded();

//instead of asserting on count- am asserting on the titles- which is more accurate than count.
const objects = await PageObjects.settings.getSavedObjectsInTable();
const objects = await PageObjects.savedObjects.getRowTitles();
expect(objects.includes('mysavedsearch')).to.be(true);
expect(objects.includes('mysavedviz')).to.be(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
export default function ({ getPageObjects, getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common', 'settings']);
const PageObjects = getPageObjects(['common', 'settings', 'savedObjects']);
const browser = getService('browser');
const find = getService('find');

Expand Down Expand Up @@ -79,7 +79,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSavedObjects();

let objects = await PageObjects.settings.getSavedObjectsInTable();
let objects = await PageObjects.savedObjects.getRowTitles();
expect(objects.includes('A Dashboard')).to.be(true);

await PageObjects.common.navigateToUrl(
Expand All @@ -99,7 +99,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

await focusAndClickButton('savedObjectEditSave');

objects = await PageObjects.settings.getSavedObjectsInTable();
objects = await PageObjects.savedObjects.getRowTitles();
expect(objects.includes('A Dashboard')).to.be(false);
expect(objects.includes('Edited Dashboard')).to.be(true);

Expand Down Expand Up @@ -127,7 +127,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await focusAndClickButton('savedObjectEditDelete');
await PageObjects.common.clickConfirmOnModal();

const objects = await PageObjects.settings.getSavedObjectsInTable();
const objects = await PageObjects.savedObjects.getRowTitles();
expect(objects.includes('A Dashboard')).to.be(false);
});

Expand All @@ -145,7 +145,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSavedObjects();

const objects = await PageObjects.settings.getSavedObjectsInTable();
const objects = await PageObjects.savedObjects.getRowTitles();
expect(objects.includes('A Pie')).to.be(true);

await PageObjects.common.navigateToUrl('management', testVisualizationUrl, {
Expand All @@ -160,7 +160,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

await focusAndClickButton('savedObjectEditSave');

await PageObjects.settings.getSavedObjectsInTable();
await PageObjects.savedObjects.getRowTitles();

await PageObjects.common.navigateToUrl('management', testVisualizationUrl, {
shouldUseHashForSubUrl: false,
Expand All @@ -173,7 +173,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

await focusAndClickButton('savedObjectEditSave');

await PageObjects.settings.getSavedObjectsInTable();
await PageObjects.savedObjects.getRowTitles();

await PageObjects.common.navigateToUrl('management', testVisualizationUrl, {
shouldUseHashForSubUrl: false,
Expand Down
2 changes: 2 additions & 0 deletions test/functional/page_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { VisualizeChartPageProvider } from './visualize_chart_page';
import { TileMapPageProvider } from './tile_map_page';
import { TagCloudPageProvider } from './tag_cloud_page';
import { VegaChartPageProvider } from './vega_chart_page';
import { SavedObjectsPageProvider } from './management/saved_objects_page';

export const pageObjects = {
common: CommonPageProvider,
Expand All @@ -61,4 +62,5 @@ export const pageObjects = {
tileMap: TileMapPageProvider,
tagCloud: TagCloudPageProvider,
vegaChart: VegaChartPageProvider,
savedObjects: SavedObjectsPageProvider,
};
184 changes: 184 additions & 0 deletions test/functional/page_objects/management/saved_objects_page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* 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 { map as mapAsync } from 'bluebird';
import { FtrProviderContext } from '../../ftr_provider_context';

export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const log = getService('log');
const retry = getService('retry');
const browser = getService('browser');
const find = getService('find');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['header', 'common']);

class SavedObjectsPage {
async searchForObject(objectName: string) {
const searchBox = await testSubjects.find('savedObjectSearchBar');
await searchBox.clearValue();
await searchBox.type(objectName);
await searchBox.pressKeys(browser.keys.ENTER);
}

async importFile(path: string, overwriteAll = true) {
log.debug(`importFile(${path})`);

log.debug(`Clicking importObjects`);
await testSubjects.click('importObjects');
await PageObjects.common.setFileInputPath(path);

if (!overwriteAll) {
log.debug(`Toggling overwriteAll`);
await testSubjects.click('importSavedObjectsOverwriteToggle');
} else {
log.debug(`Leaving overwriteAll alone`);
}
await testSubjects.click('importSavedObjectsImportBtn');
log.debug(`done importing the file`);

// Wait for all the saves to happen
await PageObjects.header.waitUntilLoadingHasFinished();
}

async checkImportSucceeded() {
await testSubjects.existOrFail('importSavedObjectsSuccess', { timeout: 20000 });
}

async checkNoneImported() {
await testSubjects.existOrFail('importSavedObjectsSuccessNoneImported', { timeout: 20000 });
}

async checkImportConflictsWarning() {
await testSubjects.existOrFail('importSavedObjectsConflictsWarning', { timeout: 20000 });
}

async checkImportLegacyWarning() {
await testSubjects.existOrFail('importSavedObjectsLegacyWarning', { timeout: 20000 });
}

async checkImportFailedWarning() {
await testSubjects.existOrFail('importSavedObjectsFailedWarning', { timeout: 20000 });
}

async clickImportDone() {
await testSubjects.click('importSavedObjectsDoneBtn');
await this.waitTableIsLoaded();
}

async clickConfirmChanges() {
await testSubjects.click('importSavedObjectsConfirmBtn');
}

async waitTableIsLoaded() {
return retry.try(async () => {
const exists = await find.existsByDisplayedByCssSelector(
'*[data-test-subj="savedObjectsTable"] .euiBasicTable-loading'
);
if (exists) {
throw new Error('Waiting');
}
return true;
});
}

async getElementsInTable() {
const rows = await testSubjects.findAll('~savedObjectsTableRow');
return mapAsync(rows, async (row) => {
const checkbox = await row.findByCssSelector('[data-test-subj*="checkboxSelectRow"]');
// return the object type aria-label="index patterns"
const objectType = await row.findByTestSubject('objectType');
const titleElement = await row.findByTestSubject('savedObjectsTableRowTitle');
// not all rows have inspect button - Advanced Settings objects don't
let inspectElement;
const innerHtml = await row.getAttribute('innerHTML');
if (innerHtml.includes('Inspect')) {
inspectElement = await row.findByTestSubject('savedObjectsTableAction-inspect');
} else {
inspectElement = null;
}
const relationshipsElement = await row.findByTestSubject(
'savedObjectsTableAction-relationships'
);
return {
checkbox,
objectType: await objectType.getAttribute('aria-label'),
titleElement,
title: await titleElement.getVisibleText(),
inspectElement,
relationshipsElement,
};
});
}

async getRowTitles() {
await this.waitTableIsLoaded();
const table = await testSubjects.find('savedObjectsTable');
const $ = await table.parseDomContent();
return $.findTestSubjects('savedObjectsTableRowTitle')
.toArray()
.map((cell) => $(cell).find('.euiTableCellContent').text());
}

async getRelationshipFlyout() {
const rows = await testSubjects.findAll('relationshipsTableRow');
return mapAsync(rows, async (row) => {
const objectType = await row.findByTestSubject('relationshipsObjectType');
const relationship = await row.findByTestSubject('directRelationship');
const titleElement = await row.findByTestSubject('relationshipsTitle');
const inspectElement = await row.findByTestSubject('relationshipsTableAction-inspect');
return {
objectType: await objectType.getAttribute('aria-label'),
relationship: await relationship.getVisibleText(),
titleElement,
title: await titleElement.getVisibleText(),
inspectElement,
};
});
}

async getTableSummary() {
const table = await testSubjects.find('savedObjectsTable');
const $ = await table.parseDomContent();
return $('tbody tr')
.toArray()
.map((row) => {
return {
title: $(row).find('td:nth-child(3) .euiTableCellContent').text(),
canViewInApp: Boolean($(row).find('td:nth-child(3) a').length),
};
});
}

async clickTableSelectAll() {
await testSubjects.click('checkboxSelectAll');
}

async canBeDeleted() {
return await testSubjects.isEnabled('savedObjectsManagementDelete');
}

async clickDelete() {
await testSubjects.click('savedObjectsManagementDelete');
await testSubjects.click('confirmModalConfirmButton');
await this.waitTableIsLoaded();
}
}

return new SavedObjectsPage();
}
Loading

0 comments on commit 6ebf56b

Please sign in to comment.