|
| 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 | +if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { |
| 9 | + describe('Assistant conversation history spec', () => { |
| 10 | + let restoreShowHome; |
| 11 | + let restoreNewThemeModal; |
| 12 | + |
| 13 | + before(() => { |
| 14 | + // Set welcome screen tracking to false |
| 15 | + restoreShowHome = setStorageItem( |
| 16 | + localStorage, |
| 17 | + 'home:welcome:show', |
| 18 | + 'false' |
| 19 | + ); |
| 20 | + // Hide new theme modal |
| 21 | + restoreNewThemeModal = setStorageItem( |
| 22 | + localStorage, |
| 23 | + 'home:newThemeModal:show', |
| 24 | + 'false' |
| 25 | + ); |
| 26 | + // Visit OSD |
| 27 | + cy.visit(`${BASE_PATH}/app/home`); |
| 28 | + // Common text to wait for to confirm page loaded, give up to 60 seconds for initial load |
| 29 | + cy.get(`input[placeholder="Ask question"]`, { timeout: 60000 }).should( |
| 30 | + 'be.length', |
| 31 | + 1 |
| 32 | + ); |
| 33 | + |
| 34 | + // Open assistant flyout |
| 35 | + // The flyout button will be detached and can't be clicked, add 10s delayed fix it. |
| 36 | + cy.wait(10000); |
| 37 | + cy.get('img[aria-label="toggle chat flyout icon"]').click(); |
| 38 | + }); |
| 39 | + after(() => { |
| 40 | + if (restoreShowHome) { |
| 41 | + restoreShowHome(); |
| 42 | + } |
| 43 | + if (restoreNewThemeModal) { |
| 44 | + restoreNewThemeModal(); |
| 45 | + } |
| 46 | + // Close assistant flyout |
| 47 | + cy.get('img[aria-label="toggle chat flyout icon"]').click(); |
| 48 | + }); |
| 49 | + |
| 50 | + beforeEach(() => { |
| 51 | + cy.get('.llm-chat-flyout', { timeout: 60000 }).should('be.visible'); |
| 52 | + }); |
| 53 | + |
| 54 | + describe('panel operations', () => { |
| 55 | + it('should toggle history list', () => { |
| 56 | + cy.get('.llm-chat-flyout button[aria-label="history"]') |
| 57 | + .should('be.visible') |
| 58 | + .click(); |
| 59 | + cy.get('.llm-chat-flyout-body') |
| 60 | + .contains('Conversations') |
| 61 | + .should('be.visible'); |
| 62 | + |
| 63 | + cy.get('.llm-chat-flyout button[aria-label="history"]') |
| 64 | + .should('be.visible') |
| 65 | + .click(); |
| 66 | + cy.get('textarea[placeholder="Ask me anything..."]').should('exist'); |
| 67 | + cy.get('.llm-chat-flyout-body') |
| 68 | + .contains('Conversations') |
| 69 | + .should('not.be.visible'); |
| 70 | + }); |
| 71 | + |
| 72 | + it('should back to chat panel', () => { |
| 73 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 74 | + cy.get('.llm-chat-flyout') |
| 75 | + .contains('Conversations') |
| 76 | + .should('be.visible'); |
| 77 | + |
| 78 | + cy.get('.llm-chat-flyout-body').contains('Back').click(); |
| 79 | + cy.get('textarea[placeholder="Ask me anything..."]').should('exist'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should hide back button in fullscreen mode', () => { |
| 83 | + cy.get('.llm-chat-flyout button[aria-label="fullScreen"]').click(); |
| 84 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 85 | + |
| 86 | + cy.get('.llm-chat-flyout') |
| 87 | + .contains('Conversations') |
| 88 | + .should('be.visible'); |
| 89 | + cy.get('textarea[placeholder="Ask me anything..."]').should('exist'); |
| 90 | + cy.get('.llm-chat-flyout-body') |
| 91 | + .contains('Back', { timeout: 3000 }) |
| 92 | + .should('not.exist'); |
| 93 | + |
| 94 | + // Back to default mode |
| 95 | + cy.get('.llm-chat-flyout button[aria-label="fullScreen"]').click(); |
| 96 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 97 | + }); |
| 98 | + }); |
| 99 | + describe('history item operations', () => { |
| 100 | + const conversations = []; |
| 101 | + |
| 102 | + before(() => { |
| 103 | + // Create conversations data |
| 104 | + cy.sendAssistantMessage({ |
| 105 | + input: { |
| 106 | + type: 'input', |
| 107 | + content: 'What are the indices in my cluster?', |
| 108 | + contentType: 'text', |
| 109 | + }, |
| 110 | + }).then((result) => { |
| 111 | + if (result.status !== 200) { |
| 112 | + throw result.body; |
| 113 | + } |
| 114 | + conversations.push(result.body); |
| 115 | + }); |
| 116 | + }); |
| 117 | + |
| 118 | + after(() => { |
| 119 | + // Clear created conversations in tests |
| 120 | + conversations.map(({ conversationId }) => |
| 121 | + cy.deleteConversation(conversationId) |
| 122 | + ); |
| 123 | + }); |
| 124 | + |
| 125 | + it('should show created conversation in the history list', () => { |
| 126 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 127 | + |
| 128 | + cy.get('.llm-chat-flyout').contains('Conversations'); |
| 129 | + conversations.forEach(({ conversationId }) => { |
| 130 | + cy.getElementByTestId(`chatHistoryItem-${conversationId}`).should( |
| 131 | + 'exist' |
| 132 | + ); |
| 133 | + }); |
| 134 | + cy.contains('What are the indices in my cluster?'); |
| 135 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 136 | + }); |
| 137 | + |
| 138 | + it('should load conversation in chat panel', () => { |
| 139 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 140 | + |
| 141 | + const conversationToLoad = conversations[0]; |
| 142 | + |
| 143 | + cy.getElementByTestId( |
| 144 | + `chatHistoryItem-${conversationToLoad.conversationId}` |
| 145 | + ) |
| 146 | + .contains(conversationToLoad.title) |
| 147 | + .click(); |
| 148 | + cy.get('textarea[placeholder="Ask me anything..."]').should('exist'); |
| 149 | + cy.get('div.llm-chat-bubble-panel-input').contains( |
| 150 | + conversationToLoad.title |
| 151 | + ); |
| 152 | + }); |
| 153 | + |
| 154 | + it('should able to update conversation title', () => { |
| 155 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 156 | + |
| 157 | + const conversationToUpdate = conversations[0]; |
| 158 | + const newTitle = 'New title'; |
| 159 | + |
| 160 | + cy.getElementByTestId( |
| 161 | + `chatHistoryItem-${conversationToUpdate.conversationId}` |
| 162 | + ) |
| 163 | + .find('button[aria-label="Edit conversation name"]') |
| 164 | + .click(); |
| 165 | + cy.contains('Edit conversation name'); |
| 166 | + |
| 167 | + cy.get('input[aria-label="Conversation name input"').type(newTitle); |
| 168 | + cy.getElementByTestId('confirmModalConfirmButton') |
| 169 | + .contains('Confirm name') |
| 170 | + .click(); |
| 171 | + |
| 172 | + conversationToUpdate.title = newTitle; |
| 173 | + cy.getElementByTestId( |
| 174 | + `chatHistoryItem-${conversationToUpdate.conversationId}` |
| 175 | + ).contains(conversationToUpdate.title); |
| 176 | + cy.contains('Edit conversation name', { timeout: 3000 }).should( |
| 177 | + 'not.exist' |
| 178 | + ); |
| 179 | + |
| 180 | + // Reset to chat panel |
| 181 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 182 | + }); |
| 183 | + |
| 184 | + it('should able to delete conversation', () => { |
| 185 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 186 | + |
| 187 | + const conversationToDelete = conversations[0]; |
| 188 | + |
| 189 | + cy.getElementByTestId( |
| 190 | + `chatHistoryItem-${conversationToDelete.conversationId}` |
| 191 | + ) |
| 192 | + .find('button[aria-label="Delete conversation"]') |
| 193 | + .click(); |
| 194 | + cy.getElementByTestId('confirmModalTitleText').contains( |
| 195 | + 'Delete conversation' |
| 196 | + ); |
| 197 | + |
| 198 | + cy.getElementByTestId('confirmModalConfirmButton') |
| 199 | + .contains('Delete conversation') |
| 200 | + .click(); |
| 201 | + |
| 202 | + cy.getElementByTestId( |
| 203 | + `chatHistoryItem-${conversationToDelete.conversationId}` |
| 204 | + ).should('not.exist'); |
| 205 | + conversations.shift(); |
| 206 | + |
| 207 | + // Reset to chat panel |
| 208 | + cy.get('.llm-chat-flyout button[aria-label="history"]').click(); |
| 209 | + }); |
| 210 | + }); |
| 211 | + }); |
| 212 | +} |
0 commit comments