Skip to content

Commit

Permalink
notebooks fix for cypress and minor bugs (opensearch-project#392)
Browse files Browse the repository at this point in the history
* notebooks fix for cypress and minor bugs

Signed-off-by: Shenoy Pratik <[email protected]>

* remove comments

Signed-off-by: Shenoy Pratik <[email protected]>

---------

Signed-off-by: Shenoy Pratik <[email protected]>
(cherry picked from commit 3219f14)
  • Loading branch information
ps48 committed Apr 19, 2023
1 parent aca3c8b commit 500e4aa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 29 deletions.
37 changes: 22 additions & 15 deletions .cypress/integration/2_notebooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -41,28 +50,29 @@ 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);
});
});

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', () => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ exports[`<NoteTable /> spec renders the empty component 1`] = `
<a
class="euiButton euiButton--primary"
data-test-subj="note-table-empty-state-create-notebook-button"
href="#/notebooks/create"
href="#/create"
rel="noreferrer"
>
<span
Expand Down
3 changes: 2 additions & 1 deletion public/components/notebooks/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class Main extends React.Component<MainProps, MainState> {
};

// Renames an existing notebook
renameNotebook = (editedNoteName: string, editedNoteID: string) => {
renameNotebook = (editedNoteName: string, editedNoteID: string): Promise<any> => {
if (editedNoteName.length >= 50 || editedNoteName.length === 0) {
this.setToast('Invalid notebook name', 'danger');
return;
Expand All @@ -143,6 +143,7 @@ export class Main extends React.Component<MainProps, MainState> {
return { data: newData };
});
this.setToast(`Notebook successfully renamed into "${editedNoteName}"`);
return res;
})
.catch((err) => {
this.setToast(
Expand Down
18 changes: 10 additions & 8 deletions public/components/notebooks/components/note_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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
Expand All @@ -124,7 +125,7 @@ export function NoteTable(props: NoteTableProps) {
getCustomModal(
onCreate,
() => {
closeModal()
closeModal();
history.goBack();
},
'Name',
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -379,7 +380,8 @@ export function NoteTable(props: NoteTableProps) {
<EuiSpacer size="m" />
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<EuiButton href="#/notebooks/create"
<EuiButton
href="#/create"
data-test-subj="note-table-empty-state-create-notebook-button"
fullWidth={false}
>
Expand Down
12 changes: 8 additions & 4 deletions public/components/notebooks/components/notebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
cloneNotebook: (newNoteName: string, noteId: string) => Promise<string>;
deleteNotebook: (noteList: string[], toastMessage?: string) => void;
setToast: (title: string, color?: string, text?: string) => void;
Expand Down Expand Up @@ -285,9 +285,13 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
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',
Expand Down

0 comments on commit 500e4aa

Please sign in to comment.