-
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.
feat: add cypress tests for conversation save to notebook
Signed-off-by: Lin Wang <[email protected]>
- Loading branch information
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
cypress/integration/plugins/dashboards-assistant/conversation_save_to_notebook_spec.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,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'); | ||
}); | ||
}); | ||
} |
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,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); | ||
} | ||
}; | ||
}; |