-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix file widget tests #1285
Fix file widget tests #1285
Conversation
fixes version conflicts, e.g. I got an error Uncaught TypeError: this.updater.enqueueCallback is not a function when using setState callback because I use React 16.x and react-jsonschema-form bundled react-dom 15.x See facebook/react#10320 (comment)
…TML form ..., navigating away from current page at least in Firefox. Reason: dispatched event was not cancelable, so preventDefault in onSubmit couldn't cancel it. Links: * <https://stackoverflow.com/a/40916998> * <https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable>
Due to the use of setImmediate() hack in setState utility function (utils.js), onSubmit() handler from props is called asynchronously. This leads to massive problems for operations requiring "trusted events", like window.open() or programmatically submitting forms with target "_blank" (which we needed) Because onSubmit() should not need the performance-related setImmiate() hack, I replaced call to setState utility function with proper this.setState() from React.
by changing to proper use of setState() without setImmediate() hacks (see rjsf-team#1197)
Possible regression could be a slowdown when using FileWidget. But if that happens it must be fixed by an improved |
Thanks for the PR. However, when I currently run tests on my machine (and the tests on the CI server), they are passing. Do you know why it might be the case that they are failing only for you? |
TL;DR: tests are OK with Node 6 (on Travis CI) but broken starting with Node 11. The PR fixes them for Node 11 and 12, while still being OK with Node 6 I just did a checkout of v1.5.0 on another, almost newly installed machine running Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-45-generic x86_64), same three errors (full log at the end of this comment). As my PR is fixing a kind of race condition, I first supposed that this race condition occurs only on my slow MacBook. But the Ubuntu machine is fast, so this couldn't be the difference. Then I noticed that Travis CI test uses Node I didn't find the cause, but I assume that some internal changes in Node (regarding event handling, timers, ...) are triggering the race condition. Tests with this PR and Node
me@ubuntu:~$ git clone https://github.com/mozilla-services/react-jsonschema-form.git
Cloning into 'react-jsonschema-form'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 5806 (delta 0), reused 0 (delta 0), pack-reused 5800
Receiving objects: 100% (5806/5806), 5.87 MiB | 4.29 MiB/s, done.
Resolving deltas: 100% (3804/3804), done.
me@ubuntu:~$ cd react-jsonschema-form/
me@ubuntu:~/react-jsonschema-form$ git checkout v1.5.0
Note: checking out 'v1.5.0'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 45ff77f Bump version 1.5.0
me@ubuntu:~/react-jsonschema-form$ npm ci
> [email protected] install /home/me/react-jsonschema-form/node_modules/fsevents
> node install
> [email protected] postinstall /home/me/react-jsonschema-form/node_modules/lint-staged
> echo "🚫💩 lint-staged installed!
Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md" && exit 0
🚫💩 lint-staged installed!
Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md
> [email protected] install /home/me/react-jsonschema-form/node_modules/husky
> node ./bin/install.js
husky
setting up hooks
done
> [email protected] prepare /home/me/react-jsonschema-form
> npm run dist
> [email protected] dist /home/me/react-jsonschema-form
> npm run build:lib && npm run build:dist
> [email protected] build:lib /home/me/react-jsonschema-form
> rimraf lib && cross-env NODE_ENV=production babel -d lib/ src/
src/components/AddButton.js -> lib/components/AddButton.js
src/components/ErrorList.js -> lib/components/ErrorList.js
src/components/Form.js -> lib/components/Form.js
src/components/IconButton.js -> lib/components/IconButton.js
src/components/fields/ArrayField.js -> lib/components/fields/ArrayField.js
src/components/fields/BooleanField.js -> lib/components/fields/BooleanField.js
src/components/fields/DescriptionField.js -> lib/components/fields/DescriptionField.js
src/components/fields/MultiSchemaField.js -> lib/components/fields/MultiSchemaField.js
src/components/fields/NullField.js -> lib/components/fields/NullField.js
src/components/fields/NumberField.js -> lib/components/fields/NumberField.js
src/components/fields/ObjectField.js -> lib/components/fields/ObjectField.js
src/components/fields/SchemaField.js -> lib/components/fields/SchemaField.js
src/components/fields/StringField.js -> lib/components/fields/StringField.js
src/components/fields/TitleField.js -> lib/components/fields/TitleField.js
src/components/fields/UnsupportedField.js -> lib/components/fields/UnsupportedField.js
src/components/fields/index.js -> lib/components/fields/index.js
src/components/widgets/AltDateTimeWidget.js -> lib/components/widgets/AltDateTimeWidget.js
src/components/widgets/AltDateWidget.js -> lib/components/widgets/AltDateWidget.js
src/components/widgets/BaseInput.js -> lib/components/widgets/BaseInput.js
src/components/widgets/CheckboxWidget.js -> lib/components/widgets/CheckboxWidget.js
src/components/widgets/CheckboxesWidget.js -> lib/components/widgets/CheckboxesWidget.js
src/components/widgets/ColorWidget.js -> lib/components/widgets/ColorWidget.js
src/components/widgets/DateTimeWidget.js -> lib/components/widgets/DateTimeWidget.js
src/components/widgets/DateWidget.js -> lib/components/widgets/DateWidget.js
src/components/widgets/EmailWidget.js -> lib/components/widgets/EmailWidget.js
src/components/widgets/FileWidget.js -> lib/components/widgets/FileWidget.js
src/components/widgets/HiddenWidget.js -> lib/components/widgets/HiddenWidget.js
src/components/widgets/PasswordWidget.js -> lib/components/widgets/PasswordWidget.js
src/components/widgets/RadioWidget.js -> lib/components/widgets/RadioWidget.js
src/components/widgets/RangeWidget.js -> lib/components/widgets/RangeWidget.js
src/components/widgets/SelectWidget.js -> lib/components/widgets/SelectWidget.js
src/components/widgets/TextWidget.js -> lib/components/widgets/TextWidget.js
src/components/widgets/TextareaWidget.js -> lib/components/widgets/TextareaWidget.js
src/components/widgets/URLWidget.js -> lib/components/widgets/URLWidget.js
src/components/widgets/UpDownWidget.js -> lib/components/widgets/UpDownWidget.js
src/components/widgets/index.js -> lib/components/widgets/index.js
src/index.js -> lib/index.js
src/types.js -> lib/types.js
src/utils.js -> lib/utils.js
src/validate.js -> lib/validate.js
> [email protected] build:dist /home/me/react-jsonschema-form
> rimraf dist && cross-env NODE_ENV=production webpack --config webpack.config.dist.js
Hash: aac815cc4258806a75fa
Version: webpack 4.20.2
Time: 9309ms
Built at: 2019-05-20 06:25:53
Asset Size Chunks Chunk Names
react-jsonschema-form.js 232 KiB 0 [emitted] main
react-jsonschema-form.js.map 823 KiB 0 [emitted] main
Entrypoint main = react-jsonschema-form.js react-jsonschema-form.js.map
[0] external {"root":"React","commonjs":"react","commonjs2":"react","amd":"react"} 42 bytes {0} [built]
[9] ./utils.js 30.8 KiB {0} [built]
[22] ./types.js 1.63 KiB {0} [built]
[67] ./validate.js 9.81 KiB {0} [built]
[120] ./index.js 299 bytes {0} [built]
+ 276 hidden modules
added 1207 packages in 23.978s
me@ubuntu:~/react-jsonschema-form$ npm test
> [email protected] test /home/me/react-jsonschema-form
> cross-env NODE_ENV=test mocha --require babel-register --require ./test/setup-jsdom.js test/**/*_test.js
Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.
anyOf
✓ should not render a select element if the anyOf keyword is not present
✓ should render a select element if the anyOf keyword is present
✓ should render a custom widget
✓ should change the rendered form when the select value is changed
✓ should handle change events
✓ should clear previous data when changing options
✓ should support options with different types
✓ should support custom fields
✓ should select the correct field when the form is rendered from existing data
✓ should select the correct field when the formData property is updated
✓ should not change the selected option when entering values
✓ should not change the selected option when entering values and the subschema uses `anyOf` (41ms)
✓ should not change the selected option when entering values and the subschema uses `allOf`
✓ should not mutate a schema that contains nested anyOf and allOf
Arrays
✓ should correctly render form inputs for anyOf inside array items
✓ should correctly render mixed types for anyOf inside array items
ArrayField
Unsupported array schema
✓ should warn on missing items descriptor
List of inputs
✓ should render a fieldset
✓ should render a fieldset legend
✓ should render a description
✓ should render a hidden list
✓ should render a customized title
✓ should render a customized description
✓ should render a customized file widget
✓ should pass rawErrors down to custom array field templates
✓ should contain no field in the list by default
✓ should have an add button
✓ should not have an add button if addable is false
✓ should add a new field when clicking the add button
✓ should not provide an add button if length equals maxItems
✓ should provide an add button if length is lesser than maxItems
✓ should not provide an add button if addable is expliclty false regardless maxItems value
✓ should ignore addable value if maxItems constraint is not satisfied
✓ should mark a non-null array item widget as required
✓ should fill an array field with data
✓ should't have reorder buttons when list length <= 1
✓ should have reorder buttons when list length >= 2
✓ should move down a field from the list
✓ should move up a field from the list
✓ should move from first to last in the list
✓ should disable move buttons on the ends of the list
✓ should not show move up/down buttons if orderable is false
✓ should remove a field from the list
✓ should not show remove button if removable is false
✓ should force revalidation when a field is removed
✓ should handle cleared field values in the array
✓ should render the input widgets with the expected ids
✓ should render nested input widgets with the expected ids
✓ should render enough inputs with proper defaults to match minItems in schema when no formData is set
✓ should render an input for each default value, even when this is greater than minItems
✓ should render enough input to match minItems, populating the first with default values, and the rest empty
✓ should render enough input to match minItems, populating the first with default values, and the rest with the item default
✓ should not add minItems extra formData entries when schema item is a multiselect
✓ should honor given formData, even when it does not meet ths minItems-requirement
Multiple choices list
Select multiple widget
✓ should render a select widget
✓ should render a select widget with a label
✓ should render a select widget with multiple attribute
✓ should render options
✓ should handle a change event
✓ should handle a blur event
✓ should handle a focus event
✓ should fill field with data
✓ should render the select widget with the expected id
✓ should pass rawErrors down to custom widgets
CheckboxesWidget
✓ should render the expected number of checkboxes
✓ should render the expected labels
✓ should handle a change event
✓ should fill field with data
✓ should render the widget with the expected id
✓ should support inline checkboxes
✓ should pass rawErrors down to custom widgets
Multiple files field
✓ should render an input[type=file] widget
✓ should render a select widget with a label
✓ should render a file widget with multiple attribute
1) should handle a change event
✓ should fill field with data
✓ should render the file widget with the expected id
✓ should pass rawErrors down to custom widgets
Nested lists
✓ should render two lists of inputs inside of a list
✓ should add an inner list when clicking the add button
✓ should pass rawErrors down to every level of custom widgets
Fixed items lists
✓ should render a fieldset
✓ should render a fieldset legend
✓ should render field widgets
✓ should mark non-null item widgets as required
✓ should fill fields with data
✓ should handle change events
✓ should generate additional fields and fill data
✓ should apply uiSchema to additionalItems
✓ should have an add button if additionalItems is an object
✓ should not have an add button if additionalItems is not set
✓ should not have an add button if addable is false
✓ [fixed-noadditional] should not provide an add button regardless maxItems
✓ [fixed] should not provide an add button if length equals maxItems
✓ [fixed] should provide an add button if length is lesser than maxItems
✓ [fixed] should not provide an add button if addable is expliclty false regardless maxItems value
✓ [fixed] should ignore addable value if maxItems constraint is not satisfied
operations for additional items
✓ should add a field when clicking add button
✓ should change the state when changing input value
✓ should remove array items when clicking remove buttons
Multiple number choices list
✓ should convert array of strings to numbers if type of items is 'number'
Title
✓ should pass field name to TitleField if there is no title
✓ should pass schema title to TitleField
✓ should pass empty schema title to TitleField
ArrayFieldTemplate
Custom ArrayFieldTemplate of string array
Stateful ArrayFieldTemplate
✓ should render a stateful custom component
not fixed items
✓ should render one root element for the array
✓ should render one add button
✓ should render one child for each array item
✓ should render text input for each array item
✓ should render move up button for all but one array items
✓ should render move down button for all but one array items
fixed items
✓ should render one root element for the array
✓ should not render an add button
✓ should render one child for each array item
✓ should render text input for each array item
✓ should not render any move up buttons
✓ should not render any move down buttons
BooleanField
✓ should render a boolean field
✓ should render a boolean field with the expected id
✓ should render a boolean field with a label
✓ should render a single label
✓ should render a description
✓ should assign a default value
✓ should default state value to undefined
✓ should handle a change event
✓ should fill field with data
✓ should render radio widgets with the expected id
✓ should have default enum option labels for radio widgets
✓ should support enum option ordering for radio widgets
✓ should support enumNames for radio widgets
✓ should support oneOf titles for radio widgets
✓ should preserve oneOf option ordering for radio widgets
✓ should support inline radio widgets
✓ should handle a focus event for radio widgets
✓ should handle a blur event for radio widgets
✓ should support enumNames for select
✓ should handle a focus event with checkbox
✓ should handle a blur event with select
✓ should render the widget with the expected id
✓ should render customized checkbox
✓ should handle a focus event with checkbox
✓ should handle a blur event with checkbox
HTML5 required attribute
✓ should not render a required attribute for simple required fields
✓ should add a required attribute if the schema uses const with a true value
✓ should add a required attribute if the schema uses an enum with a single value of true
✓ should add a required attribute if the schema uses an anyOf with a single value of true
✓ should add a required attribute if the schema uses a oneOf with a single value of true
✓ should add a required attribute if the schema uses an allOf with a value of true
Label
✓ should pass field name to widget if there is no title
✓ should pass schema title to widget
✓ should pass empty schema title to widget
SelectWidget
✓ should render a field that contains an enum of booleans
✓ should infer the value from an enum on change
✓ should render a string field with a label
✓ should assign a default value
✓ should handle a change event
✓ should render the widget with the expected id
const
✓ should render a schema that uses const with a string value
✓ should render a schema that uses const with a number value
✓ should render a schema that uses const with a boolean value
DescriptionField
✓ should return a div for a custom component
✓ should return a p for a description text
✓ should have the expected id
FieldTemplate
Custom FieldTemplate for disabled property
✓ should render with disabled when ui:disabled is truthy
✓ should render with disabled when ui:disabled is falsey
Form
Empty schema
✓ should render a form tag
✓ should render a submit button
✓ should render children buttons
on component creation
when props.formData does not equal the default values
✓ should call props.onChange with current state
when props.formData equals the default values
✓ should not call props.onChange
Option idPrefix
✓ should change the rendered ids
Changing idPrefix
✓ should work with simple example
✓ should work with oneOf
Custom field template
✓ should use the provided field template
✓ should use the provided template for labels
✓ should pass description as the provided React element
✓ should pass rawDescription as a string
✓ should pass errors as the provided React component
✓ should pass rawErrors as an array of strings
✓ should pass help as a the provided React element
✓ should pass rawHelp as a string
Custom submit buttons
✓ should submit the form when clicked
Schema definitions
✓ should use a single schema definition reference
✓ should handle multiple schema definition references
✓ should handle deeply referenced schema definitions
✓ should handle references to deep schema definitions
✓ should handle referenced definitions for array items
✓ should raise for non-existent definitions referenced
✓ should propagate referenced definition defaults
✓ should propagate nested referenced definition defaults
✓ should propagate referenced definition defaults for array items
✓ should recursively handle referenced definitions
✓ should follow recursive references
✓ should follow multiple recursive references
✓ should handle recursive references to deep schema definitions
✓ should handle multiple recursive references to deep schema definitions
✓ should priorize definition over schema type property
✓ should priorize local properties over definition ones
✓ should propagate and handle a resolved schema definition
Default value handling on clear
✓ should not set default when a text field is cleared
Defaults array items default propagation
✓ should propagate deeply nested defaults to form state (265ms)
Submit handler
✓ should call provided submit handler with form state
✓ should not call provided submit handler on validation errors
Change handler
✓ should call provided change handler on form state change
Blur handler
✓ should call provided blur handler on form input blur event
Focus handler
✓ should call provided focus handler on form input focus event
Error handler
✓ should call provided error handler on validation errors
Schema and external formData updates
when the form data is set to null
✓ should call onChange
when the schema default is changed but formData is not changed
✓ should not call onChange
when the schema default is changed and formData is changed
✓ should not call onChange
when the schema default is changed and formData is nulled
✓ should call onChange
when the onChange prop sets formData to a falsey value
✓ Should not crash due to 'Maximum call stack size exceeded...'
✓ Should not crash due to 'Maximum call stack size exceeded...'
✓ Should not crash due to 'Maximum call stack size exceeded...'
✓ Should not crash due to 'Maximum call stack size exceeded...'
✓ Should not crash due to 'Maximum call stack size exceeded...'
External formData updates
root level
✓ should update form state from new formData prop value
✓ should validate formData when the schema is updated
object level
✓ should update form state from new formData prop value
array level
✓ should update form state from new formData prop value
Error contextualization
on form state updated
Lazy validation
✓ should not update the errorSchema when the formData changes
✓ should not denote an error in the field
✓ should clean contextualized errors up when they're fixed
Live validation
✓ should update the errorSchema when the formData changes
✓ should denote the new error in the field
Disable validation onChange event
✓ should not update errorSchema when the formData changes
Disable validation onSubmit event
✓ should not update errorSchema when the formData changes
on form submitted
✓ should update the errorSchema on form submission
✓ should call the onError handler
✓ should reset errors and errorSchema state to initial state after correction and resubmission
root level
✓ should reflect the contextualized error in state
✓ should denote the error in the field
root level with multiple errors
✓ should reflect the contextualized error in state
✓ should denote the error in the field
nested field level
✓ should reflect the contextualized error in state
✓ should denote the error in the field
array indices
✓ should contextualize the error for array indices
✓ should denote the error in the item field in error
✓ should not denote errors on non impacted fields
nested array indices
✓ should contextualize the error for nested array indices
✓ should denote the error in the nested item field in error
nested arrays
✓ should contextualize the error for nested array indices
✓ should denote the error in the nested item field in error (40ms)
array nested items
✓ should contextualize the error for array nested items
✓ should denote the error in the array nested item
schema dependencies
✓ should only show error for property in selected branch
✓ should only show errors for properties in selected branch
ignoring oneOf in dependencies because there isn't exactly one subschema that is valid
ignoring oneOf in dependencies because there isn't exactly one subschema that is valid
ignoring oneOf in dependencies because there isn't exactly one subschema that is valid
ignoring oneOf in dependencies because there isn't exactly one subschema that is valid
ignoring oneOf in dependencies because there isn't exactly one subschema that is valid
✓ should not show any errors when branch is empty
Schema and formData updates
✓ should replace state when formData have keys removed
✓ should replace state when formData keys have changed
idSchema updates based on formData
✓ should not update idSchema for a falsey value
✓ should update idSchema based on truthy value
Form disable prop
✓ should enable all items
✓ should disable all items
Attributes
✓ should set attr id of form
✓ should set attr class of form
✓ should set attr name of form
✓ should set attr method of form
✓ should set attr target of form
✓ should set attr action of form
✓ should set attr autoComplete of form
✓ should set attr enctype of form
✓ should set attr acceptcharset of form
✓ should set attr novalidate of form
Custom format updates
✓ Should update custom formats when customFormats is changed
Meta schema updates
✓ Should update allowed meta schemas when additionalMetaSchemas is changed
FormContext
✓ should be passed to Form
✓ should be passed to custom field
✓ should be passed to custom widget
✓ should be passed to TemplateField
✓ should be passed to ArrayTemplateField
✓ should be passed to custom TitleField
✓ should be passed to custom DescriptionField
✓ should be passed to multiselect
✓ should be passed to files array
NullField
No widget
✓ should render a null field
✓ should render a null field with a label
✓ should assign a default value
✓ should not overwrite existing data
NumberField
TextWidget
✓ should render a number input
✓ should render a string field with a label
✓ should render a string field with a description
✓ should default state value to undefined
✓ should assign a default value
✓ should handle a change event
✓ should handle a blur event
✓ should handle a focus event
✓ should fill field with data
✓ should normalize values beginning with a decimal point
✓ should update input values correctly when formData prop changes
✓ should render the widget with the expected id
✓ should render with trailing zeroes
✓ should allow a zero to be input
✓ should render customized StringField
✓ should use step to represent the multipleOf keyword
when inputting a number that ends with a dot and/or zero it should normalize it, without changing the input value
✓ should work with an input value of 2.
✓ should work with an input value of 2.0
✓ should work with an input value of 2.3
✓ should work with an input value of 2.30
✓ should work with an input value of 2.300
✓ should work with an input value of 2.3001
✓ should work with an input value of 2.03
✓ should work with an input value of 2.003
✓ should work with an input value of 2.00300
✓ should work with an input value of 200300
SelectWidget
✓ should render a number field
✓ should infer the value from an enum on change
✓ should render a string field with a label
✓ should assign a default value
✓ should handle a change event
✓ should fill field with data
✓ should render the widget with the expected id
✓ should render a select element with a blank option, when default value is not set.
✓ should render a select element without a blank option, if a default value is set.
✓ should render a select element without a blank option, if the default value is 0.
ObjectField
schema
✓ should render a fieldset
✓ should render a fieldset legend
✓ should render a hidden object
✓ should render a customized title
✓ should render a customized description
✓ should render a default property label
✓ should render a string property
✓ should render a boolean property
✓ should handle a default object value
✓ should handle required values
✓ should fill fields with form data
✓ should handle object fields change events
✓ should handle object fields with blur events
✓ should handle object fields with focus events
✓ should render the widget with the expected id
fields ordering
✓ should use provided order
✓ should insert unordered properties at wildcard position
uiSchema order list contains extraneous properties 'wut?', 'huh?'
✓ should use provided order also if order list contains extraneous properties
✓ should throw when order list misses an existing property
✓ should throw when more than one wildcard is present
✓ should order referenced schema definitions
✓ should order referenced object schema definition properties
✓ should render the widget with the expected id
Title
✓ should pass field name to TitleField if there is no title
✓ should pass schema title to TitleField
✓ should pass empty schema title to TitleField
additionalProperties
✓ should automatically add a property field if in formData
✓ should apply uiSchema to additionalProperties
✓ should pass through non-schema properties and not throw validation errors if additionalProperties is undefined
✓ should pass through non-schema properties but throw a validation error if additionalProperties is false
✓ should still obey properties if additionalProperties is defined
✓ should render a label for the additional property key
✓ should render a label for the additional property key if additionalProperties is true
✓ should not render a label for the additional property key if additionalProperties is false
✓ should render a text input for the additional property key
✓ should render a label for the additional property value
✓ should render a text input for the additional property value
✓ should rename formData key if key input is renamed
✓ should keep order of renamed key-value pairs while renaming key
✓ should attach suffix to formData key if new key already exists when key input is renamed
✓ should not attach suffix when input is only clicked
✓ should continue incrementing suffix to formData key until that key name is unique after a key input collision
✓ should have an expand button
✓ should not have an expand button if expandable is false
✓ should add a new property when clicking the expand button
✓ should add a new property with suffix when clicking the expand button and 'newKey' already exists
✓ should not provide an expand button if length equals maxProperties
✓ should provide an expand button if length is less than maxProperties
✓ should not provide an expand button if expandable is expliclty false regardless of maxProperties value
✓ should ignore expandable value if maxProperties constraint is not satisfied
✓ should not have delete button if expand button has not been clicked
✓ should have delete button if expand button has been clicked
✓ delete button should delete key-value pair
✓ delete button should delete correct pair
✓ deleting content of value input should not delete pair
ObjectFieldTemplate
✓ should render one root element
✓ should render one title
✓ should render one description
✓ should render two property containers
oneOf
✓ should not render a select element if the oneOf keyword is not present
✓ should render a select element if the oneOf keyword is present
✓ should render a custom widget
✓ should change the rendered form when the select value is changed
✓ should handle change events
✓ should clear previous data when changing options
✓ should support options with different types
✓ should support custom fields
✓ should select the correct field when the form is rendered from existing data
✓ should select the correct field when the formData property is updated
✓ should not change the selected option when entering values on a subschema with multiple required options
✓ should empty the form data when switching from an option of type 'object'
Arrays
✓ should correctly render mixed types for oneOf inside array items
Rendering performance optimizations
Form
✓ should not render if next props are equivalent
✓ should not render if next formData are equivalent
✓ should only render changed object properties
✓ should only render changed array items
SchemaField
✓ should not render if next props are equivalent
✓ should not render if next formData are equivalent
SchemaField
Unsupported field
✓ should warn on invalid field type
Custom SchemaField component
✓ should use the specified custom SchemaType property
ui:field support
✓ should use provided direct custom component for object
✓ should use provided direct custom component for specific property
✓ should provide custom field the expected fields
✓ should use registered custom component for object
✓ should handle referenced schema definitions
✓ should not pass classNames to child component
label support
✓ should render label by default
✓ should render label if ui:options label is set to true
✓ should not render label if ui:options label is set to false
description support
✓ should render description if available from the schema
✓ should render description if available from a referenced schema
✓ should not render description if not available from schema
✓ should render a customized description field
errors
✓ should render it's own errors
✓ should pass errors to child component
Custom error rendering
✓ should pass rawErrors down to custom widgets
StringField
TextWidget
✓ should render a string field
✓ should render a string field with a label
✓ should render a string field with a description
✓ should assign a default value
✓ should default state value to undefined
✓ should handle a change event
✓ should handle a blur event
✓ should handle a focus event
✓ should handle an empty string change event
✓ should handle an empty string change event with custom ui:defaultValue
✓ should fill field with data
✓ should render the widget with the expected id
✓ should render customized TextWidget
SelectWidget
✓ should render a string field
✓ should render a string field for an enum without a type
✓ should render a string field with a label
✓ should render empty option
✓ should render empty option with placeholder text
✓ should assign a default value
✓ should reflect the change into the form state
✓ should reflect undefined into form state if empty option selected
✓ should reflect the change into the dom
✓ should reflect undefined value into the dom as empty option
✓ should fill field with data
✓ should render the widget with the expected id
✓ should render customized SelectWidget
✓ should render a select element with first option 'false' if the default value is false
✓ should render a select element and the option's length is equal the enum's length, if set the enum and the default value is empty.
✓ should render only one empty option when the default value is empty.
TextareaWidget
✓ should handle an empty string change event
✓ should handle an empty string change event with custom ui:defaultValue
✓ should render a textarea field with rows
DateTimeWidget
✓ should render an datetime-local field
✓ should assign a default value
✓ should reflect the change into the dom
✓ should fill field with data
✓ should render the widget with the expected id
✓ should reject an invalid entered datetime
✓ should render customized DateTimeWidget
✓ should allow overriding of BaseInput
DateWidget
✓ should render a date field
✓ should assign a default value
✓ should reflect the change into the dom
✓ should fill field with data
✓ should render the widget with the expected id
✓ should accept a valid entered date
✓ should reject an invalid entered date
✓ should render customized DateWidget
✓ should allow overriding of BaseInput
AltDateTimeWidget
✓ should render a datetime field (80ms)
✓ should render a string field with a main label (82ms)
✓ should assign a default value (69ms)
✓ should reflect the change into the dom (155ms)
✓ should fill field with data
✓ should render the widgets with the expected ids (66ms)
✓ should render the widgets with the expected options' values (60ms)
✓ should render the widgets with the expected options' labels (65ms)
✓ should render customized AltDateWidget
✓ should render customized AltDateTimeWidget
Action buttons
✓ should render action buttons (61ms)
✓ should set current date when pressing the Now button (88ms)
✓ should clear current date when pressing the Clear button (104ms)
AltDateWidget
✓ should render a date field
✓ should render a string field with a main label
✓ should assign a default value
✓ should reflect the change into the dom (58ms)
✓ should fill field with data (39ms)
✓ should render the widgets with the expected ids
✓ should render the widgets with the expected options' values
✓ should render the widgets with the expected options' labels (39ms)
✓ should accept a valid date
✓ should render customized AltDateWidget
Action buttons
✓ should render action buttons
✓ should set current date when pressing the Now button (41ms)
✓ should clear current date when pressing the Clear button (60ms)
EmailWidget
✓ should render an email field
✓ should render a string field with a label
✓ should render a select field with a description
✓ should assign a default value
✓ should reflect the change into the dom
✓ should fill field with data
✓ should render the widget with the expected id
✓ should reject an invalid entered email
✓ should render customized EmailWidget
URLWidget
✓ should render an url field
✓ should render a string field with a label
✓ should render a select field with a placeholder
✓ should assign a default value
✓ should reflect the change into the dom
✓ should fill field with data
✓ should render the widget with the expected id
✓ should reject an invalid entered url
✓ should render customized URLWidget
ColorWidget
✓ should render a color field
✓ should assign a default value
✓ should reflect the change into the dom
✓ should fill field with data
✓ should render the widget with the expected id
✓ should reject an invalid entered color
✓ should render customized ColorWidget
FileWidget
✓ should render a color field
✓ should assign a default value
2) should reflect the change into the dom
3) should encode file name with encodeURIComponent
✓ should render the widget with the expected id
✓ should render customized FileWidget
UpDownWidget
✓ should allow overriding of BaseInput
Label
✓ should pass field name to widget if there is no title
✓ should pass schema title to widget
✓ should pass empty schema title to widget
TitleField
✓ should return a legend
✓ should have the expected id
✓ should include only title, when field is not required
✓ should add an asterisk to the title, when field is required
uiSchema
✓ should accept a react element as help
custom classNames
✓ should apply custom class names to target widgets
custom widget
root widget
✓ should render a root custom widget
custom options
✓ should log warning when deprecated ui:widget: {component, options} api is used
✓ should cache MergedWidget instance
✓ should render merged ui:widget options for widget referenced as function
✓ should render ui:widget default options for widget referenced as function
✓ should render merged ui:widget options for widget referenced as string
✓ should render ui:widget default options for widget referenced as string
✓ should ui:option inputType for html5 input types
nested widget
✓ should render a nested custom widget
options
direct reference
✓ should render a custom widget with options
string reference
✓ should render a custom widget with options
enum fields native options
✓ should merge enumOptions with custom options
enum fields disabled options
✓ should have atleast one option disabled
enum fields disabled radio options
✓ should have atleast one radio option disabled
ui:help
✓ should render the provided help text
ui:title
✓ should render the provided title text
ui:description
✓ should render the provided description text
ui:focus
number
✓ should focus on integer input
✓ should focus on integer input, updown widget
✓ should focus on integer input, range widget
✓ should focus on integer enum input
string
✓ should focus on text input
✓ should focus on textarea
✓ should focus on password input
✓ should focus on color input
✓ should focus on email input
✓ should focus on uri input
✓ should focus on data-url input
object
✓ should focus on date input
✓ should focus on date-time input
✓ should focus on alt-date input
✓ should focus on alt-date-time input (60ms)
array
✓ should focus on multiple files input
✓ should focus on first item of a list of strings
✓ should focus on first item of a multiple choices list
boolean
✓ should focus on checkbox input
✓ should focus on radio input
✓ should focus on select input
string
file
✓ should accept a uiSchema object
textarea
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when text is updated
✓ should set a placeholder value
password
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when text is updated is checked
✓ should set a placeholder value
color
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when text is updated
hidden
✓ should accept a uiSchema object
✓ should support formData
✓ should map widget value to a typed state one
string (enum)
radio
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when value is updated
number
updown
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when value is updated
Constraint attributes
✓ should support the minimum constraint
✓ should support maximum constraint
✓ should support '0' as minimum and maximum constraints
✓ should support the multipleOf constraint
range
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when value is updated
Constraint attributes
✓ should support the minimum constraint
✓ should support maximum constraint
✓ should support '0' as minimum and maximum constraints
✓ should support the multipleOf constraint
radio
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when value is updated
hidden
✓ should accept a uiSchema object
✓ should support formData
✓ should map widget value to a typed state one
integer
updown
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when value is updated
range
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when value is updated
radio
✓ should accept a uiSchema object
✓ should support formData
✓ should update state when value is updated
hidden
✓ should accept a uiSchema object
✓ should support formData
✓ should map widget value to a typed state one
boolean
radio
✓ should accept a uiSchema object
✓ should render boolean option labels
✓ should support formData
✓ should update state when false is checked
✓ should update state when true is checked
select
✓ should accept a uiSchema object
✓ should render boolean option labels
✓ should update state when true is selected
✓ should update state when false is selected
hidden
✓ should accept a uiSchema object
✓ should support formData
✓ should map widget value to a typed state one
custom root field id
✓ should use a custom root field id for objects
✓ should use a custom root field id for arrays
✓ should use a custom root field id for array of objects
Disabled
Fields
ArrayField
✓ should disable an ArrayField
✓ should disable the Add button
✓ should disable the Delete button
ObjectField
✓ should disable an ObjectField
Widgets
✓ should disable a text widget
✓ should disabled a file widget
✓ should disable a textarea widget
✓ should disable a number text widget
✓ should disable a number widget
✓ should disable a range widget
✓ should disable a select widget
✓ should disable a checkbox widget
✓ should disable a radio widget
✓ should disable a color widget
✓ should disable a password widget
✓ should disable an email widget
✓ should disable a date widget
✓ should disable a datetime widget
✓ should disable an alternative date widget
✓ should disable an alternative datetime widget (55ms)
Readonly
Fields
ArrayField
✓ should mark as readonly an ArrayField
✓ should disable the Add button
✓ should disable the Delete button
ObjectField
✓ should mark as readonly an ObjectField
Widgets
✓ should mark as readonly a text widget
✓ should mark as readonly a file widget
✓ should mark as readonly a textarea widget
✓ should mark as readonly a number text widget
✓ should mark as readonly a number widget
✓ should mark as readonly a range widget
✓ should mark readonly as disabled on a select widget
✓ should mark as readonly a color widget
✓ should mark as readonly a password widget
✓ should mark as readonly a url widget
✓ should mark as readonly an email widget
✓ should mark as readonly a date widget
✓ should mark as readonly a datetime widget
✓ should mark readonly as disabled on an alternative date widget
✓ should mark readonly as disabled on an alternative datetime widget (54ms)
utils
getDefaultFormState()
root default
✓ should map root schema default to form state, if any
nested default
✓ should map schema object prop default to form state
✓ should default to empty object if no properties are defined
✓ should recursively map schema object default to form state
✓ should map schema array default to form state
✓ should recursively map schema array default to form state
✓ should propagate nested defaults to resulting formData by default
✓ should keep parent defaults if they don't have a node level default
✓ should support nested values in formData
✓ should use parent defaults for ArrayFields
✓ should use parent defaults for ArrayFields if declared in parent
✓ should map item defaults to fixed array default
✓ should use schema default for referenced definitions
✓ should fill array with additional items schema when items is empty
asNumber()
✓ should return a number out of a string representing a number
✓ should return a float out of a string representing a float
✓ should return the raw value if the input ends with a dot
✓ should not convert the value to an integer if the input ends with a 0
✓ should allow numbers with a 0 in the first decimal place
✓ should return undefined if the input is empty
orderProperties()
uiSchema order list contains extraneous properties 'bar', 'qux'
✓ should remove from order elements that are not in properties
✓ should order properties according to the order
✓ should replace * with properties that are absent in order
uiSchema order list contains extraneous properties 'quux', 'corge'
✓ should handle more complex ordering case correctly
isConstant
✓ should return false when neither enum nor const is defined
✓ should return true when schema enum is an array of one item
✓ should return false when schema enum contains several items
✓ should return true when schema const is defined
toConstant()
schema contains an enum array
✓ should return its first value when it contains a unique element
✓ should return schema const value when it exists
✓ should throw when it contains more than one element
isMultiSelect()
✓ should be false if uniqueItems is false
uniqueItems is true
✓ should be false if items is undefined
✓ should retrieve reference schema definitions
schema items enum is an array
✓ should be true
schema items enum is not an array
✓ should be false if oneOf/anyOf is not in items schema
✓ should be false if oneOf/anyOf schemas are not all constants
✓ should be true if oneOf/anyOf schemas are all constants
isFilesArray()
✓ should be true if items have data-url format
✓ should be false if items is undefined
mergeObjects()
✓ should't mutate the provided objects
✓ should merge two one-level deep objects
✓ should override the first object with the values from the second
✓ should override non-existing values of the first object with the values from the second
✓ should recursively merge deeply nested objects
✓ should recursively merge File objects
concatArrays option
✓ should not concat arrays by default
✓ should concat arrays when concatArrays is true
✓ should concat nested arrays when concatArrays is true
retrieveSchema()
✓ should 'resolve' a schema which contains definitions
✓ should 'resolve' escaped JSON Pointers
✓ should priorize local definitions over foreign ones
property dependencies
false condition
✓ should not add required properties
true condition
when required is not defined
✓ should define required properties
when required is defined
✓ should concat required properties
schema dependencies
conditional
false condition
✓ should not modify properties
true condition
✓ should add properties
with $ref in dependency
✓ should retrieve referenced schema
with $ref in oneOf
✓ should retrieve referenced schemas
dynamic
false condition
✓ should not modify properties
true condition
✓ should add 'first' properties given 'first' data
✓ should add 'second' properties given 'second' data
with $ref in dependency
✓ should retrieve the referenced schema
shouldRender
single level comparison checks
✓ should detect equivalent props and state
✓ should detect diffing props
✓ should detect diffing state
✓ should handle equivalent function prop
nested levels comparison checks
✓ should detect equivalent props and state
✓ should detect diffing props
✓ should detect diffing state
✓ should handle equivalent function prop
toIdSchema
✓ should return an idSchema for root field
✓ should return an idSchema for nested objects
✓ should return an idSchema for multiple nested objects
✓ schema with an id property must not corrupt the idSchema
✓ should return an idSchema for array item objects
✓ should retrieve referenced schema definitions
✓ should return an idSchema for property dependencies
✓ should return an idSchema for nested property dependencies
✓ should return an idSchema for unmet property dependencies
✓ should handle idPrefix parameter
✓ should handle null form data for object schemas
parseDateString()
✓ should raise on invalid JSON datetime
✓ should return a default object when no datetime is passed
✓ should return a default object when time should not be included
✓ should parse a valid JSON datetime string
✓ should exclude time when includeTime is false
toDateString()
✓ should transform an object to a valid json datetime if time=true
✓ should transform an object to a valid date string if time=false
pad()
✓ should pad a string with 0s
dataURItoBlob()
✓ should return the name of the file if present
✓ should return unknown if name is not provided
✓ should return ignore unsupported parameters
deepEquals()
✓ should assume functions are always equivalent
guessType()
✓ should guess the type of array values
✓ should guess the type of string values
✓ should guess the type of null values
✓ should treat undefined values as null values
✓ should guess the type of boolean values
✓ should guess the type of object values
getSchemaType()
✓ should correctly guess the type of a schema
Validation
validate.isValid()
✓ should return true if the data is valid against the schema
✓ should return false if the data is not valid against the schema
✓ should return false if the schema is invalid
validate.validateFormData()
No custom validate function
✓ should return an error list
✓ should return an errorSchema
Validating multipleOf with a float
✓ should not return an error
validating using custom meta schema
✓ should return a validation error about meta schema when meta schema is not defined
✓ should return a validation error about formData
✓ should return a validation error about formData, when used with multiple meta schemas
validating using custom string formats
✓ should return a validation error if unknown string format is used
✓ should return a validation error about formData
✓ prop updates with new custom formats are accepted
Custom validate function
✓ should return an error list
✓ should return an errorSchema
Data-Url validation
✓ Data-Url with name is accepted
✓ Data-Url without name is accepted
toErrorList()
✓ should convert an errorSchema into a flat list
transformErrors
✓ should use transformErrors function
Invalid schema
✓ should return an error list
✓ should return an errorSchema
Form integration
JSONSchema validation
Required fields
✓ should validate a required field
✓ should render errors
✓ should trigger the onError handler
Min length
✓ should validate a minLength field
✓ should render errors
✓ should trigger the onError handler
Custom Form validation
✓ should validate a simple string value
✓ should submit form on valid data
✓ should prevent form submission on invalid data
✓ should validate a simple object
✓ should validate an array of object
✓ should validate a simple array
showErrorList prop validation
Required fields
✓ should validate a required field
✓ should not render error list if showErrorList prop true
✓ should trigger the onError handler
Custom ErrorList
✓ should use CustomErrorList
Custom meta schema
✓ should be used to validate schema
804 passing (7s)
3 failing
1) ArrayField
Multiple files field
should handle a change event:
AssertionError: expected undefined to deeply equal [ Array(2) ]
at /home/me/react-jsonschema-form/test/ArrayField_test.js:917:37
at runNextTicks (internal/process/next_tick.js:47:5)
2) StringField
FileWidget
should reflect the change into the dom:
AssertionError: expected undefined to deeply equal 'data:text/plain;name=file1.txt;base64,x='
at /home/me/react-jsonschema-form/test/StringField_test.js:1613:37
at runNextTicks (internal/process/next_tick.js:47:5)
3) StringField
FileWidget
should encode file name with encodeURIComponent:
AssertionError: expected undefined to deeply equal 'data:text/plain;name=file%C3%A1%C3%A9%C3%AD%20%C3%B3%C3%BA1.txt;base64,x='
at /home/me/react-jsonschema-form/test/StringField_test.js:1644:37
at runNextTicks (internal/process/next_tick.js:47:5)
npm ERR! Test failed. See above for more details. |
@epicfaace Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Reasons for making this change
Tests for FileWidget were constantly failing (for months, years?) and I could fix them by changing FileWidget onChange handler to proper use of
setState
without any setImmediate hacks (see #1197)After the change all tests are green.
Failing tests that are now working:
Plus two very minor fixes, see other commit.
Checklist
/#contributing) of the Markdown text I've added
npm run cs-format
on my branch to conform my code to prettier coding style