Skip to content

Commit

Permalink
Support incoming Preconfigured Endpoints (elastic#203473)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
Samiul-TheSoccerFan and elasticmachine authored Dec 10, 2024
1 parent d67681d commit a5c9ed7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ export const DeleteAction: React.FC<DeleteActionProps> = ({ selectedEndpoint })
});
};

const isPreconfigured = isEndpointPreconfigured(selectedEndpoint.endpoint);
const testSubj = `inferenceUIDeleteAction-${isPreconfigured ? 'preconfigured' : 'user-defined'}`;

return (
<>
<EuiButtonIcon
aria-label={i18n.translate('xpack.searchInferenceEndpoints.actions.deleteEndpoint', {
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit a5c9ed7

Please sign in to comment.