Skip to content

Commit

Permalink
[Actions UI] Fixed Connectors edit flyout retains state after being c…
Browse files Browse the repository at this point in the history
…losed (#71911)

* [Actions UI] Fixed Connectors edit flyout retains state after being closed

* Fixed failing test
  • Loading branch information
YulNaumenko authored Jul 16, 2020
1 parent d0afbd8 commit b7bb193
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,20 @@ export const ConnectorEditFlyout = ({
consumer,
} = useActionsConnectorsContext();
const canSave = hasSaveActionsCapability(capabilities);
const closeFlyout = useCallback(() => setEditFlyoutVisibility(false), [setEditFlyoutVisibility]);

const [{ connector }, dispatch] = useReducer(connectorReducer, {
connector: { ...initialConnector, secrets: {} },
});
const [isSaving, setIsSaving] = useState<boolean>(false);
const setConnector = (key: string, value: any) => {
dispatch({ command: { type: 'setConnector' }, payload: { key, value } });
};

const closeFlyout = useCallback(() => {
setEditFlyoutVisibility(false);
setConnector('connector', { ...initialConnector, secrets: {} });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [setEditFlyoutVisibility]);

if (!editFlyoutVisible) {
return null;
Expand Down Expand Up @@ -213,7 +222,7 @@ export const ConnectorEditFlyout = ({
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiButtonEmpty onClick={closeFlyout}>
<EuiButtonEmpty onClick={closeFlyout} data-test-subj="cancelSaveEditedConnectorButton">
{i18n.translate(
'xpack.triggersActionsUI.sections.editConnectorForm.cancelButtonLabel',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
it('should edit a connector', async () => {
const connectorName = generateUniqueKey();
const updatedConnectorName = `${connectorName}updated`;

await pageObjects.triggersActionsUI.clickCreateConnectorButton();

await testSubjects.click('.slack-card');

await testSubjects.setValue('nameInput', connectorName);

await testSubjects.setValue('slackWebhookUrlInput', 'https://test');

await find.clickByCssSelector('[data-test-subj="saveNewActionButton"]:not(disabled)');

await pageObjects.common.closeToast();
await createConnector(connectorName);

await pageObjects.triggersActionsUI.searchConnectors(connectorName);

Expand Down Expand Up @@ -103,19 +92,31 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
]);
});

it('should delete a connector', async () => {
async function createConnector(connectorName: string) {
await pageObjects.triggersActionsUI.clickCreateConnectorButton();
it('should reset connector when canceling an edit', async () => {
const connectorName = generateUniqueKey();
await createConnector(connectorName);
await pageObjects.triggersActionsUI.searchConnectors(connectorName);

const searchResultsBeforeEdit = await pageObjects.triggersActionsUI.getConnectorsList();
expect(searchResultsBeforeEdit.length).to.eql(1);

await testSubjects.click('.slack-card');
await find.clickByCssSelector('[data-test-subj="connectorsTableCell-name"] button');

await testSubjects.setValue('nameInput', connectorName);
await testSubjects.setValue('nameInput', 'some test name to cancel');
await testSubjects.click('cancelSaveEditedConnectorButton');

await testSubjects.setValue('slackWebhookUrlInput', 'https://test');
await find.waitForDeletedByCssSelector('[data-test-subj="cancelSaveEditedConnectorButton"]');

await find.clickByCssSelector('[data-test-subj="saveNewActionButton"]:not(disabled)');
await pageObjects.common.closeToast();
}
await pageObjects.triggersActionsUI.searchConnectors(connectorName);

await find.clickByCssSelector('[data-test-subj="connectorsTableCell-name"] button');
const nameInputAfterCancel = await testSubjects.find('nameInput');
const textAfterCancel = await nameInputAfterCancel.getAttribute('value');
expect(textAfterCancel).to.eql(connectorName);
await testSubjects.click('euiFlyoutCloseButton');
});

it('should delete a connector', async () => {
const connectorName = generateUniqueKey();
await createConnector(connectorName);

Expand All @@ -141,19 +142,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

it('should bulk delete connectors', async () => {
async function createConnector(connectorName: string) {
await pageObjects.triggersActionsUI.clickCreateConnectorButton();

await testSubjects.click('.slack-card');

await testSubjects.setValue('nameInput', connectorName);

await testSubjects.setValue('slackWebhookUrlInput', 'https://test');

await find.clickByCssSelector('[data-test-subj="saveNewActionButton"]:not(disabled)');
await pageObjects.common.closeToast();
}

const connectorName = generateUniqueKey();
await createConnector(connectorName);

Expand Down Expand Up @@ -208,4 +196,17 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
expect(await testSubjects.exists('saveEditedActionButton')).to.be(false);
});
});

async function createConnector(connectorName: string) {
await pageObjects.triggersActionsUI.clickCreateConnectorButton();

await testSubjects.click('.slack-card');

await testSubjects.setValue('nameInput', connectorName);

await testSubjects.setValue('slackWebhookUrlInput', 'https://test');

await find.clickByCssSelector('[data-test-subj="saveNewActionButton"]:not(disabled)');
await pageObjects.common.closeToast();
}
};

0 comments on commit b7bb193

Please sign in to comment.