|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { BASE_PATH } from '../../../utils/constants'; |
| 7 | + |
| 8 | +if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { |
| 9 | + describe('Interaction trace spec', () => { |
| 10 | + before(() => { |
| 11 | + // Set welcome screen tracking to false |
| 12 | + localStorage.setItem('home:welcome:show', 'false'); |
| 13 | + // Set new theme modal to false |
| 14 | + localStorage.setItem('home:newThemeModal:show', 'false'); |
| 15 | + |
| 16 | + cy.visit(`${BASE_PATH}/app/home`); |
| 17 | + // cy.waitForLoader(); |
| 18 | + |
| 19 | + // Common text to wait for to confirm page loaded, give up to 120 seconds for initial load |
| 20 | + cy.get(`input[placeholder="Ask question"]`, { timeout: 120000 }).as( |
| 21 | + 'chatInput' |
| 22 | + ); |
| 23 | + cy.get('@chatInput').should('be.length', 1); |
| 24 | + |
| 25 | + cy.wait(1000); |
| 26 | + |
| 27 | + cy.get('@chatInput') |
| 28 | + .click() |
| 29 | + .type('What are the indices in my cluster?{enter}'); |
| 30 | + |
| 31 | + // should have a LLM Response |
| 32 | + cy.contains( |
| 33 | + 'The indices in your cluster are the names listed in the response obtained from using a tool to get information about the OpenSearch indices.' |
| 34 | + ); |
| 35 | + }); |
| 36 | + |
| 37 | + // clean up localStorage items |
| 38 | + after(() => { |
| 39 | + localStorage.removeItem('home:welcome:show'); |
| 40 | + localStorage.removeItem('home:newThemeModal:show'); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('Trace page', () => { |
| 44 | + it('open trace page and verify page content', () => { |
| 45 | + // click How was this generated? to view trace |
| 46 | + cy.contains('How was this generated?').click(); |
| 47 | + |
| 48 | + cy.get(`.llm-chat-flyout .llm-chat-flyout-body`).as('tracePage'); |
| 49 | + cy.get('@tracePage') |
| 50 | + .find(`button[aria-label="back"]`) |
| 51 | + .should('have.length', 1); |
| 52 | + |
| 53 | + cy.get('@tracePage') |
| 54 | + .find(`button[aria-label="close"]`) |
| 55 | + .should('have.length', 0); |
| 56 | + |
| 57 | + // title |
| 58 | + cy.get('@tracePage').contains('h1', 'How was this generated'); |
| 59 | + |
| 60 | + // question |
| 61 | + cy.get('@tracePage').contains('What are the indices in my cluster?'); |
| 62 | + |
| 63 | + // result |
| 64 | + cy.get('@tracePage').contains( |
| 65 | + 'The indices in your cluster are the names listed in the response obtained from using a tool to get information about the OpenSearch indices.' |
| 66 | + ); |
| 67 | + }); |
| 68 | + |
| 69 | + it('tools invocation displayed in trace steps', () => { |
| 70 | + // trace |
| 71 | + cy.get(`.llm-chat-flyout .llm-chat-flyout-body`).as('tracePage'); |
| 72 | + cy.get('@tracePage').find('.euiAccordion').should('have.length', 1); |
| 73 | + |
| 74 | + cy.get('@tracePage') |
| 75 | + .find('.euiAccordion') |
| 76 | + // tool name |
| 77 | + .contains('Step 1 - CatIndexTool') |
| 78 | + .click({ force: true }); |
| 79 | + |
| 80 | + // tool output |
| 81 | + cy.contains('Output: health status index'); |
| 82 | + }); |
| 83 | + |
| 84 | + it('trace page display correctly in fullscreen mode', () => { |
| 85 | + cy.get(`.llm-chat-flyout-header`) |
| 86 | + .find(`button[aria-label="fullScreen"]`) |
| 87 | + .click({ force: true }); |
| 88 | + |
| 89 | + // show close button |
| 90 | + cy.get(`.llm-chat-flyout .llm-chat-flyout-body`).as('tracePage'); |
| 91 | + cy.get('@tracePage') |
| 92 | + .find(`button[aria-label="close"]`) |
| 93 | + .should('have.length', 1); |
| 94 | + |
| 95 | + cy.get('@tracePage') |
| 96 | + .find(`button[aria-label="back"]`) |
| 97 | + .should('have.length', 0); |
| 98 | + |
| 99 | + // both chat and trace are both displayed |
| 100 | + cy.contains('How was this generated?').click(); |
| 101 | + }); |
| 102 | + }); |
| 103 | + }); |
| 104 | +} |
0 commit comments