[Obs AI Assistant] fix flaky test and add back test in settings (#213196)

## Summary

Closes https://github.com/elastic/kibana/issues/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
https://github.com/elastic/kibana/pull/191531

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
This commit is contained in:
Sandra G 2025-03-06 00:46:02 +08:00 committed by GitHub
parent e676a6399c
commit bccbb933c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 62 additions and 13 deletions

View file

@ -67,6 +67,8 @@ const pages = {
'management-settings-editField-observability:aiAssistantSearchConnectorIndexPattern',
saveButton: 'observabilityAiAssistantManagementBottomBarActionsButton',
aiAssistantCard: 'aiAssistantSelectionPageObservabilityCard',
resetToDefaultLink:
'management-settings-resetField-observability:aiAssistantSearchConnectorIndexPattern',
},
};

View file

@ -8,17 +8,18 @@
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', () => {
// FLAKY: https://github.com/elastic/kibana/issues/191707
describe.skip('all privileges', () => {
describe('ai assistant management privileges', () => {
describe('all privileges', () => {
before(async () => {
await createAndLoginUserWithCustomRole(getPageObjects, getService, {
// we need all these privileges to view and modify Obs AI Assistant settings view
@ -60,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', () => {