From 1e4aa55c3d45235079b98b5055a594374ef81c64 Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Fri, 5 Jan 2024 17:29:33 -0800 Subject: [PATCH 1/6] Add tests for integrations Signed-off-by: Simeon Widdis --- .../7_integrations.spec.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 cypress/integration/plugins/observability-dashboards/7_integrations.spec.js diff --git a/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js new file mode 100644 index 000000000..f2be7b956 --- /dev/null +++ b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js @@ -0,0 +1,58 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +/// + +import { BASE_PATH } from '../../../utils/base_constants'; + +const testInstanceName = 'test_integration_cypress'; + +const moveToAvailableNginxIntegration = () => { + cy.visit(`${BASE_PATH}/app/integrations#/available/nginx`); +}; + +const moveToAddedIntegrations = () => { + cy.visit(`${BASE_PATH}/app/integrations#/installed`); +}; + +const createSamples = () => { + moveToAvailableNginxIntegration(); + cy.get('[data-test-subj="try-it-button"]').click(); + cy.get('.euiToastHeader__title').should('contain', 'successfully'); +}; + +describe('Add nginx integration instance flow', () => { + it('Navigates to nginx page and triggers the adds the instance flow', () => { + createSamples(); + moveToAvailableNginxIntegration(); + cy.get('[data-test-subj="add-integration-button"]').click(); + cy.get('[data-test-subj="new-instance-name"]').should( + 'have.value', + 'nginx Integration' + ); + cy.get('[data-test-subj="create-instance-button"]').should('be.disabled'); + // Modifies the name of the integration + cy.get('[data-test-subj="new-instance-name"]').clear(); + cy.get('[data-test-subj="new-instance-name"]').type(testInstanceName); + // Validates the created sample index + cy.get('[data-test-subj="data-source-name"]').type( + 'ss4o_logs-nginx-sample-sample{enter}' + ); + cy.get('[data-test-subj="create-instance-button"]').click(); + cy.get('[data-test-subj="eventHomePageTitle"]').should( + 'contain', + testInstanceName + ); + }); + + it('Navigates to installed integrations page and verifies that installed integration exists', () => { + moveToAddedIntegrations(); + cy.contains(testInstanceName).should('exist'); + cy.get('input[type="search"]').eq(0).focus(); + cy.get('input[type="search"]').eq(0).type(`${testInstanceName}{enter}`); + cy.get('.euiTableRow').should('have.length', 1); //Filters correctly to the test integration instance + cy.get(`[data-test-subj="${testInstanceName}IntegrationLink"]`).click(); + }); +}); From 55074ca334a0585143f11548ccfb9f108e3fb7ae Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Mon, 8 Jan 2024 09:35:01 -0800 Subject: [PATCH 2/6] Add check for test instance page opening Signed-off-by: Simeon Widdis --- .../plugins/observability-dashboards/7_integrations.spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js index f2be7b956..2698bae65 100644 --- a/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js +++ b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js @@ -54,5 +54,9 @@ describe('Add nginx integration instance flow', () => { cy.get('input[type="search"]').eq(0).type(`${testInstanceName}{enter}`); cy.get('.euiTableRow').should('have.length', 1); //Filters correctly to the test integration instance cy.get(`[data-test-subj="${testInstanceName}IntegrationLink"]`).click(); + cy.get('[data-test-subj="eventHomePageTitle"]').should( + 'contain', + testInstanceName + ); }); }); From 27feec3ef6e977695372f45913610d499d7a4f20 Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Thu, 18 Jan 2024 11:36:44 -0800 Subject: [PATCH 3/6] Empty commit to re-trigger run Signed-off-by: Simeon Widdis From 58ad089a49d3ddfa9024975cb79b4f83a95195e9 Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Tue, 23 Jan 2024 13:57:14 -0800 Subject: [PATCH 4/6] Decouple integrations add and search tests Signed-off-by: Simeon Widdis --- .../7_integrations.spec.js | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js index 2698bae65..a28b9011b 100644 --- a/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js +++ b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js @@ -24,8 +24,44 @@ const createSamples = () => { }; describe('Add nginx integration instance flow', () => { - it('Navigates to nginx page and triggers the adds the instance flow', () => { + beforeEach(() => { createSamples(); + }); + + afterEach(() => { + // First delete any integration index data + cy.request({ + method: 'POST', + form: false, + url: 'api/console/proxy', + headers: { + 'content-type': 'application/json;charset=UTF-8', + 'osd-xsrf': true, + }, + qs: { + path: `ss4o_logs-nginx-*`, // All tests work with ss4o nginx data + method: 'DELETE', + }, + body: '{}', + }); + // Then clear all installed integrations + cy.request({ + method: 'POST', + form: false, + url: 'api/console/proxy', + headers: { + 'content-type': 'application/json;charset=UTF-8', + 'osd-xsrf': true, + }, + qs: { + path: `.kibana/_delete_by_query`, + method: 'POST', + }, + body: `{ "query": { "match": { "type": "integration-instance" } } }`, + }); + }); + + it('Navigates to nginx page and triggers the adds the instance flow', () => { moveToAvailableNginxIntegration(); cy.get('[data-test-subj="add-integration-button"]').click(); cy.get('[data-test-subj="new-instance-name"]').should( @@ -48,15 +84,16 @@ describe('Add nginx integration instance flow', () => { }); it('Navigates to installed integrations page and verifies that installed integration exists', () => { + const sampleName = 'nginx-sample'; moveToAddedIntegrations(); - cy.contains(testInstanceName).should('exist'); + cy.contains(sampleName).should('exist'); cy.get('input[type="search"]').eq(0).focus(); - cy.get('input[type="search"]').eq(0).type(`${testInstanceName}{enter}`); + cy.get('input[type="search"]').eq(0).type(`${sampleName}{enter}`); cy.get('.euiTableRow').should('have.length', 1); //Filters correctly to the test integration instance - cy.get(`[data-test-subj="${testInstanceName}IntegrationLink"]`).click(); + cy.get(`[data-test-subj="${sampleName}IntegrationLink"]`).click(); cy.get('[data-test-subj="eventHomePageTitle"]').should( 'contain', - testInstanceName + sampleName ); }); }); From 25c770ada51ae0eca9c3fbb27801e125338d1f9b Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Tue, 23 Jan 2024 13:58:33 -0800 Subject: [PATCH 5/6] Move instance name constant to test Signed-off-by: Simeon Widdis --- .../plugins/observability-dashboards/7_integrations.spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js index a28b9011b..ed5b2c3e4 100644 --- a/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js +++ b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js @@ -7,8 +7,6 @@ import { BASE_PATH } from '../../../utils/base_constants'; -const testInstanceName = 'test_integration_cypress'; - const moveToAvailableNginxIntegration = () => { cy.visit(`${BASE_PATH}/app/integrations#/available/nginx`); }; @@ -62,6 +60,7 @@ describe('Add nginx integration instance flow', () => { }); it('Navigates to nginx page and triggers the adds the instance flow', () => { + const testInstanceName = 'test_integration_cypress'; moveToAvailableNginxIntegration(); cy.get('[data-test-subj="add-integration-button"]').click(); cy.get('[data-test-subj="new-instance-name"]').should( From f4c5194c5f50e7a1cf413a9935e5adc4a9ae7b1f Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Tue, 23 Jan 2024 14:40:01 -0800 Subject: [PATCH 6/6] Add integrations teardown process Signed-off-by: Simeon Widdis --- .../7_integrations.spec.js | 70 +++++++++++-------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js index ed5b2c3e4..2baefcff6 100644 --- a/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js +++ b/cypress/integration/plugins/observability-dashboards/7_integrations.spec.js @@ -21,42 +21,52 @@ const createSamples = () => { cy.get('.euiToastHeader__title').should('contain', 'successfully'); }; +const integrationsTeardown = () => { + // Delete all integration instances + cy.request({ + method: 'GET', + form: false, + url: `api/integrations/store`, + headers: { + 'content-type': 'application/json;charset=UTF-8', + 'osd-xsrf': true, + }, + }).then((response) => { + for (const instance of response.body.data.hits) { + cy.request({ + method: 'DELETE', + url: `/api/integrations/store/${instance.id}`, + headers: { + 'content-type': 'application/json;charset=UTF-8', + 'osd-xsrf': true, + }, + }); + } + }); + // Also clean up indices + cy.request({ + method: 'POST', + form: false, + url: 'api/console/proxy', + headers: { + 'content-type': 'application/json;charset=UTF-8', + 'osd-xsrf': true, + }, + qs: { + path: `ss4o_logs-nginx-*`, // All tests work with ss4o nginx data + method: 'DELETE', + }, + body: '{}', + }); +}; + describe('Add nginx integration instance flow', () => { beforeEach(() => { createSamples(); }); afterEach(() => { - // First delete any integration index data - cy.request({ - method: 'POST', - form: false, - url: 'api/console/proxy', - headers: { - 'content-type': 'application/json;charset=UTF-8', - 'osd-xsrf': true, - }, - qs: { - path: `ss4o_logs-nginx-*`, // All tests work with ss4o nginx data - method: 'DELETE', - }, - body: '{}', - }); - // Then clear all installed integrations - cy.request({ - method: 'POST', - form: false, - url: 'api/console/proxy', - headers: { - 'content-type': 'application/json;charset=UTF-8', - 'osd-xsrf': true, - }, - qs: { - path: `.kibana/_delete_by_query`, - method: 'POST', - }, - body: `{ "query": { "match": { "type": "integration-instance" } } }`, - }); + integrationsTeardown(); }); it('Navigates to nginx page and triggers the adds the instance flow', () => {