diff --git a/cypress/integration/plugins/observability-dashboards/6_notebooks.spec.js b/cypress/integration/plugins/observability-dashboards/6_notebooks.spec.js index e8ba8d56c..49a4dc7e9 100644 --- a/cypress/integration/plugins/observability-dashboards/6_notebooks.spec.js +++ b/cypress/integration/plugins/observability-dashboards/6_notebooks.spec.js @@ -6,18 +6,28 @@ /// import { - delayTime, + SAMPLE_SQL_QUERY, TEST_NOTEBOOK, SAMPLE_URL, - SQL_QUERY_TEXT, - PPL_QUERY_TEXT, BASE_PATH, + delayTime, + MARKDOWN_TEXT, } from '../../../utils/constants'; +import { skipOn } from '@cypress/skip-test'; + +const moveToNotebookHome = () => { + cy.visit(`${BASE_PATH}/app/observability-notebooks#/`); +}; + const moveToTestNotebook = () => { cy.visit(`${BASE_PATH}/app/observability-notebooks#/`, { timeout: delayTime * 3, }); + + // Reload page to load notebooks if they are not flushed in OpenSearch index yet. + cy.reload(); + cy.get('.euiTableCellContent') .contains(TEST_NOTEBOOK, { timeout: delayTime * 3, @@ -25,138 +35,141 @@ const moveToTestNotebook = () => { .click(); }; -describe('Testing paragraphs', () => { +describe('Testing notebook actions', () => { + before(() => { + moveToNotebookHome(); + cy.get('a[data-test-subj="createNotebookPrimaryBtn"]').click(); + cy.get('input[data-test-subj="custom-input-modal-input"]').focus(); + cy.get('input[data-test-subj="custom-input-modal-input"]').type( + TEST_NOTEBOOK + ); + cy.get( + 'button[data-test-subj="custom-input-modal-confirm-button"]' + ).click(); + cy.get('h1[data-test-subj="notebookTitle"]') + .contains(TEST_NOTEBOOK) + .should('exist'); + }); + beforeEach(() => { moveToTestNotebook(); }); + it('Creates a code paragraph', () => { + cy.get('button[data-test-subj="emptyNotebookAddCodeBlockBtn"]').click(); + cy.get('textarea[data-test-subj="editorArea-0"]').should('exist'); + cy.get('button[data-test-subj="runRefreshBtn-0"]').contains('Run').click(); + cy.get('div[data-test-subj="paragraphInputErrorText"]') + .contains('Input is required.') + .should('exist'); + }); + it('Renders markdown', () => { - cy.get('.euiTextArea').should('not.exist'); + cy.get('button[data-test-subj="paragraphToggleInputBtn"]').click(); + cy.get('.euiCodeBlock').click(); + cy.get('textarea[data-test-subj="editorArea-0"]').clear(); + cy.get('textarea[data-test-subj="editorArea-0"]').focus(); + cy.get('textarea[data-test-subj="editorArea-0"]').type(MARKDOWN_TEXT); + + cy.get('button[data-test-subj="runRefreshBtn-0"]').click(); + cy.get('textarea[data-test-subj="editorArea-0"]').should('not.exist'); cy.get(`a[href="${SAMPLE_URL}"]`).should('exist'); cy.get('code').contains('POST').should('exist'); cy.get('td').contains('b2').should('exist'); }); - it('Shows output message', () => { - cy.get('button[aria-label="Toggle show input"]').click(); - cy.wait(delayTime); - cy.get('.euiTextColor').contains('Last successful run').should('exist'); - - cy.get('pre.input').eq(0).click(); - cy.wait(delayTime); - cy.get('.euiTextArea').type('Another text'); - cy.wait(delayTime); + it('Adds a SQL query paragraph', () => { + cy.get('button[data-test-subj="AddParagraphButton"]').click(); + cy.get('button[data-test-subj="AddCodeBlockBtn"]').click(); - cy.get('.euiTextColor').contains('Last successful run').should('exist'); - }); + cy.get('textarea[data-test-subj="editorArea-1"]').clear(); + cy.get('textarea[data-test-subj="editorArea-1"]').focus(); + cy.get('textarea[data-test-subj="editorArea-1"]').type(SAMPLE_SQL_QUERY); + cy.get('button[data-test-subj="runRefreshBtn-1"]').click(); - it('Duplicates paragraphs', () => { - cy.get('.euiButtonIcon[aria-label="Open paragraph menu"]').eq(0).click(); - cy.wait(delayTime); - cy.get('.euiContextMenuItem__text').contains('Duplicate').eq(0).click(); - cy.wait(delayTime); - cy.get('.euiButton__text').contains('Run').click(); - cy.wait(delayTime); + cy.get('textarea[data-test-subj="editorArea-1"]').should('not.exist'); + cy.get('div[data-test-subj="queryOutputText"]') + .contains('select 1') + .should('exist'); - cy.get(`a[href="${SAMPLE_URL}"]`).should('have.length.gte', 2); + cy.get('.euiDataGrid__overflow').should('exist'); }); +}); - it('Adds a dashboards visualization paragraph', () => { - cy.contains('Add paragraph').click(); - cy.wait(delayTime); - cy.get('.euiContextMenuItem__text').contains('Visualization').click(); - cy.wait(delayTime); - - cy.get('.euiButton__text').contains('Run').click(); - cy.wait(delayTime); - cy.get('.euiTextColor') - .contains('Visualization is required.') +describe('Test reporting integration if plugin installed', () => { + beforeEach(() => { + moveToNotebookHome(); + cy.get('.euiTableCellContent').contains(TEST_NOTEBOOK).click(); + cy.get('h1[data-test-subj="notebookTitle"]') + .contains(TEST_NOTEBOOK) .should('exist'); - - cy.get('.euiButton__text').contains('Browse').click(); - cy.wait(delayTime); - cy.get('.euiFieldSearch') - .focus() - .type('[Flights] Flight Count and Average Ticket Price{enter}'); - cy.wait(delayTime); - cy.get('.euiButton__text').contains('Select').click(); - cy.wait(delayTime); - cy.get('.euiButton__text').contains('Run').click(); - cy.wait(delayTime); - cy.get('div.visualization').should('exist'); + cy.get('body').then(($body) => { + skipOn($body.find('#reportingActionsButton').length <= 0); + }); }); - it('Adds a SQL query paragraph', () => { - cy.contains('Add paragraph').click(); - cy.wait(delayTime); - cy.get('.euiContextMenuItem__text').contains('Code block').click(); - cy.wait(delayTime); - - cy.get('.euiTextArea').type(SQL_QUERY_TEXT); - cy.wait(delayTime); - cy.get('.euiButton__text').contains('Run').click(); - cy.wait(delayTime * 5); - - cy.get('b').contains( - 'select * from opensearch_dashboards_sample_data_flights limit 20' - ); - - cy.get('.euiDataGrid__overflow').should('exist'); + it('Create in-context PDF report from notebook', () => { + cy.get('#reportingActionsButton').click(); + cy.get('button.euiContextMenuItem:nth-child(1)') + .contains('Download PDF') + .click(); + cy.get('#downloadInProgressLoadingModal').should('exist'); }); - it('Adds a PPL query paragraph', () => { - cy.contains('Add paragraph').click(); - cy.wait(delayTime); - cy.get('.euiContextMenuItem__text').contains('Code block').click(); - cy.wait(delayTime); - - cy.get('.euiTextArea').type(PPL_QUERY_TEXT); - cy.wait(delayTime); - cy.get('.euiButton__text').contains('Run').click(); - cy.wait(delayTime * 5); - - cy.get('b').contains('source=opensearch_dashboards_sample_data_flights'); - - cy.get('.euiDataGrid__overflow').should('exist'); + it('Create in-context PNG report from notebook', () => { + cy.get('#reportingActionsButton').click(); + cy.get('button.euiContextMenuItem:nth-child(2)') + .contains('Download PNG') + .click(); + cy.get('#downloadInProgressLoadingModal').should('exist'); }); - it('Runs all paragraphs', () => { - cy.wait(delayTime * 3); // need to wait for paragraphs to load first - cy.get('[data-test-subj="notebook-paragraph-actions-button"]').click(); - cy.wait(delayTime); - cy.get('.euiContextMenuItem__text').contains('Run all paragraphs').click(); - cy.wait(delayTime); - - cy.get(`a[href="${SAMPLE_URL}"]`).should('exist'); + it('Create on-demand report definition from context menu', () => { + cy.get('#reportingActionsButton').click(); + cy.get('button.euiContextMenuItem:nth-child(3)') + .contains('Create report definition') + .click(); + cy.location('pathname', { timeout: delayTime * 3 }).should( + 'include', + '/reports-dashboards' + ); + cy.get('#reportSettingsName').type('Create notebook on-demand report'); + cy.get('#createNewReportDefinition').click({ force: true }); }); - it('Deletes paragraphs', () => { - cy.wait(delayTime * 3); - cy.get('[data-test-subj="notebook-paragraph-actions-button"]').click(); - cy.wait(delayTime); - cy.get('.euiContextMenuItem__text') - .contains('Delete all paragraphs') + it('View reports homepage from context menu', () => { + cy.get('#reportingActionsButton').click(); + cy.get('button.euiContextMenuItem:nth-child(4)') + .contains('View reports') .click(); - cy.wait(delayTime); - cy.get('.euiButton__text').contains('Delete').click(); - cy.wait(delayTime); - - cy.get('.euiTextAlign').contains('No paragraphs').should('exist'); + cy.location('pathname', { timeout: delayTime * 3 }).should( + 'include', + '/reports-dashboards' + ); }); +}); +describe('clean up all test data', () => { it('Cleans up test notebooks', () => { - cy.get('[data-test-subj="notebook-notebook-actions-button"]').click(); - cy.wait(delayTime); - cy.get('.euiContextMenuItem__text').contains('Delete notebook').click(); - cy.wait(delayTime); - - cy.get('button.euiButton--danger').should('be.disabled'); - - cy.get('input.euiFieldText[placeholder="delete"]').type('delete'); - cy.get('button.euiButton--danger').should('not.be.disabled'); - cy.get('.euiButton__text').contains('Delete').click(); - cy.wait(delayTime * 3); - - cy.get('.euiText').contains('No notebooks').should('exist'); + moveToNotebookHome(); + cy.get('input[data-test-subj="checkboxSelectAll"]').click(); + cy.get('button[data-test-subj="notebookTableActionBtn"]').click(); + cy.get('button[data-test-subj="deleteNotebookBtn"]').click(); + cy.get( + 'button[data-test-subj="delete-notebook-modal-delete-button"]' + ).should('be.disabled'); + + cy.get('input[data-test-subj="delete-notebook-modal-input"]').focus(); + cy.get('input[data-test-subj="delete-notebook-modal-input"]').type( + 'delete' + ); + cy.get( + 'button[data-test-subj="delete-notebook-modal-delete-button"]' + ).should('not.be.disabled'); + cy.get( + 'button[data-test-subj="delete-notebook-modal-delete-button"]' + ).click(); + moveToNotebookHome(); + cy.get('div[data-test-subj="notebookEmptyTableText"]').should('exist'); }); }); diff --git a/cypress/utils/plugins/observability-dashboards/constants.js b/cypress/utils/plugins/observability-dashboards/constants.js index d138f5be3..88fd5c3f0 100644 --- a/cypress/utils/plugins/observability-dashboards/constants.js +++ b/cypress/utils/plugins/observability-dashboards/constants.js @@ -111,6 +111,10 @@ POST _plugins/_sql/_explain | a3 | b3 | c3 | d3 | `; +export const SAMPLE_SQL_QUERY = `%sql +select 1 +`; + export const SQL_QUERY_TEXT = `%sql select * from opensearch_dashboards_sample_data_flights limit 20 `;