diff --git a/x-pack/solutions/search/plugins/search_query_rules/public/components/query_rules_sets/delete_ruleset_modal.tsx b/x-pack/solutions/search/plugins/search_query_rules/public/components/query_rules_sets/delete_ruleset_modal.tsx index 1b6aaa8457fd1..3d95bcf4ca876 100644 --- a/x-pack/solutions/search/plugins/search_query_rules/public/components/query_rules_sets/delete_ruleset_modal.tsx +++ b/x-pack/solutions/search/plugins/search_query_rules/public/components/query_rules_sets/delete_ruleset_modal.tsx @@ -76,6 +76,7 @@ export const DeleteRulesetModal = ({ { setChecked(e.target.checked); diff --git a/x-pack/solutions/search/plugins/search_query_rules/public/components/query_rules_sets/query_rules_sets.tsx b/x-pack/solutions/search/plugins/search_query_rules/public/components/query_rules_sets/query_rules_sets.tsx index 729a650ceb647..caf775651d1b1 100644 --- a/x-pack/solutions/search/plugins/search_query_rules/public/components/query_rules_sets/query_rules_sets.tsx +++ b/x-pack/solutions/search/plugins/search_query_rules/public/components/query_rules_sets/query_rules_sets.tsx @@ -132,6 +132,7 @@ export const QueryRulesSets = () => { icon: 'trash', color: 'danger', type: 'icon', + 'data-test-subj': 'queryRulesSetDeleteButton', isPrimary: true, onClick: (ruleset: QueryRulesListRulesetsQueryRulesetListItem) => { useTracker?.click?.(AnalyticsEvents.deleteRulesetInlineDropdownClicked); diff --git a/x-pack/solutions/search/plugins/search_query_rules/public/components/query_ruleset_detail/query_rule_flyout/query_rule_flyout.tsx b/x-pack/solutions/search/plugins/search_query_rules/public/components/query_ruleset_detail/query_rule_flyout/query_rule_flyout.tsx index 94b9c8acbdf0f..cc5aaaad98871 100644 --- a/x-pack/solutions/search/plugins/search_query_rules/public/components/query_ruleset_detail/query_rule_flyout/query_rule_flyout.tsx +++ b/x-pack/solutions/search/plugins/search_query_rules/public/components/query_ruleset_detail/query_rule_flyout/query_rule_flyout.tsx @@ -119,6 +119,7 @@ export const QueryRuleFlyout: React.FC = ({ onClose={onClose} ownFocus={false} size="l" + data-test-subj="searchQueryRulesQueryRuleFlyout" aria-labelledby="flyoutTitle" css={css({ overflowY: 'hidden', diff --git a/x-pack/solutions/search/plugins/search_query_rules/public/components/query_ruleset_detail/query_rule_flyout/query_rule_metadata_editor.tsx b/x-pack/solutions/search/plugins/search_query_rules/public/components/query_ruleset_detail/query_rule_flyout/query_rule_metadata_editor.tsx index 122dd95052488..e1e897269ed7e 100644 --- a/x-pack/solutions/search/plugins/search_query_rules/public/components/query_ruleset_detail/query_rule_flyout/query_rule_metadata_editor.tsx +++ b/x-pack/solutions/search/plugins/search_query_rules/public/components/query_ruleset_detail/query_rule_flyout/query_rule_metadata_editor.tsx @@ -40,7 +40,7 @@ export const QueryRuleMetadataEditor: React.FC = ( const [metadataField, setMetadataField] = useState(criteria.metadata || ''); return ( - + = ({ createMo })} ), + 'data-test-subj': 'queryRulesetDetailBackButton', color: 'primary', 'aria-current': false, onClick: () => { @@ -371,7 +372,7 @@ export const QueryRulesetDetail: React.FC = ({ createMo id={splitButtonPopoverActionsId} button={ tbody.findAllByTagName('tr')); + + return Promise.all( + allRows.map(async (row) => { + const $ = await row.parseDomContent(); + return { + name: $.findTestSubject(this.TEST_IDS.QUERY_RULES_ITEM_NAME).text().trim(), + ruleCount: Number( + $.findTestSubject(this.TEST_IDS.QUERY_RULES_ITEM_RULE_COUNT).text() + ), + }; + }) + ); + }, + async clickRuleset(name: string) { + // find rulesets with name and click on it + const table = await testSubjects.findAll(this.TEST_IDS.QUERY_RULES_ITEM_NAME); + for (const item of table) { + const text = await item.getVisibleText(); + if (text === name) { + await item.click(); + return; + } + } + throw new Error(`Ruleset with name "${name}" not found`); + }, + async clickDeleteRulesetRow(index: number) { + const table = await testSubjects.find(this.TEST_IDS.QUERY_RULES_RULESETS_TABLE); + const allRows = await table + .findByTagName('tbody') + .then((tbody) => tbody.findAllByTagName('tr')); + const deleteButton = await allRows[index].findByTestSubject( + this.TEST_IDS.QUERY_RULES_ITEM_ACTIONS_DELETE_BUTTON + ); + await deleteButton.click(); + }, + async expectQueryRulesListPageComponentsToExist() { + await testSubjects.existOrFail(this.TEST_IDS.QUERY_RULES_RULESETS_TABLE); + await testSubjects.existOrFail(this.TEST_IDS.QUERY_RULES_ITEM_RULE_COUNT); + }, + async clickPaginationNext() { + await testSubjects.click(this.TEST_IDS.PAGINATION_NEXT_BUTTON); + }, + async clickPaginationPrevious() { + await testSubjects.click(this.TEST_IDS.PAGINATION_PREVIOUS_BUTTON); + }, + }, + QueryRulesDetailPage: { + TEST_IDS: { + RULESET_DETAILS_PAGE_BACK_BUTTON: 'queryRulesetDetailBackButton', + RULESET_DETAILS_PAGE_SAVE_BUTTON: 'queryRulesetDetailHeaderSaveButton', + RULESET_DETAILS_PAGE_HEADER: 'queryRulesetDetailHeader', + RULESET_DETAILS_PAGE_ACTIONS_BUTTON: 'searchQueryRulesQueryRulesetActionsButton', + RULESET_DETAILS_PAGE_DELETE_BUTTON: 'queryRulesetDetailDeleteButton', + RULESET_RULES_CONTAINER: 'searchQueryRulesDroppable', + RULESET_RULE_ITEM_NAME: 'searchQueryRulesDraggableItem', + RULESET_RULE_ITEM_ACTIONS_BUTTON: 'searchQueryRulesQueryRulesetDetailButton', + RULESET_RULE_ITEM_ACTIONS_DELETE_BUTTON: 'searchQueryRulesQueryRulesetDetailDeleteButton', + RULESET_RULE_ITEM_ACTIONS_EDIT_BUTTON: 'searchQueryRulesQueryRulesetDetailEditButton', + }, + async expectQueryRulesDetailPageNavigated(name: string) { + const h1Element = await find.byCssSelector( + `main header[data-test-subj="${this.TEST_IDS.RULESET_DETAILS_PAGE_HEADER}"] h1` + ); + const text = await h1Element.getVisibleText(); + if (text !== name) { + throw new Error(`Expected page title to be "${name}" but got "${text}"`); + } + }, + async expectQueryRulesDetailPageBackButtonToExist() { + await testSubjects.existOrFail(this.TEST_IDS.RULESET_DETAILS_PAGE_BACK_BUTTON); + }, + async expectQueryRulesDetailPageSaveButtonToExist() { + await testSubjects.existOrFail(this.TEST_IDS.RULESET_DETAILS_PAGE_SAVE_BUTTON); + }, + async clickQueryRulesDetailPageSaveButton() { + await testSubjects.click(this.TEST_IDS.RULESET_DETAILS_PAGE_SAVE_BUTTON); + }, + async clickQueryRulesDetailPageActionsButton() { + await testSubjects.click(this.TEST_IDS.RULESET_DETAILS_PAGE_ACTIONS_BUTTON); + }, + async clickQueryRulesDetailPageDeleteButton() { + await testSubjects.click(this.TEST_IDS.RULESET_DETAILS_PAGE_DELETE_BUTTON); + }, + async clickEditRulesetRule(id: number) { + const items = await testSubjects.findAll(this.TEST_IDS.RULESET_RULE_ITEM_NAME); + if (items[id]) { + const actionButton = await items[id].findByTestSubject( + this.TEST_IDS.RULESET_RULE_ITEM_ACTIONS_BUTTON + ); + await actionButton.click(); + await testSubjects.click(this.TEST_IDS.RULESET_RULE_ITEM_ACTIONS_EDIT_BUTTON); + } else { + throw new Error(`Ruleset rule with id "${id}" not found`); + } + }, + }, + QueryRulesCreateRulesetModal: { + TEST_IDS: { + CREATE_QUERY_RULES_SET_MODAL_INPUT: 'searchRulesetCreateRulesetModalFieldText', + CREATE_QUERY_RULES_SET_MODAL_CREATE_BUTTON: 'searchRulesetCreateRulesetModalCreateButton', + }, + async setQueryRulesSetName(name: string) { + await testSubjects.setValue(this.TEST_IDS.CREATE_QUERY_RULES_SET_MODAL_INPUT, name); + }, + async clickSaveButton() { + await testSubjects.click(this.TEST_IDS.CREATE_QUERY_RULES_SET_MODAL_CREATE_BUTTON); + }, + }, + QueryRulesDeleteRulesetModal: { + TEST_IDS: { + DELETE_QUERY_RULES_RULESET_MODAL_DELETE_BUTTON: + 'searchRulesetDeleteRulesetModalDeleteButton', + DELETE_QUERY_RULES_RULESET_MODAL_ACKNOWLEDGE_BUTTON: 'confirmDeleteRulesetCheckbox', + DELETE_QUERY_RULES_RULESET_MODAL_CANCEL_BUTTON: + 'searchRulesetDeleteRulesetModalCancelButton', + }, + async clickDeleteButton() { + await testSubjects.click(this.TEST_IDS.DELETE_QUERY_RULES_RULESET_MODAL_DELETE_BUTTON); + }, + async clickAcknowledgeButton() { + await testSubjects.click(this.TEST_IDS.DELETE_QUERY_RULES_RULESET_MODAL_ACKNOWLEDGE_BUTTON); + }, + async clickCancelButton() { + await testSubjects.click(this.TEST_IDS.DELETE_QUERY_RULES_RULESET_MODAL_CANCEL_BUTTON); + }, + async clickConfirmDeleteModal() { + await testSubjects.click('confirmModalConfirmButton'); + }, + }, + QueryRulesRuleFlyout: { + TEST_IDS: { + RULE_FLYOUT: 'searchQueryRulesQueryRuleFlyout', + RULE_FLYOUT_UPDATE_BUTTON: 'searchQueryRulesQueryRuleFlyoutUpdateButton', + RULE_FLYOUT_PIN_MORE_BUTTON: 'searchQueryRulesPinMoreButton', + RULE_FLYOUT_METADATA_ADD_BUTTON: 'searchQueryRulesQueryRuleMetadataEditorAddCriteriaButton', + RULE_FLYOUT_DOCUMENT_DRAGGABLE_ID: 'editableResultDocumentId', + RULE_FLYOUT_DOCUMENT_INDEX: 'editableResultIndexSelector', + RULE_FLYOUT_ACTION_TYPE_EXCLUDE: 'searchQueryRulesQueryRuleActionTypeExclude', + RULE_FLYOUT_ACTION_TYPE_PINNED: 'searchQueryRulesQueryRuleActionTypePinned', + RULE_FLYOUT_CRITERIA_CUSTOM: 'searchQueryRulesQueryRuleCriteriaCustom', + RULE_FLYOUT_CRITERIA_ALWAYS: 'searchQueryRulesQueryRuleCriteriaAlways', + RULE_FLYOUT_CRITERIA_METADATA_BLOCK: 'searchQueryRulesQueryRuleMetadataEditor', + RULE_FLYOUT_CRITERIA_METADATA_BLOCK_FIELD: 'searchQueryRulesQueryRuleMetadataEditorField', + RULE_FLYOUT_CRITERIA_METADATA_BLOCK_VALUES: 'searchQueryRulesQueryRuleMetadataEditorValues', + }, + async expectRuleFlyoutToExist() { + await testSubjects.existOrFail(this.TEST_IDS.RULE_FLYOUT); + }, + async clickUpdateButton() { + await testSubjects.click(this.TEST_IDS.RULE_FLYOUT_UPDATE_BUTTON); + }, + async clickActionTypeExclude() { + await testSubjects.click(this.TEST_IDS.RULE_FLYOUT_ACTION_TYPE_EXCLUDE); + }, + async clickActionTypePinned() { + await testSubjects.click(this.TEST_IDS.RULE_FLYOUT_ACTION_TYPE_PINNED); + }, + async clickCriteriaCustom() { + await testSubjects.click(this.TEST_IDS.RULE_FLYOUT_CRITERIA_CUSTOM); + }, + async clickCriteriaAlways() { + await testSubjects.click(this.TEST_IDS.RULE_FLYOUT_CRITERIA_ALWAYS); + }, + async changeDocumentIdField(id: number, newValue: string = '') { + const documentFields = await testSubjects.findAll( + this.TEST_IDS.RULE_FLYOUT_DOCUMENT_DRAGGABLE_ID + ); + if (documentFields[id]) { + const targetField = documentFields[id]; + await targetField.click(); + await targetField.type(newValue); + } else { + await testSubjects.click(this.TEST_IDS.RULE_FLYOUT_PIN_MORE_BUTTON); + await this.changeDocumentIdField(id); + } + }, + async changeDocumentIndexField(id: number, newValue: string = '') { + const comboBoxes = await testSubjects.findAll(this.TEST_IDS.RULE_FLYOUT_DOCUMENT_INDEX); + if (comboBoxes[id]) { + const targetComboBox = comboBoxes[id]; + await targetComboBox.click(); + await comboBox.setCustom(this.TEST_IDS.RULE_FLYOUT_DOCUMENT_INDEX, newValue); + // Press tab to ensure the value is set correctly + await browser.pressKeys(Key.TAB); + } + }, + async changeMetadataField(id: number, newValue: string = '') { + const metadataFields = await testSubjects.findAll( + this.TEST_IDS.RULE_FLYOUT_CRITERIA_METADATA_BLOCK + ); + if (metadataFields[id]) { + const targetMetadataBlock = metadataFields[id]; + const targetField = await targetMetadataBlock.findByTestSubject( + this.TEST_IDS.RULE_FLYOUT_CRITERIA_METADATA_BLOCK_FIELD + ); + await targetField.click(); + await targetField.type(newValue); + } else { + await testSubjects.click(this.TEST_IDS.RULE_FLYOUT_METADATA_ADD_BUTTON); + await this.changeMetadataField(id); + } + }, + async changeMetadataValues(_: number, newValue: string = '') { + await comboBox.setCustom( + this.TEST_IDS.RULE_FLYOUT_CRITERIA_METADATA_BLOCK_VALUES, + newValue + ); + }, + }, + }; +} diff --git a/x-pack/test_serverless/functional/test_suites/search/config.feature_flags.ts b/x-pack/test_serverless/functional/test_suites/search/config.feature_flags.ts index 23e2bd6018a20..1b83a4d508da7 100644 --- a/x-pack/test_serverless/functional/test_suites/search/config.feature_flags.ts +++ b/x-pack/test_serverless/functional/test_suites/search/config.feature_flags.ts @@ -21,6 +21,8 @@ export default createTestConfig({ kbnServerArgs: [ `--xpack.cloud.id=ES3_FTR_TESTS:ZmFrZS1kb21haW4uY2xkLmVsc3RjLmNvJGZha2Vwcm9qZWN0aWQuZXMkZmFrZXByb2plY3RpZC5rYg==`, `--uiSettings.overrides.searchPlayground:searchModeEnabled=true`, + `--uiSettings.overrides.queryRules:queryRulesEnabled=true`, + '--xpack.searchQueryRules.enabled=true', ], // load tests in the index file testFiles: [require.resolve('./index.feature_flags.ts')], @@ -41,6 +43,9 @@ export default createTestConfig({ searchSynonyms: { pathname: '/app/elasticsearch/search_synonyms', }, + searchQueryRules: { + pathname: '/app/elasticsearch/query_rules', + }, elasticsearchStart: { pathname: '/app/elasticsearch/start', }, diff --git a/x-pack/test_serverless/functional/test_suites/search/index.feature_flags.ts b/x-pack/test_serverless/functional/test_suites/search/index.feature_flags.ts index 40fd0debb74d5..27d42fa6399e9 100644 --- a/x-pack/test_serverless/functional/test_suites/search/index.feature_flags.ts +++ b/x-pack/test_serverless/functional/test_suites/search/index.feature_flags.ts @@ -13,6 +13,7 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./search_synonyms/search_synonyms_overview')); loadTestFile(require.resolve('./search_synonyms/search_synonym_detail')); loadTestFile(require.resolve('./search_playground/search_relevance')); + loadTestFile(require.resolve('./search_query_rules/search_query_rules_overview')); loadTestFile(require.resolve('./search_playground/saved_playgrounds')); }); } diff --git a/x-pack/test_serverless/functional/test_suites/search/search_query_rules/search_query_rules_overview.ts b/x-pack/test_serverless/functional/test_suites/search/search_query_rules/search_query_rules_overview.ts new file mode 100644 index 0000000000000..37dd83ca8dbcb --- /dev/null +++ b/x-pack/test_serverless/functional/test_suites/search/search_query_rules/search_query_rules_overview.ts @@ -0,0 +1,268 @@ +/* + * 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 expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ getPageObjects, getService }: FtrProviderContext) { + const pageObjects = getPageObjects([ + 'svlCommonPage', + 'svlCommonNavigation', + 'searchQueryRules', + 'embeddedConsole', + 'common', + ]); + const browser = getService('browser'); + const es = getService('es'); + const retry = getService('retry'); + + const createTestRuleset = async (rulesetId: string) => { + await es.transport.request({ + path: `_query_rules/${rulesetId}`, + method: 'PUT', + body: { + rules: [ + { + rule_id: 'rule1', + type: 'pinned', + criteria: [ + { + type: 'fuzzy', + metadata: 'query_string', + values: ['puggles', 'pugs'], + }, + { + type: 'exact', + metadata: 'user_country', + values: ['us'], + }, + ], + actions: { + docs: [ + { + _index: 'my-index-000001', + _id: 'id1', + }, + { + _index: 'my-index-000002', + _id: 'id2', + }, + ], + }, + }, + ], + }, + }); + }; + + const deleteTestRuleset = async (rulesetId: string) => { + await es.transport.request({ + path: `_query_rules/${rulesetId}`, + method: 'DELETE', + }); + }; + + const createTestIndex = async (indexName: string, docId: string) => { + await es.transport.request({ + path: `${indexName}/_doc/${docId}`, + method: 'PUT', + body: { + title: 'Pugs are the best', + }, + }); + }; + + const deleteTestIndex = async (indexName: string) => { + await es.transport.request({ + path: indexName, + method: 'DELETE', + }); + }; + + describe('Serverless Query Rules Overview', function () { + before(async () => { + try { + await deleteTestRuleset('my-test-ruleset'); + } catch (error) { + // Ignore errors if ruleset doesn't exist or cannot be deleted + } + await pageObjects.svlCommonPage.loginWithRole('developer'); + await createTestIndex('my-index-000001', 'W08XfZcBY'); + }); + + beforeEach(async () => { + await pageObjects.svlCommonNavigation.sidenav.clickLink({ + deepLinkId: 'searchQueryRules', + }); + }); + + describe('Creating a query ruleset from an empty deployment', () => { + it('is Empty State page loaded successfully', async () => { + await pageObjects.searchQueryRules.QueryRulesEmptyPromptPage.expectQueryRulesEmptyPromptPageComponentsToExist(); + }); + it('should be able to create a new ruleset', async () => { + await pageObjects.searchQueryRules.QueryRulesEmptyPromptPage.clickCreateQueryRulesSetButton(); + await pageObjects.searchQueryRules.QueryRulesCreateRulesetModal.setQueryRulesSetName( + 'my-test-ruleset' + ); + await pageObjects.searchQueryRules.QueryRulesCreateRulesetModal.clickSaveButton(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.expectQueryRulesDetailPageNavigated( + 'my-test-ruleset' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.expectRuleFlyoutToExist(); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeDocumentIdField( + 0, + 'W08XfZcBY' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeDocumentIndexField( + 0, + 'my-index-000001' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeMetadataValues(0, 'pugs'); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeMetadataField( + 0, + 'my_query_field' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.clickUpdateButton(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.expectQueryRulesDetailPageBackButtonToExist(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.expectQueryRulesDetailPageSaveButtonToExist(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.clickQueryRulesDetailPageSaveButton(); + + // give time for the ruleset to be created + await pageObjects.common.sleep(400); + await pageObjects.svlCommonNavigation.sidenav.clickLink({ + deepLinkId: 'searchQueryRules', + }); + await pageObjects.searchQueryRules.QueryRulesManagementPage.expectQueryRulesTableToExist(); + }); + }); + + describe('Adding a new ruleset in a non-empty deployment', () => { + before(async () => { + await pageObjects.svlCommonNavigation.sidenav.clickLink({ + deepLinkId: 'searchQueryRules', + }); + }); + it('should be able to create a new ruleset on top of an existing one', async () => { + await pageObjects.searchQueryRules.QueryRulesManagementPage.expectQueryRulesTableToExist(); + await pageObjects.searchQueryRules.QueryRulesManagementPage.clickCreateQueryRulesRulesetButton(); + await pageObjects.searchQueryRules.QueryRulesCreateRulesetModal.setQueryRulesSetName( + 'my-test-ruleset-2' + ); + await pageObjects.searchQueryRules.QueryRulesCreateRulesetModal.clickSaveButton(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.expectQueryRulesDetailPageNavigated( + 'my-test-ruleset-2' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.expectRuleFlyoutToExist(); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeDocumentIndexField( + 0, + 'my-index-000001' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeDocumentIdField( + 0, + 'W08XfZcBY' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeMetadataValues(0, 'pugs'); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeMetadataField( + 0, + 'my_query_field' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.clickUpdateButton(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.expectQueryRulesDetailPageBackButtonToExist(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.expectQueryRulesDetailPageSaveButtonToExist(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.clickQueryRulesDetailPageSaveButton(); + + // give time for the ruleset to be created + await pageObjects.common.sleep(400); + await pageObjects.svlCommonNavigation.sidenav.clickLink({ + deepLinkId: 'searchQueryRules', + }); + await pageObjects.searchQueryRules.QueryRulesManagementPage.expectQueryRulesTableToExist(); + await retry.try(async () => { + const results = + await pageObjects.searchQueryRules.QueryRulesManagementPage.getQueryRulesRulesetsList(); + await expect(results.length).to.equal(2); + }); + }); + after(async () => { + try { + await deleteTestRuleset('my-test-ruleset-2'); + } catch (error) { + // Ignore errors if ruleset doesn't exist or cannot be deleted + } + }); + }); + describe('Deleting a query ruleset from the ruleset details page', () => { + before(async () => { + await createTestRuleset('my-test-ruleset'); + await browser.refresh(); + }); + it('should be able to delete an existing ruleset and render the empty state', async () => { + await pageObjects.searchQueryRules.QueryRulesManagementPage.expectQueryRulesTableToExist(); + await pageObjects.searchQueryRules.QueryRulesManagementPage.clickRuleset('my-test-ruleset'); + await pageObjects.searchQueryRules.QueryRulesDetailPage.clickQueryRulesDetailPageActionsButton(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.clickQueryRulesDetailPageDeleteButton(); + await pageObjects.searchQueryRules.QueryRulesDeleteRulesetModal.clickAcknowledgeButton(); + await pageObjects.searchQueryRules.QueryRulesDeleteRulesetModal.clickConfirmDeleteModal(); + await pageObjects.searchQueryRules.QueryRulesEmptyPromptPage.expectQueryRulesEmptyPromptPageComponentsToExist(); + }); + }); + describe('Deleting a query ruleset from the ruleset management page', () => { + before(async () => { + await createTestRuleset('my-test-ruleset'); + await pageObjects.common.sleep(500); + await browser.navigateTo('about:blank'); + await pageObjects.common.navigateToApp('searchQueryRules'); + }); + it('should be able to delete an existing ruleset and render the empty state', async () => { + await pageObjects.searchQueryRules.QueryRulesManagementPage.expectQueryRulesTableToExist(); + await pageObjects.searchQueryRules.QueryRulesManagementPage.clickDeleteRulesetRow(0); + await pageObjects.searchQueryRules.QueryRulesDeleteRulesetModal.clickAcknowledgeButton(); + await pageObjects.searchQueryRules.QueryRulesDeleteRulesetModal.clickConfirmDeleteModal(); + await pageObjects.searchQueryRules.QueryRulesEmptyPromptPage.expectQueryRulesEmptyPromptPageComponentsToExist(); + }); + }); + describe('Editing a query ruleset with document pinning/exclude', () => { + before(async () => { + await createTestRuleset('my-test-ruleset'); + await pageObjects.common.sleep(500); + await browser.navigateTo('about:blank'); + await pageObjects.common.navigateToApp('searchQueryRules'); + }); + it('should edit the document id and the criteria field', async () => { + await pageObjects.searchQueryRules.QueryRulesManagementPage.expectQueryRulesTableToExist(); + await pageObjects.searchQueryRules.QueryRulesManagementPage.clickRuleset('my-test-ruleset'); + await pageObjects.searchQueryRules.QueryRulesDetailPage.clickEditRulesetRule(0); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.expectRuleFlyoutToExist(); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeDocumentIdField( + 0, + 'W08XfZcBYqFvZsDKwTp4' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.clickActionTypePinned(); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.clickActionTypeExclude(); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.changeMetadataField( + 0, + 'my_query_field' + ); + await pageObjects.searchQueryRules.QueryRulesRuleFlyout.clickUpdateButton(); + await pageObjects.searchQueryRules.QueryRulesDetailPage.clickQueryRulesDetailPageSaveButton(); + }); + after(async () => { + try { + await deleteTestRuleset('my-test-ruleset'); + } catch (error) { + // Ignore errors if ruleset doesn't exist or cannot be deleted + } + try { + await deleteTestIndex('my-index-000001'); + } catch (error) { + // Ignore errors if index doesn't exist or cannot be deleted + } + }); + }); + }); +}