Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Upgrade Formik to v2.x to reduce vulnerability (#236)
Browse files Browse the repository at this point in the history
* Upgrade Formik from 1.1.1 to ^2.2.5

* Change all rejected promise of errors caused by throw to resolved promise of errors with return in validation functions for Monitor and Destination

* In ManageEmailGroups.js and ManageSender.js, initialize "initialValues" variable that used for Formik with an empty object

* Fix unit test failure due to the upgrade
  • Loading branch information
ftianli-amzn authored Jan 26, 2021
1 parent 23a14dd commit 2260715
Show file tree
Hide file tree
Showing 17 changed files with 899 additions and 1,236 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"brace": "0.11.1",
"formik": "1.1.1",
"formik": "^2.2.5",
"lodash": "^4.17.20",
"query-string": "^6.13.2",
"react-router-dom": "^5.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('WhereExpression', () => {
button.simulate('keyDown', { keyCode: 27 });
expect(closeExpression).toHaveBeenCalled();
});
test('should render text input for the text data types', () => {
test('should render text input for the text data types', async () => {
const wrapper = mount(getMountWrapper(true));
wrapper
.find('[data-test-subj="comboBoxSearchInput"]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import AnomalyDetectors from '../AnomalyDetectors';
import { httpClientMock } from '../../../../../../test/mocks';
import { CoreContext } from '../../../../../utils/CoreContext';

// Used to wait until all of the promises have cleared, especially waiting for asynchronous Formik's handlers.
const runAllPromises = () => new Promise(setImmediate);

const renderEmptyMessage = jest.fn();
function getMountWrapper() {
return mount(
Expand All @@ -46,7 +49,7 @@ describe('AnomalyDetectors', () => {
expect(wrapper).toMatchSnapshot();
});

test('should be able to select the detector', (done) => {
test('should be able to select the detector', async () => {
httpClientMock.post.mockResolvedValueOnce({
ok: true,
detectors: [{ name: 'sample-detector', id: 'sample-id', feature_attributes: [] }],
Expand All @@ -57,15 +60,23 @@ describe('AnomalyDetectors', () => {
response: { anomalyResult: { anomalies: [], featureData: [] }, detector: {} },
});
const wrapper = getMountWrapper();
setTimeout(() => {
wrapper
.find('[data-test-subj="comboBoxSearchInput"]')
.hostNodes()
.simulate('change', { target: { value: 'sample-detector' } })
.simulate('keyDown', { key: 'ArrowDown' })
.simulate('keyDown', { key: 'Enter' });
expect(wrapper.instance().state.values.detectorId).toEqual('sample-id');
done();
});

wrapper
.find('[data-test-subj="comboBoxSearchInput"]')
.hostNodes()
.simulate('change', { target: { value: 'sample-detect' } });

await runAllPromises();

wrapper
.find('[data-test-subj="comboBoxInput"]')
.hostNodes()
.simulate('keyDown', { key: 'ArrowDown' })
.simulate('keyDown', { key: 'Enter' });

// Validate the specific detector is in the input field
expect(wrapper.find('[data-test-subj="comboBoxInput"]').hostNodes().text()).toEqual(
'sample-detector'
);
});
});
Loading

0 comments on commit 2260715

Please sign in to comment.