forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: yubonluo <yubonluo@amazon.com>
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/plugins/saved_objects_management/public/lib/duplicate_saved_objects.test.ts
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,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { httpServiceMock } from '../../../../core/public/mocks'; | ||
import { duplicateSavedObjects } from './duplicate_saved_objects'; | ||
|
||
describe('copy saved objects', () => { | ||
it('make http call with body provided', async () => { | ||
const httpClient = httpServiceMock.createStartContract(); | ||
const objects = [ | ||
{ type: 'dashboard', id: '1' }, | ||
{ type: 'visualization', id: '2' }, | ||
]; | ||
const includeReferencesDeep = true; | ||
const targetWorkspace = '1'; | ||
await duplicateSavedObjects(httpClient, objects, includeReferencesDeep, targetWorkspace); | ||
expect(httpClient.post).toMatchInlineSnapshot( | ||
'', | ||
` | ||
[MockFunction] { | ||
"calls": Array [ | ||
Array [ | ||
"/api/saved_objects/_copy", | ||
Object { | ||
"body": "{\\"objects\\":[{\\"type\\":\\"dashboard\\",\\"id\\":\\"1\\"},{\\"type\\":\\"visualization\\",\\"id\\":\\"2\\"}],\\"includeReferencesDeep\\":true,\\"targetWorkspace\\":\\"1\\"}", | ||
}, | ||
], | ||
], | ||
"results": Array [ | ||
Object { | ||
"type": "return", | ||
"value": undefined, | ||
}, | ||
], | ||
} | ||
` | ||
); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
...aved_objects_management/public/management_section/objects_table/components/utils.test.tsx
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,66 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { WorkspaceAttribute, WorkspaceObject, WorkspacesStart } from 'opensearch-dashboards/public'; | ||
import { | ||
WorkspaceOption, | ||
capitalizeFirstLetter, | ||
getTargetWorkspacesOptions, | ||
workspaceToOption, | ||
} from './utils'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
describe('duplicate mode utils', () => { | ||
it('should covert workspace to option', () => { | ||
const workspace: WorkspaceAttribute = { | ||
id: '1', | ||
name: 'Workspace 1', | ||
}; | ||
const workspaceOption: WorkspaceOption = workspaceToOption(workspace); | ||
expect(workspaceOption.label).toBe(workspace.name); | ||
expect(workspaceOption.key).toBe(workspace.id); | ||
expect(workspaceOption.value).toBe(workspace); | ||
}); | ||
|
||
it('should add suffix when workspace is current workspace', () => { | ||
const workspace: WorkspaceAttribute = { | ||
id: '1', | ||
name: 'Workspace 1', | ||
}; | ||
const workspaceOption: WorkspaceOption = workspaceToOption(workspace, '1'); | ||
expect(workspaceOption.label).toBe('Workspace 1 (current)'); | ||
expect(workspaceOption.key).toBe(workspace.id); | ||
expect(workspaceOption.value).toBe(workspace); | ||
}); | ||
|
||
it('should get target workspace options', () => { | ||
const workspaces: WorkspacesStart = { | ||
currentWorkspaceId$: new BehaviorSubject<string>('1'), | ||
currentWorkspace$: new BehaviorSubject<WorkspaceObject | null>({ | ||
id: '1', | ||
name: 'Workspace 1', | ||
}), | ||
workspaceList$: new BehaviorSubject<WorkspaceObject[]>([ | ||
{ id: '1', name: 'Workspace 1' }, | ||
{ id: '2', name: 'Workspace 2', libraryReadonly: false }, | ||
{ id: '3', name: 'Workspace 3', libraryReadonly: true }, | ||
]), | ||
initialized$: new BehaviorSubject<boolean>(true), | ||
}; | ||
const optionContainCurrent: WorkspaceOption[] = getTargetWorkspacesOptions(workspaces, '1'); | ||
expect(optionContainCurrent.length).toBe(1); | ||
expect(optionContainCurrent[0].key).toBe('2'); | ||
expect(optionContainCurrent[0].label).toBe('Workspace 2'); | ||
|
||
const workspaceOption: WorkspaceOption[] = getTargetWorkspacesOptions(workspaces); | ||
expect(workspaceOption.length).toBe(2); | ||
}); | ||
|
||
it('should capitalize first letter', () => { | ||
const workspaceName: string = 'workspace'; | ||
const capitalizedName: string = capitalizeFirstLetter(workspaceName); | ||
expect(capitalizedName).toBe('Workspace'); | ||
}); | ||
}); |
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