Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .worktrees/backport-2.x
Submodule backport-2.x added at 23743f

Large diffs are not rendered by default.

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 @@ -9,6 +9,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
77 changes: 77 additions & 0 deletions cypress/utils/dashboards/saved_objects_management/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

Cypress.Commands.add('selectDataSourceForImport', (dataSourceTitle) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we reuse existing util to select data source from data source selector?

'selectFromDataSourceSelector',

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I tried this one, but I found the selector on import page does not have the input, while the dev tools has this functionality, if reusing, it can break

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, let's use your util for import then. Great finding, let me file an issue on OSD to make "isClearable" prop consistent across all places that consumes this selector in OSD

cy.getElementByTestId('dataSourceSelectorComboBox').click();
cy.get('.euiFilterSelectItem')
.contains(dataSourceTitle) // Find the element containing dataSourceTitle
.click();
});

Cypress.Commands.add('deleteAllSavedObjects', () => {
const types = [
'index-pattern',
'visualization',
'dashboard',
'search',
'query',
'url',
'augment-vis',
'homepage',
'data-source',
'visualization-visbuilder',
'config',
];
types.forEach((type) => {
cy.deleteSavedObjectByType(type);
});
});

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++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I assume 29 is the number of conflicting saved objects. Could this be extracted into a variable like numConflictingSavedObjects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the length of the test file length, good suggestion if we consider always using this as the test file

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
Loading