From 37fe66903fea88d250d91b1d291b283551d74541 Mon Sep 17 00:00:00 2001 From: David Cui <53581635+davidcui1225@users.noreply.github.com> Date: Tue, 7 Dec 2021 11:23:49 -0800 Subject: [PATCH] Add Case Coverage tests for Create Report Definition (#239) * add & refactor cypress tests, add css selectors in report settings & report trigger Signed-off-by: David Cui * remove comment and update jest snapshot Signed-off-by: David Cui --- .../.cypress/integration/01-create.spec.ts | 264 ++++++++++++++---- .../report_settings.test.tsx.snap | 60 ++-- .../report_settings/report_settings.tsx | 3 +- .../report_trigger/report_trigger.tsx | 5 +- dashboards-reports/test/jest.config.js | 2 +- 5 files changed, 242 insertions(+), 92 deletions(-) diff --git a/dashboards-reports/.cypress/integration/01-create.spec.ts b/dashboards-reports/.cypress/integration/01-create.spec.ts index ef16a52c..65b4999d 100644 --- a/dashboards-reports/.cypress/integration/01-create.spec.ts +++ b/dashboards-reports/.cypress/integration/01-create.spec.ts @@ -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'); +} \ No newline at end of file diff --git a/dashboards-reports/public/components/report_definitions/report_settings/__tests__/__snapshots__/report_settings.test.tsx.snap b/dashboards-reports/public/components/report_definitions/report_settings/__tests__/__snapshots__/report_settings.test.tsx.snap index 1a714557..32269bf6 100644 --- a/dashboards-reports/public/components/report_definitions/report_settings/__tests__/__snapshots__/report_settings.test.tsx.snap +++ b/dashboards-reports/public/components/report_definitions/report_settings/__tests__/__snapshots__/report_settings.test.tsx.snap @@ -212,14 +212,14 @@ exports[` panel dashboard create from in-context 1`] = `
@@ -256,7 +256,7 @@ exports[` panel dashboard create from in-context 1`] = ` panel display errors on create 1`] = `
@@ -1439,7 +1439,7 @@ exports[` panel display errors on create 1`] = ` panel render component 1`] = `
@@ -2629,7 +2629,7 @@ exports[` panel render component 1`] = ` panel render edit, dashboard source 1`] = `
@@ -3239,7 +3239,7 @@ exports[` panel render edit, dashboard source 1`] = ` panel render edit, dashboard source 2`] = `
@@ -3864,7 +3864,7 @@ exports[` panel render edit, dashboard source 2`] = ` panel render edit, saved search source 1`] = `
@@ -4489,7 +4489,7 @@ exports[` panel render edit, saved search source 1`] = ` panel render edit, visualization source 1`] = `
@@ -5114,7 +5114,7 @@ exports[` panel render edit, visualization source 1`] = ` panel render edit, visualization source 2`] = `
@@ -5739,7 +5739,7 @@ exports[` panel render edit, visualization source 2`] = ` panel saved search create from in-context 1`] = `
@@ -6360,7 +6360,7 @@ exports[` panel saved search create from in-context 1`] = ` panel visualization create from in-context 1`] = `
@@ -7543,7 +7543,7 @@ exports[` panel visualization create from in-context 1`] = ` /offline-module-cache/'], - testPathIgnorePatterns: ['/build/', '/node_modules/'], + testPathIgnorePatterns: ['/build/', '/node_modules/', '/public/components/report_definitions/delivery/'], transformIgnorePatterns: ['/node_modules'], moduleNameMapper: { '\\.(css|less|sass|scss)$': '/test/__mocks__/styleMock.js',