Skip to content

Commit

Permalink
[ML] Transforms: Add functional tests for UI permissions (elastic#106693
Browse files Browse the repository at this point in the history
)

* [ML] Transforms: Add functional tests for UI permissions

* [ML] Fix for edit flyout action

* [ML] Stabilize tests that open the actions menu
  • Loading branch information
peteharverson authored and kibanamachine committed Jul 28, 2021
1 parent d796576 commit 09bb1a1
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,33 @@ export const EditTransformFlyoutForm: FC<EditTransformFlyoutFormProps> = ({
)}
paddingSize="s"
>
<EditTransformFlyoutFormTextInput
dataTestSubj="transformEditFlyoutDestinationIndexInput"
errorMessages={formFields.destinationIndex.errorMessages}
label={i18n.translate(
'xpack.transform.transformList.editFlyoutFormDestinationIndexLabel',
{
defaultMessage: 'Destination index',
}
)}
onChange={(value) => dispatch({ field: 'destinationIndex', value })}
value={formFields.destinationIndex.value}
/>

<EditTransformFlyoutFormTextInput
dataTestSubj="transformEditFlyoutDestinationPipelineInput"
errorMessages={formFields.destinationPipeline.errorMessages}
label={i18n.translate(
'xpack.transform.transformList.editFlyoutFormDestinationPipelineLabel',
{
defaultMessage: 'Pipeline',
}
)}
onChange={(value) => dispatch({ field: 'destinationPipeline', value })}
value={formFields.destinationPipeline.value}
/>
<div data-test-subj="transformEditAccordionDestinationContent">
<EditTransformFlyoutFormTextInput
dataTestSubj="transformEditFlyoutDestinationIndexInput"
errorMessages={formFields.destinationIndex.errorMessages}
label={i18n.translate(
'xpack.transform.transformList.editFlyoutFormDestinationIndexLabel',
{
defaultMessage: 'Destination index',
}
)}
onChange={(value) => dispatch({ field: 'destinationIndex', value })}
value={formFields.destinationIndex.value}
/>

<EditTransformFlyoutFormTextInput
dataTestSubj="transformEditFlyoutDestinationPipelineInput"
errorMessages={formFields.destinationPipeline.errorMessages}
label={i18n.translate(
'xpack.transform.transformList.editFlyoutFormDestinationPipelineLabel',
{
defaultMessage: 'Pipeline',
}
)}
onChange={(value) => dispatch({ field: 'destinationPipeline', value })}
value={formFields.destinationPipeline.value}
/>
</div>
</EuiAccordion>

<EuiSpacer size="l" />
Expand All @@ -109,31 +111,33 @@ export const EditTransformFlyoutForm: FC<EditTransformFlyoutFormProps> = ({
)}
paddingSize="s"
>
<EditTransformFlyoutFormTextInput
dataTestSubj="transformEditFlyoutRetentionPolicyFieldInput"
errorMessages={formFields.retentionPolicyField.errorMessages}
label={i18n.translate(
'xpack.transform.transformList.editFlyoutFormRetentionPolicyFieldLabel',
{
defaultMessage: 'Field',
}
)}
onChange={(value) => dispatch({ field: 'retentionPolicyField', value })}
value={formFields.retentionPolicyField.value}
/>

<EditTransformFlyoutFormTextInput
dataTestSubj="transformEditFlyoutRetentionPolicyMaxAgeInput"
errorMessages={formFields.retentionPolicyMaxAge.errorMessages}
label={i18n.translate(
'xpack.transform.transformList.editFlyoutFormRetentionMaxAgeFieldLabel',
{
defaultMessage: 'Max age',
}
)}
onChange={(value) => dispatch({ field: 'retentionPolicyMaxAge', value })}
value={formFields.retentionPolicyMaxAge.value}
/>
<div data-test-subj="transformEditAccordionRetentionPolicyContent">
{' '}
<EditTransformFlyoutFormTextInput
dataTestSubj="transformEditFlyoutRetentionPolicyFieldInput"
errorMessages={formFields.retentionPolicyField.errorMessages}
label={i18n.translate(
'xpack.transform.transformList.editFlyoutFormRetentionPolicyFieldLabel',
{
defaultMessage: 'Field',
}
)}
onChange={(value) => dispatch({ field: 'retentionPolicyField', value })}
value={formFields.retentionPolicyField.value}
/>
<EditTransformFlyoutFormTextInput
dataTestSubj="transformEditFlyoutRetentionPolicyMaxAgeInput"
errorMessages={formFields.retentionPolicyMaxAge.errorMessages}
label={i18n.translate(
'xpack.transform.transformList.editFlyoutFormRetentionMaxAgeFieldLabel',
{
defaultMessage: 'Max age',
}
)}
onChange={(value) => dispatch({ field: 'retentionPolicyMaxAge', value })}
value={formFields.retentionPolicyMaxAge.value}
/>
</div>
</EuiAccordion>

<EuiSpacer size="l" />
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/transform/cloning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export default function ({ getService }: FtrProviderContext) {
await transform.table.assertTransformRowActions(testData.originalConfig.id, false);

await transform.testExecution.logTestStep('should display the define pivot step');
await transform.table.clickTransformRowAction('Clone');
await transform.table.clickTransformRowAction(testData.originalConfig.id, 'Clone');
await transform.wizard.assertSelectedTransformFunction(testData.type);
await transform.wizard.assertDefineStepActive();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ export default function ({ getService }: FtrProviderContext) {
await transform.table.assertTransformRowActions(testData.transformId, false);

await transform.testExecution.logTestStep('should navigate to discover');
await transform.table.clickTransformRowAction('Discover');
await transform.table.clickTransformRowAction(testData.transformId, 'Discover');

if (testData.discoverAdjustSuperDatePicker) {
await transform.discover.assertNoResults(testData.destinationIndex);
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/functional/apps/transform/deleting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function ({ getService }: FtrProviderContext) {
);

await transform.testExecution.logTestStep('should stop the transform');
await transform.table.clickTransformRowAction('Stop');
await transform.table.clickTransformRowAction(testData.originalConfig.id, 'Stop');
}

await transform.testExecution.logTestStep('should display the stopped transform');
Expand All @@ -117,7 +117,7 @@ export default function ({ getService }: FtrProviderContext) {
'Delete',
true
);
await transform.table.clickTransformRowAction('Delete');
await transform.table.clickTransformRowAction(testData.originalConfig.id, 'Delete');
await transform.table.assertTransformDeleteModalExists();

await transform.testExecution.logTestStep('should delete the transform');
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/transform/editing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function ({ getService }: FtrProviderContext) {
await transform.table.assertTransformRowActions(testData.originalConfig.id, false);

await transform.testExecution.logTestStep('should show the edit flyout');
await transform.table.clickTransformRowAction('Edit');
await transform.table.clickTransformRowAction(testData.originalConfig.id, 'Edit');
await transform.editFlyout.assertTransformEditFlyoutExists();
});

Expand Down
1 change: 1 addition & 0 deletions x-pack/test/functional/apps/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
await transform.securityUI.logout();
});

loadTestFile(require.resolve('./permissions'));
loadTestFile(require.resolve('./creation_index_pattern'));
loadTestFile(require.resolve('./creation_saved_search'));
loadTestFile(require.resolve('./creation_runtime_mappings'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* 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 { getPivotTransformConfig } from '../index';

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

export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const transform = getService('transform');

describe('for user with full transform access', function () {
describe('with no data loaded', function () {
before(async () => {
await transform.securityUI.loginAsTransformPowerUser();
});

after(async () => {
await transform.securityUI.logout();
});

it('should display elements in the Transform list page correctly', async () => {
await transform.testExecution.logTestStep('should load the Transform list page');
await transform.navigation.navigateTo();
await transform.management.assertTransformListPageExists();

await transform.testExecution.logTestStep('should display the stats bar');
await transform.management.assertTransformStatsBarExists();

await transform.testExecution.logTestStep(
'should display the "No transforms found" message'
);
await transform.management.assertNoTransformsFoundMessageExists();

await transform.testExecution.logTestStep(
'should display an enabled "Create first transform" button'
);
await transform.management.assertCreateFirstTransformButtonExists();
await transform.management.assertCreateFirstTransformButtonEnabled(true);
});
});

describe('with data loaded', function () {
const PREFIX = 'permissions_full_access';
const transformConfigWithPivot = getPivotTransformConfig(PREFIX, false);

before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/ecommerce');
await transform.testResources.createIndexPatternIfNeeded('ft_ecommerce', 'order_date');

await transform.api.createAndRunTransform(
transformConfigWithPivot.id,
transformConfigWithPivot
);

await transform.testResources.setKibanaTimeZoneToUTC();
await transform.securityUI.loginAsTransformPowerUser();
});

after(async () => {
await transform.testResources.deleteIndexPatternByTitle(
transformConfigWithPivot.dest.index
);
await transform.api.deleteIndices(transformConfigWithPivot.dest.index);
await transform.api.cleanTransformIndices();
});

it('should display elements in the Transform list page correctly', async () => {
await transform.testExecution.logTestStep('should load the Transform list page');
await transform.navigation.navigateTo();
await transform.management.assertTransformListPageExists();

await transform.testExecution.logTestStep('should display the stats bar');
await transform.management.assertTransformStatsBarExists();

await transform.testExecution.logTestStep('should display the transforms table');
await transform.management.assertTransformsTableExists();

await transform.testExecution.logTestStep(
'should display an enabled "Create a transform" button'
);
await transform.management.assertCreateNewTransformButtonExists();
await transform.management.assertCreateNewTransformButtonEnabled(true);

await transform.testExecution.logTestStep(
'should display the expected transform in the transform list'
);
await transform.table.refreshTransformList();
await transform.table.filterWithSearchString(transformConfigWithPivot.id, 1);

await transform.testExecution.logTestStep('should show the actions popover');
await transform.table.assertTransformRowActionsButtonEnabled(
transformConfigWithPivot.id,
true
);
await transform.table.assertTransformRowActions(transformConfigWithPivot.id, false);

await transform.testExecution.logTestStep('should have the edit action enabled');
await transform.table.assertTransformRowActionEnabled(
transformConfigWithPivot.id,
'Edit',
true
);

await transform.testExecution.logTestStep('should have the clone action enabled');
await transform.table.assertTransformRowActionEnabled(
transformConfigWithPivot.id,
'Clone',
true
);
await transform.testExecution.logTestStep('should have the delete action enabled');
await transform.table.assertTransformRowActionEnabled(
transformConfigWithPivot.id,
'Delete',
true
);
await transform.testExecution.logTestStep('should have the Discover action disabled');
await transform.table.assertTransformRowActionEnabled(
transformConfigWithPivot.id,
'Discover',
false
);
await transform.testExecution.logTestStep('should have the start action disabled');
await transform.table.assertTransformRowActionEnabled(
transformConfigWithPivot.id,
'Start',
false
);

await transform.testExecution.logTestStep('should show content in the expanded table row');
await transform.table.assertTransformExpandedRow();
});

it('should display controls in the edit flyout correctly', async () => {
await transform.testExecution.logTestStep('should show the edit flyout');
await transform.table.clickTransformRowAction(transformConfigWithPivot.id, 'Edit');
await transform.editFlyout.assertTransformEditFlyoutExists();

await transform.testExecution.logTestStep('should have the description input enabled');
await transform.editFlyout.assertTransformEditFlyoutInputEnabled('Description', true);

await transform.testExecution.logTestStep('should have the frequency input enabled');
await transform.editFlyout.assertTransformEditFlyoutInputEnabled('Frequency', true);

await transform.testExecution.logTestStep('should have the destination inputs enabled');
await transform.editFlyout.openTransformEditAccordionDestinationSettings();
await transform.editFlyout.assertTransformEditFlyoutInputEnabled('DestinationIndex', true);
await transform.editFlyout.assertTransformEditFlyoutInputEnabled(
'DestinationPipeline',
true
);

await transform.testExecution.logTestStep(
'should have the retention policy inputs enabled'
);
await transform.editFlyout.openTransformEditAccordionRetentionPolicySettings();
await transform.editFlyout.assertTransformEditFlyoutInputEnabled(
'RetentionPolicyField',
true
);
await transform.editFlyout.assertTransformEditFlyoutInputEnabled(
'RetentionPolicyMaxAge',
true
);

await transform.testExecution.logTestStep(
'should have the advanced settings inputs enabled'
);
await transform.editFlyout.openTransformEditAccordionAdvancedSettings();
await transform.editFlyout.assertTransformEditFlyoutInputEnabled('DocsPerSecond', true);
await transform.editFlyout.assertTransformEditFlyoutInputEnabled('MaxPageSearchSize', true);

await transform.testExecution.logTestStep(
'should have the update button enabled after making an edit'
);
await transform.editFlyout.assertTransformEditFlyoutInputExists('Frequency');
await transform.editFlyout.setTransformEditFlyoutInputValue('Frequency', '10m');
await transform.editFlyout.assertUpdateTransformButtonExists();
await transform.editFlyout.assertUpdateTransformButtonEnabled(true);
});
});
});
}
15 changes: 15 additions & 0 deletions x-pack/test/functional/apps/transform/permissions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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('permissions', function () {
loadTestFile(require.resolve('./full_transform_access'));
loadTestFile(require.resolve('./read_transform_access'));
});
}
Loading

0 comments on commit 09bb1a1

Please sign in to comment.