Skip to content

Commit

Permalink
[ML] Functional tests - add UI permission tests (#76368) (#76738)
Browse files Browse the repository at this point in the history
This PR adds automated tests for ML UI permissions with both permission models (ES based and spaces based).
  • Loading branch information
pheyos authored Sep 4, 2020
1 parent 37685e9 commit d001cf2
Show file tree
Hide file tree
Showing 91 changed files with 2,802 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ class LinksMenuUI extends Component {
defaultMessage: 'Select action for anomaly at {time}',
values: { time: formatHumanReadableDateTimeSeconds(anomaly.time) },
})}
data-test-subj="mlAnomaliesListRowActionsButton"
/>
);

Expand All @@ -404,6 +405,7 @@ class LinksMenuUI extends Component {
this.closePopover();
this.openCustomUrl(customUrl);
}}
data-test-subj={`mlAnomaliesListRowActionCustomUrlButton_${index}`}
>
{customUrl.url_name}
</EuiContextMenuItem>
Expand All @@ -420,6 +422,7 @@ class LinksMenuUI extends Component {
this.closePopover();
this.viewSeries();
}}
data-test-subj="mlAnomaliesListRowActionViewSeriesButton"
>
<FormattedMessage
id="xpack.ml.anomaliesTable.linksMenu.viewSeriesLabel"
Expand All @@ -438,6 +441,7 @@ class LinksMenuUI extends Component {
this.closePopover();
this.viewExamples();
}}
data-test-subj="mlAnomaliesListRowActionViewExamplesButton"
>
<FormattedMessage
id="xpack.ml.anomaliesTable.linksMenu.viewExamplesLabel"
Expand All @@ -456,6 +460,7 @@ class LinksMenuUI extends Component {
this.closePopover();
this.props.showRuleEditorFlyout(anomaly);
}}
data-test-subj="mlAnomaliesListRowActionConfigureRulesButton"
>
<FormattedMessage
id="xpack.ml.anomaliesTable.linksMenu.configureRulesLabel"
Expand All @@ -473,7 +478,7 @@ class LinksMenuUI extends Component {
panelPaddingSize="none"
anchorPosition="downLeft"
>
<EuiContextMenuPanel items={items} />
<EuiContextMenuPanel items={items} data-test-subj="mlAnomaliesListRowActionsMenu" />
</EuiPopover>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const RecognizedResult = ({ config, indexPattern, savedSearch }) => {
return (
<EuiFlexItem>
<CreateJobLinkCard
data-test-subj={id}
data-test-subj={`mlRecognizerCard ${config.id}`}
href={href}
title={config.title}
description={config.description}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ export function ItemsGrid({
const pageItems = items.slice(startIndex, startIndex + itemsPerPage);
const gridItems = pageItems.map((item, index) => {
return (
<EuiFlexItem key={`ml_grid_item_${index}`}>
<EuiFlexItem key={`ml_grid_item_${index}`} data-test-subj={`mlGridItem ${item}`}>
<EuiCheckbox
id={`ml_grid_item_${index}`}
label={item}
checked={selectedItems.indexOf(item) >= 0}
onChange={(e) => {
setItemSelected(item, e.target.checked);
}}
data-test-subj={`mlGridItemCheckbox`}
/>
</EuiFlexItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export const DataFrameAnalyticsList: FC<Props> = ({

if (analytics.length === 0) {
return (
<>
<div data-test-subj="mlAnalyticsJobList">
<AnalyticsEmptyPrompt
isManagementTable={isManagementTable}
disabled={disabled}
Expand All @@ -227,7 +227,7 @@ export const DataFrameAnalyticsList: FC<Props> = ({
{isSourceIndexModalVisible === true && (
<SourceSelection onClose={() => setIsSourceIndexModalVisible(false)} />
)}
</>
</div>
);
}

Expand All @@ -251,7 +251,7 @@ export const DataFrameAnalyticsList: FC<Props> = ({
);

return (
<>
<div data-test-subj="mlAnalyticsJobList">
{modals}
{!isManagementTable && <EuiSpacer size="m" />}
<EuiFlexGroup justifyContent="spaceBetween">
Expand Down Expand Up @@ -301,6 +301,6 @@ export const DataFrameAnalyticsList: FC<Props> = ({
{isSourceIndexModalVisible === true && (
<SourceSelection onClose={() => setIsSourceIndexModalVisible(false)} />
)}
</>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function ResultLinks({ jobs }) {
aria-label={openJobsInSingleMetricViewerText}
className="results-button"
isDisabled={singleMetricEnabled === false || jobActionsDisabled === true}
data-test-subj={`openJobsInSingleMetricViewer openJobsInSingleMetricViewer-${jobs[0].id}`}
data-test-subj="mlOpenJobsInSingleMetricViewerButton"
/>
</EuiToolTip>
)}
Expand All @@ -66,7 +66,7 @@ export function ResultLinks({ jobs }) {
aria-label={openJobsInAnomalyExplorerText}
className="results-button"
isDisabled={jobActionsDisabled === true}
data-test-subj={`openJobsInAnomalyExplorer openJobsInSingleAnomalyExplorer-${jobs[0].id}`}
data-test-subj="mlOpenJobsInAnomalyExplorerButton"
/>
</EuiToolTip>
<div className="actions-border" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MultiJobActionsMenuUI extends Component {
disabled={
anyJobsDeleting || (this.canDeleteJob === false && this.canStartStopDatafeed === false)
}
data-test-subj="mlADJobListMultiSelectManagementActionsButton"
/>
);

Expand All @@ -69,6 +70,7 @@ class MultiJobActionsMenuUI extends Component {
this.props.showDeleteJobModal(this.props.jobs);
this.closePopover();
}}
data-test-subj="mlADJobListMultiSelectDeleteJobActionButton"
>
<FormattedMessage
id="xpack.ml.jobsList.multiJobsActions.deleteJobsLabel"
Expand All @@ -88,6 +90,7 @@ class MultiJobActionsMenuUI extends Component {
closeJobs(this.props.jobs);
this.closePopover();
}}
data-test-subj="mlADJobListMultiSelectCloseJobActionButton"
>
<FormattedMessage
id="xpack.ml.jobsList.multiJobsActions.closeJobsLabel"
Expand All @@ -108,6 +111,7 @@ class MultiJobActionsMenuUI extends Component {
stopDatafeeds(this.props.jobs, this.props.refreshJobs);
this.closePopover();
}}
data-test-subj="mlADJobListMultiSelectStopDatafeedActionButton"
>
<FormattedMessage
id="xpack.ml.jobsList.multiJobsActions.stopDatafeedsLabel"
Expand All @@ -128,6 +132,7 @@ class MultiJobActionsMenuUI extends Component {
this.props.showStartDatafeedModal(this.props.jobs);
this.closePopover();
}}
data-test-subj="mlADJobListMultiSelectStartDatafeedActionButton"
>
<FormattedMessage
id="xpack.ml.jobsList.multiJobsActions.startDatafeedsLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class GroupSelector extends Component {
)}
onClick={() => this.togglePopover()}
disabled={this.canUpdateJob === false}
data-test-subj="mlADJobListMultiSelectEditJobGroupsButton"
/>
</EuiToolTip>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export class MultiJobActions extends Component {
render() {
const jobsSelected = this.props.selectedJobs.length > 0;
return (
<div className={`multi-select-actions${jobsSelected ? '' : '-no-display'}`}>
<div
className={`multi-select-actions${jobsSelected ? '' : '-no-display'}`}
data-test-subj={`mlADJobListMultiSelectActionsArea ${jobsSelected ? 'active' : 'inactive'}`}
>
{jobsSelected && (
<Fragment>
<EuiTitle size="s" style={{ display: 'inline' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {

export const AccessDeniedPage = () => (
<Fragment>
<EuiPage>
<EuiPage data-test-subj="mlPageAccessDenied">
<EuiPageBody>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ViewLink: FC<Props> = ({ item }) => {
iconType="visTable"
aria-label={viewJobResultsButtonText}
className="results-button"
data-test-subj="mlAnalyticsJobViewButton"
data-test-subj="mlOverviewAnalyticsJobViewButton"
isDisabled={disabled}
>
{i18n.translate('xpack.ml.overview.analytics.viewActionName', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const AnalyticsPanel: FC<Props> = ({ jobCreationDisabled }) => {
fill
iconType="plusInCircle"
isDisabled={jobCreationDisabled}
data-test-subj="mlOverviewCreateDFAJobButton"
>
{i18n.translate('xpack.ml.overview.analyticsList.createJobButtonText', {
defaultMessage: 'Create job',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export const AnomalyDetectionPanel: FC<Props> = ({ jobCreationDisabled }) => {
fill
iconType="plusInCircle"
isDisabled={jobCreationDisabled}
data-test-subj="mlOverviewCreateADJobButton"
>
{i18n.translate('xpack.ml.overview.anomalyDetection.createJobButtonText', {
defaultMessage: 'Create job',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const CalendarForm = ({
checked={isGlobalCalendar}
onChange={onGlobalCalendarChange}
disabled={saving === true || canCreateCalendar === false}
data-test-subj="mlCalendarApplyToAllJobsSwitch"
/>

{isGlobalCalendar === false && (
Expand All @@ -166,6 +167,7 @@ export const CalendarForm = ({
selectedOptions={selectedJobOptions}
onChange={onJobSelection}
isDisabled={saving === true || canCreateCalendar === false}
data-test-subj="mlCalendarJobSelection"
/>
</EuiFormRow>

Expand All @@ -183,6 +185,7 @@ export const CalendarForm = ({
selectedOptions={selectedGroupOptions}
onChange={onGroupSelection}
isDisabled={saving === true || canCreateCalendar === false}
data-test-subj="mlCalendarJobGroupSelection"
/>
</EuiFormRow>
</>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { TIME_FORMAT } from '../../../../../../common/constants/time_format';

function DeleteButton({ onClick, canDeleteCalendar }) {
function DeleteButton({ onClick, canDeleteCalendar, testSubj }) {
return (
<Fragment>
<EuiButtonEmpty
size="xs"
color="danger"
onClick={onClick}
isDisabled={canDeleteCalendar === false}
data-test-subj={testSubj}
>
<FormattedMessage
id="xpack.ml.calendarsEdit.eventsTable.deleteButtonLabel"
Expand Down Expand Up @@ -90,7 +91,7 @@ export const EventsTable = ({
name: '',
render: (event) => (
<DeleteButton
data-test-subj="mlEventDelete"
testSubj="mlCalendarEventDeleteButton"
canDeleteCalendar={canDeleteCalendar}
onClick={() => {
onDeleteClick(event.event_id);
Expand All @@ -105,7 +106,7 @@ export const EventsTable = ({
<EuiButton
isDisabled={canCreateCalendar === false}
key="ml_new_event"
data-test-subj="mlNewEvent"
data-test-subj="mlCalendarNewEventButton"
size="s"
iconType="plusInCircle"
onClick={showNewEventModal}
Expand All @@ -118,7 +119,7 @@ export const EventsTable = ({
<EuiButton
isDisabled={canCreateCalendar === false}
key="ml_import_event"
data-test-subj="mlImportEvents"
data-test-subj="mlCalendarImportEventsButton"
size="s"
iconType="importAction"
onClick={showImportModal}
Expand All @@ -145,6 +146,10 @@ export const EventsTable = ({
pagination={pagination}
sorting={sorting}
search={showSearchBar ? search : undefined}
data-test-subj="mlCalendarEventsTable"
rowProps={(item) => ({
'data-test-subj': `mlCalendarEventListRow row-${item.description}`,
})}
/>
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('ImportModal', () => {
instance.setState(testState);
wrapper.update();
expect(wrapper.state('selectedEvents').length).toBe(2);
const deleteButton = wrapper.find('[data-test-subj="mlEventDelete"]');
const deleteButton = wrapper.find('[data-test-subj="mlCalendarEventDeleteButton"]');
const button = deleteButton.find('EuiButtonEmpty').first();
button.simulate('click');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class NewCalendarUI extends Component {
return (
<Fragment>
<NavigationMenu tabId="settings" />
<EuiPage className="mlCalendarEditForm">
<EuiPage className="mlCalendarEditForm" data-test-subj="mlPageCalendarEdit">
<EuiPageBody>
<EuiPageContent
className="mlCalendarEditForm__content"
Expand Down
Loading

0 comments on commit d001cf2

Please sign in to comment.