Skip to content

Commit a394382

Browse files
feat: add cypress tests for conversation save to notebook (#1028) (#1043)
Signed-off-by: Lin Wang <[email protected]> (cherry picked from commit d1e5414) Co-authored-by: Lin Wang <[email protected]>
1 parent 6ad8c9c commit a394382

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { BASE_PATH } from '../../../utils/constants';
6+
import { setStorageItem } from '../../../utils/plugins/dashboards-assistant/helpers';
7+
8+
const QUESTION = 'What are the indices in my cluster?';
9+
const FINAL_ANSWER =
10+
'The indices in your cluster are the names listed in the response obtained from using a tool to get information about the OpenSearch indices.';
11+
12+
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
13+
describe('Assistant conversation save to notebook spec', () => {
14+
let restoreShowHome;
15+
let restoreNewThemeModal;
16+
let restoreTenantSwitchModal;
17+
18+
beforeEach(() => {
19+
// Set welcome screen tracking to false
20+
restoreShowHome = setStorageItem(
21+
localStorage,
22+
'home:welcome:show',
23+
'false'
24+
);
25+
// Hide new theme modal
26+
restoreNewThemeModal = setStorageItem(
27+
localStorage,
28+
'home:newThemeModal:show',
29+
'false'
30+
);
31+
restoreTenantSwitchModal = setStorageItem(
32+
sessionStorage,
33+
'opendistro::security::tenant::show_popup',
34+
'false'
35+
);
36+
// Visit OSD
37+
cy.visit(`${BASE_PATH}/app/home`);
38+
// Common text to wait for to confirm page loaded, give up to 120 seconds for initial load
39+
cy.get(`input[placeholder="Ask question"]`, { timeout: 120000 }).as(
40+
'chatInput'
41+
);
42+
cy.get('@chatInput').should('be.length', 1);
43+
44+
cy.wait(10000);
45+
46+
cy.get('@chatInput').click().type(`${QUESTION}{enter}`);
47+
48+
// should have a LLM Response
49+
cy.contains(FINAL_ANSWER);
50+
});
51+
52+
afterEach(() => {
53+
if (restoreShowHome) {
54+
restoreShowHome();
55+
}
56+
if (restoreNewThemeModal) {
57+
restoreNewThemeModal();
58+
}
59+
if (restoreTenantSwitchModal) {
60+
restoreTenantSwitchModal();
61+
}
62+
});
63+
64+
it('show succeed toast after saved notebook', () => {
65+
cy.get('button[aria-label="toggle chat context menu"]').click();
66+
cy.contains('Save to notebook').click();
67+
cy.get('input[aria-label="Notebook name input"]').type('test notebook');
68+
cy.get('button[data-test-subj="confirmSaveToNotebookButton"]').click();
69+
70+
cy.get('div[aria-label="Notification message list"]')
71+
.contains('This conversation was saved as')
72+
.should('be.visible');
73+
});
74+
75+
it('show conversation details in the created notebook page', () => {
76+
cy.get('button[aria-label="toggle chat context menu"]').click();
77+
cy.contains('Save to notebook').click();
78+
cy.get('input[aria-label="Notebook name input"]').type('test notebook');
79+
cy.get('button[data-test-subj="confirmSaveToNotebookButton"]').click();
80+
81+
// Click created notebook link in current tab
82+
cy.get('div[aria-label="Notification message list"]')
83+
.contains('test notebook')
84+
.invoke('removeAttr', 'target')
85+
.as('testNotebookLink');
86+
87+
cy.wait(1000);
88+
cy.get('@testNotebookLink').click();
89+
90+
cy.location('pathname').should('contains', 'app/observability-notebooks');
91+
92+
cy.waitForLoader();
93+
cy.contains(QUESTION).should('be.visible');
94+
cy.contains(FINAL_ANSWER).should('be.visible');
95+
});
96+
});
97+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
export const setStorageItem = (storage, key, value) => {
7+
const oldValue = storage.getItem(key);
8+
storage.setItem(key, value);
9+
return () => {
10+
if (oldValue === null) {
11+
storage.removeItem(key);
12+
} else {
13+
storage.setItem(key, oldValue);
14+
}
15+
};
16+
};

0 commit comments

Comments
 (0)