-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[workspace] Add integration test cases for workspace assets. #1639
Merged
SuZhou-Joe
merged 5 commits into
opensearch-project:main
from
SuZhou-Joe:feature/workspace_assets_ft
Nov 17, 2024
+184
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f28f744
feat: add functional test for workspace assets
SuZhou-Joe 1344fde
feat: make it compatible with mds case
SuZhou-Joe 91810cd
feat: optimize based on comments
SuZhou-Joe 1eeef2b
feat: update
SuZhou-Joe c29c2f6
feat: remove data sources after test
SuZhou-Joe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
184 changes: 184 additions & 0 deletions
184
...opensearch-dashboards/opensearch-dashboards/workspace-plugin/mds_workspace_assets.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { BASE_PATH } from '../../../../utils/base_constants'; | ||
|
||
let sourceWorkspaceName = 'test_source_workspace'; | ||
let targetWorkspaceName = 'test_target_workspace'; | ||
|
||
let sourceWorkspaceId = ''; | ||
let targetWorkspaceId = ''; | ||
let datasourceId = ''; | ||
|
||
const setupWorkspace = (workspaceName, datasourceId) => { | ||
return cy | ||
.createWorkspace({ | ||
name: workspaceName, | ||
settings: { | ||
...(datasourceId ? { dataSources: [datasourceId] } : {}), | ||
}, | ||
}) | ||
.then((value) => { | ||
// load sample data | ||
cy.loadSampleDataForWorkspace('ecommerce', value, datasourceId); | ||
cy.wrap(value); | ||
}); | ||
}; | ||
|
||
if (Cypress.env('WORKSPACE_ENABLED')) { | ||
describe('Workspace assets', () => { | ||
before(() => { | ||
cy.deleteWorkspaceByName(sourceWorkspaceName); | ||
cy.deleteWorkspaceByName(targetWorkspaceName); | ||
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { | ||
cy.createDataSourceNoAuth().then((result) => { | ||
datasourceId = result[0]; | ||
expect(datasourceId).to.be.a('string').that.is.not.empty; | ||
setupWorkspace(sourceWorkspaceName, datasourceId).then( | ||
(value) => (sourceWorkspaceId = value) | ||
); | ||
setupWorkspace(targetWorkspaceName, datasourceId).then( | ||
(value) => (targetWorkspaceId = value) | ||
); | ||
}); | ||
} else { | ||
setupWorkspace(sourceWorkspaceName).then( | ||
(value) => (sourceWorkspaceId = value) | ||
); | ||
setupWorkspace(targetWorkspaceName).then( | ||
(value) => (targetWorkspaceId = value) | ||
); | ||
} | ||
}); | ||
|
||
after(() => { | ||
SuZhou-Joe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Uninstallation will delete the data index | ||
// and workspace deletion will remove all the saved objects within the workspace, | ||
// so calling `removeSampleDataForWorkspace` once is good enough. | ||
cy.removeSampleDataForWorkspace( | ||
'ecommerce', | ||
sourceWorkspaceId, | ||
datasourceId | ||
); | ||
cy.deleteWorkspaceByName(sourceWorkspaceName); | ||
cy.deleteWorkspaceByName(targetWorkspaceName); | ||
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) { | ||
cy.deleteDataSource(datasourceId); | ||
} | ||
sourceWorkspaceId = ''; | ||
targetWorkspaceId = ''; | ||
}); | ||
|
||
it('Should not list assets from other workspace and generate correct url for inspect url inside a workspace', () => { | ||
cy.visit(`${BASE_PATH}/w/${sourceWorkspaceId}/app/objects`); | ||
cy.getElementByTestId('savedObjectsTableRowTitle').should('exist'); | ||
cy.getElementByTestId('savedObjectsTableColumn-workspace_column').should( | ||
'not.exist' | ||
); | ||
cy.contains('opensearch_dashboards_sample_data_ecommerce'); | ||
// Electron old version may not support search event, so we manually trigger a search event | ||
cy.getElementByTestId('savedObjectSearchBar') | ||
.type('opensearch_dashboards_sample_data_ecommerce{enter}') | ||
.trigger('search'); | ||
cy.getElementByTestId('savedObjectsTableRowTitle').should( | ||
'have.length', | ||
1 | ||
); | ||
|
||
// Click more -> inspect | ||
cy.getElementByTestId('euiCollapsedItemActionsButton') | ||
.click() | ||
.getElementByTestId('savedObjectsTableAction-inspect') | ||
.click(); | ||
cy.location('pathname').should( | ||
'include', | ||
`/w/${sourceWorkspaceId}/app/indexPatterns` | ||
); | ||
}); | ||
|
||
it('Should list assets from workspaces with permission and generate correct url for inspect url outside workspace', () => { | ||
cy.visit(`${BASE_PATH}/app/objects`); | ||
cy.getElementByTestId('savedObjectsTableColumn-workspace_column').should( | ||
'exist' | ||
); | ||
// Electron old version may not support search event, so we manually trigger a search event | ||
cy.getElementByTestId('savedObjectSearchBar') | ||
.type('opensearch_dashboards_sample_data_ecommerce{enter}') | ||
.trigger('search'); | ||
cy.getElementByTestId('savedObjectsTableRowTitle').should( | ||
'have.length', | ||
2 | ||
); | ||
|
||
// Find the row belong to the target workspace | ||
cy.contains(targetWorkspaceName) | ||
.parents('.euiTableRow') | ||
// Click more -> inspect | ||
.find('[data-test-subj="euiCollapsedItemActionsButton"]') | ||
.click() | ||
.getElementByTestId('savedObjectsTableAction-inspect') | ||
.click(); | ||
cy.location('pathname').should( | ||
'include', | ||
`/w/${targetWorkspaceId}/app/indexPatterns` | ||
); | ||
}); | ||
|
||
// TODO: this test case should be removed once index pattern access outside of workspace being blocked in the future. | ||
it('Should not show set as default button when outside workspace', () => { | ||
cy.request({ | ||
url: `${BASE_PATH}/api/opensearch-dashboards/management/saved_objects/_find?workspaces=${targetWorkspaceId}&page=1&type=index-pattern`, | ||
headers: { | ||
'Osd-Xsrf': 'osd-fetch', | ||
}, | ||
}) | ||
.then((resp) => { | ||
cy.wrap(resp.body.saved_objects).should('have.length', 1); | ||
cy.wrap(resp.body.saved_objects[0].id); | ||
}) | ||
.then((indexPatternId) => { | ||
cy.visit(`${BASE_PATH}/app/indexPatterns/patterns/${indexPatternId}`); | ||
SuZhou-Joe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cy.contains('opensearch_dashboards_sample_data_ecommerce'); | ||
cy.getElementByTestId('setDefaultIndexPatternButton').should( | ||
'not.exist' | ||
); | ||
}); | ||
}); | ||
|
||
it('Short url should be able to be generated multiple times and preserve workspace info', () => { | ||
cy.visit(`${BASE_PATH}/w/${sourceWorkspaceId}/app/visualize`); | ||
cy.contains(/\[eCommerce\] Markdown/).click(); | ||
cy.getElementByTestId('shareTopNavButton') | ||
.click() | ||
.getElementByTestId('sharePanel-Permalinks') | ||
.click() | ||
.getElementByTestId('useShortUrl') | ||
.as('generateShortUrlButton') | ||
.click(); | ||
|
||
// Should generate successfully | ||
cy.getElementByTestId('copyShareUrlButton') | ||
.invoke('attr', 'data-share-url') | ||
.should('include', `${BASE_PATH}/goto`); | ||
|
||
// Regeneration should work without error | ||
cy.get('@generateShortUrlButton').click(); | ||
cy.getElementByTestId('copyShareUrlButton') | ||
.invoke('attr', 'data-share-url') | ||
.should('include', `${BASE_PATH}/w/${sourceWorkspaceId}`); | ||
cy.get('@generateShortUrlButton').click(); | ||
cy.getElementByTestId('copyShareUrlButton') | ||
.invoke('attr', 'data-share-url') | ||
.then((shortUrl) => { | ||
cy.wrap(shortUrl).should('include', `${BASE_PATH}/goto`); | ||
cy.visit(`${BASE_PATH}/w/${sourceWorkspaceId}/app/objects`); | ||
cy.contains('Workspace assets'); | ||
cy.visit(shortUrl); | ||
cy.location('pathname').should('include', `/w/${sourceWorkspaceId}`); | ||
cy.contains(/\[eCommerce\] Markdown/); | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used to verify the data source creation successfully?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, from API side.