Skip to content

Commit

Permalink
feat: add cypress tests for conversation save to notebook
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam committed Jan 31, 2024
1 parent b5a0786 commit 79912ff
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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');
});
});
}
16 changes: 16 additions & 0 deletions cypress/utils/plugins/dashboards-assistant/helpers.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
};

0 comments on commit 79912ff

Please sign in to comment.