diff --git a/cypress/integration/plugins/dashboards-assistant/conversation_save_to_notebook_spec.js b/cypress/integration/plugins/dashboards-assistant/conversation_save_to_notebook_spec.js new file mode 100644 index 000000000..8dead32a3 --- /dev/null +++ b/cypress/integration/plugins/dashboards-assistant/conversation_save_to_notebook_spec.js @@ -0,0 +1,95 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { BASE_PATH } from '../../../utils/constants'; +import { setStorageItem } from '../../../utils/plugins/dashboards-assistant/helpers'; + +const QUESTION = 'What are the indices in my cluster?'; +const FINAL_ANSWER = + 'The indices in your cluster are the names listed in the response obtained from using a tool to get information about the OpenSearch indices.'; + +if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { + describe('Assistant conversation save to notebook spec', () => { + let restoreShowHome; + let restoreNewThemeModal; + let restoreTenantSwitchModal; + + before(() => { + // Set welcome screen tracking to false + restoreShowHome = setStorageItem( + localStorage, + 'home:welcome:show', + 'false' + ); + // Hide new theme modal + restoreNewThemeModal = setStorageItem( + localStorage, + 'home:newThemeModal:show', + 'false' + ); + }); + + after(() => { + if (restoreShowHome) { + restoreShowHome(); + } + if (restoreNewThemeModal) { + restoreNewThemeModal(); + } + if (restoreTenantSwitchModal) { + restoreTenantSwitchModal(); + } + }); + + beforeEach(() => { + // Visit OSD + cy.visit(`${BASE_PATH}/app/home`); + // 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().type(`${QUESTION}{enter}`); + + // should have a LLM Response + cy.contains(FINAL_ANSWER); + }); + + it('show succeed toast after saved notebook', () => { + cy.get('button[aria-label="toggle chat context menu"]').click(); + cy.contains('Save to notebook').click(); + cy.get('input[aria-label="Notebook name input"]').type('test notebook'); + cy.get('button[data-test-subj="confirmSaveToNotebookButton"]').click(); + + cy.get('div[aria-label="Notification message list"]') + .contains('This conversation was saved as') + .should('be.visible'); + }); + + it('show conversation history in the created notebook page', () => { + cy.get('button[aria-label="toggle chat context menu"]').click(); + cy.contains('Save to notebook').click(); + cy.get('input[aria-label="Notebook name input"]').type('test notebook'); + cy.get('button[data-test-subj="confirmSaveToNotebookButton"]').click(); + + // Click created notebook link in current tab + cy.get('div[aria-label="Notification message list"]') + .contains('test notebook') + .invoke('removeAttr', 'target') + .as('testNotebookLink'); + + cy.wait(1000); + cy.get('@testNotebookLink').click(); + + cy.location('pathname').should('contains', 'app/observability-notebooks'); + + cy.waitForLoader(); + cy.contains(QUESTION).should('be.visible'); + cy.contains(FINAL_ANSWER).should('be.visible'); + }); + }); +} diff --git a/cypress/utils/plugins/dashboards-assistant/helpers.js b/cypress/utils/plugins/dashboards-assistant/helpers.js new file mode 100644 index 000000000..73d061e08 --- /dev/null +++ b/cypress/utils/plugins/dashboards-assistant/helpers.js @@ -0,0 +1,16 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export const setStorageItem = (storage, key, value) => { + const oldValue = localStorage.getItem(key); + storage.setItem(key, value); + return () => { + if (oldValue === null) { + storage.removeItem(key); + } else { + storage.setItem(key, oldValue); + } + }; +};