Support incoming Preconfigured Endpoints (#203473)

## Summary

Currently, the FTR tests are written to expect only two preconfigured
endpoints. However, there might be more incoming, and this PR
generalizes these tests so they do not depend on the number of
preconfigured endpoints in the future.



### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [X] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [X] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Samiul Monir 2024-12-10 16:09:31 -05:00 committed by GitHub
parent d67681d519
commit a5c9ed7bb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 55 deletions

View file

@ -40,20 +40,20 @@ describe('Delete Action', () => {
it('renders', () => {
render(<Wrapper item={mockItem} />);
expect(screen.getByTestId('inferenceUIDeleteAction')).toBeEnabled();
expect(screen.getByTestId(/inferenceUIDeleteAction/)).toBeEnabled();
});
it('disable the delete action for preconfigured endpoint', () => {
const preconfiguredMockItem = { ...mockItem, endpoint: '.multilingual-e5-small-elasticsearch' };
render(<Wrapper item={preconfiguredMockItem} />);
expect(screen.getByTestId('inferenceUIDeleteAction')).toBeDisabled();
expect(screen.getByTestId(/inferenceUIDeleteAction/)).toBeDisabled();
});
it('loads confirm delete modal', () => {
render(<Wrapper item={mockItem} />);
fireEvent.click(screen.getByTestId('inferenceUIDeleteAction'));
fireEvent.click(screen.getByTestId(/inferenceUIDeleteAction/));
expect(screen.getByTestId('deleteModalForInferenceUI')).toBeInTheDocument();
});
});

View file

@ -33,6 +33,9 @@ export const DeleteAction: React.FC<DeleteActionProps> = ({ selectedEndpoint })
});
};
const isPreconfigured = isEndpointPreconfigured(selectedEndpoint.endpoint);
const testSubj = `inferenceUIDeleteAction-${isPreconfigured ? 'preconfigured' : 'user-defined'}`;
return (
<>
<EuiButtonIcon
@ -40,8 +43,8 @@ export const DeleteAction: React.FC<DeleteActionProps> = ({ selectedEndpoint })
defaultMessage: 'Delete inference endpoint {selectedEndpointName}',
values: { selectedEndpointName: selectedEndpoint.endpoint },
})}
data-test-subj="inferenceUIDeleteAction"
disabled={isEndpointPreconfigured(selectedEndpoint.endpoint)}
data-test-subj={testSubj}
disabled={isPreconfigured}
key="delete"
iconType="trash"
color="danger"

View file

@ -127,7 +127,7 @@ describe('When the tabular page is loaded', () => {
it('should only disable delete action for preconfigured endpoints', () => {
render(<TabularPage inferenceEndpoints={inferenceEndpoints} />);
const deleteActions = screen.getAllByTestId('inferenceUIDeleteAction');
const deleteActions = screen.getAllByTestId(/inferenceUIDeleteAction/);
expect(deleteActions[0]).toBeDisabled();
expect(deleteActions[1]).toBeDisabled();

View file

@ -27,53 +27,29 @@ export function SvlSearchInferenceManagementPageProvider({ getService }: FtrProv
const table = await testSubjects.find('inferenceEndpointTable');
const rows = await table.findAllByClassName('euiTableRow');
expect(rows.length).to.equal(2);
// we need at least one (ELSER) otherwise index_mapping might experience some issues
expect(rows.length).to.greaterThan(1);
const elserEndpointCell = await rows[0].findByTestSubject('endpointCell');
const elserEndpointName = await elserEndpointCell.getVisibleText();
expect(elserEndpointName).to.contain('.elser-2-elasticsearch');
const texts = await Promise.all(rows.map((row) => row.getVisibleText()));
const hasElser2 = texts.some((text) => text.includes('.elser-2'));
const hasE5 = texts.some((text) => text.includes('.multilingual-e5'));
const elserProviderCell = await rows[0].findByTestSubject('providerCell');
const elserProviderName = await elserProviderCell.getVisibleText();
expect(elserProviderName).to.contain('Elasticsearch');
expect(elserProviderName).to.contain('.elser_model_2');
const elserTypeCell = await rows[0].findByTestSubject('typeCell');
const elserTypeName = await elserTypeCell.getVisibleText();
expect(elserTypeName).to.contain('sparse_embedding');
const e5EndpointCell = await rows[1].findByTestSubject('endpointCell');
const e5EndpointName = await e5EndpointCell.getVisibleText();
expect(e5EndpointName).to.contain('.multilingual-e5-small-elasticsearch');
const e5ProviderCell = await rows[1].findByTestSubject('providerCell');
const e5ProviderName = await e5ProviderCell.getVisibleText();
expect(e5ProviderName).to.contain('Elasticsearch');
expect(e5ProviderName).to.contain('.multilingual-e5-small');
const e5TypeCell = await rows[1].findByTestSubject('typeCell');
const e5TypeName = await e5TypeCell.getVisibleText();
expect(e5TypeName).to.contain('text_embedding');
expect(hasElser2).to.be(true);
expect(hasE5).to.be(true);
},
async expectPreconfiguredEndpointsCannotBeDeleted() {
const table = await testSubjects.find('inferenceEndpointTable');
const rows = await table.findAllByClassName('euiTableRow');
const elserDeleteAction = await rows[0].findByTestSubject('inferenceUIDeleteAction');
const e5DeleteAction = await rows[1].findByTestSubject('inferenceUIDeleteAction');
expect(await elserDeleteAction.isEnabled()).to.be(false);
expect(await e5DeleteAction.isEnabled()).to.be(false);
const preconfigureEndpoints = await testSubjects.findAll(
'inferenceUIDeleteAction-preconfigured'
);
for (const endpoint of preconfigureEndpoints) {
expect(await endpoint.isEnabled()).to.be(false);
}
},
async expectEndpointWithoutUsageTobeDelete() {
const table = await testSubjects.find('inferenceEndpointTable');
const rows = await table.findAllByClassName('euiTableRow');
const userCreatedEndpoint = await rows[2].findByTestSubject('inferenceUIDeleteAction');
await userCreatedEndpoint.click();
const userDefinedEdnpoint = await testSubjects.find('inferenceUIDeleteAction-user-defined');
await userDefinedEdnpoint.click();
await testSubjects.existOrFail('deleteModalForInferenceUI');
await testSubjects.existOrFail('deleteModalInferenceEndpointName');
@ -83,12 +59,8 @@ export function SvlSearchInferenceManagementPageProvider({ getService }: FtrProv
},
async expectEndpointWithUsageTobeDelete() {
const table = await testSubjects.find('inferenceEndpointTable');
const rows = await table.findAllByClassName('euiTableRow');
const userCreatedEndpoint = await rows[2].findByTestSubject('inferenceUIDeleteAction');
await userCreatedEndpoint.click();
const userDefinedEdnpoint = await testSubjects.find('inferenceUIDeleteAction-user-defined');
await userDefinedEdnpoint.click();
await testSubjects.existOrFail('deleteModalForInferenceUI');
await testSubjects.existOrFail('deleteModalInferenceEndpointName');

View file

@ -37,10 +37,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await pageObjects.svlCommonPage.loginWithRole('developer');
});
after(async () => {
await ml.api.cleanMlIndices();
});
beforeEach(async () => {
await svlSearchNavigation.navigateToInferenceManagementPage();
});