From eeaf705a46d71d6b7d5a8e24ea33702c250645a4 Mon Sep 17 00:00:00 2001 From: Junqiu Lei Date: Wed, 28 Aug 2024 15:39:13 -0700 Subject: [PATCH] Add test cases to dashboards maps Signed-off-by: Junqiu Lei --- .../sample_geo.json | 8 ++++ .../0_add_saved_object.js | 34 +++++++++++++ .../1_import_vector_map_tab.spec.js | 4 +- .../2_opensearchMapLayer.spec.js | 23 +++------ .../3_add_saved_object.spec.js | 25 +++------- .../4_documentsLayer.spec.js | 27 +++-------- .../5_add_map_to_dashboard.spec.js | 37 ++++++++++++++ .../6_geojson_file_upload.spec.js | 48 +++++++++++++++++++ package-lock.json | 20 ++++++++ package.json | 1 + 10 files changed, 172 insertions(+), 55 deletions(-) create mode 100644 cypress/fixtures/plugins/custom-import-map-dashboards/sample_geo.json create mode 100644 cypress/integration/plugins/custom-import-map-dashboards/0_add_saved_object.js create mode 100644 cypress/integration/plugins/custom-import-map-dashboards/5_add_map_to_dashboard.spec.js create mode 100644 cypress/integration/plugins/custom-import-map-dashboards/6_geojson_file_upload.spec.js diff --git a/cypress/fixtures/plugins/custom-import-map-dashboards/sample_geo.json b/cypress/fixtures/plugins/custom-import-map-dashboards/sample_geo.json new file mode 100644 index 000000000..6145026a5 --- /dev/null +++ b/cypress/fixtures/plugins/custom-import-map-dashboards/sample_geo.json @@ -0,0 +1,8 @@ +{ + "type": "FeatureCollection", + "name": "sample", + "features": [ + { "type": "Feature", "properties": { "iso2": "IN", "iso3": "IND", "name": "Abc" }, "geometry": { "type": "MultiPolygon", "coordinates": [[[[70.6640625,39.639537564366684],[69.78515625,37.020098201368114],[69.60937499999999,33.7243396617476],[69.9609375,29.99300228455108],[69.2578125,27.839076094777816],[69.60937499999999,26.588527147308614],[70.6640625,25.799891182088334],[70.13671875,24.206889622398023],[67.67578124999999,23.885837699862005],[69.78515625,21.616579336740603],[73.30078125,17.644022027872726],[75.76171875,13.581920900545844],[76.2890625,10.487811882056695],[77.51953125,8.233237111274565],[79.453125,11.178401873711785],[80.15625,16.97274101999902],[85.78125,19.973348786110602],[90.703125,21.616579336740603],[95.80078125,21.616579336740603],[96.85546875,26.27371402440643],[97.3828125,28.613459424004414],[92.98828125,30.14512718337613],[88.9453125,29.6880527498568],[83.84765625,30.14512718337613],[80.33203125,34.161818161230386],[81.2109375,37.020098201368114],[76.2890625,38.272688535980976],[71.54296874999999,39.774769485295465],[70.6640625,39.639537564366684]]]] } }, + { "type": "Feature", "properties": { "iso2": "CN", "iso3": "CHN", "name": "Xyz" }, "geometry": { "type": "MultiPolygon", "coordinates": [[ [ [ 113.36476, 22.1579 ], [ 113.35401, 22.13085 ], [ 113.33619, 22.10049 ], [ 113.31365, 22.0764 ], [ 113.28907, 22.06851 ], [ 113.27914, 22.07469 ], [ 113.26881, 22.08832 ], [ 113.26417, 22.10493 ], [ 113.27174, 22.12002 ], [ 113.27914, 22.1232 ], [ 113.28972, 22.12547 ], [ 113.29868, 22.12857 ], [ 113.30274, 22.13398 ], [ 113.30421, 22.14183 ], [ 113.30844, 22.14863 ], [ 113.31495, 22.154 ], [ 113.32309, 22.1579 ], [ 113.32797, 22.14582 ], [ 113.33546, 22.14887 ], [ 113.34718, 22.15644 ], [ 113.36476, 22.1579 ] ] ], [ [ [ 113.59352, 22.78482 ], [ 113.60288, 22.77245 ], [ 113.60279, 22.76264 ], [ 113.59457, 22.75609 ], [ 113.57984, 22.75373 ], [ 113.55828, 22.75788 ], [ 113.54461, 22.76878 ], [ 113.53566, 22.78433 ], [ 113.52858, 22.80215 ], [ 113.52117, 22.78791 ], [ 113.50611, 22.79804 ], [ 113.49529, 22.81387 ], [ 113.4808, 22.84931 ], [ 113.47397, 22.84931 ], [ 113.47316, 22.82538 ], [ 113.4559, 22.83076 ], [ 113.43409, 22.84907 ], [ 113.40211, 22.88288 ], [ 113.39617, 22.8981 ], [ 113.40512, 22.90811 ], [ 113.43295, 22.91201 ], [ 113.4756, 22.9007 ], [ 113.4878, 22.89281 ], [ 113.52703, 22.84663 ], [ 113.54672, 22.83487 ], [ 113.57301, 22.83006 ], [ 113.57643, 22.82392 ], [ 113.58766, 22.79462 ], [ 113.59352, 22.78482 ] ] ] ] } } + ] +} diff --git a/cypress/integration/plugins/custom-import-map-dashboards/0_add_saved_object.js b/cypress/integration/plugins/custom-import-map-dashboards/0_add_saved_object.js new file mode 100644 index 000000000..f3273f35a --- /dev/null +++ b/cypress/integration/plugins/custom-import-map-dashboards/0_add_saved_object.js @@ -0,0 +1,34 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { BASE_PATH } from '../../../utils/constants'; +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { CURRENT_TENANT } from '../../../utils/commands'; + +const miscUtils = new MiscUtils(cy); + +describe('Add flights dataset saved object', () => { + before(() => { + CURRENT_TENANT.newTenant = 'global'; + cy.deleteAllIndices(); + miscUtils.addSampleData(); + cy.wait(10000); + }); + + after(() => { + miscUtils.removeSampleData(); + }); + + it('check if maps saved object of flights dataset can be found and open', () => { + cy.visit(`${BASE_PATH}/app/maps-dashboards`); + cy.contains( + '[Flights] Flights Status on Maps Destination Location' + ).click(); + cy.get('[data-test-subj="layerControlPanel"]').should( + 'contain', + 'Flights On Time' + ); + }); +}); diff --git a/cypress/integration/plugins/custom-import-map-dashboards/1_import_vector_map_tab.spec.js b/cypress/integration/plugins/custom-import-map-dashboards/1_import_vector_map_tab.spec.js index 0099d7960..fb495b0bd 100644 --- a/cypress/integration/plugins/custom-import-map-dashboards/1_import_vector_map_tab.spec.js +++ b/cypress/integration/plugins/custom-import-map-dashboards/1_import_vector_map_tab.spec.js @@ -6,15 +6,17 @@ /// import { BASE_PATH } from '../../../utils/constants'; -import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; import { CURRENT_TENANT } from '../../../utils/commands'; +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; const miscUtils = new MiscUtils(cy); + describe('Verify the presence of import custom map tab in region map plugin', () => { before(() => { CURRENT_TENANT.newTenant = 'global'; cy.deleteAllIndices(); miscUtils.addSampleData(); + cy.wait(15000); // Load region map visualization with sample data opensearch_dashboards_sample_data_flights cy.visit( diff --git a/cypress/integration/plugins/custom-import-map-dashboards/2_opensearchMapLayer.spec.js b/cypress/integration/plugins/custom-import-map-dashboards/2_opensearchMapLayer.spec.js index f2536f73b..c4f79a23d 100644 --- a/cypress/integration/plugins/custom-import-map-dashboards/2_opensearchMapLayer.spec.js +++ b/cypress/integration/plugins/custom-import-map-dashboards/2_opensearchMapLayer.spec.js @@ -5,21 +5,16 @@ import { BASE_PATH } from '../../../utils/constants'; import { CURRENT_TENANT } from '../../../utils/commands'; +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); describe('Default OpenSearch base map layer', () => { before(() => { CURRENT_TENANT.newTenant = 'global'; - cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { - retryOnStatusCodeFailure: true, - timeout: 60000, - }); - cy.wait(5000); - cy.get('div[data-test-subj="sampleDataSetCardflights"]', { - timeout: 60000, - }) - .contains(/(Add|View) data/) - .click(); - cy.wait(60000); + cy.deleteAllIndices(); + miscUtils.addSampleData(); + cy.wait(15000); }); it('check if default OpenSearch map layer can be open', () => { @@ -49,10 +44,6 @@ describe('Default OpenSearch base map layer', () => { }); after(() => { - cy.visit(`${BASE_PATH}/app/home#/tutorial_directory`); - cy.wait(5000); - cy.get('button[data-test-subj="removeSampleDataSetflights"]') - .should('be.visible') - .click(); + miscUtils.removeSampleData(); }); }); diff --git a/cypress/integration/plugins/custom-import-map-dashboards/3_add_saved_object.spec.js b/cypress/integration/plugins/custom-import-map-dashboards/3_add_saved_object.spec.js index 2d8b29495..aa629653b 100644 --- a/cypress/integration/plugins/custom-import-map-dashboards/3_add_saved_object.spec.js +++ b/cypress/integration/plugins/custom-import-map-dashboards/3_add_saved_object.spec.js @@ -5,31 +5,20 @@ import { BASE_PATH } from '../../../utils/constants'; import { CURRENT_TENANT } from '../../../utils/commands'; +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); describe('Add flights dataset saved object', () => { before(() => { CURRENT_TENANT.newTenant = 'global'; - cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { - retryOnStatusCodeFailure: true, - timeout: 60000, - }); - cy.wait(5000); - cy.get('div[data-test-subj="sampleDataSetCardflights"]', { - timeout: 60000, - }) - .contains(/Add data/) - .click(); - cy.wait(60000); + cy.deleteAllIndices(); + miscUtils.addSampleData(); + cy.wait(15000); }); after(() => { - cy.visit(`${BASE_PATH}/app/home#/tutorial_directory`); - cy.wait(5000); - cy.get('button[data-test-subj="removeSampleDataSetflights"]', { - timeout: 120000, - }) - .should('be.visible') - .click(); + miscUtils.removeSampleData(); }); it('check if maps saved object of flights dataset can be found and open', () => { diff --git a/cypress/integration/plugins/custom-import-map-dashboards/4_documentsLayer.spec.js b/cypress/integration/plugins/custom-import-map-dashboards/4_documentsLayer.spec.js index 07fe01765..012bf5598 100644 --- a/cypress/integration/plugins/custom-import-map-dashboards/4_documentsLayer.spec.js +++ b/cypress/integration/plugins/custom-import-map-dashboards/4_documentsLayer.spec.js @@ -5,21 +5,16 @@ import { BASE_PATH } from '../../../utils/constants'; import { CURRENT_TENANT } from '../../../utils/commands'; +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); describe('Documents layer', () => { before(() => { CURRENT_TENANT.newTenant = 'global'; - cy.visit(`${BASE_PATH}/app/home#/tutorial_directory/sampleData`, { - retryOnStatusCodeFailure: true, - timeout: 60000, - }); - cy.wait(5000); - cy.get('div[data-test-subj="sampleDataSetCardflights"]', { - timeout: 60000, - }) - .contains(/(Add|View) data/) - .click(); - cy.wait(60000); + cy.deleteAllIndices(); + miscUtils.addSampleData(); + cy.wait(15000); }); const uniqueName = 'saved-map-' + Date.now().toString(); @@ -76,10 +71,6 @@ describe('Documents layer', () => { cy.wait(30000); cy.visit(`${BASE_PATH}/app/maps-dashboards`); cy.wait(10000); - cy.get('[data-test-subj="mapListingPage"]', { timeout: 120000 }).should( - 'contain', - uniqueName - ); cy.contains(uniqueName).click(); cy.get('[data-test-subj="layerControlPanel"]').should( 'contain', @@ -88,10 +79,6 @@ describe('Documents layer', () => { }); after(() => { - cy.visit(`${BASE_PATH}/app/home#/tutorial_directory`); - cy.wait(5000); - cy.get('button[data-test-subj="removeSampleDataSetflights"]') - .should('be.visible') - .click(); + miscUtils.removeSampleData(); }); }); diff --git a/cypress/integration/plugins/custom-import-map-dashboards/5_add_map_to_dashboard.spec.js b/cypress/integration/plugins/custom-import-map-dashboards/5_add_map_to_dashboard.spec.js new file mode 100644 index 000000000..d143601c0 --- /dev/null +++ b/cypress/integration/plugins/custom-import-map-dashboards/5_add_map_to_dashboard.spec.js @@ -0,0 +1,37 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { BASE_PATH } from '../../../utils/constants'; +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { CURRENT_TENANT } from '../../../utils/commands'; + +const miscUtils = new MiscUtils(cy); + +describe('Add map to dashboard', () => { + before(() => { + CURRENT_TENANT.newTenant = 'global'; + cy.deleteAllIndices(); + miscUtils.addSampleData(); + cy.wait(15000); + }); + + it('Add new map to dashboard', () => { + const testMapName = 'saved-map-' + Date.now().toString(); + cy.visit(`${BASE_PATH}/app/dashboards`); + cy.get('[data-test-subj="newItemButton"]').click(); + cy.get('button[data-test-subj="dashboardAddNewPanelButton"]').click(); + cy.get('button[data-test-subj="visType-customImportMap"]').click(); + cy.wait(5000).get('button[data-test-subj="mapSaveButton"]').click(); + cy.wait(5000).get('[data-test-subj="savedObjectTitle"]').type(testMapName); + cy.wait(5000) + .get('[data-test-subj="confirmSaveSavedObjectButton"]') + .click(); + cy.get('.embPanel__titleText').should('contain', testMapName); + }); + + after(() => { + miscUtils.removeSampleData(); + }); +}); diff --git a/cypress/integration/plugins/custom-import-map-dashboards/6_geojson_file_upload.spec.js b/cypress/integration/plugins/custom-import-map-dashboards/6_geojson_file_upload.spec.js new file mode 100644 index 000000000..c98eeb7a7 --- /dev/null +++ b/cypress/integration/plugins/custom-import-map-dashboards/6_geojson_file_upload.spec.js @@ -0,0 +1,48 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { BASE_PATH } from '../../../utils/constants'; +import { CURRENT_TENANT } from '../../../utils/commands'; +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import 'cypress-file-upload'; + +const miscUtils = new MiscUtils(cy); + +describe('Verify successful custom geojson file upload', () => { + before(() => { + CURRENT_TENANT.newTenant = 'global'; + cy.deleteAllIndices(); + miscUtils.addSampleData(); + cy.wait(15000); + + // Load region map visualization with sample data opensearch_dashboards_sample_data_flights + cy.visit( + `${BASE_PATH}/app/visualize#/create?type=region_map&indexPattern=d3d7af60-4c81-11e8-b3d7-01146121b73d`, + { + retryOnStatusCodeFailure: true, + timeout: 60000, + } + ); + }); + + it('checks if the file uploaded successfully', () => { + // Click on "Import Vector Map" tab, which is part of customImportMap plugin + cy.contains('Import Vector Map').click({ force: true }); + + cy.get('[data-testId="filePicker"]').attachFile( + 'plugins/custom-import-map-dashboards/sample_geo.json' + ); + cy.get('[data-testId="customIndex"]').type('sample'); + cy.contains('Import file').click({ force: true }); + cy.contains( + 'Successfully added 2 features to sample-map. Refresh to visualize the uploaded map.', + { timeout: 240000 } + ); + }); + + after(() => { + miscUtils.removeSampleData(); + }); +}); diff --git a/package-lock.json b/package-lock.json index 5740ead3a..b2e54dae1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@faker-js/faker": "^7.6.0", "commander": "^9.4.1", "cypress": "9.5.4", + "cypress-file-upload": "^5.0.8", "cypress-multi-reporters": "^1.5.0", "cypress-real-events": "1.7.6", "eslint": "^7.0.0", @@ -939,6 +940,18 @@ "node": ">=12.0.0" } }, + "node_modules/cypress-file-upload": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/cypress-file-upload/-/cypress-file-upload-5.0.8.tgz", + "integrity": "sha512-+8VzNabRk3zG6x8f8BWArF/xA/W0VK4IZNx3MV0jFWrJS/qKn8eHfa5nU73P9fOQAgwHFJx7zjg4lwOnljMO8g==", + "dev": true, + "engines": { + "node": ">=8.2.1" + }, + "peerDependencies": { + "cypress": ">3.0.0" + } + }, "node_modules/cypress-multi-reporters": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/cypress-multi-reporters/-/cypress-multi-reporters-1.5.0.tgz", @@ -4754,6 +4767,13 @@ } } }, + "cypress-file-upload": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/cypress-file-upload/-/cypress-file-upload-5.0.8.tgz", + "integrity": "sha512-+8VzNabRk3zG6x8f8BWArF/xA/W0VK4IZNx3MV0jFWrJS/qKn8eHfa5nU73P9fOQAgwHFJx7zjg4lwOnljMO8g==", + "dev": true, + "requires": {} + }, "cypress-multi-reporters": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/cypress-multi-reporters/-/cypress-multi-reporters-1.5.0.tgz", diff --git a/package.json b/package.json index e8398d60d..59d66bc47 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "@faker-js/faker": "^7.6.0", "commander": "^9.4.1", "cypress": "9.5.4", + "cypress-file-upload": "^5.0.8", "cypress-multi-reporters": "^1.5.0", "cypress-real-events": "1.7.6", "eslint": "^7.0.0",