Skip to content

Commit

Permalink
Add import saved object mds test
Browse files Browse the repository at this point in the history
Signed-off-by: yujin-emma <[email protected]>
  • Loading branch information
yujin-emma committed Jun 3, 2024
1 parent 4ddffc9 commit bb0d184
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 4,603 deletions.
17 changes: 5 additions & 12 deletions cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"viewportHeight": 1320,
"env": {
"openSearchUrl": "http://localhost:9200",
"remoteDataSourceNoAuthUrl": "https://search-md-bug-bash-no-auth-7lvre4fioe3ikmdznjmhjrmsga.us-west-2.es.amazonaws.com",
"remoteDataSourceBasicAuthUrl": "https://search-sddd-nj2nc32tf7wspntbyvzjn5emwu.us-east-1.es.amazonaws.com",
"remoteDataSourceBasicAuthUsername": "Admin",
"remoteDataSourceBasicAuthPassword": "Admin_123",
"remoteDataSourceNoAuthUrl": "http://localhost:9201",
"remoteDataSourceBasicAuthUrl": "https://localhost:9202",
"remoteDataSourceBasicAuthUsername": "admin",
"remoteDataSourceBasicAuthPassword": "admin",
"SECURITY_ENABLED": false,
"AGGREGATION_VIEW": false,
"MULTITENANCY_ENABLED": true,
Expand All @@ -29,16 +29,9 @@
"DASHBOARDS_ASSISTANT_ENABLED": false,
"WORKSPACE_ENABLED": false,
"SAVED_OBJECTS_PERMISSION_ENABLED": false,
"DISABLE_LOCAL_CLUSTER": false,
"browserPermissions": {
"clipboard": "allow"
}
}
}








This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { CURRENT_TENANT } from '../../../utils/commands';
import 'cypress-file-upload';

const miscUtils = new MiscUtils(cy);

if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
let dataSourceTitle;

describe('import saved object test', () => {
before(() => {
// Go to the saved object page
cy.deleteAllDataSources();
cy.wait(1000);

cy.deleteAllSavedObjects();
miscUtils.visitPage('app/management/opensearch-dashboards/objects');

CURRENT_TENANT.newTenant = 'global';
cy.wait(1000);

// create data source
cy.createDataSourceNoAuth().then((result) => {
dataSourceTitle = result[1];
});
cy.reload(true);
cy.wait(1000);
});

after(() => {
cy.deleteAllSavedObjects();
});

it('can import saved objects from ndjson file and create new copies', () => {
cy.uploadSavedObjectsToDataSource(
'createNewCopiesEnabled',
'',
dataSourceTitle
);
});
it('can import saved objects from ndjson file and automatically override conflict', () => {
cy.uploadSavedObjectsToDataSource(
'createNewCopiesDisabled',
'overwriteEnabled',
dataSourceTitle
);
});

it('can import saved objects from ndjson file and request action when conflict exit', () => {
cy.uploadSavedObjectsToDataSource(
'createNewCopiesDisabled',
'overwriteDisabled',
dataSourceTitle
);
});
});
}
1 change: 1 addition & 0 deletions cypress/utils/dashboards/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import './vis_type_table/commands';
import './vis_type_vega/commands';
import './vis-augmenter/commands';
import './data_explorer/commands';
import './saved_objects_management/commands';

Cypress.Commands.add('waitForLoader', () => {
const opts = { log: false };
Expand Down
73 changes: 73 additions & 0 deletions cypress/utils/dashboards/saved_objects_management/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

Cypress.Commands.add('selectDataSourceForImport', (dataSourceTitle) => {
cy.getElementByTestId('dataSourceSelectorComboBox').click();
cy.get('.euiFilterSelectItem')
.contains(dataSourceTitle) // Find the element containing dataSourceTitle
.click();
});

Cypress.Commands.add('deleteAllSavedObjects', () => {
cy.wait(1000);
cy.deleteSavedObjectByType('dashboard');
cy.wait(1000);
cy.deleteSavedObjectByType('index-pattern');
cy.wait(1000);
cy.deleteSavedObjectByType('search');
cy.wait(1000);
cy.deleteSavedObjectByType('visualization');
cy.wait(1000);
cy.deleteSavedObjectByType('metrics');
cy.wait(1000);
cy.deleteSavedObjectByType('vega');
});

Cypress.Commands.add(
'uploadSavedObjectsToDataSource',
(importMode, override, dataSourceTitle) => {
cy.contains('button', 'Import').click();
cy.wait(1000);
cy.fixture(
'dashboard/opensearch_dashboards/saved_objects_management/mds_log_objects.ndjson'
).then((fileContent) => {
cy.get('input[type="file"]').attachFile({
fileContent: fileContent,
fileName: 'mds_log_objects.ndjson',
mimeType: 'text/plain', // use 'application/json' to treat the ndsjon as json, keep 'text/plain' to use ndjson
});
});
cy.wait(1000);
cy.selectDataSourceForImport(dataSourceTitle); // choose the data source that is created at the beginning of the test
cy.handleImportMode(importMode);
if (override !== '') {
cy.handleImportMode(override);
}
cy.wait(1000);
cy.getElementByTestId('importSavedObjectsImportBtn').click({
force: true,
});
cy.getElementByTestId('importSavedObjectsConfirmBtn').click({
force: true,
});
cy.wait(1000);
if (importMode === 'createNewCopiesEnabled') {
cy.contains('new').should('be.visible');
} else {
if (override !== 'overwriteEnabled') {
for (let i = 0; i < 29; i++) {
cy.getElementByTestId('confirmModalConfirmButton').click();
}
cy.getElementByTestId('confirmModalCancelButton').click();
}
cy.contains('error').should('not.exist');
}
cy.getElementByTestId('importSavedObjectsDoneBtn').click({ force: true });
}
);

Cypress.Commands.add('handleImportMode', (importMode) => {
cy.get(`#${importMode}`).check({ force: true });
});
Loading

0 comments on commit bb0d184

Please sign in to comment.