-
Notifications
You must be signed in to change notification settings - Fork 868
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
[Multiple Datasource] Handle form values(request payload) if the selected type is available in the authentication registry. #6049
Merged
Flyingliuhub
merged 12 commits into
opensearch-project:main
from
xinruiba:xinrui_Token_Exchange_DataSourceSubmit
Mar 8, 2024
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dfd7d1d
[Token Exchange Unification] Send registered crendentail field for da…
xinruiba 2a3003e
[UT] Add unit test for extractRegisteredAuthTypeCredentials newly def…
xinruiba ef3f1eb
[UT] add more test cases for util.ts
xinruiba 4373151
[UT] Add test cases for datasource creation form and datasource editi…
xinruiba 8d5ccb7
[Token Exchange Unification + UT] Button create-data-source and save-…
xinruiba 769051c
Merge branch 'main' into xinrui_Token_Exchange_DataSourceSubmit
xinruiba 7ba6252
Merge branch 'main' into xinrui_Token_Exchange_DataSourceSubmit
xinruiba 5216e53
Update changelog file
xinruiba 702f592
Merge branch 'main' into xinrui_Token_Exchange_DataSourceSubmit
xinruiba aaca03e
Merge branch 'main' into xinrui_Token_Exchange_DataSourceSubmit
xinruiba 2c03bf5
Merge branch 'main' into xinrui_Token_Exchange_DataSourceSubmit
xinruiba a93ac4b
Addressing comments
xinruiba 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { | |
mockManagementPlugin, | ||
existingDatasourceNamesList, | ||
mockDataSourceAttributesWithNoAuth, | ||
mockDataSourceAttributesWithRegisteredAuth, | ||
} from '../../../../mocks'; | ||
import { OpenSearchDashboardsContextProvider } from '../../../../../../opensearch_dashboards_react/public'; | ||
import { EditDataSourceForm } from './edit_data_source_form'; | ||
|
@@ -344,17 +345,33 @@ describe('Datasource Management: Edit Datasource Form', () => { | |
|
||
describe('With Registered Authentication', () => { | ||
let component: ReactWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>; | ||
const mockCredentialForm = jest.fn(); | ||
const updateInputFieldAndBlur = ( | ||
comp: ReactWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>, | ||
fieldName: string, | ||
updatedValue: string, | ||
isTestSubj?: boolean | ||
) => { | ||
const field = isTestSubj ? comp.find(fieldName) : comp.find({ name: fieldName }); | ||
act(() => { | ||
field.last().simulate('change', { target: { value: updatedValue } }); | ||
}); | ||
comp.update(); | ||
act(() => { | ||
field.last().simulate('focus').simulate('blur'); | ||
}); | ||
comp.update(); | ||
}; | ||
|
||
test('should call registered crendential form', () => { | ||
const mockedCredentialForm = jest.fn(); | ||
const authTypeToBeTested = 'Some Auth Type'; | ||
const authMethodToBeTest = { | ||
name: authTypeToBeTested, | ||
credentialSourceOption: { | ||
value: authTypeToBeTested, | ||
inputDisplay: 'some input', | ||
}, | ||
credentialForm: mockCredentialForm, | ||
credentialForm: mockedCredentialForm, | ||
} as AuthenticationMethod; | ||
|
||
const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); | ||
|
@@ -380,6 +397,69 @@ describe('With Registered Authentication', () => { | |
} | ||
); | ||
|
||
expect(mockCredentialForm).toHaveBeenCalled(); | ||
expect(mockedCredentialForm).toHaveBeenCalled(); | ||
}); | ||
|
||
test('should update the form with registered auth type on click save changes', async () => { | ||
const mockedCredentialForm = jest.fn(); | ||
const mockedSubmitHandler = jest.fn(); | ||
const authMethodToBeTest = { | ||
name: 'Some Auth Type', | ||
credentialSourceOption: { | ||
value: 'Some Auth Type', | ||
inputDisplay: 'some input', | ||
}, | ||
credentialForm: mockedCredentialForm, | ||
crendentialFormField: {}, | ||
} as AuthenticationMethod; | ||
|
||
const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); | ||
mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); | ||
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTest); | ||
|
||
component = mount( | ||
wrapWithIntl( | ||
<EditDataSourceForm | ||
existingDataSource={mockDataSourceAttributesWithRegisteredAuth} | ||
existingDatasourceNamesList={existingDatasourceNamesList} | ||
onDeleteDataSource={jest.fn()} | ||
handleSubmit={mockedSubmitHandler} | ||
handleTestConnection={jest.fn()} | ||
displayToastMessage={jest.fn()} | ||
/> | ||
), | ||
{ | ||
wrappingComponent: OpenSearchDashboardsContextProvider, | ||
wrappingComponentProps: { | ||
services: mockedContext, | ||
}, | ||
} | ||
); | ||
|
||
await new Promise((resolve) => | ||
setTimeout(() => { | ||
updateInputFieldAndBlur(component, descriptionFieldIdentifier, ''); | ||
expect( | ||
// @ts-ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need //@ts-ignore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, will remove it. |
||
component.find(descriptionFormRowIdentifier).first().props().isInvalid | ||
).toBeUndefined(); | ||
xinruiba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
resolve(); | ||
}, 100) | ||
); | ||
await new Promise((resolve) => | ||
setTimeout(() => { | ||
/* Updated description*/ | ||
updateInputFieldAndBlur(component, descriptionFieldIdentifier, 'testDescription'); | ||
expect( | ||
// @ts-ignore | ||
component.find(descriptionFormRowIdentifier).first().props().isInvalid | ||
).toBeUndefined(); | ||
xinruiba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
expect(component.find('[data-test-subj="datasource-edit-saveButton"]').exists()).toBe(true); | ||
component.find('[data-test-subj="datasource-edit-saveButton"]').first().simulate('click'); | ||
expect(mockedSubmitHandler).toHaveBeenCalled(); | ||
resolve(); | ||
}, 100) | ||
); | ||
}); | ||
}); |
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
Oops, something went wrong.
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.
I would say something simpler, e.g. "Handle form values(request payload) if the selected type is available in the authentication registry." or something like that. Same for PR title.
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.
Thanks for the comment~
Will using the suggested title.