Skip to content

Commit 9fa9bbf

Browse files
authored
notebook test updates (opensearch-project#1021)
Signed-off-by: Shenoy Pratik <[email protected]>
1 parent e1cd6f6 commit 9fa9bbf

File tree

2 files changed

+125
-108
lines changed

2 files changed

+125
-108
lines changed

cypress/integration/plugins/observability-dashboards/6_notebooks.spec.js

Lines changed: 121 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -6,157 +6,170 @@
66
/// <reference types="cypress" />
77

88
import {
9-
delayTime,
9+
SAMPLE_SQL_QUERY,
1010
TEST_NOTEBOOK,
1111
SAMPLE_URL,
12-
SQL_QUERY_TEXT,
13-
PPL_QUERY_TEXT,
1412
BASE_PATH,
13+
delayTime,
14+
MARKDOWN_TEXT,
1515
} from '../../../utils/constants';
1616

17+
import { skipOn } from '@cypress/skip-test';
18+
19+
const moveToNotebookHome = () => {
20+
cy.visit(`${BASE_PATH}/app/observability-notebooks#/`);
21+
};
22+
1723
const moveToTestNotebook = () => {
1824
cy.visit(`${BASE_PATH}/app/observability-notebooks#/`, {
1925
timeout: delayTime * 3,
2026
});
27+
28+
// Reload page to load notebooks if they are not flushed in OpenSearch index yet.
29+
cy.reload();
30+
2131
cy.get('.euiTableCellContent')
2232
.contains(TEST_NOTEBOOK, {
2333
timeout: delayTime * 3,
2434
})
2535
.click();
2636
};
2737

28-
describe('Testing paragraphs', () => {
38+
describe('Testing notebook actions', () => {
39+
before(() => {
40+
moveToNotebookHome();
41+
cy.get('a[data-test-subj="createNotebookPrimaryBtn"]').click();
42+
cy.get('input[data-test-subj="custom-input-modal-input"]').focus();
43+
cy.get('input[data-test-subj="custom-input-modal-input"]').type(
44+
TEST_NOTEBOOK
45+
);
46+
cy.get(
47+
'button[data-test-subj="custom-input-modal-confirm-button"]'
48+
).click();
49+
cy.get('h1[data-test-subj="notebookTitle"]')
50+
.contains(TEST_NOTEBOOK)
51+
.should('exist');
52+
});
53+
2954
beforeEach(() => {
3055
moveToTestNotebook();
3156
});
3257

58+
it('Creates a code paragraph', () => {
59+
cy.get('button[data-test-subj="emptyNotebookAddCodeBlockBtn"]').click();
60+
cy.get('textarea[data-test-subj="editorArea-0"]').should('exist');
61+
cy.get('button[data-test-subj="runRefreshBtn-0"]').contains('Run').click();
62+
cy.get('div[data-test-subj="paragraphInputErrorText"]')
63+
.contains('Input is required.')
64+
.should('exist');
65+
});
66+
3367
it('Renders markdown', () => {
34-
cy.get('.euiTextArea').should('not.exist');
68+
cy.get('button[data-test-subj="paragraphToggleInputBtn"]').click();
69+
cy.get('.euiCodeBlock').click();
70+
cy.get('textarea[data-test-subj="editorArea-0"]').clear();
71+
cy.get('textarea[data-test-subj="editorArea-0"]').focus();
72+
cy.get('textarea[data-test-subj="editorArea-0"]').type(MARKDOWN_TEXT);
73+
74+
cy.get('button[data-test-subj="runRefreshBtn-0"]').click();
75+
cy.get('textarea[data-test-subj="editorArea-0"]').should('not.exist');
3576
cy.get(`a[href="${SAMPLE_URL}"]`).should('exist');
3677
cy.get('code').contains('POST').should('exist');
3778
cy.get('td').contains('b2').should('exist');
3879
});
3980

40-
it('Shows output message', () => {
41-
cy.get('button[aria-label="Toggle show input"]').click();
42-
cy.wait(delayTime);
43-
cy.get('.euiTextColor').contains('Last successful run').should('exist');
44-
45-
cy.get('pre.input').eq(0).click();
46-
cy.wait(delayTime);
47-
cy.get('.euiTextArea').type('Another text');
48-
cy.wait(delayTime);
81+
it('Adds a SQL query paragraph', () => {
82+
cy.get('button[data-test-subj="AddParagraphButton"]').click();
83+
cy.get('button[data-test-subj="AddCodeBlockBtn"]').click();
4984

50-
cy.get('.euiTextColor').contains('Last successful run').should('exist');
51-
});
85+
cy.get('textarea[data-test-subj="editorArea-1"]').clear();
86+
cy.get('textarea[data-test-subj="editorArea-1"]').focus();
87+
cy.get('textarea[data-test-subj="editorArea-1"]').type(SAMPLE_SQL_QUERY);
88+
cy.get('button[data-test-subj="runRefreshBtn-1"]').click();
5289

53-
it.skip('Duplicates paragraphs', () => {
54-
cy.get('.euiButtonIcon[aria-label="Open paragraph menu"]').eq(0).click();
55-
cy.wait(delayTime);
56-
cy.get('.euiContextMenuItem__text').contains('Duplicate').eq(0).click();
57-
cy.wait(delayTime);
58-
cy.get('.euiButton__text').contains('Run').click();
59-
cy.wait(delayTime);
90+
cy.get('textarea[data-test-subj="editorArea-1"]').should('not.exist');
91+
cy.get('div[data-test-subj="queryOutputText"]')
92+
.contains('select 1')
93+
.should('exist');
6094

61-
cy.get(`a[href="${SAMPLE_URL}"]`).should('have.length.gte', 2);
95+
cy.get('.euiDataGrid__overflow').should('exist');
6296
});
97+
});
6398

64-
it('Adds a dashboards visualization paragraph', () => {
65-
cy.contains('Add paragraph').click();
66-
cy.wait(delayTime);
67-
cy.get('.euiContextMenuItem__text').contains('Visualization').click();
68-
cy.wait(delayTime);
69-
70-
cy.get('.euiButton__text').contains('Run').click();
71-
cy.wait(delayTime);
72-
cy.get('.euiTextColor')
73-
.contains('Visualization is required.')
99+
describe('Test reporting integration if plugin installed', () => {
100+
beforeEach(() => {
101+
moveToNotebookHome();
102+
cy.get('.euiTableCellContent').contains(TEST_NOTEBOOK).click();
103+
cy.get('h1[data-test-subj="notebookTitle"]')
104+
.contains(TEST_NOTEBOOK)
74105
.should('exist');
75-
76-
cy.get('.euiButton__text').contains('Browse').click();
77-
cy.wait(delayTime);
78-
cy.get('.euiFieldSearch')
79-
.focus()
80-
.type('[Flights] Flight Count and Average Ticket Price{enter}');
81-
cy.wait(delayTime);
82-
cy.get('.euiButton__text').contains('Select').click();
83-
cy.wait(delayTime);
84-
cy.get('.euiButton__text').contains('Run').click();
85-
cy.wait(delayTime);
86-
cy.get('div.visualization').should('exist');
106+
cy.get('body').then(($body) => {
107+
skipOn($body.find('#reportingActionsButton').length <= 0);
108+
});
87109
});
88110

89-
it('Adds a SQL query paragraph', () => {
90-
cy.contains('Add paragraph').click();
91-
cy.wait(delayTime);
92-
cy.get('.euiContextMenuItem__text').contains('Code block').click();
93-
cy.wait(delayTime);
94-
95-
cy.get('.euiTextArea').type(SQL_QUERY_TEXT);
96-
cy.wait(delayTime);
97-
cy.get('.euiButton__text').contains('Run').click();
98-
cy.wait(delayTime * 5);
99-
100-
cy.get('b').contains(
101-
'select * from opensearch_dashboards_sample_data_flights limit 20'
102-
);
103-
104-
cy.get('.euiDataGrid__overflow').should('exist');
111+
it('Create in-context PDF report from notebook', () => {
112+
cy.get('#reportingActionsButton').click();
113+
cy.get('button.euiContextMenuItem:nth-child(1)')
114+
.contains('Download PDF')
115+
.click();
116+
cy.get('#downloadInProgressLoadingModal').should('exist');
105117
});
106118

107-
it('Adds a PPL query paragraph', () => {
108-
cy.contains('Add paragraph').click();
109-
cy.wait(delayTime);
110-
cy.get('.euiContextMenuItem__text').contains('Code block').click();
111-
cy.wait(delayTime);
112-
113-
cy.get('.euiTextArea').type(PPL_QUERY_TEXT);
114-
cy.wait(delayTime);
115-
cy.get('.euiButton__text').contains('Run').click();
116-
cy.wait(delayTime * 5);
117-
118-
cy.get('b').contains('source=opensearch_dashboards_sample_data_flights');
119-
120-
cy.get('.euiDataGrid__overflow').should('exist');
119+
it('Create in-context PNG report from notebook', () => {
120+
cy.get('#reportingActionsButton').click();
121+
cy.get('button.euiContextMenuItem:nth-child(2)')
122+
.contains('Download PNG')
123+
.click();
124+
cy.get('#downloadInProgressLoadingModal').should('exist');
121125
});
122126

123-
it('Runs all paragraphs', () => {
124-
cy.wait(delayTime * 3); // need to wait for paragraphs to load first
125-
cy.get('[data-test-subj="notebook-paragraph-actions-button"]').click();
126-
cy.wait(delayTime);
127-
cy.get('.euiContextMenuItem__text').contains('Run all paragraphs').click();
128-
cy.wait(delayTime);
129-
130-
cy.get(`a[href="${SAMPLE_URL}"]`).should('exist');
127+
it('Create on-demand report definition from context menu', () => {
128+
cy.get('#reportingActionsButton').click();
129+
cy.get('button.euiContextMenuItem:nth-child(3)')
130+
.contains('Create report definition')
131+
.click();
132+
cy.location('pathname', { timeout: delayTime * 3 }).should(
133+
'include',
134+
'/reports-dashboards'
135+
);
136+
cy.get('#reportSettingsName').type('Create notebook on-demand report');
137+
cy.get('#createNewReportDefinition').click({ force: true });
131138
});
132139

133-
it('Deletes paragraphs', () => {
134-
cy.wait(delayTime * 3);
135-
cy.get('[data-test-subj="notebook-paragraph-actions-button"]').click();
136-
cy.wait(delayTime);
137-
cy.get('.euiContextMenuItem__text')
138-
.contains('Delete all paragraphs')
140+
it('View reports homepage from context menu', () => {
141+
cy.get('#reportingActionsButton').click();
142+
cy.get('button.euiContextMenuItem:nth-child(4)')
143+
.contains('View reports')
139144
.click();
140-
cy.wait(delayTime);
141-
cy.get('.euiButton__text').contains('Delete').click();
142-
cy.wait(delayTime);
143-
144-
cy.get('.euiTextAlign').contains('No paragraphs').should('exist');
145+
cy.location('pathname', { timeout: delayTime * 3 }).should(
146+
'include',
147+
'/reports-dashboards'
148+
);
145149
});
150+
});
146151

152+
describe('clean up all test data', () => {
147153
it('Cleans up test notebooks', () => {
148-
cy.get('[data-test-subj="notebook-notebook-actions-button"]').click();
149-
cy.wait(delayTime);
150-
cy.get('.euiContextMenuItem__text').contains('Delete notebook').click();
151-
cy.wait(delayTime);
152-
153-
cy.get('button.euiButton--danger').should('be.disabled');
154-
155-
cy.get('input.euiFieldText[placeholder="delete"]').type('delete');
156-
cy.get('button.euiButton--danger').should('not.be.disabled');
157-
cy.get('.euiButton__text').contains('Delete').click();
158-
cy.wait(delayTime * 3);
159-
160-
cy.get('.euiText').contains('No notebooks').should('exist');
154+
moveToNotebookHome();
155+
cy.get('input[data-test-subj="checkboxSelectAll"]').click();
156+
cy.get('button[data-test-subj="notebookTableActionBtn"]').click();
157+
cy.get('button[data-test-subj="deleteNotebookBtn"]').click();
158+
cy.get(
159+
'button[data-test-subj="delete-notebook-modal-delete-button"]'
160+
).should('be.disabled');
161+
162+
cy.get('input[data-test-subj="delete-notebook-modal-input"]').focus();
163+
cy.get('input[data-test-subj="delete-notebook-modal-input"]').type(
164+
'delete'
165+
);
166+
cy.get(
167+
'button[data-test-subj="delete-notebook-modal-delete-button"]'
168+
).should('not.be.disabled');
169+
cy.get(
170+
'button[data-test-subj="delete-notebook-modal-delete-button"]'
171+
).click();
172+
moveToNotebookHome();
173+
cy.get('div[data-test-subj="notebookEmptyTableText"]').should('exist');
161174
});
162175
});

cypress/utils/plugins/observability-dashboards/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ POST _plugins/_sql/_explain
104104
| a3 | b3 | c3 | d3 |
105105
`;
106106

107+
export const SAMPLE_SQL_QUERY = `%sql
108+
select 1
109+
`;
110+
107111
export const SQL_QUERY_TEXT = `%sql
108112
select * from opensearch_dashboards_sample_data_flights limit 20
109113
`;

0 commit comments

Comments
 (0)