Skip to content

Commit

Permalink
Merge branch 'main' into intl_pack_upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored May 28, 2024
2 parents 46284e5 + 49925a3 commit 3c59599
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ export const CodeEditorInput = ({

const updateValue = useCallback(
async (newValue: string, onUpdateFn) => {
const isJsonArray = Array.isArray(JSON.parse(defaultValue || '{}'));
const parsedValue = newValue || (isJsonArray ? '[]' : '{}');
let parsedValue;

// Validate JSON syntax
if (field.type === 'json') {
try {
const isJsonArray = Array.isArray(JSON.parse(defaultValue || 'null'));
parsedValue = newValue || (isJsonArray ? '[]' : '{}');
JSON.parse(parsedValue);
} catch (e) {
onUpdateFn({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ describe('MarkdownEditorInput', () => {
const input = getByTestId(`${TEST_SUBJ_PREFIX_FIELD}-${id}`);
fireEvent.change(input, { target: { value: '# New Markdown Title' } });

await waitFor(() =>
await waitFor(() => {
expect(defaultProps.onInputChange).not.toHaveBeenCalledWith({
error: expect.any(String),
});

expect(defaultProps.onInputChange).toHaveBeenCalledWith({
type: 'markdown',
unsavedValue: '# New Markdown Title',
})
);
});
});
});
});

0 comments on commit 3c59599

Please sign in to comment.