Skip to content

Commit 3219f14

Browse files
authored
notebooks fix for cypress and minor bugs (opensearch-project#392)
* notebooks fix for cypress and minor bugs Signed-off-by: Shenoy Pratik <sgguruda@amazon.com> * remove comments Signed-off-by: Shenoy Pratik <sgguruda@amazon.com> --------- Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
1 parent a6c1ebc commit 3219f14

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

.cypress/integration/2_notebooks.spec.js

+22-15
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,26 @@ import { SAMPLE_PANEL } from '../utils/panel_constants';
2121
import { skipOn } from '@cypress/skip-test';
2222

2323
const moveToEventsHome = () => {
24-
cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/event_analytics/`);
24+
cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-logs#/`);
2525
cy.wait(delay * 3);
2626
};
2727

2828
const moveToPanelHome = () => {
29-
cy.visit(
30-
`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/operational_panels/`
31-
);
29+
cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/`);
3230
cy.wait(delay * 3);
3331
};
3432

33+
const moveToTestNotebook = () => {
34+
cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-notebooks#/`, {
35+
timeout: 6000,
36+
});
37+
cy.get('.euiTableCellContent')
38+
.contains(TEST_NOTEBOOK, {
39+
timeout: 6000,
40+
})
41+
.click();
42+
};
43+
3544
describe('Adding sample data and visualization', () => {
3645
it('Adds sample flights data for visualization paragraph', () => {
3746
cy.visit(`${Cypress.env('opensearchDashboards')}/app/home#/tutorial_directory/sampleData`);
@@ -41,28 +50,29 @@ describe('Adding sample data and visualization', () => {
4150
});
4251

4352
it('Add sample observability data', () => {
44-
moveToPanelHome();
45-
cy.get('.euiButton__text').contains('Actions').trigger('mouseover').click();
53+
moveToEventsHome();
54+
cy.get('button[data-test-subj="eventHomeAction"]').trigger('mouseover').click();
4655
cy.wait(100);
47-
cy.get('.euiContextMenuItem__text').contains('Add samples').trigger('mouseover').click();
56+
cy.get('button[data-test-subj="eventHomeAction__addSamples"]').trigger('mouseover').click();
4857
cy.wait(100 * 3);
4958
cy.get('.euiModalHeader__title[data-test-subj="confirmModalTitleText"]')
5059
.contains('Add samples')
5160
.should('exist');
5261
cy.wait(100);
53-
cy.get('.euiButton__text').contains('Yes').trigger('mouseover').click();
62+
cy.get('button[data-test-subj="confirmModalConfirmButton"]').trigger('mouseover').click();
5463
cy.wait(100 * 5);
5564
cy.route2('POST', '/addSamplePanels').as('addSamples');
5665
cy.wait('@addSamples').then(() => {
57-
cy.get('.euiTableCellContent').contains(SAMPLE_PANEL).should('exist');
66+
cy.get('.euiToastHeader__title').should('contain', 'successfully');
5867
});
5968
cy.wait(100);
6069
});
6170
});
6271

6372
describe('Testing notebooks table', () => {
6473
beforeEach(() => {
65-
cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/notebooks`);
74+
cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-notebooks#/`);
75+
cy.wait(delay);
6676
});
6777

6878
it('Notebooks table empty state', () => {
@@ -178,7 +188,7 @@ describe('Testing notebooks table', () => {
178188

179189
describe('Test reporting integration if plugin installed', () => {
180190
beforeEach(() => {
181-
cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/notebooks`);
191+
cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-notebooks#/`);
182192
cy.get('.euiTableCellContent').contains(TEST_NOTEBOOK).click();
183193
cy.wait(delay * 3);
184194
cy.get('body').then(($body) => {
@@ -222,8 +232,7 @@ describe('Test reporting integration if plugin installed', () => {
222232

223233
describe('Testing paragraphs', () => {
224234
beforeEach(() => {
225-
cy.visit(`${Cypress.env('opensearchDashboards')}/app/observability-dashboards#/notebooks`);
226-
cy.get('.euiTableCellContent').contains(TEST_NOTEBOOK).click();
235+
moveToTestNotebook();
227236
});
228237

229238
it('Goes into a notebook and creates paragraphs', () => {
@@ -550,7 +559,5 @@ describe('clean up all test data', () => {
550559
});
551560
cy.get('button.euiButton--danger').should('not.be.disabled');
552561
cy.get('.euiButton__text').contains('Delete').trigger('mouseover').click();
553-
554-
cy.get('.euiTextAlign').contains('No Operational Panels').should('exist');
555562
});
556563
});

public/components/notebooks/components/__tests__/__snapshots__/note_table.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ exports[`<NoteTable /> spec renders the empty component 1`] = `
10851085
<a
10861086
class="euiButton euiButton--primary"
10871087
data-test-subj="note-table-empty-state-create-notebook-button"
1088-
href="#/notebooks/create"
1088+
href="#/create"
10891089
rel="noreferrer"
10901090
>
10911091
<span

public/components/notebooks/components/main.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class Main extends React.Component<MainProps, MainState> {
121121
};
122122

123123
// Renames an existing notebook
124-
renameNotebook = (editedNoteName: string, editedNoteID: string) => {
124+
renameNotebook = (editedNoteName: string, editedNoteID: string): Promise<any> => {
125125
if (editedNoteName.length >= 50 || editedNoteName.length === 0) {
126126
this.setToast('Invalid notebook name', 'danger');
127127
return;
@@ -143,6 +143,7 @@ export class Main extends React.Component<MainProps, MainState> {
143143
return { data: newData };
144144
});
145145
this.setToast(`Notebook successfully renamed into "${editedNoteName}"`);
146+
return res;
146147
})
147148
.catch((err) => {
148149
this.setToast(

public/components/notebooks/components/note_table.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ export function NoteTable({
120120
};
121121

122122
const onDelete = async () => {
123-
const toastMessage = `Notebook${selectedNotebooks.length > 1 ? 's' : ' "' + selectedNotebooks[0].path + '"'
124-
} successfully deleted!`;
123+
const toastMessage = `Notebook${
124+
selectedNotebooks.length > 1 ? 's' : ' "' + selectedNotebooks[0].path + '"'
125+
} successfully deleted!`;
125126
await deleteNotebook(
126127
selectedNotebooks.map((note) => note.id),
127128
toastMessage
@@ -350,8 +351,8 @@ export function NoteTable({
350351
items={
351352
searchQuery
352353
? notebooks.filter((notebook) =>
353-
notebook.path.toLowerCase().includes(searchQuery.toLowerCase())
354-
)
354+
notebook.path.toLowerCase().includes(searchQuery.toLowerCase())
355+
)
355356
: notebooks
356357
}
357358
itemId="id"
@@ -390,7 +391,7 @@ export function NoteTable({
390391
<EuiFlexGroup justifyContent="center">
391392
<EuiFlexItem grow={false}>
392393
<EuiButton
393-
href="#/notebooks/create"
394+
href="#/create"
394395
data-test-subj="note-table-empty-state-create-notebook-button"
395396
fullWidth={false}
396397
>

public/components/notebooks/components/notebook.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ interface NotebookProps {
7575
http: CoreStart['http'];
7676
parentBreadcrumb: ChromeBreadcrumb;
7777
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void;
78-
renameNotebook: (newNoteName: string, noteId: string) => void;
78+
renameNotebook: (newNoteName: string, noteId: string) => Promise<any>;
7979
cloneNotebook: (newNoteName: string, noteId: string) => Promise<string>;
8080
deleteNotebook: (noteList: string[], toastMessage?: string) => void;
8181
setToast: (title: string, color?: string, text?: string) => void;
@@ -282,9 +282,13 @@ export class Notebook extends Component<NotebookProps, NotebookState> {
282282
this.setState({
283283
modalLayout: getCustomModal(
284284
(newName: string) => {
285-
this.props.renameNotebook(newName, this.props.openedNoteId);
286-
this.setState({ isModalVisible: false });
287-
this.loadNotebook();
285+
this.props.renameNotebook(newName, this.props.openedNoteId).then((res) => {
286+
this.setState({ isModalVisible: false });
287+
window.location.assign(`#/${res.message.objectId}`);
288+
setTimeout(() => {
289+
this.loadNotebook();
290+
}, 300);
291+
});
288292
},
289293
() => this.setState({ isModalVisible: false }),
290294
'Name',

0 commit comments

Comments
 (0)