Skip to content

Commit

Permalink
Refactor 6_notebooks.spec.js (#1174)
Browse files Browse the repository at this point in the history
* Refactor 6_notebooks.spec.js

Signed-off-by: Simeon Widdis <[email protected]>

* Simplify reporting integration before-each

Signed-off-by: Simeon Widdis <[email protected]>

* Avoid using this on notebook name access

Signed-off-by: Simeon Widdis <[email protected]>

---------

Signed-off-by: Simeon Widdis <[email protected]>
  • Loading branch information
Swiddis authored Mar 27, 2024
1 parent aee07c8 commit 8ec090c
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
/// <reference types="cypress" />

import {
TEST_NOTEBOOK,
SAMPLE_URL,
BASE_PATH,
delayTime,
Expand All @@ -16,81 +15,119 @@ import {

import { skipOn } from '@cypress/skip-test';

let loadedOnce = 0;
const testNotebookName = () => {
let code = (Math.random() + 1).toString(36).substring(7);
return `Test Notebook ${code}`;
};

const moveToNotebookHome = () => {
cy.visit(`${BASE_PATH}/app/observability-notebooks#/`);
};

const moveToTestNotebook = () => {
const moveToTestNotebook = (notebookName) => {
cy.visit(`${BASE_PATH}/app/observability-notebooks#/`, {
timeout: delayTime * 3,
});

// Force refresh the observablity index and reload page to load notebooks.
if (loadedOnce === 0) {
cy.request({
cy.request({
method: 'POST',
failOnStatusCode: false,
form: false,
url: 'api/console/proxy',
headers: {
'content-type': 'application/json;charset=UTF-8',
'osd-xsrf': true,
},
qs: {
path: `${OBSERVABILITY_INDEX_NAME}/_refresh`,
method: 'POST',
failOnStatusCode: false,
form: false,
url: 'api/console/proxy',
headers: {
'content-type': 'application/json;charset=UTF-8',
'osd-xsrf': true,
},
qs: {
path: `${OBSERVABILITY_INDEX_NAME}/_refresh`,
method: 'POST',
},
});
cy.reload();
loadedOnce = 1;
}
},
});
cy.reload();

cy.get('.euiTableCellContent')
.contains(TEST_NOTEBOOK, {
.contains(notebookName, {
timeout: delayTime * 3,
})
.click();
};

const makeTestNotebook = () => {
let notebookName = testNotebookName();

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(notebookName);
cy.get('button[data-test-subj="custom-input-modal-confirm-button"]').click();
cy.get('h1[data-test-subj="notebookTitle"]')
.contains(notebookName)
.should('exist');

return notebookName;
};

const makeParagraph = () => {
cy.get('button[data-test-subj="emptyNotebookAddCodeBlockBtn"]').click();
cy.get('textarea[data-test-subj="editorArea-0"]').should('exist');
};

const makePopulatedParagraph = () => {
makeParagraph();
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();
};

const deleteNotebook = (notebookName) => {
moveToNotebookHome();

cy.contains('.euiTableRow', notebookName)
.find('input[type="checkbox"]')
.check();

cy.get('button[data-test-subj="notebookTableActionBtn"]').click();
cy.get('button[data-test-subj="deleteNotebookBtn"]').click();

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.contains('.euiTableRow', notebookName).should('not.exist');
};

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(() => {
let notebookName = makeTestNotebook();
moveToTestNotebook(notebookName);
cy.wrap({ name: notebookName }).as('notebook');
});

beforeEach(() => {
moveToTestNotebook();
afterEach(() => {
cy.get('@notebook').then((notebook) => {
deleteNotebook(notebook.name);
});
});

it('Creates a code paragraph', () => {
cy.get('button[data-test-subj="emptyNotebookAddCodeBlockBtn"]').click();
cy.get('textarea[data-test-subj="editorArea-0"]').should('exist');
makeParagraph();

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('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();
makePopulatedParagraph();
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');
Expand All @@ -100,14 +137,18 @@ describe('Testing notebook actions', () => {

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');
let notebookName = makeTestNotebook();
cy.get('body').then(($body) => {
skipOn($body.find('#reportingActionsButton').length <= 0);
});
makePopulatedParagraph();
cy.wrap({ name: notebookName }).as('notebook');
});

afterEach(() => {
cy.get('@notebook').then((notebook) => {
deleteNotebook(notebook.name);
});
});

it('Create in-context PDF report from notebook', () => {
Expand Down Expand Up @@ -150,28 +191,3 @@ describe('Test reporting integration if plugin installed', () => {
);
});
});

describe('clean up all test data', () => {
it('Cleans up test notebooks', () => {
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');
});
});
22 changes: 12 additions & 10 deletions cypress/utils/plugins/observability-dashboards/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ export const setTimeFilter = (setEndTime = false, refresh = true) => {
cy.get('.euiTab__content').contains('Absolute').click();
cy.get('input[data-test-subj="superDatePickerAbsoluteDateInput"]', {
timeout: TIMEOUT_DELAY,
})
.focus()
.type('{selectall}' + startTime, { force: true });
}).focus();
cy.get('input[data-test-subj="superDatePickerAbsoluteDateInput"]', {
timeout: TIMEOUT_DELAY,
}).type('{selectall}' + startTime, { force: true });
if (setEndTime) {
cy.wait(delayTime);
cy.get(
Expand All @@ -74,16 +75,16 @@ export const setTimeFilter = (setEndTime = false, refresh = true) => {
cy.get('.euiTab__content').contains('Absolute').click();
cy.get('input[data-test-subj="superDatePickerAbsoluteDateInput"]', {
timeout: TIMEOUT_DELAY,
})
.focus()
.type('{selectall}' + endTime, { force: true });
}).focus();
cy.get('input[data-test-subj="superDatePickerAbsoluteDateInput"]', {
timeout: TIMEOUT_DELAY,
}).type('{selectall}' + endTime, { force: true });
}
if (refresh) cy.get('.euiButton__text').contains('Refresh').click();
cy.wait(delayTime);
};

// notebooks
export const TEST_NOTEBOOK = 'Test Notebook';
export const SAMPLE_URL =
'https://github.com/opensearch-project/sql/tree/main/sql-jdbc';
export const MARKDOWN_TEXT = `%md
Expand Down Expand Up @@ -301,9 +302,10 @@ export const moveToEditPage = () => {
export const changeTimeTo24 = (timeUnit) => {
cy.get('[data-test-subj="superDatePickerToggleQuickMenuButton"]', {
timeout: TIMEOUT_DELAY,
})
.trigger('mouseover')
.click();
}).trigger('mouseover');
cy.get('[data-test-subj="superDatePickerToggleQuickMenuButton"]', {
timeout: TIMEOUT_DELAY,
}).click();
cy.wait(delayTime);
cy.get('[aria-label="Time unit"]', { timeout: TIMEOUT_DELAY }).select(
timeUnit
Expand Down

0 comments on commit 8ec090c

Please sign in to comment.