Skip to content

Commit

Permalink
[8.x] [ResponseOps][NewRuleForm] Update functional tests to use new r…
Browse files Browse the repository at this point in the history
…ule form for stack management (#198915) (#202212)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][NewRuleForm] Update functional tests to use new rule
form for stack management
(#198915)](#198915)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Janki
Salvi","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-28T16:50:07Z","message":"[ResponseOps][NewRuleForm]
Update functional tests to use new rule form for stack management
(#198915)\n\n## Summary\r\n\r\nMeta issue
https://github.com/elastic/kibana/issues/196235\r\n\r\nThis PR updates
existing e2e tests to use the new rule form instead of\r\nold rule
flyout for `stack management > rules`\r\n\r\n### Flaky test
runner\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7488\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7530\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"a89698712b77fd6d4745e82123dccb2758b42e63","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","v9.0.0","Feature:Alerting/RulesManagement","backport:prev-minor","v8.18.0"],"title":"[ResponseOps][NewRuleForm]
Update functional tests to use new rule form for stack
management","number":198915,"url":"https://github.com/elastic/kibana/pull/198915","mergeCommit":{"message":"[ResponseOps][NewRuleForm]
Update functional tests to use new rule form for stack management
(#198915)\n\n## Summary\r\n\r\nMeta issue
https://github.com/elastic/kibana/issues/196235\r\n\r\nThis PR updates
existing e2e tests to use the new rule form instead of\r\nold rule
flyout for `stack management > rules`\r\n\r\n### Flaky test
runner\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7488\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7530\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"a89698712b77fd6d4745e82123dccb2758b42e63"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198915","number":198915,"mergeCommit":{"message":"[ResponseOps][NewRuleForm]
Update functional tests to use new rule form for stack management
(#198915)\n\n## Summary\r\n\r\nMeta issue
https://github.com/elastic/kibana/issues/196235\r\n\r\nThis PR updates
existing e2e tests to use the new rule form instead of\r\nold rule
flyout for `stack management > rules`\r\n\r\n### Flaky test
runner\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7488\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7530\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"a89698712b77fd6d4745e82123dccb2758b42e63"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Janki Salvi <[email protected]>
  • Loading branch information
kibanamachine and js-jankisalvi authored Nov 28, 2024
1 parent c171c0e commit 4581688
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 352 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
multiConsumerSelection,
validConsumers,
ruleType,
ruleTypes,
}),
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('rulePage', () => {
render(<RulePage onCancel={onCancel} onSave={onSave} />);

fireEvent.click(screen.getByTestId('rulePageFooterCancelButton'));
expect(screen.getByTestId('ruleFormCancelModal')).toBeInTheDocument();
expect(screen.getByTestId('confirmRuleCloseModal')).toBeInTheDocument();
});

test('should not display discard changes modal id no changes are made in the form', () => {
Expand Down Expand Up @@ -181,6 +181,6 @@ describe('rulePage', () => {
render(<RulePage onCancel={onCancel} onSave={onSave} />);

fireEvent.click(screen.getByTestId('rulePageFooterCancelButton'));
expect(screen.queryByTestId('ruleFormCancelModal')).not.toBeInTheDocument();
expect(screen.queryByTestId('confirmRuleCloseModal')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const RulePage = (props: RulePageProps) => {
<EuiConfirmModal
onCancel={() => setIsCancelModalOpen(false)}
onConfirm={onCancel}
data-test-subj="ruleFormCancelModal"
data-test-subj="confirmRuleCloseModal"
buttonColor="danger"
defaultFocusedButton="confirm"
title={RULE_FORM_CANCEL_MODAL_TITLE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AlertConsumers, RuleCreationValidConsumer } from '@kbn/rule-data-utils'
import { RuleTypeWithDescription } from '../../common/types';
import { MULTI_CONSUMER_RULE_TYPE_IDS } from '../constants';
import { FEATURE_NAME_MAP } from '../translations';
import { getAuthorizedConsumers } from './get_authorized_consumers';

export const getValidatedMultiConsumer = ({
multiConsumerSelection,
Expand All @@ -33,10 +34,12 @@ export const getInitialMultiConsumer = ({
multiConsumerSelection,
validConsumers,
ruleType,
ruleTypes,
}: {
multiConsumerSelection?: RuleCreationValidConsumer | null;
validConsumers: RuleCreationValidConsumer[];
ruleType: RuleTypeWithDescription;
ruleTypes: RuleTypeWithDescription[];
}): RuleCreationValidConsumer | null => {
// If rule type doesn't support multi-consumer or no valid consumers exists,
// return nothing
Expand All @@ -54,6 +57,23 @@ export const getInitialMultiConsumer = ({
return AlertConsumers.OBSERVABILITY;
}

const selectedAvailableRuleType = ruleTypes.find((availableRuleType) => {
return availableRuleType.id === ruleType.id;
});

if (!selectedAvailableRuleType?.authorizedConsumers) {
return null;
}

const authorizedConsumers = getAuthorizedConsumers({
ruleType: selectedAvailableRuleType,
validConsumers,
});

if (authorizedConsumers.length === 1) {
return authorizedConsumers[0];
}

// User passed in null explicitly, won't set initial consumer
if (multiConsumerSelection === null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/services/ml/alerting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function MachineLearningAlertingProvider(
async selectAnomalyDetectionAlertType() {
await retry.tryForTime(5000, async () => {
await testSubjects.click('xpack.ml.anomaly_detection_alert-SelectOption');
await testSubjects.existOrFail(`mlAnomalyAlertForm`, { timeout: 1000 });
await testSubjects.existOrFail(`mlAnomalyAlertForm`);
});
},

Expand Down
10 changes: 4 additions & 6 deletions x-pack/test/functional/services/rules/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function RulesCommonServiceProvider({ getService, getPageObject }: FtrPro
},

async cancelRuleCreation() {
await testSubjects.click('cancelSaveRuleButton');
await testSubjects.click('rulePageFooterCancelButton');
await testSubjects.existOrFail('confirmRuleCloseModal');
await testSubjects.click('confirmRuleCloseModal > confirmModalConfirmButton');
await testSubjects.missingOrFail('confirmRuleCloseModal');
Expand All @@ -43,8 +43,6 @@ export function RulesCommonServiceProvider({ getService, getPageObject }: FtrPro
await browser.refresh();
await this.clickCreateAlertButton();
await testSubjects.click(`.index-threshold-SelectOption`);
await testSubjects.scrollIntoView('ruleNameInput');
await testSubjects.setValue('ruleNameInput', alertName);
await testSubjects.scrollIntoView('selectIndexExpression');
await testSubjects.click('selectIndexExpression');
await comboBox.set('thresholdIndexesComboBox', 'k');
Expand All @@ -55,9 +53,6 @@ export function RulesCommonServiceProvider({ getService, getPageObject }: FtrPro
await fieldOptions[1].click();
});
await testSubjects.click('closePopover');
// need this two out of popup clicks to close them
const nameInput = await testSubjects.find('ruleNameInput');
await nameInput.click();

await testSubjects.click('whenExpression');
await testSubjects.click('whenExpressionSelect');
Expand All @@ -74,6 +69,9 @@ export function RulesCommonServiceProvider({ getService, getPageObject }: FtrPro
const ofOptions = ofOptionsString.trim().split('\n');
expect(ofOptions.length > 0).to.be(true);
await comboBox.set('availableFieldsOptionsComboBox', ofOptions[0]);

await testSubjects.scrollIntoView('ruleDetailsNameInput');
await testSubjects.setValue('ruleDetailsNameInput', alertName);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

await testSubjects.click('thresholdPopover');
await testSubjects.setValue('alertThresholdInput0', '1');
await testSubjects.click('saveEditedRuleButton');
await testSubjects.click('rulePageFooterSaveButton');
await PageObjects.header.waitUntilLoadingHasFinished();

await openAlertResults(RULE_NAME);
Expand Down Expand Up @@ -622,8 +622,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.header.waitUntilLoadingHasFinished();

await retry.waitFor('rule name value is correct', async () => {
await testSubjects.setValue('ruleNameInput', newAlert);
const ruleName = await testSubjects.getAttribute('ruleNameInput', 'value');
await testSubjects.setValue('ruleDetailsNameInput', newAlert);
const ruleName = await testSubjects.getAttribute('ruleDetailsNameInput', 'value');
return ruleName === newAlert;
});

Expand All @@ -641,10 +641,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
);
await sourceDataViewOption.click();

await testSubjects.click('saveRuleButton');
await testSubjects.click('rulePageFooterSaveButton');

await retry.waitFor('confirmation modal', async () => {
return await testSubjects.exists('confirmModalConfirmButton');
return await testSubjects.exists('rulePageConfirmCreateRule');
});

await testSubjects.click('confirmModalConfirmButton');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await pageObjects.triggersActionsUI.setAlertName('ml-test-alert');
await pageObjects.triggersActionsUI.setAlertInterval(10, 's');
await pageObjects.triggersActionsUI.saveAlert();
await ml.navigation.navigateToAlertsAndAction();
await pageObjects.triggersActionsUI.clickOnAlertInAlertsList('ml-test-alert');
});
});
Expand Down
Loading

0 comments on commit 4581688

Please sign in to comment.