| 1 |
import { createSchemaUtils, englishStringTranslator, WidgetProps, RJSFSchema } from '@rjsf/utils'; |
| 2 |
import { getDefaultRegistry } from '@rjsf/core'; |
| 3 |
import validator from '@rjsf/validator-ajv8'; |
| 4 |
|
| 5 |
import Templates from '../../src/Templates'; |
| 6 |
import BaseInputTemplate from '../../src/BaseInputTemplate'; |
| 7 |
|
| 8 |
export const mockSchema: RJSFSchema = { |
| 9 |
type: 'array', |
| 10 |
items: { |
| 11 |
type: 'string', |
| 12 |
}, |
| 13 |
}; |
| 14 |
|
| 15 |
export const mockEventHandlers = (): void => void 0; |
| 16 |
|
| 17 |
export const mockSchemaUtils = createSchemaUtils(validator, mockSchema); |
| 18 |
|
| 19 |
export function mockRegistry() { |
| 20 |
return { |
| 21 |
fields: {}, |
| 22 |
widgets: { TextWidget: BaseInputTemplate }, |
| 23 |
templates: { ...getDefaultRegistry().templates, ...Templates }, |
| 24 |
formContext: {}, |
| 25 |
rootSchema: {}, |
| 26 |
schemaUtils: mockSchemaUtils, |
| 27 |
translateString: englishStringTranslator, |
| 28 |
}; |
| 29 |
} |
| 30 |
|
| 31 |
export function makeWidgetMockProps(props: Partial<WidgetProps> = {}): WidgetProps { |
| 32 |
return { |
| 33 |
uiSchema: {}, |
| 34 |
schema: mockSchema, |
| 35 |
required: true, |
| 36 |
disabled: false, |
| 37 |
readonly: true, |
| 38 |
autofocus: true, |
| 39 |
label: 'Some simple label', |
| 40 |
onChange: mockEventHandlers, |
| 41 |
onBlur: mockEventHandlers, |
| 42 |
onFocus: mockEventHandlers, |
| 43 |
multiple: false, |
| 44 |
rawErrors: [''], |
| 45 |
value: 'value', |
| 46 |
options: {}, |
| 47 |
formContext: {}, |
| 48 |
id: '_id', |
| 49 |
name: '_name', |
| 50 |
placeholder: '', |
| 51 |
registry: mockRegistry(), |
| 52 |
...props, |
| 53 |
}; |
| 54 |
} |