-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workspace]Fix error toasts in sample data page (#8842)
* Set default index pattern when workspace disabled Signed-off-by: Lin Wang <[email protected]> * Move saved objects first to avoid partial deleted Signed-off-by: Lin Wang <[email protected]> * Skip ui setting update for non workspace admin Signed-off-by: Lin Wang <[email protected]> * Add UT for sample_data_client Signed-off-by: Lin Wang <[email protected]> * Changeset file for PR #8842 created/updated --------- Signed-off-by: Lin Wang <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3f65938
commit af429b6
Showing
6 changed files
with
215 additions
and
23 deletions.
There are no files selected for viewing
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,2 @@ | ||
fix: | ||
- [Workspace]Fix error toasts in sample data page ([#8842](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8842)) |
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
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
167 changes: 167 additions & 0 deletions
167
src/plugins/home/public/application/sample_data_client.test.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,167 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { BehaviorSubject } from 'rxjs'; | ||
import { setServices } from '../application/opensearch_dashboards_services'; | ||
import { installSampleDataSet, uninstallSampleDataSet } from './sample_data_client'; | ||
|
||
const mockHttp = { | ||
post: jest.fn(), | ||
delete: jest.fn(), | ||
}; | ||
|
||
const mockUiSettings = { | ||
isDefault: jest.fn(), | ||
set: jest.fn(), | ||
get: jest.fn(), | ||
}; | ||
|
||
const mockApplication = { | ||
capabilities: { | ||
workspaces: { | ||
enabled: false, | ||
permissionEnabled: false, | ||
}, | ||
}, | ||
}; | ||
|
||
const mockIndexPatternService = { | ||
clearCache: jest.fn(), | ||
}; | ||
|
||
const mockWorkspace = { | ||
currentWorkspace$: new BehaviorSubject(), | ||
}; | ||
|
||
const mockServices = { | ||
workspaces: mockWorkspace, | ||
http: mockHttp, | ||
uiSettings: mockUiSettings, | ||
application: mockApplication, | ||
indexPatternService: mockIndexPatternService, | ||
}; | ||
|
||
setServices(mockServices); | ||
|
||
describe('installSampleDataSet', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockUiSettings.isDefault.mockReturnValue(true); | ||
setServices(mockServices); | ||
}); | ||
|
||
it('should install the sample data set and set the default index', async () => { | ||
const id = 'sample-data-id'; | ||
const sampleDataDefaultIndex = 'sample-data-index'; | ||
const dataSourceId = 'data-source-id'; | ||
|
||
await installSampleDataSet(id, sampleDataDefaultIndex, dataSourceId); | ||
|
||
expect(mockHttp.post).toHaveBeenCalledWith(`/api/sample_data/${id}`, { | ||
query: expect.anything(), | ||
}); | ||
expect(mockUiSettings.set).toHaveBeenCalledWith('defaultIndex', sampleDataDefaultIndex); | ||
expect(mockIndexPatternService.clearCache).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should install the sample data set and not set the default index when workspace is enabled', async () => { | ||
const id = 'sample-data-id'; | ||
const sampleDataDefaultIndex = 'sample-data-index'; | ||
const dataSourceId = 'data-source-id'; | ||
|
||
setServices({ | ||
...mockServices, | ||
workspaces: { | ||
currentWorkspace$: new BehaviorSubject(), | ||
}, | ||
application: { | ||
capabilities: { | ||
workspaces: { | ||
enabled: true, | ||
permissionEnabled: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await installSampleDataSet(id, sampleDataDefaultIndex, dataSourceId); | ||
|
||
expect(mockHttp.post).toHaveBeenCalledWith(`/api/sample_data/${id}`, { | ||
query: expect.anything(), | ||
}); | ||
expect(mockUiSettings.set).not.toHaveBeenCalled(); | ||
expect(mockIndexPatternService.clearCache).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('uninstallSampleDataSet', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockUiSettings.isDefault.mockReturnValue(false); | ||
setServices(mockServices); | ||
}); | ||
|
||
it('should uninstall the sample data set and clear the default index', async () => { | ||
const id = 'sample-data-id'; | ||
const sampleDataDefaultIndex = 'sample-data-index'; | ||
const dataSourceId = 'data-source-id'; | ||
|
||
mockUiSettings.get.mockReturnValue(sampleDataDefaultIndex); | ||
|
||
await uninstallSampleDataSet(id, sampleDataDefaultIndex, dataSourceId); | ||
|
||
expect(mockHttp.delete).toHaveBeenCalledWith(`/api/sample_data/${id}`, { | ||
query: expect.anything(), | ||
}); | ||
expect(mockUiSettings.set).toHaveBeenCalledWith('defaultIndex', null); | ||
expect(mockIndexPatternService.clearCache).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should uninstall the sample data set and not clear the default index when workspace is enabled', async () => { | ||
const id = 'sample-data-id'; | ||
const sampleDataDefaultIndex = 'sample-data-index'; | ||
const dataSourceId = 'data-source-id'; | ||
|
||
setServices({ | ||
...mockServices, | ||
workspaces: { | ||
currentWorkspace$: new BehaviorSubject(), | ||
}, | ||
application: { | ||
capabilities: { | ||
workspaces: { | ||
enabled: true, | ||
permissionEnabled: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await uninstallSampleDataSet(id, sampleDataDefaultIndex, dataSourceId); | ||
|
||
expect(mockHttp.delete).toHaveBeenCalledWith(`/api/sample_data/${id}`, { | ||
query: expect.anything(), | ||
}); | ||
expect(mockUiSettings.set).not.toHaveBeenCalled(); | ||
expect(mockIndexPatternService.clearCache).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should uninstall the sample data set and not clear the default index when it is not the sample data index', async () => { | ||
const id = 'sample-data-id'; | ||
const sampleDataDefaultIndex = 'sample-data-index'; | ||
const dataSourceId = 'data-source-id'; | ||
|
||
mockUiSettings.isDefault.mockReturnValue(false); | ||
mockUiSettings.get.mockReturnValue('other-index'); | ||
|
||
await uninstallSampleDataSet(id, sampleDataDefaultIndex, dataSourceId); | ||
|
||
expect(mockHttp.delete).toHaveBeenCalledWith(`/api/sample_data/${id}`, { | ||
query: expect.anything(), | ||
}); | ||
expect(mockUiSettings.set).not.toHaveBeenCalled(); | ||
expect(mockIndexPatternService.clearCache).toHaveBeenCalled(); | ||
}); | ||
}); |
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
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