-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
159 additions
and
35 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 |
---|---|---|
|
@@ -13,4 +13,4 @@ export const setup = (props: any) => | |
wrapComponent: false, | ||
}, | ||
defaultProps: props, | ||
}); | ||
})(); |
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
77 changes: 77 additions & 0 deletions
77
...c/app/components/mappings_editor/components/load_mappings/load_mappings_provider.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,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
jest.mock('@elastic/eui', () => ({ | ||
...jest.requireActual('@elastic/eui'), | ||
// Mocking EuiCodeEditor, which uses React Ace under the hood | ||
EuiCodeEditor: (props: any) => ( | ||
<input | ||
data-test-subj="mockCodeEditor" | ||
onChange={(syntheticEvent: any) => { | ||
props.onChange(syntheticEvent.jsonString); | ||
}} | ||
/> | ||
), | ||
})); | ||
|
||
import { registerTestBed, nextTick, TestBed } from '../../../../../../../../../test_utils'; | ||
import { LoadMappingsProvider } from './load_mappings_provider'; | ||
|
||
const ComponentToTest = ({ onJson }: { onJson: () => void }) => ( | ||
<LoadMappingsProvider onJson={onJson}> | ||
{openModal => ( | ||
<button onClick={openModal} data-test-subj="load-json-button"> | ||
Load JSON | ||
</button> | ||
)} | ||
</LoadMappingsProvider> | ||
); | ||
|
||
const setup = (props: any) => | ||
registerTestBed(ComponentToTest, { | ||
memoryRouter: { wrapComponent: false }, | ||
defaultProps: props, | ||
})(); | ||
|
||
const openModalWithJsonContent = ({ find, component }: TestBed) => async (json: any) => { | ||
find('load-json-button').simulate('click'); | ||
component.update(); | ||
|
||
// Set the mappings to load | ||
// @ts-ignore | ||
await act(async () => { | ||
find('mockCodeEditor').simulate('change', { | ||
jsonString: JSON.stringify(json), | ||
}); | ||
await nextTick(300); // There is a debounce in the JsonEditor that we need to wait for | ||
}); | ||
}; | ||
|
||
describe('<LoadMappingsProvider />', () => { | ||
test('it should forward valid mapping definition', async () => { | ||
const mappingsToLoad = { | ||
properties: { | ||
title: { | ||
type: 'text', | ||
}, | ||
}, | ||
}; | ||
|
||
const onJson = jest.fn(); | ||
const testBed = await setup({ onJson }); | ||
|
||
// Open the modal and add the JSON | ||
await openModalWithJsonContent(testBed)(mappingsToLoad); | ||
|
||
// Confirm | ||
testBed.find('confirmModalConfirmButton').simulate('click'); | ||
|
||
const [jsonReturned] = onJson.mock.calls[0]; | ||
expect(jsonReturned).toEqual({ ...mappingsToLoad, dynamic_templates: [] }); | ||
}); | ||
}); |
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