From fff6a5f1df039c75d47ec5d11b1e5e845288ed3b Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Wed, 24 Jan 2024 17:18:50 +0800 Subject: [PATCH 1/5] feat: add test cases for assistant conversation history Signed-off-by: Lin Wang --- .../coversation_history_sepc.js | 201 ++++++++++++++++++ .../plugins/dashboards-assistant/commands.js | 16 +- .../plugins/dashboards-assistant/constants.js | 7 + 3 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js diff --git a/cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js b/cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js new file mode 100644 index 000000000..369e1bf4f --- /dev/null +++ b/cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js @@ -0,0 +1,201 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { BASE_PATH } from '../../../utils/constants'; +import '@cypress/skip-test/support'; + +const conversations = []; +const constructConversations = () => { + cy.sendMessage({ + input: { + type: 'input', + content: 'What are the indices in my cluster?', + contentType: 'text', + }, + }).then((result) => { + if (result.status !== 200) { + throw result.body; + } + conversations.push(result.body); + }); +}; + +const clearConversations = () => + conversations.map(({ conversationId }) => + cy.deleteConversation(conversationId) + ); + +if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { + describe('Assistant conversation history spec', () => { + before(() => { + // Set welcome screen tracking to false + localStorage.setItem('home:welcome:show', 'false'); + // Hide new theme modal + localStorage.setItem('home:newThemeModal:show', 'false'); + // Visit OSD + cy.visit(`${BASE_PATH}/app/home`); + // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load + cy.get(`input[placeholder="Ask question"]`, { timeout: 60000 }).should( + 'be.length', + 1 + ); + + // Open chat flyout + cy.get('body') + .then(($body) => $body.find('.llm-chat-flyout').length !== 0) + .then((chatFlyoutOpened) => { + if (!chatFlyoutOpened) { + cy.get('img[aria-label="toggle chat flyout icon"]').click(); + } + }); + }); + after(() => { + // Close Chat bot + cy.get('body') + .then(($body) => $body.find('.llm-chat-flyout').length !== 0) + .then((chatFlyoutOpened) => { + if (chatFlyoutOpened) { + cy.get('img[aria-label="toggle chat flyout icon"]').click(); + } + }); + }); + describe('panel operations', () => { + it('should show created conversation in the history list', () => { + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + + cy.get('.llm-chat-flyout').contains('Conversations'); + conversations.forEach(({ conversationId }) => { + cy.get( + `div[data-test-subj="chatHistoryItem-${conversationId}"]` + ).should('exist'); + }); + cy.contains('What are the indices in my cluster?'); + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + }); + + it('should toggle history list', () => { + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + cy.get('.llm-chat-flyout-body') + .contains('Conversations') + .should('be.visible'); + + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + cy.get('textarea[placeholder="Ask me anything..."]').should('exist'); + cy.get('.llm-chat-flyout-body') + .contains('Conversations') + .should('not.be.visible'); + }); + + it('should back to chat panel', () => { + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + cy.get('.llm-chat-flyout') + .contains('Conversations') + .should('be.visible'); + + cy.get('.llm-chat-flyout-body').contains('Back').click(); + cy.get('textarea[placeholder="Ask me anything..."]').should('exist'); + }); + + it('should hide back button in fullscreen mode', () => { + cy.get('.llm-chat-flyout button[aria-label="fullScreen"]').click(); + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + + cy.get('.llm-chat-flyout') + .contains('Conversations') + .should('be.visible'); + cy.get('textarea[placeholder="Ask me anything..."]').should('exist'); + cy.get('.llm-chat-flyout-body') + .contains('Back', { timeout: 3000 }) + .should('not.exist'); + + // Back to default mode + cy.get('.llm-chat-flyout button[aria-label="fullScreen"]').click(); + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + }); + }); + describe('history item operations', () => { + before(() => { + // Create conversations data + constructConversations(); + }); + + after(() => { + // Clear created conversations in tests + clearConversations(); + }); + + it('should load conversation in chat panel', () => { + cy.skipOn(conversations.length === 0); + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + + const conversationToLoad = conversations[0]; + + cy.get( + `div[data-test-subj="chatHistoryItem-${conversationToLoad.conversationId}"]` + ) + .contains(conversationToLoad.title) + .click(); + cy.get('textarea[placeholder="Ask me anything..."]').should('exist'); + cy.get('div.llm-chat-bubble-panel-input').contains( + conversationToLoad.title + ); + }); + + it('should able to update conversation title', () => { + cy.skipOn(conversations.length === 0); + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + + const conversationToUpdate = conversations[0]; + const newTitle = 'New title'; + + cy.get( + `div[data-test-subj="chatHistoryItem-${conversationToUpdate.conversationId}"] button[aria-label="Edit conversation name"]` + ).click(); + cy.contains('Edit conversation name'); + + cy.get('input[aria-label="Conversation name input"').type(newTitle); + cy.get('button[data-test-subj="confirmModalConfirmButton"]') + .contains('Confirm name') + .click(); + + conversationToUpdate.title = newTitle; + cy.get( + `div[data-test-subj="chatHistoryItem-${conversationToUpdate.conversationId}"]` + ).contains(conversationToUpdate.title); + cy.contains('Edit conversation name', { timeout: 3000 }).should( + 'not.exist' + ); + + // Reset to chat panel + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + }); + + it('should able to delete conversation', () => { + cy.skipOn(conversations.length === 0); + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + + const conversationToDelete = conversations[0]; + + cy.get( + `div[data-test-subj="chatHistoryItem-${conversationToDelete.conversationId}"] button[aria-label="Delete conversation"]` + ).click(); + cy.get('div[data-test-subj="confirmModalTitleText"]').contains( + 'Delete conversation' + ); + + cy.get('button[data-test-subj="confirmModalConfirmButton"]') + .contains('Delete conversation') + .click(); + + cy.get( + `div[data-test-subj="chatHistoryItem-${conversationToDelete.conversationId}"]` + ).should('not.exist'); + conversations.shift(); + + // Reset to chat panel + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + }); + }); + }); +} diff --git a/cypress/utils/plugins/dashboards-assistant/commands.js b/cypress/utils/plugins/dashboards-assistant/commands.js index 51df1be8a..99fb63628 100644 --- a/cypress/utils/plugins/dashboards-assistant/commands.js +++ b/cypress/utils/plugins/dashboards-assistant/commands.js @@ -4,9 +4,10 @@ */ import FlowTemplateJSON from '../../../fixtures/plugins/dashboards-assistant/flow-template.json'; -import { BACKEND_BASE_PATH } from '../../constants'; -import { ML_COMMONS_API } from './constants'; +import { BACKEND_BASE_PATH, BASE_PATH } from '../../constants'; +import { ML_COMMONS_API, ASSISTANT_API } from './constants'; import clusterSettings from '../../../fixtures/plugins/dashboards-assistant/cluster_settings.json'; +import { apiRequest } from '../../helpers'; Cypress.Commands.add('addAssistantRequiredSettings', () => { cy.request('PUT', `${BACKEND_BASE_PATH}/_cluster/settings`, clusterSettings); @@ -152,3 +153,14 @@ Cypress.Commands.add('stopDummyServer', () => { } }); }); + +Cypress.Commands.add('sendMessage', (body) => + apiRequest(`${BASE_PATH}${ASSISTANT_API.SEND_MESSAGE}`, 'POST', body) +); + +Cypress.Commands.add('deleteConversation', (conversationId) => + apiRequest( + `${BASE_PATH}${ASSISTANT_API.CONVERSATION}/${conversationId}`, + 'DELETE' + ) +); diff --git a/cypress/utils/plugins/dashboards-assistant/constants.js b/cypress/utils/plugins/dashboards-assistant/constants.js index 16592accb..c8340b5ed 100644 --- a/cypress/utils/plugins/dashboards-assistant/constants.js +++ b/cypress/utils/plugins/dashboards-assistant/constants.js @@ -15,3 +15,10 @@ export const ML_COMMONS_API = { CREATE_MODEL: `${ML_COMMONS_API_PREFIX}/models/_register`, CREATE_AGENT: `${ML_COMMONS_API_PREFIX}/agents/_register`, }; + +export const ASSISTANT_API_BASE = '/api/assistant'; + +export const ASSISTANT_API = { + SEND_MESSAGE: `${ASSISTANT_API_BASE}/send_message`, + CONVERSATION: `${ASSISTANT_API_BASE}/conversation`, +}; From d3fd8977a49edd1541469f3515bbb10199c13404 Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Wed, 24 Jan 2024 18:12:16 +0800 Subject: [PATCH 2/5] feat: move created history test below Signed-off-by: Lin Wang --- .../coversation_history_sepc.js | 66 +++++++++---------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js b/cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js index 369e1bf4f..aee183846 100644 --- a/cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js +++ b/cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js @@ -5,27 +5,6 @@ import { BASE_PATH } from '../../../utils/constants'; import '@cypress/skip-test/support'; -const conversations = []; -const constructConversations = () => { - cy.sendMessage({ - input: { - type: 'input', - content: 'What are the indices in my cluster?', - contentType: 'text', - }, - }).then((result) => { - if (result.status !== 200) { - throw result.body; - } - conversations.push(result.body); - }); -}; - -const clearConversations = () => - conversations.map(({ conversationId }) => - cy.deleteConversation(conversationId) - ); - if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { describe('Assistant conversation history spec', () => { before(() => { @@ -61,19 +40,6 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { }); }); describe('panel operations', () => { - it('should show created conversation in the history list', () => { - cy.get('.llm-chat-flyout button[aria-label="history"]').click(); - - cy.get('.llm-chat-flyout').contains('Conversations'); - conversations.forEach(({ conversationId }) => { - cy.get( - `div[data-test-subj="chatHistoryItem-${conversationId}"]` - ).should('exist'); - }); - cy.contains('What are the indices in my cluster?'); - cy.get('.llm-chat-flyout button[aria-label="history"]').click(); - }); - it('should toggle history list', () => { cy.get('.llm-chat-flyout button[aria-label="history"]').click(); cy.get('.llm-chat-flyout-body') @@ -115,14 +81,42 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { }); }); describe('history item operations', () => { + const conversations = []; + before(() => { // Create conversations data - constructConversations(); + cy.sendMessage({ + input: { + type: 'input', + content: 'What are the indices in my cluster?', + contentType: 'text', + }, + }).then((result) => { + if (result.status !== 200) { + throw result.body; + } + conversations.push(result.body); + }); }); after(() => { // Clear created conversations in tests - clearConversations(); + conversations.map(({ conversationId }) => + cy.deleteConversation(conversationId) + ); + }); + + it('should show created conversation in the history list', () => { + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + + cy.get('.llm-chat-flyout').contains('Conversations'); + conversations.forEach(({ conversationId }) => { + cy.get( + `div[data-test-subj="chatHistoryItem-${conversationId}"]` + ).should('exist'); + }); + cy.contains('What are the indices in my cluster?'); + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); }); it('should load conversation in chat panel', () => { From 9b3355004d342e840f679a0746872eb64419807b Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Wed, 24 Jan 2024 18:21:01 +0800 Subject: [PATCH 3/5] rename coversation_history_spec to conversation_history_spec Signed-off-by: Lin Wang --- .../{coversation_history_sepc.js => conversation_history_spec.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cypress/integration/plugins/dashboards-assistant/{coversation_history_sepc.js => conversation_history_spec.js} (100%) diff --git a/cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js b/cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js similarity index 100% rename from cypress/integration/plugins/dashboards-assistant/coversation_history_sepc.js rename to cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js From 4f6e751a36c6af260eb6457a5be7384ccff13806 Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Thu, 25 Jan 2024 12:02:14 +0800 Subject: [PATCH 4/5] Address pr comments Signed-off-by: Lin Wang --- .../conversation_history_spec.js | 69 ++++++++++++------- .../plugins/dashboards-assistant/commands.js | 2 +- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js b/cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js index aee183846..fc9198fcc 100644 --- a/cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js +++ b/cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js @@ -3,15 +3,32 @@ * SPDX-License-Identifier: Apache-2.0 */ import { BASE_PATH } from '../../../utils/constants'; -import '@cypress/skip-test/support'; + +const setLocalStorageItem = (key, value) => { + const oldValue = localStorage.getItem(key); + localStorage.setItem(key, value); + return () => { + if (oldValue === null) { + localStorage.removeItem(key); + } else { + localStorage.setItem(key, oldValue); + } + }; +}; if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { describe('Assistant conversation history spec', () => { + let restoreShowHome; + let restoreNewThemeModal; + before(() => { // Set welcome screen tracking to false - localStorage.setItem('home:welcome:show', 'false'); + restoreShowHome = setLocalStorageItem('home:welcome:show', 'false'); // Hide new theme modal - localStorage.setItem('home:newThemeModal:show', 'false'); + restoreNewThemeModal = setLocalStorageItem( + 'home:newThemeModal:show', + 'false' + ); // Visit OSD cy.visit(`${BASE_PATH}/app/home`); // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load @@ -20,33 +37,38 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { 1 ); - // Open chat flyout - cy.get('body') - .then(($body) => $body.find('.llm-chat-flyout').length !== 0) - .then((chatFlyoutOpened) => { - if (!chatFlyoutOpened) { - cy.get('img[aria-label="toggle chat flyout icon"]').click(); - } - }); + // Open assistant flyout + // The flyout button will be detached and can't be clicked, add 10s delayed fix it. + cy.wait(10000); + cy.get('img[aria-label="toggle chat flyout icon"]').click(); }); after(() => { - // Close Chat bot - cy.get('body') - .then(($body) => $body.find('.llm-chat-flyout').length !== 0) - .then((chatFlyoutOpened) => { - if (chatFlyoutOpened) { - cy.get('img[aria-label="toggle chat flyout icon"]').click(); - } - }); + if (restoreShowHome) { + restoreShowHome(); + } + if (restoreNewThemeModal) { + restoreNewThemeModal(); + } + // Close assistant flyout + cy.get('img[aria-label="toggle chat flyout icon"]').click(); }); + + beforeEach(() => { + cy.get('.llm-chat-flyout', { timeout: 60000 }).should('be.visible'); + }); + describe('panel operations', () => { it('should toggle history list', () => { - cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + cy.get('.llm-chat-flyout button[aria-label="history"]') + .should('be.visible') + .click(); cy.get('.llm-chat-flyout-body') .contains('Conversations') .should('be.visible'); - cy.get('.llm-chat-flyout button[aria-label="history"]').click(); + cy.get('.llm-chat-flyout button[aria-label="history"]') + .should('be.visible') + .click(); cy.get('textarea[placeholder="Ask me anything..."]').should('exist'); cy.get('.llm-chat-flyout-body') .contains('Conversations') @@ -85,7 +107,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { before(() => { // Create conversations data - cy.sendMessage({ + cy.sendAssistantMessage({ input: { type: 'input', content: 'What are the indices in my cluster?', @@ -120,7 +142,6 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { }); it('should load conversation in chat panel', () => { - cy.skipOn(conversations.length === 0); cy.get('.llm-chat-flyout button[aria-label="history"]').click(); const conversationToLoad = conversations[0]; @@ -137,7 +158,6 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { }); it('should able to update conversation title', () => { - cy.skipOn(conversations.length === 0); cy.get('.llm-chat-flyout button[aria-label="history"]').click(); const conversationToUpdate = conversations[0]; @@ -166,7 +186,6 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { }); it('should able to delete conversation', () => { - cy.skipOn(conversations.length === 0); cy.get('.llm-chat-flyout button[aria-label="history"]').click(); const conversationToDelete = conversations[0]; diff --git a/cypress/utils/plugins/dashboards-assistant/commands.js b/cypress/utils/plugins/dashboards-assistant/commands.js index 99fb63628..8197c9d80 100644 --- a/cypress/utils/plugins/dashboards-assistant/commands.js +++ b/cypress/utils/plugins/dashboards-assistant/commands.js @@ -154,7 +154,7 @@ Cypress.Commands.add('stopDummyServer', () => { }); }); -Cypress.Commands.add('sendMessage', (body) => +Cypress.Commands.add('sendAssistantMessage', (body) => apiRequest(`${BASE_PATH}${ASSISTANT_API.SEND_MESSAGE}`, 'POST', body) ); From 3ac435b4c14373dc5361a37f37495af9f0c02b0f Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Tue, 30 Jan 2024 17:22:35 +0800 Subject: [PATCH 5/5] refactor: move setStorageItem to helpers and change to getElementByTestId Signed-off-by: Lin Wang --- .../conversation_history_spec.js | 62 +++++++++---------- .../plugins/dashboards-assistant/helpers.js | 16 +++++ 2 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 cypress/utils/plugins/dashboards-assistant/helpers.js diff --git a/cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js b/cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js index fc9198fcc..0349481b9 100644 --- a/cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js +++ b/cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js @@ -3,18 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ import { BASE_PATH } from '../../../utils/constants'; - -const setLocalStorageItem = (key, value) => { - const oldValue = localStorage.getItem(key); - localStorage.setItem(key, value); - return () => { - if (oldValue === null) { - localStorage.removeItem(key); - } else { - localStorage.setItem(key, oldValue); - } - }; -}; +import { setStorageItem } from '../../../utils/plugins/dashboards-assistant/helpers'; if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { describe('Assistant conversation history spec', () => { @@ -23,9 +12,14 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { before(() => { // Set welcome screen tracking to false - restoreShowHome = setLocalStorageItem('home:welcome:show', 'false'); + restoreShowHome = setStorageItem( + localStorage, + 'home:welcome:show', + 'false' + ); // Hide new theme modal - restoreNewThemeModal = setLocalStorageItem( + restoreNewThemeModal = setStorageItem( + localStorage, 'home:newThemeModal:show', 'false' ); @@ -133,9 +127,9 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { cy.get('.llm-chat-flyout').contains('Conversations'); conversations.forEach(({ conversationId }) => { - cy.get( - `div[data-test-subj="chatHistoryItem-${conversationId}"]` - ).should('exist'); + cy.getElementByTestId(`chatHistoryItem-${conversationId}`).should( + 'exist' + ); }); cy.contains('What are the indices in my cluster?'); cy.get('.llm-chat-flyout button[aria-label="history"]').click(); @@ -146,8 +140,8 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { const conversationToLoad = conversations[0]; - cy.get( - `div[data-test-subj="chatHistoryItem-${conversationToLoad.conversationId}"]` + cy.getElementByTestId( + `chatHistoryItem-${conversationToLoad.conversationId}` ) .contains(conversationToLoad.title) .click(); @@ -163,19 +157,21 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { const conversationToUpdate = conversations[0]; const newTitle = 'New title'; - cy.get( - `div[data-test-subj="chatHistoryItem-${conversationToUpdate.conversationId}"] button[aria-label="Edit conversation name"]` - ).click(); + cy.getElementByTestId( + `chatHistoryItem-${conversationToUpdate.conversationId}` + ) + .find('button[aria-label="Edit conversation name"]') + .click(); cy.contains('Edit conversation name'); cy.get('input[aria-label="Conversation name input"').type(newTitle); - cy.get('button[data-test-subj="confirmModalConfirmButton"]') + cy.getElementByTestId('confirmModalConfirmButton') .contains('Confirm name') .click(); conversationToUpdate.title = newTitle; - cy.get( - `div[data-test-subj="chatHistoryItem-${conversationToUpdate.conversationId}"]` + cy.getElementByTestId( + `chatHistoryItem-${conversationToUpdate.conversationId}` ).contains(conversationToUpdate.title); cy.contains('Edit conversation name', { timeout: 3000 }).should( 'not.exist' @@ -190,19 +186,21 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { const conversationToDelete = conversations[0]; - cy.get( - `div[data-test-subj="chatHistoryItem-${conversationToDelete.conversationId}"] button[aria-label="Delete conversation"]` - ).click(); - cy.get('div[data-test-subj="confirmModalTitleText"]').contains( + cy.getElementByTestId( + `chatHistoryItem-${conversationToDelete.conversationId}` + ) + .find('button[aria-label="Delete conversation"]') + .click(); + cy.getElementByTestId('confirmModalTitleText').contains( 'Delete conversation' ); - cy.get('button[data-test-subj="confirmModalConfirmButton"]') + cy.getElementByTestId('confirmModalConfirmButton') .contains('Delete conversation') .click(); - cy.get( - `div[data-test-subj="chatHistoryItem-${conversationToDelete.conversationId}"]` + cy.getElementByTestId( + `chatHistoryItem-${conversationToDelete.conversationId}` ).should('not.exist'); conversations.shift(); diff --git a/cypress/utils/plugins/dashboards-assistant/helpers.js b/cypress/utils/plugins/dashboards-assistant/helpers.js new file mode 100644 index 000000000..53093a530 --- /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 = storage.getItem(key); + storage.setItem(key, value); + return () => { + if (oldValue === null) { + storage.removeItem(key); + } else { + storage.setItem(key, oldValue); + } + }; +};