Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notebooks fix for cypress and minor bugs #392

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 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,30 @@ 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('.euiTableCellContent').contains(SAMPLE_PANEL).should('exist');
ps48 marked this conversation as resolved.
Show resolved Hide resolved
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 +189,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 +233,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 +560,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
11 changes: 6 additions & 5 deletions public/components/notebooks/components/note_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ export function NoteTable({
};

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 Down Expand Up @@ -350,8 +351,8 @@ export function NoteTable({
items={
searchQuery
? notebooks.filter((notebook) =>
notebook.path.toLowerCase().includes(searchQuery.toLowerCase())
)
notebook.path.toLowerCase().includes(searchQuery.toLowerCase())
)
: notebooks
}
itemId="id"
Expand Down Expand Up @@ -390,7 +391,7 @@ export function NoteTable({
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<EuiButton
href="#/notebooks/create"
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 @@ interface 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 @@ -282,9 +282,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