Skip to content

Commit

Permalink
test(search_playground): support combobox context field selection
Browse files Browse the repository at this point in the history
  • Loading branch information
TattdCodeMonkey committed Feb 11, 2025
1 parent 28bc22a commit 9bbdd10
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jest.mock('../../hooks/use_source_indices_field', () => ({
elser_query_fields: [],
dense_vector_query_fields: [],
bm25_query_fields: ['field1', 'field2'],
source_fields: ['context_field1', 'context_field2'],
source_fields: ['title', 'description'],
semantic_fields: [],
},
index2: {
elser_query_fields: [],
dense_vector_query_fields: [],
bm25_query_fields: ['field1', 'field2'],
source_fields: ['context_field1', 'context_field2'],
bm25_query_fields: ['foo', 'bar'],
source_fields: ['body'],
semantic_fields: [],
},
},
Expand All @@ -47,8 +47,8 @@ const MockFormProvider = ({ children }: { children: React.ReactElement }) => {
[ChatFormFields.indices]: ['index1'],
[ChatFormFields.docSize]: 1,
[ChatFormFields.sourceFields]: {
index1: ['context_field1'],
index2: ['context_field2'],
index1: ['title'],
index2: ['body'],
},
},
});
Expand All @@ -67,9 +67,15 @@ describe('EditContextFlyout component tests', () => {
});

it('should see the context fields', async () => {
expect(screen.getByTestId('contextFieldsSelectable-0')).toBeInTheDocument();
fireEvent.click(screen.getByTestId('contextFieldsSelectable-0'));
const fields = await screen.findAllByTestId('contextField');
expect(fields.length).toBe(2);
expect(screen.getByTestId('contextFieldsSelectable-index1')).toBeInTheDocument();
const listButton = screen
.getByTestId('contextFieldsSelectable-index1')
.querySelector('[data-test-subj="comboBoxToggleListButton"]');
expect(listButton).not.toBeNull();
fireEvent.click(listButton!);

for (const field of ['title', 'description']) {
expect(screen.getByTestId(`contextField-${field}`)).toBeInTheDocument();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function (ftrContext: FtrProviderContext) {
describe('Playground', () => {
before(async () => {
proxy = await createLlmProxy(log);
await pageObjects.common.navigateToApp('enterpriseSearchApplications/playground');
await pageObjects.common.navigateToApp('searchPlayground');
});

after(async () => {
Expand Down Expand Up @@ -166,7 +166,10 @@ export default function (ftrContext: FtrProviderContext) {
});

it('show edit context', async () => {
await pageObjects.searchPlayground.PlaygroundChatPage.expectEditContextOpens();
await pageObjects.searchPlayground.PlaygroundChatPage.expectEditContextOpens(
'basic_index',
['baz']
);
});

it('save selected fields between modes', async () => {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/test/functional/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ export default async function ({ readConfigFile }) {
elasticsearchIndices: {
pathname: '/app/elasticsearch/indices',
},
searchPlayground: {
pathname: '/app/search_playground',
},
},

suiteTags: {
Expand Down
25 changes: 17 additions & 8 deletions x-pack/test/functional/page_objects/search_playground_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { FtrProviderContext } from '../ftr_provider_context';
export function SearchPlaygroundPageProvider({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const browser = getService('browser');
const comboBox = getService('comboBox');
const selectIndex = async () => {
await testSubjects.existOrFail('addDataSourcesButton');
await testSubjects.click('addDataSourcesButton');
Expand Down Expand Up @@ -212,14 +213,21 @@ export function SearchPlaygroundPageProvider({ getService }: FtrProviderContext)
await testSubjects.click('chatMode');
},

async expectEditContextOpens() {
async expectEditContextOpens(
indexName: string = 'basic_index',
expectedSelectedFields: string[] = ['baz']
) {
await testSubjects.click('chatMode');
await testSubjects.existOrFail('contextFieldsSelectable-0');
await testSubjects.click('contextFieldsSelectable-0');
await testSubjects.existOrFail('contextField');
const fields = await testSubjects.findAll('contextField');

expect(fields.length).to.be(1);
await testSubjects.existOrFail(`contextFieldsSelectable-${indexName}`);
for (const field of expectedSelectedFields) {
await testSubjects.existOrFail(`contextField-${field}`);
}
expect(
await comboBox.doesComboBoxHaveSelectedOptions(`contextFieldsSelectable-${indexName}`)
).to.be(true);
expect(
await comboBox.getComboBoxSelectedOptions(`contextFieldsSelectable-${indexName}`)
).to.eql(expectedSelectedFields);
},

async expectSaveFieldsBetweenModes() {
Expand All @@ -230,11 +238,12 @@ export function SearchPlaygroundPageProvider({ getService }: FtrProviderContext)
await testSubjects.click('chatMode');
await testSubjects.click('queryMode');
await testSubjects.existOrFail('field-baz-false');
await testSubjects.click('chatMode');
},

async clickManageButton() {
await testSubjects.click('manageConnectorsLink');
await testSubjects.existOrFail('manageConnectorsLink');
await testSubjects.click('manageConnectorsLink');
await browser.switchTab(1);
await testSubjects.existOrFail('edit-connector-flyout');
await browser.closeCurrentWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});

it('show edit context', async () => {
await pageObjects.searchPlayground.PlaygroundChatPage.expectEditContextOpens();
await pageObjects.searchPlayground.PlaygroundChatPage.expectEditContextOpens(
'basic_index',
['baz']
);
});

it('save selected fields between modes', async () => {
Expand Down

0 comments on commit 9bbdd10

Please sign in to comment.