Skip to content

Commit

Permalink
Add upgrade rule smoke tests (#136048)
Browse files Browse the repository at this point in the history
* Add upgrade rule smoke tests

* Add version check

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
liza-mae and kibanamachine authored Jul 20, 2022
1 parent 74691b6 commit d862f6f
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 0 deletions.
14 changes: 14 additions & 0 deletions x-pack/test/upgrade/apps/rules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('upgrade', function () {
loadTestFile(require.resolve('./rules_smoke_tests'));
});
}
65 changes: 65 additions & 0 deletions x-pack/test/upgrade/apps/rules/rules_smoke_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 semver from 'semver';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getPageObjects, getService }: FtrProviderContext) {
const pageObjects = getPageObjects(['common', 'header']);
const rulesHelper = getService('rulesHelper');
const log = getService('log');
const testSubjects = getService('testSubjects');

describe('upgrade rules smoke tests', function describeIndexTests() {
before(async function () {
log.debug(process.env.ORIGINAL_VERSION!);
if (semver.lt(process.env.ORIGINAL_VERSION!, '7.13.0-SNAPSHOT')) {
log.debug('Skipping! These tests are valid only for 7.13+ versions');
this.skip();
}
});
const spaces = [
{ space: 'default', basePath: '' },
{ space: 'automation', basePath: 's/automation' },
];

spaces.forEach(({ space, basePath }) => {
describe('space: ' + space, () => {
before(async () => {
await pageObjects.common.navigateToUrl(
'management',
'insightsAndAlerting/triggersActions/rules',
{
ensureCurrentUrl: false,
shouldLoginIfPrompted: true,
shouldUseHashForSubUrl: false,
basePath,
}
);
await pageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.click('rulesTab');
});
it('shows created rule with no errors', async () => {
const createdRuleName = 'Upgrade Rule';
await testSubjects.click('rulesTab');
await rulesHelper.searchRules('"' + createdRuleName + '"');
const workAround = process.env.TEST_RULE_WORKAROUND ? true : false;
if (workAround) {
await rulesHelper.disableEnableRule();
}
const searchResults = await rulesHelper.getRulesList();
expect(searchResults.length).to.equal(1);
expect(searchResults[0].name).to.contain(createdRuleName);
expect(searchResults[0].interval).to.equal('1 min');
expect(searchResults[0].status).to.equal('Enabled');
expect(searchResults[0].lastResponse).to.equal('Ok');
});
});
});
});
}
3 changes: 3 additions & 0 deletions x-pack/test/upgrade/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { FtrConfigProviderContext } from '@kbn/test';
import { pageObjects } from '../functional/page_objects';
import { ReportingAPIProvider } from './services/reporting_upgrade_services';
import { MapsHelper } from './services/maps_upgrade_services';
import { RulesHelper } from './services/rules_upgrade_services';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const apiConfig = await readConfigFile(require.resolve('../api_integration/config'));
Expand All @@ -27,6 +28,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('./apps/logs'),
require.resolve('./apps/maps'),
require.resolve('./apps/reporting'),
require.resolve('./apps/rules'),
],

pageObjects,
Expand All @@ -36,6 +38,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
...functionalConfig.get('services'),
reportingAPI: ReportingAPIProvider,
mapsHelper: MapsHelper,
rulesHelper: RulesHelper,
},

screenshots: {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/test/upgrade/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import { services as functionalServices } from '../../functional/services';
import { services as reportingServices } from './reporting_upgrade_services';
import { services as mapsUpgradeServices } from './maps_upgrade_services';
import { services as rulesUpgradeServices } from './rules_upgrade_services';

export const services = {
...functionalServices,
...reportingServices,
...mapsUpgradeServices,
...rulesUpgradeServices,
};
107 changes: 107 additions & 0 deletions x-pack/test/upgrade/services/rules_upgrade_services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* 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 { FtrProviderContext } from '../ftr_provider_context';
import {
CustomCheerio,
CustomCheerioStatic,
} from '../../../../test/functional/services/lib/web_element_wrapper/custom_cheerio_api';

export function RulesHelper({ getPageObjects, getService }: FtrProviderContext) {
const find = getService('find');
const browser = getService('browser');
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const pageObjects = getPageObjects(['common', 'header']);
const ENTER_KEY = '\uE007';

function getRowItemData(row: CustomCheerio, $: CustomCheerioStatic) {
return {
name: $(row).findTestSubject('rulesTableCell-name').find('.euiTableCellContent').text(),
duration: $(row)
.findTestSubject('rulesTableCell-duration')
.find('.euiTableCellContent')
.text(),
interval: $(row)
.findTestSubject('rulesTableCell-interval')
.find('.euiTableCellContent')
.text(),
tags: $(row)
.findTestSubject('rulesTableCell-tagsPopover')
.find('.euiTableCellContent')
.text(),
lastResponse: $(row)
.findTestSubject('rulesTableCell-lastResponse')
.find('.euiTableCellContent')
.text(),
status: $(row).findTestSubject('rulesTableCell-status').find('.euiTableCellContent').text(),
};
}

return {
async searchRules(searchText: string) {
const searchBox = await testSubjects.find('ruleSearchField');
await searchBox.click();
await searchBox.clearValue();
await searchBox.type(searchText);
await searchBox.pressKeys(ENTER_KEY);
await find.byCssSelector(
'.euiBasicTable[data-test-subj="rulesList"]:not(.euiBasicTable-loading)'
);
},
async getRulesList() {
const table = await find.byCssSelector('[data-test-subj="rulesList"] table');
const $ = await table.parseDomContent();
return $.findTestSubjects('rule-row')
.toArray()
.map((row) => {
return getRowItemData(row, $);
});
},

async isStatus(status: string): Promise<boolean> {
const actionsDropdown = await testSubjects.find('statusDropdown');
const currentStatus = await actionsDropdown.getVisibleText();
if (currentStatus === status) {
return true;
}
return false;
},

async changeStatus(status: string) {
if (await this.isStatus(status)) {
return;
}
const actionsDropdown = await testSubjects.find('statusDropdown');
await actionsDropdown.click();
const actionsMenuElem = await testSubjects.find('ruleStatusMenu');
const actionsMenuItemElem = await actionsMenuElem.findByTestSubject(
'statusDropdown' + status + 'Item'
);
await actionsMenuItemElem.click();
await actionsDropdown.findByClassName('euiLoadingSpinner euiLoadingSpinner--small');
await retry.try(async () => {
await this.getRulesList();
expect(await this.isStatus(status)).to.eql(true);
});
},

async disableEnableRule() {
await this.changeStatus('Disabled');
await this.changeStatus('Enabled');
const searchResults = await this.getRulesList();
expect(searchResults[0].lastResponse).to.equal('Pending');
await browser.refresh();
await pageObjects.header.waitUntilLoadingHasFinished();
},
};
}

export const services = {
rulesHelper: RulesHelper,
};

0 comments on commit d862f6f

Please sign in to comment.