-
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.
Merge remote-tracking branch 'upstream/main' into apm-rule-types-package
- Loading branch information
Showing
2,195 changed files
with
8,167 additions
and
6,076 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
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
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
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
80 changes: 80 additions & 0 deletions
80
...m/plugins/shared/cases/public/components/connectors/servicenow/json_editor_field.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,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React, { type ComponentProps } from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { JsonEditorField } from './json_editor_field'; | ||
import { MockedCodeEditor } from '@kbn/code-editor-mock'; | ||
import type { FieldHook } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; | ||
import type { MockedMonacoEditor } from '@kbn/code-editor-mock/monaco_mock'; | ||
|
||
jest.mock('@kbn/code-editor', () => { | ||
const original = jest.requireActual('@kbn/code-editor'); | ||
return { | ||
...original, | ||
CodeEditor: (props: ComponentProps<typeof MockedMonacoEditor>) => ( | ||
<MockedCodeEditor {...props} /> | ||
), | ||
}; | ||
}); | ||
|
||
const setXJson = jest.fn(); | ||
const XJson = { | ||
useXJsonMode: (value: unknown) => ({ | ||
convertToJson: (toJson: unknown) => toJson, | ||
setXJson, | ||
xJson: value, | ||
}), | ||
}; | ||
|
||
jest.mock('@kbn/es-ui-shared-plugin/public', () => { | ||
const original = jest.requireActual('@kbn/es-ui-shared-plugin/public'); | ||
return { | ||
...original, | ||
XJson, | ||
}; | ||
}); | ||
|
||
describe('JsonEditorField', () => { | ||
const setValue = jest.fn(); | ||
const props = { | ||
field: { | ||
label: 'my label', | ||
helpText: 'help', | ||
value: 'foobar', | ||
setValue, | ||
errors: [], | ||
} as unknown as FieldHook<unknown, string>, | ||
paramsProperty: 'myField', | ||
label: 'label', | ||
dataTestSubj: 'foobarTestSubj', | ||
}; | ||
|
||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
it('renders as expected', async () => { | ||
render(<JsonEditorField {...props} />); | ||
|
||
expect(await screen.findByTestId('foobarTestSubj')).toBeInTheDocument(); | ||
expect(await screen.findByTestId('myFieldJsonEditor')).toBeInTheDocument(); | ||
expect(await screen.findByText('my label')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls setValue and xJson on editor change', async () => { | ||
render(<JsonEditorField {...props} />); | ||
|
||
await userEvent.click(await screen.findByTestId('myFieldJsonEditor')); | ||
await userEvent.paste('JSON'); | ||
|
||
await waitFor(() => { | ||
expect(setValue).toBeCalledWith('foobarJSON'); | ||
}); | ||
|
||
expect(setXJson).toBeCalledWith('foobarJSON'); | ||
}); | ||
}); |
Oops, something went wrong.