From 500e4aa36ef9a050cf9f635ec98aa4d3daecb3b4 Mon Sep 17 00:00:00 2001 From: Shenoy Pratik Date: Tue, 18 Apr 2023 19:08:36 -0700 Subject: [PATCH] notebooks fix for cypress and minor bugs (#392) * notebooks fix for cypress and minor bugs Signed-off-by: Shenoy Pratik * remove comments Signed-off-by: Shenoy Pratik --------- Signed-off-by: Shenoy Pratik (cherry picked from commit 3219f143515e53e7e9d82ee4ee962adf6d820b4b) --- .cypress/integration/2_notebooks.spec.js | 37 +++++++++++-------- .../__snapshots__/note_table.test.tsx.snap | 2 +- .../components/notebooks/components/main.tsx | 3 +- .../notebooks/components/note_table.tsx | 18 +++++---- .../notebooks/components/notebook.tsx | 12 ++++-- 5 files changed, 43 insertions(+), 29 deletions(-) diff --git a/.cypress/integration/2_notebooks.spec.js b/.cypress/integration/2_notebooks.spec.js index 5743cd07af..bd78ef24ae 100644 --- a/.cypress/integration/2_notebooks.spec.js +++ b/.cypress/integration/2_notebooks.spec.js @@ -21,17 +21,26 @@ import { SAMPLE_PANEL } from '../utils/panel_constants'; import { skipOn } from '@cypress/skip-test'; const moveToEventsHome = () => { - cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/event_analytics/`); + cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-logs#/`); cy.wait(delay * 3); }; const moveToPanelHome = () => { - cy.visit( - `${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/operational_panels/` - ); + cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/`); cy.wait(delay * 3); }; +const moveToTestNotebook = () => { + cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-notebooks#/`, { + timeout: 6000, + }); + cy.get('.euiTableCellContent') + .contains(TEST_NOTEBOOK, { + timeout: 6000, + }) + .click(); +}; + describe('Adding sample data and visualization', () => { it('Adds sample flights data for visualization paragraph', () => { cy.visit(`${Cypress.env('opensearchDashboards')}/app/home#/tutorial_directory/sampleData`); @@ -41,20 +50,20 @@ describe('Adding sample data and visualization', () => { }); it('Add sample observability data', () => { - moveToPanelHome(); - cy.get('.euiButton__text').contains('Actions').trigger('mouseover').click(); + moveToEventsHome(); + cy.get('button[data-test-subj="eventHomeAction"]').trigger('mouseover').click(); cy.wait(100); - cy.get('.euiContextMenuItem__text').contains('Add samples').trigger('mouseover').click(); + cy.get('button[data-test-subj="eventHomeAction__addSamples"]').trigger('mouseover').click(); cy.wait(100 * 3); cy.get('.euiModalHeader__title[data-test-subj="confirmModalTitleText"]') .contains('Add samples') .should('exist'); cy.wait(100); - cy.get('.euiButton__text').contains('Yes').trigger('mouseover').click(); + cy.get('button[data-test-subj="confirmModalConfirmButton"]').trigger('mouseover').click(); cy.wait(100 * 5); cy.route2('POST', '/addSamplePanels').as('addSamples'); cy.wait('@addSamples').then(() => { - cy.get('.euiTableCellContent').contains(SAMPLE_PANEL).should('exist'); + cy.get('.euiToastHeader__title').should('contain', 'successfully'); }); cy.wait(100); }); @@ -62,7 +71,8 @@ describe('Adding sample data and visualization', () => { describe('Testing notebooks table', () => { beforeEach(() => { - cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/notebooks`); + cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-notebooks#/`); + cy.wait(delay); }); it('Notebooks table empty state', () => { @@ -178,7 +188,7 @@ describe('Testing notebooks table', () => { describe('Test reporting integration if plugin installed', () => { beforeEach(() => { - cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/notebooks`); + cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-notebooks#/`); cy.get('.euiTableCellContent').contains(TEST_NOTEBOOK).click(); cy.wait(delay * 3); cy.get('body').then(($body) => { @@ -222,8 +232,7 @@ describe('Test reporting integration if plugin installed', () => { describe('Testing paragraphs', () => { beforeEach(() => { - cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/notebooks`); - cy.get('.euiTableCellContent').contains(TEST_NOTEBOOK).click(); + moveToTestNotebook(); }); it('Goes into a notebook and creates paragraphs', () => { @@ -550,7 +559,5 @@ describe('clean up all test data', () => { }); cy.get('button.euiButton--danger').should('not.be.disabled'); cy.get('.euiButton__text').contains('Delete').trigger('mouseover').click(); - - cy.get('.euiTextAlign').contains('No Operational Panels').should('exist'); }); }); diff --git a/public/components/notebooks/components/__tests__/__snapshots__/note_table.test.tsx.snap b/public/components/notebooks/components/__tests__/__snapshots__/note_table.test.tsx.snap index 552a09624b..ae60cd7409 100644 --- a/public/components/notebooks/components/__tests__/__snapshots__/note_table.test.tsx.snap +++ b/public/components/notebooks/components/__tests__/__snapshots__/note_table.test.tsx.snap @@ -1085,7 +1085,7 @@ exports[` spec renders the empty component 1`] = ` { }; // Renames an existing notebook - renameNotebook = (editedNoteName: string, editedNoteID: string) => { + renameNotebook = (editedNoteName: string, editedNoteID: string): Promise => { if (editedNoteName.length >= 50 || editedNoteName.length === 0) { this.setToast('Invalid notebook name', 'danger'); return; @@ -143,6 +143,7 @@ export class Main extends React.Component { return { data: newData }; }); this.setToast(`Notebook successfully renamed into "${editedNoteName}"`); + return res; }) .catch((err) => { this.setToast( diff --git a/public/components/notebooks/components/note_table.tsx b/public/components/notebooks/components/note_table.tsx index 465e6e1988..97ea434f7d 100644 --- a/public/components/notebooks/components/note_table.tsx +++ b/public/components/notebooks/components/note_table.tsx @@ -81,8 +81,8 @@ export function NoteTable(props: NoteTableProps) { }, []); useEffect(() => { - const url = window.location.hash.split('/') - if (url[url.length-1] === 'create') { + const url = window.location.hash.split('/'); + if (url[url.length - 1] === 'create') { createNote(); } }, [location]); @@ -110,8 +110,9 @@ export function NoteTable(props: NoteTableProps) { }; const onDelete = async () => { - const toastMessage = `Notebook${selectedNotebooks.length > 1 ? 's' : ' "' + selectedNotebooks[0].path + '"' - } successfully deleted!`; + const toastMessage = `Notebook${ + selectedNotebooks.length > 1 ? 's' : ' "' + selectedNotebooks[0].path + '"' + } successfully deleted!`; await deleteNotebook( selectedNotebooks.map((note) => note.id), toastMessage @@ -124,7 +125,7 @@ export function NoteTable(props: NoteTableProps) { getCustomModal( onCreate, () => { - closeModal() + closeModal(); history.goBack(); }, 'Name', @@ -340,8 +341,8 @@ export function NoteTable(props: NoteTableProps) { items={ searchQuery ? notebooks.filter((notebook) => - notebook.path.toLowerCase().includes(searchQuery.toLowerCase()) - ) + notebook.path.toLowerCase().includes(searchQuery.toLowerCase()) + ) : notebooks } itemId="id" @@ -379,7 +380,8 @@ export function NoteTable(props: NoteTableProps) { - diff --git a/public/components/notebooks/components/notebook.tsx b/public/components/notebooks/components/notebook.tsx index 6f0aadba36..a68f87c46f 100644 --- a/public/components/notebooks/components/notebook.tsx +++ b/public/components/notebooks/components/notebook.tsx @@ -75,7 +75,7 @@ type NotebookProps = { http: CoreStart['http']; parentBreadcrumb: ChromeBreadcrumb; setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void; - renameNotebook: (newNoteName: string, noteId: string) => void; + renameNotebook: (newNoteName: string, noteId: string) => Promise; cloneNotebook: (newNoteName: string, noteId: string) => Promise; deleteNotebook: (noteList: string[], toastMessage?: string) => void; setToast: (title: string, color?: string, text?: string) => void; @@ -285,9 +285,13 @@ export class Notebook extends Component { this.setState({ modalLayout: getCustomModal( (newName: string) => { - this.props.renameNotebook(newName, this.props.openedNoteId); - this.setState({ isModalVisible: false }); - this.loadNotebook(); + this.props.renameNotebook(newName, this.props.openedNoteId).then((res) => { + this.setState({ isModalVisible: false }); + window.location.assign(`#/${res.message.objectId}`); + setTimeout(() => { + this.loadNotebook(); + }, 300); + }); }, () => this.setState({ isModalVisible: false }), 'Name',