Skip to content

Commit c46263e

Browse files
authored
Add chatbot test cases for default data source change (#1386)
* Add test cases for default data source change Signed-off-by: Lin Wang <[email protected]> * Fix get title from undefined Signed-off-by: Lin Wang <[email protected]> * Go to data source list first Signed-off-by: Lin Wang <[email protected]> * Wait two seconds Signed-off-by: Lin Wang <[email protected]> * Delete all data sources every time Signed-off-by: Lin Wang <[email protected]> * Delete all data sources before each case Signed-off-by: Lin Wang <[email protected]> * Wait for 3s Signed-off-by: Lin Wang <[email protected]> --------- Signed-off-by: Lin Wang <[email protected]>
1 parent 6a453ef commit c46263e

File tree

2 files changed

+152
-20
lines changed

2 files changed

+152
-20
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
const manualSetDefaultDataSource = (dataSourceTitle) => {
7+
// Go to data source list
8+
cy.getElementByTestId('dataSources').click();
9+
10+
cy.wait(1000);
11+
12+
// Goto data source detail page
13+
cy.contains(dataSourceTitle).click();
14+
15+
if (
16+
cy.getElementByTestId('editSetDefaultDataSource').contains('Set as default')
17+
) {
18+
cy.wait(2000);
19+
cy.getElementByTestId('editSetDefaultDataSource').click();
20+
}
21+
// Back to data source list
22+
cy.getElementByTestId('dataSources').click();
23+
};
24+
25+
const openChatBotAndSendMessage = () => {
26+
// Common text to wait for to confirm page loaded, give up to 120 seconds for initial load
27+
cy.get(`input[placeholder="Ask question"]`, { timeout: 120000 }).as(
28+
'chatInput'
29+
);
30+
cy.get('@chatInput').should('be.length', 1);
31+
32+
cy.wait(1000);
33+
34+
cy.get('@chatInput').click();
35+
36+
cy.get('@chatInput').type('What are the indices in my cluster?{enter}');
37+
38+
// should have a LLM Response
39+
cy.contains(
40+
'The indices in your cluster are the names listed in the response obtained from using a tool to get information about the OpenSearch indices.'
41+
).should('be.visible');
42+
43+
// Should have three bubbles
44+
cy.get('[aria-label="chat message bubble"]').should('have.length', 3);
45+
};
46+
47+
if (
48+
Cypress.env('DASHBOARDS_ASSISTANT_ENABLED') &&
49+
Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')
50+
) {
51+
describe('Assistant basic spec', () => {
52+
beforeEach(function () {
53+
cy.deleteAllDataSources();
54+
// create default data source
55+
cy.createDataSourceNoAuth({ title: 'DefaultDataSource' }).then(
56+
([dataSourceId]) => cy.setDefaultDataSource(dataSourceId)
57+
);
58+
// create new data source
59+
cy.createDataSourceNoAuth({ title: 'NewDataSource' }).as('newDataSource');
60+
61+
// Wait 3s for data source created
62+
cy.wait(3000);
63+
64+
cy.visit('/app/management/opensearch-dashboards/dataSources');
65+
cy.waitForLoader();
66+
});
67+
68+
it('should reload history with new data source id', function () {
69+
// The header may render multiple times, wait for UI to be stable
70+
cy.wait(5000);
71+
// enable to toggle and show Chatbot
72+
cy.get(`img[aria-label="toggle chat flyout icon"]`).click();
73+
cy.get('.llm-chat-flyout button[aria-label="history"]')
74+
.should('be.visible')
75+
.click();
76+
77+
cy.intercept('GET', '/api/assistant/conversations**').as(
78+
'loadConversationsRequest'
79+
);
80+
81+
manualSetDefaultDataSource(this.newDataSource[1]);
82+
83+
cy.wait('@loadConversationsRequest').then(({ request }) => {
84+
expect(request.url).contains(this.newDataSource[0]);
85+
});
86+
});
87+
88+
it('should not reset to chat tab after data source change in history page', function () {
89+
openChatBotAndSendMessage();
90+
91+
cy.get('.llm-chat-flyout button[aria-label="history"]')
92+
.should('be.visible')
93+
.click();
94+
95+
manualSetDefaultDataSource(this.newDataSource[1]);
96+
97+
// Should reset conversation and stay history page
98+
cy.get('h3').contains('OpenSearch Assistant').should('be.visible');
99+
cy.get('h3').contains('Conversations').should('be.visible');
100+
});
101+
102+
it('should reset chat conversation after data source changed', function () {
103+
openChatBotAndSendMessage();
104+
105+
manualSetDefaultDataSource(this.newDataSource[1]);
106+
107+
// Should reset chat
108+
cy.get('h3').contains('OpenSearch Assistant').should('be.visible');
109+
cy.get('[aria-label="chat message bubble"]').should('have.length', 1);
110+
});
111+
112+
it('should reset chat tab after data source changed in trace page', function () {
113+
openChatBotAndSendMessage();
114+
// click view trace button
115+
cy.get(`[aria-label="How was this generated?"]`).click();
116+
cy.contains('How was this generated').should('be.visible');
117+
118+
manualSetDefaultDataSource(this.newDataSource[1]);
119+
120+
// Should reset chat tab
121+
cy.get('#how-was-this-generated').should('not.exist');
122+
cy.get('h3').contains('OpenSearch Assistant').should('be.visible');
123+
});
124+
125+
after(() => {
126+
cy.deleteAllDataSources();
127+
});
128+
});
129+
}

cypress/utils/dashboards/datasource-management-dashboards-plugin/commands.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,31 @@ Cypress.Commands.add('deleteAllDataSources', () => {
3535
);
3636
});
3737

38-
Cypress.Commands.add('createDataSourceNoAuth', () => {
39-
cy.request({
40-
method: 'POST',
41-
url: `${BASE_PATH}/api/saved_objects/data-source`,
42-
headers: {
43-
'osd-xsrf': true,
44-
},
45-
body: {
46-
attributes: {
47-
title: 'RemoteDataSourceNoAuth',
48-
endpoint: Cypress.env('remoteDataSourceNoAuthUrl'),
49-
auth: {
50-
type: 'no_auth',
38+
Cypress.Commands.add(
39+
'createDataSourceNoAuth',
40+
({ title = 'RemoteDataSourceNoAuth' } = {}) => {
41+
cy.request({
42+
method: 'POST',
43+
url: `${BASE_PATH}/api/saved_objects/data-source`,
44+
headers: {
45+
'osd-xsrf': true,
46+
},
47+
body: {
48+
attributes: {
49+
title,
50+
endpoint: Cypress.env('remoteDataSourceNoAuthUrl'),
51+
auth: {
52+
type: 'no_auth',
53+
},
5154
},
5255
},
53-
},
54-
}).then((resp) => {
55-
if (resp && resp.body && resp.body.id) {
56-
return [resp.body.id, 'RemoteDataSourceNoAuth'];
57-
}
58-
});
59-
});
56+
}).then((resp) => {
57+
if (resp && resp.body && resp.body.id) {
58+
return [resp.body.id, title];
59+
}
60+
});
61+
}
62+
);
6063

6164
Cypress.Commands.add('createDataSourceBasicAuth', () => {
6265
cy.request({

0 commit comments

Comments
 (0)