-
Notifications
You must be signed in to change notification settings - Fork 848
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VizBuilder] Create a new wizard directly on a dashboard (#2384)
* Create a new wizard directly on a dashboard After selecting a dashboard, create a new wizard directly from the dashboard and have the option to add to that dashboard. Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com> * hook change to solve browser warning Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com> * Move onsave out from getTopNavConfig function and added unit tests Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com> * Add changelog Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com> Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
- Loading branch information
1 parent
551ffa3
commit b75e07d
Showing
7 changed files
with
350 additions
and
93 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
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
157 changes: 157 additions & 0 deletions
157
src/plugins/wizard/public/application/utils/get_top_nav_config.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,157 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { WizardServices } from '../../types'; | ||
import { getOnSave } from './get_top_nav_config'; | ||
import { createWizardServicesMock } from './mocks'; | ||
|
||
describe('getOnSave', () => { | ||
let savedWizardVis: any; | ||
let originatingApp: string | undefined; | ||
let visualizationIdFromUrl: string; | ||
let dispatch: any; | ||
let mockServices: jest.Mocked<WizardServices>; | ||
let onSaveProps: { | ||
newTitle: string; | ||
newCopyOnSave: boolean; | ||
isTitleDuplicateConfirmed: boolean; | ||
onTitleDuplicate: any; | ||
newDescription: string; | ||
returnToOrigin: boolean; | ||
}; | ||
|
||
beforeEach(() => { | ||
savedWizardVis = { | ||
id: '1', | ||
title: 'save wizard wiz title', | ||
description: '', | ||
visualizationState: '', | ||
styleState: '', | ||
version: 0, | ||
copyOnSave: true, | ||
searchSourceFields: {}, | ||
save: jest.fn().mockReturnValue('1'), | ||
}; | ||
originatingApp = ''; | ||
visualizationIdFromUrl = ''; | ||
dispatch = jest.fn(); | ||
mockServices = createWizardServicesMock(); | ||
|
||
onSaveProps = { | ||
newTitle: 'new title', | ||
newCopyOnSave: false, | ||
isTitleDuplicateConfirmed: false, | ||
onTitleDuplicate: jest.fn(), | ||
newDescription: 'new description', | ||
returnToOrigin: true, | ||
}; | ||
}); | ||
|
||
test('return undefined when savedWizardVis is null', async () => { | ||
savedWizardVis = null; | ||
const onSave = getOnSave( | ||
savedWizardVis, | ||
originatingApp, | ||
visualizationIdFromUrl, | ||
dispatch, | ||
mockServices | ||
); | ||
const onSaveResult = await onSave(onSaveProps); | ||
|
||
expect(onSaveResult).toBeUndefined(); | ||
}); | ||
|
||
test('savedWizardVis get saved correctly', async () => { | ||
const onSave = getOnSave( | ||
savedWizardVis, | ||
originatingApp, | ||
visualizationIdFromUrl, | ||
dispatch, | ||
mockServices | ||
); | ||
const onSaveReturn = await onSave(onSaveProps); | ||
expect(savedWizardVis).toMatchInlineSnapshot(` | ||
Object { | ||
"copyOnSave": false, | ||
"description": "new description", | ||
"id": "1", | ||
"save": [MockFunction] { | ||
"calls": Array [ | ||
Array [ | ||
Object { | ||
"confirmOverwrite": false, | ||
"isTitleDuplicateConfirmed": false, | ||
"onTitleDuplicate": [MockFunction], | ||
"returnToOrigin": true, | ||
}, | ||
], | ||
], | ||
"results": Array [ | ||
Object { | ||
"type": "return", | ||
"value": "1", | ||
}, | ||
], | ||
}, | ||
"searchSourceFields": Object {}, | ||
"styleState": "", | ||
"title": "new title", | ||
"version": 0, | ||
"visualizationState": "", | ||
} | ||
`); | ||
expect(onSaveReturn?.id).toBe('1'); | ||
}); | ||
|
||
test('savedWizardVis does not change title with a null id', async () => { | ||
savedWizardVis.save = jest.fn().mockReturnValue(null); | ||
const onSave = getOnSave( | ||
savedWizardVis, | ||
originatingApp, | ||
visualizationIdFromUrl, | ||
dispatch, | ||
mockServices | ||
); | ||
const onSaveResult = await onSave(onSaveProps); | ||
expect(savedWizardVis.title).toBe('save wizard wiz title'); | ||
expect(onSaveResult?.id).toBeNull(); | ||
}); | ||
|
||
test('create a new wizard from dashboard', async () => { | ||
savedWizardVis.id = undefined; | ||
savedWizardVis.save = jest.fn().mockReturnValue('2'); | ||
originatingApp = 'dashboard'; | ||
onSaveProps.returnToOrigin = true; | ||
|
||
const onSave = getOnSave( | ||
savedWizardVis, | ||
originatingApp, | ||
visualizationIdFromUrl, | ||
dispatch, | ||
mockServices | ||
); | ||
const onSaveResult = await onSave(onSaveProps); | ||
expect(onSaveResult?.id).toBe('2'); | ||
expect(dispatch).toBeCalledTimes(0); | ||
}); | ||
|
||
test('edit an exising wizard from dashboard', async () => { | ||
savedWizardVis.copyOnSave = false; | ||
onSaveProps.newDescription = 'new description after editing'; | ||
originatingApp = 'dashboard'; | ||
onSaveProps.returnToOrigin = true; | ||
const onSave = getOnSave( | ||
savedWizardVis, | ||
originatingApp, | ||
visualizationIdFromUrl, | ||
dispatch, | ||
mockServices | ||
); | ||
const onSaveResult = await onSave(onSaveProps); | ||
expect(onSaveResult?.id).toBe('1'); | ||
expect(mockServices.application.navigateToApp).toBeCalledTimes(1); | ||
expect(savedWizardVis.description).toBe('new description after editing'); | ||
}); | ||
}); |
Oops, something went wrong.