Skip to content

Commit

Permalink
Addressing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Oct 18, 2022
1 parent 31db0ca commit f67d32b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ const CloseAlertComponent: React.FC<SubActionProps<OpsgenieCloseAlertParams>> =

CloseAlertComponent.displayName = 'CloseAlertComponent';

const actionOptions = [
{
value: OpsgenieSubActions.CreateAlert,
text: i18n.CREATE_ALERT_ACTION,
},
{
value: OpsgenieSubActions.CloseAlert,
text: i18n.CLOSE_ALERT_ACTION,
},
];

const OpsgenieParamFields: React.FC<ActionParamsProps<OpsgenieActionParams>> = ({
actionParams,
editAction,
Expand All @@ -136,17 +147,6 @@ const OpsgenieParamFields: React.FC<ActionParamsProps<OpsgenieActionParams>> = (

const currentSubAction = useRef<string>(subAction ?? OpsgenieSubActions.CreateAlert);

const actionOptions = [
{
value: OpsgenieSubActions.CreateAlert,
text: i18n.CREATE_ALERT_ACTION,
},
{
value: OpsgenieSubActions.CloseAlert,
text: i18n.CLOSE_ALERT_ACTION,
},
];

const onActionChange = useCallback(
(event: React.ChangeEvent<HTMLSelectElement>) => {
editAction('subAction', event.target.value, index);
Expand Down
10 changes: 1 addition & 9 deletions x-pack/test/functional/services/actions/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ export function ActionsCommonServiceProvider({ getService, getPageObject }: FtrP
const testSubjects = getService('testSubjects');

return {
async clickCreateFirstConnectorButton() {
const createBtn = await testSubjects.find('createFirstActionButton');
const createBtnIsVisible = await createBtn.isDisplayed();
if (createBtnIsVisible) {
await createBtn.click();
}
},

async openNewConnectorForm(name: string) {
const createBtn = await testSubjects.find('createActionButton');
const createBtnIsVisible = await createBtn.isDisplayed();
if (createBtnIsVisible) {
await createBtn.click();
} else {
await this.clickCreateFirstConnectorButton();
await testSubjects.click('createFirstActionButton');
}

await testSubjects.click(`.${name}-card`);
Expand Down
14 changes: 7 additions & 7 deletions x-pack/test/functional/services/actions/opsgenie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

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

Expand All @@ -19,16 +20,15 @@ export function ActionsOpsgenieServiceProvider(
common: ActionsCommon
) {
const testSubjects = getService('testSubjects');
const find = getService('find');

return {
async createNewConnector(fields: ConnectorFormFields) {
await common.openNewConnectorForm('opsgenie');
await this.setConnectorFields(fields);

await find.clickByCssSelector(
'[data-test-subj="create-connector-flyout-save-btn"]:not(disabled)'
);
const flyOutSaveButton = await testSubjects.find('create-connector-flyout-save-btn');
expect(await flyOutSaveButton.isEnabled()).to.be(true);
await flyOutSaveButton.click();
},

async setConnectorFields({ name, apiUrl, apiKey }: ConnectorFormFields) {
Expand All @@ -40,9 +40,9 @@ export function ActionsOpsgenieServiceProvider(
async updateConnectorFields(fields: ConnectorFormFields) {
await this.setConnectorFields(fields);

await find.clickByCssSelector(
'[data-test-subj="edit-connector-flyout-save-btn"]:not(disabled)'
);
const editFlyOutSaveButton = await testSubjects.find('edit-connector-flyout-save-btn');
expect(await editFlyOutSaveButton.isEnabled()).to.be(true);
await editFlyOutSaveButton.click();
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { ObjectRemover } from '../../../lib/object_remover';
import { generateUniqueKey } from '../../../lib/get_test_data';
import { getConnector, createConnectorAndObjectRemover, createSlackConnector } from './utils';
import {
getConnectorByName,
createSlackConnectorAndObjectRemover,
createSlackConnector,
} from './utils';

export default ({ getPageObjects, getPageObject, getService }: FtrProviderContext) => {
const testSubjects = getService('testSubjects');
Expand All @@ -22,7 +26,11 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex

describe('General connector functionality', function () {
before(async () => {
objectRemover = await createConnectorAndObjectRemover({ getPageObject, getService });
objectRemover = await createSlackConnectorAndObjectRemover({ getService });
});

beforeEach(async () => {
await pageObjects.common.navigateToApp('triggersActionsConnectors');
});

after(async () => {
Expand Down Expand Up @@ -60,7 +68,7 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex
actionType: 'Slack',
},
]);
const connector = await getConnector(connectorName, supertest);
const connector = await getConnectorByName(connectorName, supertest);
objectRemover.add(connector.id, 'action', 'actions');
});

Expand All @@ -69,8 +77,7 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex
const updatedConnectorName = `${connectorName}updated`;
const createdAction = await createSlackConnector({
name: connectorName,
getPageObject,
getService,
supertest,
});
objectRemover.add(createdAction.id, 'action', 'actions');
await browser.refresh();
Expand Down Expand Up @@ -169,8 +176,7 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex
const connectorName = generateUniqueKey();
const createdAction = await createSlackConnector({
name: connectorName,
getPageObject,
getService,
supertest,
});
objectRemover.add(createdAction.id, 'action', 'actions');
await browser.refresh();
Expand Down Expand Up @@ -199,11 +205,10 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex

it('should delete a connector', async () => {
const connectorName = generateUniqueKey();
await createSlackConnector({ name: connectorName, getPageObject, getService });
await createSlackConnector({ name: connectorName, supertest });
const createdAction = await createSlackConnector({
name: generateUniqueKey(),
getPageObject,
getService,
supertest,
});
objectRemover.add(createdAction.id, 'action', 'actions');
await browser.refresh();
Expand All @@ -229,11 +234,10 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex

it('should bulk delete connectors', async () => {
const connectorName = generateUniqueKey();
await createSlackConnector({ name: connectorName, getPageObject, getService });
await createSlackConnector({ name: connectorName, supertest });
const createdAction = await createSlackConnector({
name: generateUniqueKey(),
getPageObject,
getService,
supertest,
});
objectRemover.add(createdAction.id, 'action', 'actions');
await browser.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,33 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { ObjectRemover } from '../../../lib/object_remover';
import { generateUniqueKey } from '../../../lib/get_test_data';
import { createConnector, createConnectorAndObjectRemover, getConnector } from './utils';
import { createConnector, createSlackConnectorAndObjectRemover, getConnectorByName } from './utils';

export default ({ getPageObjects, getPageObject, getService }: FtrProviderContext) => {
export default ({ getPageObjects, getService }: FtrProviderContext) => {
const testSubjects = getService('testSubjects');
const pageObjects = getPageObjects(['common', 'triggersActionsUI', 'header']);
const find = getService('find');
const retry = getService('retry');
const supertest = getService('supertest');
const actions = getService('actions');
const rules = getService('rules');
const browser = getService('browser');
let objectRemover: ObjectRemover;

describe('Opsgenie', () => {
before(async () => {
objectRemover = await createConnectorAndObjectRemover({ getPageObject, getService });
objectRemover = await createSlackConnectorAndObjectRemover({ getService });
});

after(async () => {
await objectRemover.removeAll();
});

describe('connector page', () => {
beforeEach(async () => {
await pageObjects.common.navigateToApp('triggersActionsConnectors');
});

it('should create the connector', async () => {
const connectorName = generateUniqueKey();

Expand All @@ -52,7 +57,7 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex
actionType: 'Opsgenie',
},
]);
const connector = await getConnector(connectorName, supertest);
const connector = await getConnectorByName(connectorName, supertest);
objectRemover.add(connector.id, 'action', 'actions');
});

Expand All @@ -61,6 +66,7 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex
const updatedConnectorName = `${connectorName}updated`;
const createdAction = await createOpsgenieConnector(connectorName);
objectRemover.add(createdAction.id, 'action', 'actions');
browser.refresh();

await pageObjects.triggersActionsUI.searchConnectors(connectorName);

Expand Down Expand Up @@ -93,6 +99,8 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex
const connectorName = generateUniqueKey();
const createdAction = await createOpsgenieConnector(connectorName);
objectRemover.add(createdAction.id, 'action', 'actions');
browser.refresh();

await pageObjects.triggersActionsUI.searchConnectors(connectorName);

const searchResultsBeforeEdit = await pageObjects.triggersActionsUI.getConnectorsList();
Expand All @@ -119,6 +127,7 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex
const connectorName = generateUniqueKey();
const createdAction = await createOpsgenieConnector(connectorName);
objectRemover.add(createdAction.id, 'action', 'actions');
browser.refresh();

await pageObjects.triggersActionsUI.searchConnectors(connectorName);

Expand Down Expand Up @@ -236,8 +245,7 @@ export default ({ getPageObjects, getPageObject, getService }: FtrProviderContex
config: { apiUrl: 'https//test.com' },
secrets: { apiKey: '1234' },
connectorTypeId: '.opsgenie',
getPageObject,
getService,
supertest,
});
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import { ObjectRemover } from '../../../lib/object_remover';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { getTestActionData } from '../../../lib/get_test_data';

export const createConnectorAndObjectRemover = async ({
getPageObject,
export const createSlackConnectorAndObjectRemover = async ({
getService,
}: {
getPageObject: FtrProviderContext['getPageObject'];
getService: FtrProviderContext['getService'];
}) => {
const supertest = getService('supertest');
Expand All @@ -25,8 +23,7 @@ export const createConnectorAndObjectRemover = async ({
const testData = getTestActionData();
const createdAction = await createSlackConnector({
name: testData.name,
getPageObject,
getService,
supertest,
});
objectRemover.add(createdAction.id, 'action', 'actions');

Expand All @@ -35,26 +32,23 @@ export const createConnectorAndObjectRemover = async ({

export const createSlackConnector = async ({
name,
getPageObject,
getService,
supertest,
}: {
name: string;
getPageObject: FtrProviderContext['getPageObject'];
getService: FtrProviderContext['getService'];
supertest: SuperTest.SuperTest<SuperTest.Test>;
}) => {
const connector = await createConnector({
name,
config: {},
secrets: { webhookUrl: 'https://test.com' },
connectorTypeId: '.slack',
getPageObject,
getService,
supertest,
});

return connector;
};

export const getConnector = async (
export const getConnectorByName = async (
name: string,
supertest: SuperTest.SuperTest<SuperTest.Test>
) => {
Expand All @@ -71,19 +65,14 @@ export const createConnector = async ({
config,
secrets,
connectorTypeId,
getPageObject,
getService,
supertest,
}: {
name: string;
config: Record<string, unknown>;
secrets: Record<string, unknown>;
connectorTypeId: string;
getPageObject: FtrProviderContext['getPageObject'];
getService: FtrProviderContext['getService'];
supertest: SuperTest.SuperTest<SuperTest.Test>;
}) => {
const common = getPageObject('common');
const supertest = getService('supertest');

const { body: createdAction } = await supertest
.post(`/api/actions/connector`)
.set('kbn-xsrf', 'foo')
Expand All @@ -95,7 +84,5 @@ export const createConnector = async ({
})
.expect(200);

await common.navigateToApp('triggersActionsConnectors');

return createdAction;
};

0 comments on commit f67d32b

Please sign in to comment.