-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 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]> (cherry picked from commit c46263e) Co-authored-by: Lin Wang <[email protected]>
- Loading branch information
1 parent
ff0a607
commit 57f48b4
Showing
2 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
cypress/integration/plugins/dashboards-assistant/mds_chatbot_default_data_source_change.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
const manualSetDefaultDataSource = (dataSourceTitle) => { | ||
// Go to data source list | ||
cy.getElementByTestId('dataSources').click(); | ||
|
||
cy.wait(1000); | ||
|
||
// Goto data source detail page | ||
cy.contains(dataSourceTitle).click(); | ||
|
||
if ( | ||
cy.getElementByTestId('editSetDefaultDataSource').contains('Set as default') | ||
) { | ||
cy.wait(2000); | ||
cy.getElementByTestId('editSetDefaultDataSource').click(); | ||
} | ||
// Back to data source list | ||
cy.getElementByTestId('dataSources').click(); | ||
}; | ||
|
||
const openChatBotAndSendMessage = () => { | ||
// Common text to wait for to confirm page loaded, give up to 120 seconds for initial load | ||
cy.get(`input[placeholder="Ask question"]`, { timeout: 120000 }).as( | ||
'chatInput' | ||
); | ||
cy.get('@chatInput').should('be.length', 1); | ||
|
||
cy.wait(1000); | ||
|
||
cy.get('@chatInput').click(); | ||
|
||
cy.get('@chatInput').type('What are the indices in my cluster?{enter}'); | ||
|
||
// should have a LLM Response | ||
cy.contains( | ||
'The indices in your cluster are the names listed in the response obtained from using a tool to get information about the OpenSearch indices.' | ||
).should('be.visible'); | ||
|
||
// Should have three bubbles | ||
cy.get('[aria-label="chat message bubble"]').should('have.length', 3); | ||
}; | ||
|
||
if ( | ||
Cypress.env('DASHBOARDS_ASSISTANT_ENABLED') && | ||
Cypress.env('DATASOURCE_MANAGEMENT_ENABLED') | ||
) { | ||
describe('Assistant basic spec', () => { | ||
beforeEach(function () { | ||
cy.deleteAllDataSources(); | ||
// create default data source | ||
cy.createDataSourceNoAuth({ title: 'DefaultDataSource' }).then( | ||
([dataSourceId]) => cy.setDefaultDataSource(dataSourceId) | ||
); | ||
// create new data source | ||
cy.createDataSourceNoAuth({ title: 'NewDataSource' }).as('newDataSource'); | ||
|
||
// Wait 3s for data source created | ||
cy.wait(3000); | ||
|
||
cy.visit('/app/management/opensearch-dashboards/dataSources'); | ||
cy.waitForLoader(); | ||
}); | ||
|
||
it('should reload history with new data source id', function () { | ||
// The header may render multiple times, wait for UI to be stable | ||
cy.wait(5000); | ||
// enable to toggle and show Chatbot | ||
cy.get(`img[aria-label="toggle chat flyout icon"]`).click(); | ||
cy.get('.llm-chat-flyout button[aria-label="history"]') | ||
.should('be.visible') | ||
.click(); | ||
|
||
cy.intercept('GET', '/api/assistant/conversations**').as( | ||
'loadConversationsRequest' | ||
); | ||
|
||
manualSetDefaultDataSource(this.newDataSource[1]); | ||
|
||
cy.wait('@loadConversationsRequest').then(({ request }) => { | ||
expect(request.url).contains(this.newDataSource[0]); | ||
}); | ||
}); | ||
|
||
it('should not reset to chat tab after data source change in history page', function () { | ||
openChatBotAndSendMessage(); | ||
|
||
cy.get('.llm-chat-flyout button[aria-label="history"]') | ||
.should('be.visible') | ||
.click(); | ||
|
||
manualSetDefaultDataSource(this.newDataSource[1]); | ||
|
||
// Should reset conversation and stay history page | ||
cy.get('h3').contains('OpenSearch Assistant').should('be.visible'); | ||
cy.get('h3').contains('Conversations').should('be.visible'); | ||
}); | ||
|
||
it('should reset chat conversation after data source changed', function () { | ||
openChatBotAndSendMessage(); | ||
|
||
manualSetDefaultDataSource(this.newDataSource[1]); | ||
|
||
// Should reset chat | ||
cy.get('h3').contains('OpenSearch Assistant').should('be.visible'); | ||
cy.get('[aria-label="chat message bubble"]').should('have.length', 1); | ||
}); | ||
|
||
it('should reset chat tab after data source changed in trace page', function () { | ||
openChatBotAndSendMessage(); | ||
// click view trace button | ||
cy.get(`[aria-label="How was this generated?"]`).click(); | ||
cy.contains('How was this generated').should('be.visible'); | ||
|
||
manualSetDefaultDataSource(this.newDataSource[1]); | ||
|
||
// Should reset chat tab | ||
cy.get('#how-was-this-generated').should('not.exist'); | ||
cy.get('h3').contains('OpenSearch Assistant').should('be.visible'); | ||
}); | ||
|
||
after(() => { | ||
cy.deleteAllDataSources(); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters