Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[functional test][saved objects] update tests for additional copy saved objects to space #74907

Merged
merged 6 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion test/functional/apps/management/_import_objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['common', 'settings', 'header', 'savedObjects']);
const testSubjects = getService('testSubjects');
const log = getService('log');
const find = getService('find');

describe('import objects', function describeIndexTests() {
describe('.ndjson file', () => {
Expand All @@ -48,13 +49,26 @@ export default function ({ getService, getPageObjects }) {
);
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
await PageObjects.common.sleep(5000);

// get all the elements in the table, and index them by the 'title' visible text field
const elements = keyBy(await PageObjects.savedObjects.getElementsInTable(), 'title');
log.debug("check that 'Log Agents' is in table as a visualization");
expect(elements['Log Agents'].objectType).to.eql('visualization');

await elements['logstash-*'].relationshipsElement.click();
// there's either a menu of actions
if (elements['logstash-*'].menuElement) {
await elements['logstash-*'].menuElement?.click();
// Wait for context menu to render
const menuPanel = await find.byCssSelector('.euiContextMenuPanel');
await (
await menuPanel.findByTestSubject('savedObjectsTableAction-relationships')
).click();
} else {
// or the action elements are on the row without the menu
await elements['logstash-*'].relationshipsElement.click();
}

const flyout = keyBy(await PageObjects.savedObjects.getRelationshipFlyout(), 'title');
log.debug(
"check that 'Shared-Item Visualization AreaChart' shows 'logstash-*' as it's Parent"
Expand Down Expand Up @@ -219,6 +233,7 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.savedObjects.checkImportSucceeded();
await PageObjects.savedObjects.clickImportDone();
const objects = await PageObjects.savedObjects.getRowTitles();
console.log(objects);
const isSavedObjectImported = objects.includes('Log Agents');
expect(isSavedObjectImported).to.be(true);
});
Expand Down
39 changes: 31 additions & 8 deletions test/functional/page_objects/management/saved_objects_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv
await searchBox.clearValue();
await searchBox.type(objectName);
await searchBox.pressKeys(browser.keys.ENTER);
await PageObjects.header.waitUntilLoadingHasFinished();
}

async importFile(path: string, overwriteAll = true) {
Expand Down Expand Up @@ -107,23 +108,45 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv
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')) {
// Advanced Settings has 2 actions,
// data-test-subj="savedObjectsTableAction-relationships"
// data-test-subj="savedObjectsTableAction-copy_saved_objects_to_space"
// Some other objects have the ...
// data-test-subj="euiCollapsedItemActionsButton"
// Maybe some objects still have the inspect element visible?
// !!! Also note that since we don't have spaces on OSS, the actions for the same object can be different depending on OSS or not
let menuElement = null;
let inspectElement = null;
let relationshipsElement = null;
let copySaveObjectsElement = null;
const actions = await row.findByClassName('euiTableRowCell--hasActions');
// getting the innerHTML and checking if it 'includes' a string is faster than a timeout looking for each element
const actionsHTML = await actions.getAttribute('innerHTML');
if (actionsHTML.includes('euiCollapsedItemActionsButton')) {
menuElement = await row.findByTestSubject('euiCollapsedItemActionsButton');
}
if (actionsHTML.includes('savedObjectsTableAction-inspect')) {
inspectElement = await row.findByTestSubject('savedObjectsTableAction-inspect');
} else {
inspectElement = null;
}
const relationshipsElement = await row.findByTestSubject(
'savedObjectsTableAction-relationships'
);
if (actionsHTML.includes('savedObjectsTableAction-relationships')) {
relationshipsElement = await row.findByTestSubject(
'savedObjectsTableAction-relationships'
);
}
if (actionsHTML.includes('savedObjectsTableAction - copy_saved_objects_to_space')) {
copySaveObjectsElement = await row.findByTestSubject(
'savedObjectsTableAction - copy_saved_objects_to_space'
);
}
return {
checkbox,
objectType: await objectType.getAttribute('aria-label'),
titleElement,
title: await titleElement.getVisibleText(),
menuElement,
inspectElement,
relationshipsElement,
copySaveObjectsElement,
};
});
}
Expand Down
3 changes: 1 addition & 2 deletions x-pack/test/functional/apps/spaces/copy_saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export default function spaceSelectorFunctonalTests({
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['security', 'settings', 'copySavedObjectsToSpace']);

// TODO: Flakey again https://github.com/elastic/kibana/issues/44575#issuecomment-528864287
describe.skip('Copy Saved Objects to Space', function () {
describe('Copy Saved Objects to Space', function () {
before(async () => {
await esArchiver.load('spaces/copy_saved_objects');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { keyBy } from 'lodash';
import { FtrProviderContext } from '../ftr_provider_context';

function extractCountFromSummary(str: string) {
Expand All @@ -16,28 +17,27 @@ export function CopySavedObjectsToSpacePageProvider({
}: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const find = getService('find');
const { savedObjects } = getPageObjects(['savedObjects']);
const { savedObjects, common } = getPageObjects(['savedObjects', 'common']);

return {
async openCopyToSpaceFlyoutForObject(objectName: string) {
// This searchForObject narrows down the objects to those matching ANY of the words in the objectName.
// Hopefully the one we want is on the first page of results.
await savedObjects.searchForObject(objectName);
await common.sleep(1000);

// Click action button to show context menu
await find.clickByCssSelector(
'table.euiTable tbody tr.euiTableRow td.euiTableRowCell:last-child .euiButtonIcon'
);

// Wait for context menu to render
await find.existsByCssSelector('.euiContextMenuPanel');

const actions = await find.allByCssSelector('.euiContextMenuItem');

for (const action of actions) {
const actionText = await action.getVisibleText();
if (actionText === 'Copy to space') {
await action.click();
break;
}
// this gets all the elements in the saved object table and keys them by title
const elements = keyBy(await savedObjects.getElementsInTable(), 'title');
// If there are more than 2 "actions" on the saved object we get the ... menu
// if there is the ... action menu we need to click it and click the copy saved object element
if (elements[objectName].menuElement) {
await elements[objectName].menuElement?.click();
// Wait for context menu to render
await find.existsByCssSelector('.euiContextMenuPanel');
await testSubjects.click('savedObjectsTableAction-copy_saved_objects_to_space');
} else {
// or there might be the copy saved object element without the menu
await elements[objectName].copySaveObjectsElement?.click();
}

await testSubjects.existOrFail('copy-to-space-flyout');
Expand Down