|
| 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 | +} |
0 commit comments