From c7f294eb74b45eae93d284a7ed4bf7b02dc940dc Mon Sep 17 00:00:00 2001 From: Sandra G Date: Thu, 6 Mar 2025 21:48:28 +0800 Subject: [PATCH] [8.x] [Obs AI Assistant] fix flaky test and add back test in settings (#213196) (#213316) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [[Obs AI Assistant] fix flaky test and add back test in settings (#213196)](https://github.com/elastic/kibana/pull/213196) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) --- .../common/ui/index.ts | 2 + .../settings_security.spec.ts | 70 ++++++++++++++++--- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts b/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts index d072cc3777a7d..647f7cbcc3051 100644 --- a/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts +++ b/x-pack/test/observability_ai_assistant_functional/common/ui/index.ts @@ -67,6 +67,8 @@ const pages = { 'management-settings-editField-observability:aiAssistantSearchConnectorIndexPattern', saveButton: 'observabilityAiAssistantManagementBottomBarActionsButton', aiAssistantCard: 'aiAssistantSelectionPageObservabilityCard', + resetToDefaultLink: + 'management-settings-resetField-observability:aiAssistantSearchConnectorIndexPattern', }, }; diff --git a/x-pack/test/observability_ai_assistant_functional/tests/feature_controls/settings_security.spec.ts b/x-pack/test/observability_ai_assistant_functional/tests/feature_controls/settings_security.spec.ts index 2a7f8cc3d3a55..1fd0d9d62fcf9 100644 --- a/x-pack/test/observability_ai_assistant_functional/tests/feature_controls/settings_security.spec.ts +++ b/x-pack/test/observability_ai_assistant_functional/tests/feature_controls/settings_security.spec.ts @@ -8,15 +8,17 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; import { createAndLoginUserWithCustomRole, deleteAndLogoutUser } from './helpers'; +import { interceptRequest } from '../../common/intercept_request'; export default function ({ getPageObjects, getService }: FtrProviderContext) { - const browser = getService('browser'); const PageObjects = getPageObjects(['common', 'error', 'navigationalSearch', 'security']); const ui = getService('observabilityAIAssistantUI'); const testSubjects = getService('testSubjects'); + const retry = getService('retry'); + const toasts = getService('toasts'); + const driver = getService('__webdriver__'); - // Failing: See https://github.com/elastic/kibana/issues/191707 - describe.skip('ai assistant management privileges', () => { + describe('ai assistant management privileges', () => { describe('all privileges', () => { before(async () => { await createAndLoginUserWithCustomRole(getPageObjects, getService, { @@ -59,22 +61,68 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await testSubjects.existOrFail(ui.pages.settings.settingsPage); }); it('allows updating of an advanced setting', async () => { - const testSearchConnectorIndexPattern = 'my-logs-index-pattern'; + await PageObjects.common.navigateToUrl('obsAIAssistantManagement', '', { + ensureCurrentUrl: false, + shouldLoginIfPrompted: false, + shouldUseHashForSubUrl: false, + }); + const testSearchConnectorIndexPattern = 'my-search-index-pattern'; const searchConnectorIndexPatternInput = await testSubjects.find( ui.pages.settings.searchConnectorIndexPatternInput ); + // make sure the input is empty (default value) await searchConnectorIndexPatternInput.clearValue(); await searchConnectorIndexPatternInput.type(testSearchConnectorIndexPattern); const saveButton = await testSubjects.find(ui.pages.settings.saveButton); await saveButton.click(); - await browser.refresh(); - const searchConnectorIndexPatternInputValue = - await searchConnectorIndexPatternInput.getAttribute('value'); - expect(searchConnectorIndexPatternInputValue).to.be(testSearchConnectorIndexPattern); - // reset the value - await searchConnectorIndexPatternInput.clearValue(); - await searchConnectorIndexPatternInput.type('logs-*'); + // wait for page to refrsh + await testSubjects.missingOrFail(ui.pages.settings.searchConnectorIndexPatternInput, { + timeout: 2000, + }); + // wait for the new page to fully load + await testSubjects.existOrFail(ui.pages.settings.searchConnectorIndexPatternInput, { + timeout: 2000, + }); + expect(await searchConnectorIndexPatternInput.getAttribute('value')).to.be( + testSearchConnectorIndexPattern + ); + // reset the value back to default + const resetToDefaultLink = await testSubjects.find(ui.pages.settings.resetToDefaultLink); + await resetToDefaultLink.click(); + + expect(await searchConnectorIndexPatternInput.getAttribute('value')).to.be(''); await saveButton.click(); + await testSubjects.missingOrFail(ui.pages.settings.searchConnectorIndexPatternInput, { + timeout: 2000, + }); + // wait for the new page to fully load + await testSubjects.existOrFail(ui.pages.settings.searchConnectorIndexPatternInput, { + timeout: 2000, + }); + expect(await searchConnectorIndexPatternInput.getAttribute('value')).to.be(''); + }); + it('displays failure toast on failed request', async () => { + const searchConnectorIndexPatternInput = await testSubjects.find( + ui.pages.settings.searchConnectorIndexPatternInput + ); + await searchConnectorIndexPatternInput.clearValue(); + await searchConnectorIndexPatternInput.type('test'); + + await interceptRequest( + driver.driver, + '*kibana\\/settings*', + (responseFactory) => { + return responseFactory.fail(); + }, + async () => { + await testSubjects.click(ui.pages.settings.saveButton); + } + ); + + await retry.waitFor('Error saving settings toast', async () => { + const count = await toasts.getCount(); + return count > 0; + }); }); }); describe('with advancedSettings read privilege', () => {