Skip to content

Commit

Permalink
Add Case Coverage tests for Create Report Definition (opensearch-proj…
Browse files Browse the repository at this point in the history
…ect#239)

* add & refactor cypress tests, add css selectors in report settings & report trigger

Signed-off-by: David Cui <davidcui@amazon.com>

* remove comment and update jest snapshot

Signed-off-by: David Cui <davidcui@amazon.com>
  • Loading branch information
davidcui1225 authored Dec 7, 2021
1 parent c8fcf5d commit dae3b44
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 92 deletions.
264 changes: 205 additions & 59 deletions .cypress/integration/01-create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,90 +19,236 @@ describe('Adding sample data', () => {

describe('Cypress', () => {
it('Visits Reporting homepage', () => {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/reports-dashboards#/`);
cy.location('pathname', { timeout: 60000 }).should(
'include',
'/reports-dashboards'
);
visitReportingLandingPage();
});

it('Visit Create page', () => {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/reports-dashboards#/`);
cy.location('pathname', { timeout: 60000 }).should(
'include',
'/reports-dashboards'
);
cy.wait(12500); // wait for the page to load
cy.get('#createReportHomepageButton').click({ force: true });
visitCreateReportDefinitionPage();
});

it('Create a new on-demand report definition', () => {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/reports-dashboards#/`);
cy.location('pathname', { timeout: 60000 }).should(
'include',
'/reports-dashboards'
);
cy.wait(12500);
cy.get('#createReportHomepageButton').click();
it('Create a new on-demand dashboard report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress dashboard on-demand report');
setReportDefinitionDescription('Description for cypress test');
selectReportSourceComboBox();

// enter a report name
cy.get('#reportSettingsName').type('Create cypress test on-demand report');
// // select drop-down option in report source list
cy.contains('[Logs] Web Traffic').click();

cy.wait(500);
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

// enter a report description
cy.get('#reportSettingsDescription').type('Description for cypress test');
it('Create a new on-demand visualization report definition', ()=> {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress vis on-demand report');
setReportDefinitionDescription('Description for cypress test');
selectReportSource('#visualizationReportSource');
selectReportSourceComboBox();
cy.wait(500);
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

it('Create a new on-demand saved search report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress saved search on-demand report');
setReportDefinitionDescription('Description for cypress test');
selectReportSource('#savedSearchReportSource');
selectReportSourceComboBox();
cy.wait(500);
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

// select a report source
cy.get('[data-test-subj="comboBoxInput"]').eq(0).click({ force: true });
it('Create a new dashboard daily recurring report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress dashboard daily scheduled report');
setReportDefinitionDescription('Description for cypress test');
selectReportSourceComboBox();

// select drop-down option in report source list
cy.contains('[Logs] Web Traffic').click();

cy.wait(500);

// create an on-demand report definition
cy.get('#createNewReportDefinition').click({ force: true });

cy.wait(12500);

// check that re-direct to
cy.get('#reportDefinitionDetailsLink').should('exist');
setReportTriggerToSchedule();
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

it('Create a new scheduled report definition', () => {
cy.visit(`${Cypress.env('opensearchDashboards')}/app/reports-dashboards#/`);
cy.location('pathname', { timeout: 60000 }).should(
'include',
'/reports-dashboards'
);
cy.wait(12500);
cy.get('#createReportHomepageButton').click();

// enter a report name
cy.get('#reportSettingsName').type('Create cypress test scheduled report');
it('Create a new visualization daily recurring report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress vis daily scheduled report');
setReportDefinitionDescription('Description for cypress test');
selectReportSource('#visualizationReportSource');
selectReportSourceComboBox();
cy.wait(500);
setReportTriggerToSchedule();
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

// enter a report description
cy.get('#reportSettingsDescription').type('Description for cypress test');
it('Create a new saved search daily recurring report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress search daily scheduled report');
setReportDefinitionDescription('Description for cypress test');
selectReportSource('#savedSearchReportSource');
selectReportSourceComboBox();
setReportTriggerToSchedule();
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

// select a report source
cy.get('[data-test-subj="comboBoxInput"]').eq(0).click({ force: true });
it('Create a new dashboard interval recurring report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress dashboard recurring report');
setReportDefinitionDescription('Description for cypress test');
selectReportSourceComboBox();

// select drop-down option in report source list
cy.contains('[Logs] Web Traffic').click();

cy.wait(500);
setReportTriggerToSchedule();
selectIntervalScheduleFrequency();
inputTextIntoField('#recurringByIntervalNumber', '5');
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

it('Create a new visualization interval recurring report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress vis interval recurring report');
selectReportSource('#visualizationReportSource');
selectReportSourceComboBox();
setReportTriggerToSchedule();
selectIntervalScheduleFrequency();
inputTextIntoField('#recurringByIntervalNumber', '5');
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

// set report trigger to Schedule option
cy.get('[type="radio"]').check({ force: true });
it('Create a new saved search interval recurring report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress saved search interval recurring report');
selectReportSource('#savedSearchReportSource');
selectReportSourceComboBox();
setReportTriggerToSchedule();
selectIntervalScheduleFrequency();
inputTextIntoField('#recurringByIntervalNumber', '5');
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

// set source back to saved search for testing purpose
cy.get('#savedSearchReportSource').check({ force: true });
it('Create a dashboard cron-based report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress dashboard cron definition');
selectReportSourceComboBox();

// select drop-down option in report source list
cy.contains('[Logs] Web Traffic').click();
cy.wait(500);
setReportTriggerToSchedule();
selectCronBasedRequestTime();
inputTextIntoField('#cronExpressionFieldText', '0 12 * * *');
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

// create scheduled report definition
cy.get('#createNewReportDefinition').click({ force: true });
it('Create a visualization cron-based report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress vis cron definition');
selectReportSource('#visualizationReportSource');
selectReportSourceComboBox();
setReportTriggerToSchedule();
selectCronBasedRequestTime();
inputTextIntoField('#cronExpressionFieldText', '0 12 * * *');
cy.wait(500);
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});

cy.wait(12500);

// check that re-direct to
cy.get('#reportDefinitionDetailsLink').should('exist');
it('Create a saved search cron-based report definition', () => {
visitCreateReportDefinitionPage();
setReportDefinitionName('Cypress search cron definition');
selectReportSource('#savedSearchReportSource');
selectReportSourceComboBox();
setReportTriggerToSchedule();
selectCronBasedRequestTime();
inputTextIntoField('#cronExpressionFieldText', '0 12 * * *');
cy.wait(500);
clickCreateReportDefinitionButton();
cy.wait(3000);
verifyOnReportingLandingPage();
});
});

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(
'include',
'/reports-dashboards'
);
cy.wait(3000);
cy.get('#createReportHomepageButton').click();
}

function setReportDefinitionName(name: string) {
cy.get('#reportSettingsName').type(name);
}

function setReportDefinitionDescription(description: string) {
cy.get('#reportSettingsDescription').type(description);
}

function selectReportSource(name: string) {
cy.get(name).click({force: true});
}

function selectReportSourceComboBox() {
cy.get('[data-test-subj="comboBoxInput"]').eq(0).click({ force: true });
}

function setReportTriggerToSchedule() {
cy.get('#Schedule').check({ force: true });
}

function selectIntervalScheduleFrequency() {
cy.get('#recurringFrequencySelect').select('By interval');
}

function selectCronBasedRequestTime() {
cy.contains('Cron based').click({ force: true });
}

function inputTextIntoField(selector: string, text: string) {
cy.get(selector).type(text);
}

function clickCreateReportDefinitionButton() {
cy.get('#createNewReportDefinition').click({ force: true });
}

function verifyOnReportingLandingPage() {
cy.get('#reportDefinitionDetailsLink').should('exist');
}
Loading

0 comments on commit dae3b44

Please sign in to comment.