Skip to content

Commit

Permalink
[Obs AI Assistant] fix flaky test and add back test in settings (elas…
Browse files Browse the repository at this point in the history
…tic#213196)

## Summary

Closes elastic#191707

Summarize your PR. If it involves visual changes include a screenshot or
gif.

- Fixes flaky test`allows updating of an advanced setting` by making
sure to wait for page refresh
- Adds back test to check for toast on error
elastic#191531

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
(cherry picked from commit bccbb93)

# Conflicts:
#	x-pack/test/observability_ai_assistant_functional/tests/feature_controls/settings_security.spec.ts
  • Loading branch information
neptunian committed Mar 6, 2025
1 parent 317042b commit 251ff6e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const pages = {
'management-settings-editField-observability:aiAssistantSearchConnectorIndexPattern',
saveButton: 'observabilityAiAssistantManagementBottomBarActionsButton',
aiAssistantCard: 'aiAssistantSelectionPageObservabilityCard',
resetToDefaultLink:
'management-settings-resetField-observability:aiAssistantSearchConnectorIndexPattern',
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 251ff6e

Please sign in to comment.