Skip to content

Commit

Permalink
Add Cypress Case Coverage on Details Pages (#250)
Browse files Browse the repository at this point in the history
* add and refactor cypress tests for details pages

Signed-off-by: David Cui <[email protected]>

* update jest snapshots

Signed-off-by: David Cui <[email protected]>

* add utils.js file to store functions used in multiple cypress tests

Signed-off-by: David Cui <[email protected]>
  • Loading branch information
davidcui1225 authored Dec 9, 2021
1 parent 546a128 commit 9daf116
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 45 deletions.
10 changes: 2 additions & 8 deletions dashboards-reports/.cypress/integration/01-create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { visitReportingLandingPage } from "../support/utils";

describe('Adding sample data', () => {
it('Adds sample data', () => {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/home#/tutorial_directory/sampleData`);
Expand Down Expand Up @@ -195,14 +197,6 @@ describe('Cypress', () => {
});
});

function visitReportingLandingPage() {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/reports-dashboards#/`);
cy.location('pathname', { timeout: 60000 }).should(
'include',
'/reports-dashboards'
);
}

function visitCreateReportDefinitionPage() {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/reports-dashboards#/`);
cy.location('pathname', { timeout: 60000 }).should(
Expand Down
124 changes: 94 additions & 30 deletions dashboards-reports/.cypress/integration/03-details.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,109 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { visitReportingLandingPage } from "../support/utils";

describe('Cypress', () => {
it('Visit report definition details page', () => {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/reports-dashboards#/`);
cy.location('pathname', { timeout: 60000 }).should(
'include',
'/reports-dashboards'
);
visitReportingLandingPage();
cy.wait(5000);
visitReportDefinitionDetailsPage();
verifyReportDefinitionDetailsURL();
verifyDeleteDefinitionButtonExists();
verifyGenerateReportFromFileFormatExists();
});

cy.wait(12500);
it('Go to edit report definition from report definition details', () => {
visitReportingLandingPage();
cy.wait(5000);
visitReportDefinitionDetailsPage();
verifyEditDefinitionButtonExists();
clickEditReportDefinitionButton();
verifyEditReportDefinitionURL();
});

cy.get('#reportDefinitionDetailsLink').first().click();
it('Verify report source URL on report definition details', () => {
visitReportingLandingPage();
cy.wait(5000);
visitReportDefinitionDetailsPage();
verifyReportDefinitionSourceURLExists();

});

cy.url().should('include', 'report_definition_details');
it('Delete report definition from details page', () => {
visitReportingLandingPage();
cy.wait(5000);
visitReportDefinitionDetailsPage();
verifyDeleteDefinitionButtonExists();
deleteReportDefinition();
verifyDeleteSuccess();
});

cy.get('#deleteReportDefinitionButton').should('exist');
it('Visit report details page', () => {
visitReportingLandingPage();
cy.wait(5000);
visitReportDetailsPage();
verifyReportDetailsURL();
});

cy.get('#editReportDefinitionButton').should('exist');
it('Verify report source URL on report details', () => {
visitReportingLandingPage();
cy.wait(5000);
visitReportDetailsPage();
verifyReportDetailsSourceURLExists();
});
});

if (cy.get('body').contains('Schedule details')) {
cy.wait(1000);
cy.get('#changeStatusFromDetailsButton').click();
} else {
cy.wait(1000);
cy.get('#generateReportFromDetailsButton').click();
}
function visitReportDefinitionDetailsPage() {
cy.get('#reportDefinitionDetailsLink').first().click();
}

cy.get('#deleteReportDefinitionButton').click();
});
function verifyReportDefinitionDetailsURL() {
cy.url().should('include', 'report_definition_details');
}

it('Visit report details page', () => {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/reports-dashboards#/`);
cy.location('pathname', { timeout: 60000 }).should(
'include',
'/reports-dashboards'
);
function verifyDeleteDefinitionButtonExists() {
cy.get('#deleteReportDefinitionButton').should('exist');
}

cy.wait(12500);
cy.get('#reportDetailsLink').first().click();
function verifyEditDefinitionButtonExists() {
cy.get('#editReportDefinitionButton').should('exist');
}

cy.url().should('include', 'report_details');
});
});
function clickEditReportDefinitionButton() {
cy.get('#editReportDefinitionButton').click({ force: true });
}

function verifyEditReportDefinitionURL() {
cy.url().should('include', 'edit');
}

function verifyReportDefinitionSourceURLExists() {
cy.get('#reportDefinitionSourceURL').should('exist');
}

function verifyReportDetailsSourceURLExists() {
cy.get('#reportDetailsSourceURL').should('exist');
}

function verifyGenerateReportFromFileFormatExists() {
cy.get('#generateReportFromDetailsFileFormat').should('exist');
}

function deleteReportDefinition() {
cy.get('#deleteReportDefinitionButton').click();
cy.wait(500);
cy.get('button.euiButton:nth-child(2)').click({ force: true });
}

function verifyDeleteSuccess() {
cy.get('#deleteReportDefinitionSuccessToast').should('exist');
}

function visitReportDetailsPage() {
cy.get('#reportDetailsLink').first().click();
}

function verifyReportDetailsURL() {
cy.url().should('include', 'report_details');
}
2 changes: 1 addition & 1 deletion dashboards-reports/.cypress/support/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
export const ADMIN_AUTH = {
username: 'admin',
password: 'admin',
};
};
12 changes: 12 additions & 0 deletions dashboards-reports/.cypress/support/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export function visitReportingLandingPage() {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/reports-dashboards#/`);
cy.location('pathname', { timeout: 60000 }).should(
'include',
'/reports-dashboards'
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ exports[`<ReportDefinitionDetails /> panel render 5 hours recurring definition d
<a
class="euiLink euiLink--primary"
href=""
id="reportDefinitionSourceURL"
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -242,7 +243,7 @@ exports[`<ReportDefinitionDetails /> panel render 5 hours recurring definition d
>
<button
class="euiLink euiLink--primary"
id="generateReportFromDetailsButton"
id="generateReportFromDetailsFileFormat"
type="button"
>
undefined
Expand Down Expand Up @@ -592,6 +593,7 @@ exports[`<ReportDefinitionDetails /> panel render disabled daily definition, cli
<a
class="euiLink euiLink--primary"
href=""
id="reportDefinitionSourceURL"
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -634,7 +636,7 @@ exports[`<ReportDefinitionDetails /> panel render disabled daily definition, cli
>
<button
class="euiLink euiLink--primary"
id="generateReportFromDetailsButton"
id="generateReportFromDetailsFileFormat"
type="button"
>
undefined
Expand Down Expand Up @@ -984,6 +986,7 @@ exports[`<ReportDefinitionDetails /> panel render on demand definition details 1
<a
class="euiLink euiLink--primary"
href=""
id="reportDefinitionSourceURL"
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -1026,7 +1029,7 @@ exports[`<ReportDefinitionDetails /> panel render on demand definition details 1
>
<button
class="euiLink euiLink--primary"
id="generateReportFromDetailsButton"
id="generateReportFromDetailsFileFormat"
type="button"
>
undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export function ReportDefinitionDetails(props: { match?: any; setBreadcrumbs?: a
return (
<EuiLink
onClick={downloadIconDownload}
id="generateReportFromDetailsButton"
id="generateReportFromDetailsFileFormat"
>
{formatUpper + ' '}
<EuiIcon type="importAction" />
Expand All @@ -507,7 +507,10 @@ export function ReportDefinitionDetails(props: { match?: any; setBreadcrumbs?: a

const sourceURL = (data: ReportDefinitionDetails) => {
return (
<EuiLink href={`${data.baseUrl}`} target="_blank">
<EuiLink
id="reportDefinitionSourceURL"
href={`${data.baseUrl}`} target="_blank"
>
{data['source']}
</EuiLink>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ exports[`<ReportDetails /> panel render 5 hours recurring component 1`] = `
<a
class="euiLink euiLink--primary"
href="http://localhost:5601/app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g=(time:(from:'2020-10-23T20:53:35.315Z',to:'2020-10-23T21:23:35.316Z'))"
id="reportDetailsSourceURL"
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -538,6 +539,7 @@ exports[`<ReportDetails /> panel render on-demand component 1`] = `
<a
class="euiLink euiLink--primary"
href="http://localhost:5601/app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g=(time:(from:'2020-10-23T20:53:35.315Z',to:'2020-10-23T21:23:35.316Z'))"
id="reportDetailsSourceURL"
rel="noopener noreferrer"
target="_blank"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ export function ReportDetails(props: { match?: any; setBreadcrumbs?: any; httpCl

const sourceURL = (data: ReportDetails) => {
return (
<EuiLink href={`${data.queryUrl}`} target="_blank">
<EuiLink
id="reportDetailsSourceURL"
href={`${data.queryUrl}`} target="_blank"
>
{data['source']}
</EuiLink>
);
Expand Down

0 comments on commit 9daf116

Please sign in to comment.