@wirenboard/json-editor 2.5.3-wb13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env-dist +2 -0
- package/.eslintrc +7 -0
- package/.gitattributes +1 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +9 -0
- package/.github/issue_template +25 -0
- package/.github/workflows/build.yml +58 -0
- package/.travis.yml +70 -0
- package/CHANGELOG.md +915 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +20 -0
- package/Makefile +26 -0
- package/README.md +1646 -0
- package/README_ADDON.md +573 -0
- package/UPGRADING.md +46 -0
- package/build/CssToJson.js +55 -0
- package/codecept.conf.js +35 -0
- package/config/.eslintrc +7 -0
- package/config/codeceptjs_helpers.js +139 -0
- package/config/helpers.js +10 -0
- package/config/karma.conf.js +93 -0
- package/config/readme.md +31 -0
- package/config/webpack.common.js +75 -0
- package/config/webpack.dev.js +15 -0
- package/config/webpack.nonmin.js +19 -0
- package/config/webpack.prod.js +25 -0
- package/dist/jsoneditor.js +14 -0
- package/dist/nonmin/jsoneditor.js +29097 -0
- package/dist/nonmin/jsoneditor.js.map +1 -0
- package/docs/ace_editor.html +56 -0
- package/docs/advanced.html +136 -0
- package/docs/basic.html +63 -0
- package/docs/basic_person.json +26 -0
- package/docs/choices.html +86 -0
- package/docs/cleave.html +132 -0
- package/docs/colorpicker.html +194 -0
- package/docs/css_integration.html +135 -0
- package/docs/datetime.html +305 -0
- package/docs/describedby.html +161 -0
- package/docs/enumsource.html +67 -0
- package/docs/images/categoriesDemo.png +0 -0
- package/docs/images/inheritance_tree.png +0 -0
- package/docs/images/jsoneditor.png +0 -0
- package/docs/imask.html +192 -0
- package/docs/index.html +579 -0
- package/docs/materialize_css.html +164 -0
- package/docs/meta_schema.json +705 -0
- package/docs/multiple_upload_base64.html +65 -0
- package/docs/person.json +73 -0
- package/docs/polyfills/assign.js +29 -0
- package/docs/radio.html +156 -0
- package/docs/recursive.html +170 -0
- package/docs/select2.html +99 -0
- package/docs/selectize.html +100 -0
- package/docs/signature.html +42 -0
- package/docs/starrating.html +137 -0
- package/docs/upload.html +131 -0
- package/docs/uuid.html +70 -0
- package/docs/wysiwyg.html +56 -0
- package/jasmine.json +11 -0
- package/json-editor-json-editor-2.5.3-wb13.tgz +0 -0
- package/package.json +100 -0
- package/release-notes.md +88 -0
- package/src/core.js +412 -0
- package/src/defaults.js +402 -0
- package/src/editor.js +707 -0
- package/src/editors/ace.js +89 -0
- package/src/editors/array/choices.js +103 -0
- package/src/editors/array/select2.js +110 -0
- package/src/editors/array/selectize.js +103 -0
- package/src/editors/array.css +9 -0
- package/src/editors/array.css.js +3 -0
- package/src/editors/array.js +818 -0
- package/src/editors/autocomplete.js +58 -0
- package/src/editors/base64.js +157 -0
- package/src/editors/button.js +97 -0
- package/src/editors/checkbox.js +95 -0
- package/src/editors/choices.css +3 -0
- package/src/editors/choices.css.js +3 -0
- package/src/editors/choices.js +69 -0
- package/src/editors/colorpicker.js +103 -0
- package/src/editors/datetime.js +141 -0
- package/src/editors/describedby.js +188 -0
- package/src/editors/enum.js +136 -0
- package/src/editors/hidden.js +127 -0
- package/src/editors/index.js +81 -0
- package/src/editors/info.js +20 -0
- package/src/editors/integer.js +19 -0
- package/src/editors/ip.js +36 -0
- package/src/editors/jodit.js +64 -0
- package/src/editors/multiple.js +409 -0
- package/src/editors/multiselect.js +218 -0
- package/src/editors/null.js +18 -0
- package/src/editors/number.js +51 -0
- package/src/editors/object.css +41 -0
- package/src/editors/object.css.js +3 -0
- package/src/editors/object.js +1290 -0
- package/src/editors/radio.js +111 -0
- package/src/editors/sceditor.js +72 -0
- package/src/editors/select.js +370 -0
- package/src/editors/select2.js +110 -0
- package/src/editors/selectize.js +112 -0
- package/src/editors/signature.js +113 -0
- package/src/editors/simplemde.js +100 -0
- package/src/editors/starrating.css +52 -0
- package/src/editors/starrating.css.js +3 -0
- package/src/editors/starrating.js +135 -0
- package/src/editors/stepper.js +27 -0
- package/src/editors/string.js +372 -0
- package/src/editors/table.js +516 -0
- package/src/editors/upload.js +321 -0
- package/src/editors/uuid.js +56 -0
- package/src/iconlib.js +24 -0
- package/src/iconlibs/bootstrap2.js +28 -0
- package/src/iconlibs/bootstrap3.js +28 -0
- package/src/iconlibs/fontawesome3.js +28 -0
- package/src/iconlibs/fontawesome4.js +28 -0
- package/src/iconlibs/fontawesome5.js +28 -0
- package/src/iconlibs/foundation2.js +24 -0
- package/src/iconlibs/foundation3.js +28 -0
- package/src/iconlibs/index.js +25 -0
- package/src/iconlibs/jqueryui.js +28 -0
- package/src/iconlibs/materialicons.js +49 -0
- package/src/iconlibs/openiconic.js +28 -0
- package/src/iconlibs/spectre.js +28 -0
- package/src/resolvers.js +128 -0
- package/src/schemaloader.js +408 -0
- package/src/style.css +150 -0
- package/src/style.css.js +3 -0
- package/src/templates/default.js +52 -0
- package/src/templates/ejs.js +13 -0
- package/src/templates/handlebars.js +1 -0
- package/src/templates/hogan.js +10 -0
- package/src/templates/index.js +21 -0
- package/src/templates/lodash.js +9 -0
- package/src/templates/markup.js +9 -0
- package/src/templates/mustache.js +9 -0
- package/src/templates/swig.js +1 -0
- package/src/templates/underscore.js +9 -0
- package/src/theme.js +659 -0
- package/src/themes/barebones.css +35 -0
- package/src/themes/barebones.css.js +3 -0
- package/src/themes/barebones.js +28 -0
- package/src/themes/bootstrap2.js +319 -0
- package/src/themes/bootstrap3.css +0 -0
- package/src/themes/bootstrap3.css.js +3 -0
- package/src/themes/bootstrap3.js +315 -0
- package/src/themes/bootstrap4.css +89 -0
- package/src/themes/bootstrap4.css.js +3 -0
- package/src/themes/bootstrap4.js +690 -0
- package/src/themes/bootstrap5.css.js +3 -0
- package/src/themes/foundation.js +569 -0
- package/src/themes/html.css +60 -0
- package/src/themes/html.css.js +3 -0
- package/src/themes/html.js +71 -0
- package/src/themes/index.js +28 -0
- package/src/themes/jqueryui.js +198 -0
- package/src/themes/materialize.js +426 -0
- package/src/themes/spectre.css +208 -0
- package/src/themes/spectre.css.js +3 -0
- package/src/themes/spectre.js +406 -0
- package/src/themes/tailwind.css +249 -0
- package/src/themes/tailwind.css.js +3 -0
- package/src/themes/tailwind.js +443 -0
- package/src/utilities.js +138 -0
- package/src/validator.js +877 -0
- package/src/validators/ip-validator.js +51 -0
- package/tests/Dockerfile +3 -0
- package/tests/README.md +48 -0
- package/tests/codeceptjs/codecept.json +42 -0
- package/tests/codeceptjs/constrains/if-then-else_test.js +143 -0
- package/tests/codeceptjs/core_test.js +217 -0
- package/tests/codeceptjs/editors/advanced_test.js +13 -0
- package/tests/codeceptjs/editors/array_any_of_test.js +50 -0
- package/tests/codeceptjs/editors/array_test.js +900 -0
- package/tests/codeceptjs/editors/button_test.js +35 -0
- package/tests/codeceptjs/editors/checkbox_test.js +21 -0
- package/tests/codeceptjs/editors/colorpicker_test.js +27 -0
- package/tests/codeceptjs/editors/datetime_test.js +33 -0
- package/tests/codeceptjs/editors/inheritance_test.js +11 -0
- package/tests/codeceptjs/editors/integer_test.js +84 -0
- package/tests/codeceptjs/editors/issues/issue-gh-812_test.js +32 -0
- package/tests/codeceptjs/editors/jodit_test.js +24 -0
- package/tests/codeceptjs/editors/multiselect_test.js +8 -0
- package/tests/codeceptjs/editors/number_test.js +82 -0
- package/tests/codeceptjs/editors/object_test.js +204 -0
- package/tests/codeceptjs/editors/option-no_default_values_test.js +42 -0
- package/tests/codeceptjs/editors/programmatic-changes_test.js +20 -0
- package/tests/codeceptjs/editors/radio_test.js +10 -0
- package/tests/codeceptjs/editors/rating_test.js +13 -0
- package/tests/codeceptjs/editors/select_test.js +22 -0
- package/tests/codeceptjs/editors/stepper_test.js +27 -0
- package/tests/codeceptjs/editors/string_test.js +118 -0
- package/tests/codeceptjs/editors/table-confirm-delete_test.js +67 -0
- package/tests/codeceptjs/editors/tabs_test.js +14 -0
- package/tests/codeceptjs/editors/uuid_test.js +21 -0
- package/tests/codeceptjs/editors/validation_test.js +14 -0
- package/tests/codeceptjs/meta-schema_test.js +17 -0
- package/tests/codeceptjs/schemaloader_test.js +13 -0
- package/tests/codeceptjs/steps.d.ts +13 -0
- package/tests/codeceptjs/steps_file.js +12 -0
- package/tests/codeceptjs/themes_test.js +519 -0
- package/tests/docker-compose.yml +34 -0
- package/tests/fixtures/basic_person.json +26 -0
- package/tests/fixtures/nested_object.json +26 -0
- package/tests/fixtures/person.json +55 -0
- package/tests/fixtures/recursive.json +8 -0
- package/tests/fixtures/some_types.json +32 -0
- package/tests/fixtures/string.json +3 -0
- package/tests/fixtures/validation.json +1140 -0
- package/tests/pages/_demo.html +475 -0
- package/tests/pages/advanced.html +137 -0
- package/tests/pages/anyof.html +80 -0
- package/tests/pages/array-anyof.html +142 -0
- package/tests/pages/array-checkboxes.html +41 -0
- package/tests/pages/array-choices.html +45 -0
- package/tests/pages/array-integers.html +37 -0
- package/tests/pages/array-move-events.html +61 -0
- package/tests/pages/array-multiselects.html +42 -0
- package/tests/pages/array-nested-arrays.html +40 -0
- package/tests/pages/array-numbers.html +37 -0
- package/tests/pages/array-objects.html +42 -0
- package/tests/pages/array-ratings.html +40 -0
- package/tests/pages/array-selectize.html +51 -0
- package/tests/pages/array-selects.html +36 -0
- package/tests/pages/array-strings.html +36 -0
- package/tests/pages/array.html +42 -0
- package/tests/pages/assets/pages.css +130 -0
- package/tests/pages/button-callbacks.html +77 -0
- package/tests/pages/checkbox-labels.html +114 -0
- package/tests/pages/colorpicker-no-3rd-party.html +43 -0
- package/tests/pages/colorpicker-use-vanilla-picker.html +50 -0
- package/tests/pages/core.html +118 -0
- package/tests/pages/datetime.html +76 -0
- package/tests/pages/form-name.html +108 -0
- package/tests/pages/grid-strict.html +311 -0
- package/tests/pages/grid.html +284 -0
- package/tests/pages/if-then-else-allOf.html +117 -0
- package/tests/pages/inheritance.html +76 -0
- package/tests/pages/integer.html +68 -0
- package/tests/pages/issues/_template.html +50 -0
- package/tests/pages/issues/issue-gh-812.html +110 -0
- package/tests/pages/issues/issue-gh-823-meta-schema.html +35 -0
- package/tests/pages/issues/issue-gh-848.html +81 -0
- package/tests/pages/meta_schema.json +705 -0
- package/tests/pages/number.html +89 -0
- package/tests/pages/object-no-additional-properties.html +65 -0
- package/tests/pages/object-no-duplicated-id.html +68 -0
- package/tests/pages/object-required-properties.html +236 -0
- package/tests/pages/object-with-dependencies-array.html +46 -0
- package/tests/pages/object-with-dependencies.html +60 -0
- package/tests/pages/object.html +79 -0
- package/tests/pages/oneof.html +103 -0
- package/tests/pages/option-no_default_values.html +58 -0
- package/tests/pages/programmatic-changes.html +120 -0
- package/tests/pages/read-only.html +105 -0
- package/tests/pages/select.html +41 -0
- package/tests/pages/stepper.html +59 -0
- package/tests/pages/string-ace-editor.html +52 -0
- package/tests/pages/string-cleave.html +46 -0
- package/tests/pages/string-custom-attributes.html +62 -0
- package/tests/pages/string-formats.html +52 -0
- package/tests/pages/string-formats2.html +57 -0
- package/tests/pages/string-jodit-editor.html +49 -0
- package/tests/pages/string-sceditor.html +62 -0
- package/tests/pages/table-move-events.html +56 -0
- package/tests/pages/table.html +46 -0
- package/tests/pages/tabs.html +131 -0
- package/tests/pages/themes.html +527 -0
- package/tests/pages/translate-property.html +247 -0
- package/tests/pages/urn.html +93 -0
- package/tests/pages/uuid.html +72 -0
- package/tests/pages/validation.html +99 -0
- package/tests/unit/.eslintrc +8 -0
- package/tests/unit/core.spec.js +309 -0
- package/tests/unit/defaults.spec.js +40 -0
- package/tests/unit/editor.spec.js +160 -0
- package/tests/unit/editors/array.spec.js +86 -0
- package/tests/unit/editors/object.spec.js +79 -0
- package/tests/unit/editors/table.spec.js +91 -0
- package/tests/unit/readme.md +35 -0
- package/tests/unit/schemaloader.spec.js +498 -0
- package/tests/unit/validator.spec.js +94 -0
- package/tests/unit/validators/ip-validator.spec.js +62 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { JSONEditor } from '../../../src/core'
|
|
2
|
+
|
|
3
|
+
const fixture = [
|
|
4
|
+
{
|
|
5
|
+
title: 'Table Editor Test',
|
|
6
|
+
schema: {
|
|
7
|
+
type: 'array',
|
|
8
|
+
format: 'table',
|
|
9
|
+
items: {
|
|
10
|
+
type: ['boolean', 'string', 'null', 'number']
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
value: [false]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: 'Table Editor Test',
|
|
17
|
+
schema: {
|
|
18
|
+
type: 'array',
|
|
19
|
+
format: 'table',
|
|
20
|
+
items: {
|
|
21
|
+
type: ['boolean', 'string', 'null', 'number']
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
value: ['']
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
title: 'Table Editor Test',
|
|
28
|
+
schema: {
|
|
29
|
+
type: 'array',
|
|
30
|
+
format: 'table',
|
|
31
|
+
items: {
|
|
32
|
+
type: ['boolean', 'string', 'null', 'number']
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
value: [0]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
title: 'Table Editor Test',
|
|
39
|
+
schema: {
|
|
40
|
+
type: 'array',
|
|
41
|
+
format: 'table',
|
|
42
|
+
items: {
|
|
43
|
+
type: 'string'
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
options: {
|
|
47
|
+
use_default_values: false
|
|
48
|
+
},
|
|
49
|
+
value: ['']
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
title: 'Table Editor Test',
|
|
53
|
+
schema: {
|
|
54
|
+
type: 'array',
|
|
55
|
+
format: 'table',
|
|
56
|
+
items: {
|
|
57
|
+
type: 'number'
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
options: {
|
|
61
|
+
use_default_values: false
|
|
62
|
+
},
|
|
63
|
+
value: [0]
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
describe('Table Editor', () => {
|
|
68
|
+
let element
|
|
69
|
+
let editor
|
|
70
|
+
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
document.body.insertAdjacentHTML(
|
|
73
|
+
'afterbegin',
|
|
74
|
+
'<div id="fixture"></div>')
|
|
75
|
+
element = document.getElementById('fixture')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
editor.destroy()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
fixture.forEach(spec => {
|
|
83
|
+
it(spec.title, () => {
|
|
84
|
+
editor = new JSONEditor(element, {
|
|
85
|
+
schema: spec.schema
|
|
86
|
+
})
|
|
87
|
+
editor.setValue(spec.value);
|
|
88
|
+
expect(editor.getValue()).toEqual(spec.value)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Unit Tests
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
Unit tests are implemented using the [Jasmine](https://jasmine.github.io/) framework.
|
|
6
|
+
|
|
7
|
+
## Karma Test Runner
|
|
8
|
+
|
|
9
|
+
### Running
|
|
10
|
+
|
|
11
|
+
You can continuously watch and debug unit tests using:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm run test
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The browser will start and run each unit test in a random sequence, showing the result. If tests are target code is edited, the code will be recompiled and the tests re-run.
|
|
18
|
+
|
|
19
|
+
### Debugging
|
|
20
|
+
|
|
21
|
+
To debug tests click the debug button in the browser - this will allow you to select each test to run in debug mode.
|
|
22
|
+
|
|
23
|
+
You can set breakpoints on the original code by:
|
|
24
|
+
|
|
25
|
+
1. Opening Chrome developer tools
|
|
26
|
+
2. Opening the Sources tab
|
|
27
|
+
3. Expanding the Webpack://./tests/unit/ hierarchy to display your test file
|
|
28
|
+
4. Clicking on the line number to place the breakpoint
|
|
29
|
+
|
|
30
|
+
## File hierarchy
|
|
31
|
+
|
|
32
|
+
Test files should have the same name as their target files but ending with `.spec.js` instead of `.js` and their subpath relative to this directory should be the same as the target file's relative to the `./src/` directory.
|
|
33
|
+
|
|
34
|
+
So a file testing `/src/editors/validator.js` should have the path `./tests/unit/editors/validator.spec.js`
|
|
35
|
+
|
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
/* global describe beforeEach it expect */
|
|
2
|
+
|
|
3
|
+
import { SchemaLoader } from '../../src/schemaloader'
|
|
4
|
+
import { createFakeServer } from 'sinon'
|
|
5
|
+
|
|
6
|
+
describe('SchemaLoader', () => {
|
|
7
|
+
let loader
|
|
8
|
+
let fileBase
|
|
9
|
+
let fetchUrl
|
|
10
|
+
|
|
11
|
+
describe('when no external ref', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
fetchUrl =
|
|
14
|
+
document.location.origin + document.location.pathname.toString()
|
|
15
|
+
loader = new SchemaLoader()
|
|
16
|
+
fileBase = loader._getFileBase(document.location.toString())
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('should create a loader', () => {
|
|
20
|
+
expect(loader).toBeTruthy()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('load schema without $ref', () => {
|
|
24
|
+
const schema = {
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: {
|
|
27
|
+
name: { type: 'string' }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
loader.load(schema, schema => {}, fetchUrl, fileBase)
|
|
31
|
+
const urls = Object.keys(loader.refs)
|
|
32
|
+
expect(urls.length).toEqual(0)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('load schema with $ref', () => {
|
|
36
|
+
const schema = {
|
|
37
|
+
definitions: {
|
|
38
|
+
name: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
minLength: 4
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
fname: { $ref: '#/definitions/name' },
|
|
46
|
+
lname: { $ref: '#/definitions/name' }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
loader.load(schema, schema => {}, fetchUrl, fileBase)
|
|
50
|
+
const urls = Object.keys(loader.refs)
|
|
51
|
+
expect(urls.length).toEqual(1)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('load schema with urn: $ref', () => {
|
|
55
|
+
const schema = {
|
|
56
|
+
definitions: {
|
|
57
|
+
fname: {
|
|
58
|
+
id: 'urn:fname',
|
|
59
|
+
type: 'string',
|
|
60
|
+
default: 'John',
|
|
61
|
+
minLength: 4
|
|
62
|
+
},
|
|
63
|
+
lname: {
|
|
64
|
+
$id: 'urn:lname',
|
|
65
|
+
type: 'string',
|
|
66
|
+
default: 'Doe',
|
|
67
|
+
minLength: 4
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
fname: { $ref: 'urn:fname' },
|
|
73
|
+
lname: { $ref: 'urn:lname' }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
loader.load(schema, schema => {}, fetchUrl, fileBase)
|
|
77
|
+
const urls = Object.keys(loader.refs)
|
|
78
|
+
expect(urls.length).toEqual(4)
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
describe('when external absolute ref exists', () => {
|
|
83
|
+
it('should set oprion { ajax: true }', done => {
|
|
84
|
+
const response = {
|
|
85
|
+
type: 'string',
|
|
86
|
+
minLength: 4
|
|
87
|
+
}
|
|
88
|
+
const server = createFakeServer()
|
|
89
|
+
server.autoRespond = true
|
|
90
|
+
window.XMLHttpRequest = server.xhr
|
|
91
|
+
server.respondWith('/string.json', [
|
|
92
|
+
200,
|
|
93
|
+
{ 'Content-Type': 'application/json' },
|
|
94
|
+
JSON.stringify(response)
|
|
95
|
+
])
|
|
96
|
+
fetchUrl =
|
|
97
|
+
document.location.origin + document.location.pathname.toString()
|
|
98
|
+
loader = new SchemaLoader({ ajax: true })
|
|
99
|
+
fileBase = loader._getFileBase(document.location.toString())
|
|
100
|
+
|
|
101
|
+
const schema = {
|
|
102
|
+
type: 'object',
|
|
103
|
+
properties: {
|
|
104
|
+
fname: { $ref: '/string.json' },
|
|
105
|
+
lname: { $ref: '/string.json' }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
loader.load(
|
|
109
|
+
schema,
|
|
110
|
+
schema => {
|
|
111
|
+
const urls = Object.keys(loader.refs)
|
|
112
|
+
expect(urls.length).toEqual(1)
|
|
113
|
+
done()
|
|
114
|
+
server.restore()
|
|
115
|
+
},
|
|
116
|
+
fetchUrl,
|
|
117
|
+
fileBase
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('when external relative $ref exists', () => {
|
|
123
|
+
it('should set oprion { ajax: true }', done => {
|
|
124
|
+
const response = {
|
|
125
|
+
type: 'string',
|
|
126
|
+
minLength: 4
|
|
127
|
+
}
|
|
128
|
+
const server = createFakeServer()
|
|
129
|
+
server.autoRespond = true
|
|
130
|
+
window.XMLHttpRequest = server.xhr
|
|
131
|
+
server.respondWith('/string.json', [
|
|
132
|
+
200,
|
|
133
|
+
{ 'Content-Type': 'application/json' },
|
|
134
|
+
JSON.stringify(response)
|
|
135
|
+
])
|
|
136
|
+
fetchUrl =
|
|
137
|
+
document.location.origin + document.location.pathname.toString()
|
|
138
|
+
loader = new SchemaLoader({ ajax: true })
|
|
139
|
+
fileBase = loader._getFileBase(document.location.toString())
|
|
140
|
+
|
|
141
|
+
const schema = {
|
|
142
|
+
type: 'object',
|
|
143
|
+
properties: {
|
|
144
|
+
fname: { $ref: 'string.json' },
|
|
145
|
+
lname: { $ref: 'string.json' }
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
loader.load(
|
|
149
|
+
schema,
|
|
150
|
+
schema => {
|
|
151
|
+
const urls = Object.keys(loader.refs)
|
|
152
|
+
expect(urls.length).toEqual(1)
|
|
153
|
+
done()
|
|
154
|
+
server.restore()
|
|
155
|
+
},
|
|
156
|
+
fetchUrl,
|
|
157
|
+
fileBase
|
|
158
|
+
)
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe('when external absolute-to-relative $ref exists', () => {
|
|
163
|
+
it('can get refs recursively', done => {
|
|
164
|
+
const schema1 = {
|
|
165
|
+
type: 'object',
|
|
166
|
+
properties: {
|
|
167
|
+
fname: { $ref: '/schema/main.json' },
|
|
168
|
+
lname: { $ref: '/schema/main.json' }
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const schema2 = {
|
|
172
|
+
$ref: 'registry/sub.json'
|
|
173
|
+
}
|
|
174
|
+
const schema3 = {
|
|
175
|
+
type: 'string',
|
|
176
|
+
minLength: 4
|
|
177
|
+
}
|
|
178
|
+
const server = createFakeServer()
|
|
179
|
+
server.autoRespond = true
|
|
180
|
+
window.XMLHttpRequest = server.xhr
|
|
181
|
+
server.respondWith('/schema/main.json', [
|
|
182
|
+
200,
|
|
183
|
+
{ 'Content-Type': 'application/json' },
|
|
184
|
+
JSON.stringify(schema2)
|
|
185
|
+
])
|
|
186
|
+
server.respondWith('/schema/registry/sub.json', [
|
|
187
|
+
200,
|
|
188
|
+
{ 'Content-Type': 'application/json' },
|
|
189
|
+
JSON.stringify(schema3)
|
|
190
|
+
])
|
|
191
|
+
fetchUrl =
|
|
192
|
+
document.location.origin + document.location.pathname.toString()
|
|
193
|
+
loader = new SchemaLoader({ ajax: true })
|
|
194
|
+
fileBase = loader._getFileBase(document.location.toString())
|
|
195
|
+
loader.load(
|
|
196
|
+
schema1,
|
|
197
|
+
schema => {
|
|
198
|
+
expect(Object.keys(loader.refs).length).toBe(2)
|
|
199
|
+
done()
|
|
200
|
+
server.restore()
|
|
201
|
+
},
|
|
202
|
+
fetchUrl,
|
|
203
|
+
fileBase
|
|
204
|
+
)
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
describe('when external relative-to-relative $ref exists', () => {
|
|
209
|
+
it('can get refs recursively', done => {
|
|
210
|
+
const schema1 = {
|
|
211
|
+
type: 'object',
|
|
212
|
+
properties: {
|
|
213
|
+
fname: { $ref: 'schema/main.json' },
|
|
214
|
+
lname: { $ref: 'schema/main.json' }
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const schema2 = {
|
|
218
|
+
$ref: 'registry/sub.json'
|
|
219
|
+
}
|
|
220
|
+
const schema3 = {
|
|
221
|
+
type: 'string',
|
|
222
|
+
minLength: 4
|
|
223
|
+
}
|
|
224
|
+
const server = createFakeServer()
|
|
225
|
+
server.autoRespond = true
|
|
226
|
+
window.XMLHttpRequest = server.xhr
|
|
227
|
+
server.respondWith('/schema/main.json', [
|
|
228
|
+
200,
|
|
229
|
+
{ 'Content-Type': 'application/json' },
|
|
230
|
+
JSON.stringify(schema2)
|
|
231
|
+
])
|
|
232
|
+
server.respondWith('/schema/registry/sub.json', [
|
|
233
|
+
200,
|
|
234
|
+
{ 'Content-Type': 'application/json' },
|
|
235
|
+
JSON.stringify(schema3)
|
|
236
|
+
])
|
|
237
|
+
fetchUrl =
|
|
238
|
+
document.location.origin + document.location.pathname.toString()
|
|
239
|
+
loader = new SchemaLoader({ ajax: true })
|
|
240
|
+
fileBase = loader._getFileBase(document.location.toString())
|
|
241
|
+
loader.load(
|
|
242
|
+
schema1,
|
|
243
|
+
schema => {
|
|
244
|
+
console.log(loader.refs)
|
|
245
|
+
expect(Object.keys(loader.refs).length).toBe(2)
|
|
246
|
+
done()
|
|
247
|
+
server.restore()
|
|
248
|
+
},
|
|
249
|
+
fetchUrl,
|
|
250
|
+
fileBase
|
|
251
|
+
)
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
describe('when external absolute $ref with json pointer exists', () => {
|
|
256
|
+
it('can get refs', done => {
|
|
257
|
+
const schema1 = {
|
|
258
|
+
type: 'object',
|
|
259
|
+
properties: {
|
|
260
|
+
'test-1': { $ref: '/common.schema.json#' },
|
|
261
|
+
'test-2': { $ref: '/common.schema.json#/definitions/known-product' },
|
|
262
|
+
'test-3': {
|
|
263
|
+
type: 'object',
|
|
264
|
+
properties: {
|
|
265
|
+
Product: { $ref: '/common.schema.json#/definitions/known-product' }
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const schema2 = {
|
|
271
|
+
definitions: {
|
|
272
|
+
'known-product': {
|
|
273
|
+
title: 'product',
|
|
274
|
+
type: 'string',
|
|
275
|
+
enum: [ 'power', 'hydrogen', 'heat' ]
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
title: 'test',
|
|
279
|
+
properties: {
|
|
280
|
+
customer: { type: 'string' },
|
|
281
|
+
product: { $ref: '#/definitions/known-product' }
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const server = createFakeServer()
|
|
285
|
+
server.autoRespond = true
|
|
286
|
+
window.XMLHttpRequest = server.xhr
|
|
287
|
+
server.respondWith('/common.schema.json', [
|
|
288
|
+
200,
|
|
289
|
+
{ 'Content-Type': 'application/json' },
|
|
290
|
+
JSON.stringify(schema2)
|
|
291
|
+
])
|
|
292
|
+
fetchUrl =
|
|
293
|
+
document.location.origin + document.location.pathname.toString()
|
|
294
|
+
loader = new SchemaLoader({ ajax: true })
|
|
295
|
+
fileBase = loader._getFileBase(document.location.toString())
|
|
296
|
+
loader.load(
|
|
297
|
+
schema1,
|
|
298
|
+
schema => {
|
|
299
|
+
console.log(loader.refs)
|
|
300
|
+
expect(Object.keys(loader.refs).length).toBe(2)
|
|
301
|
+
done()
|
|
302
|
+
server.restore()
|
|
303
|
+
},
|
|
304
|
+
fetchUrl,
|
|
305
|
+
fileBase
|
|
306
|
+
)
|
|
307
|
+
})
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
describe('when external relative $ref with json pointer exists', () => {
|
|
311
|
+
it('can get refs', done => {
|
|
312
|
+
const schema1 = {
|
|
313
|
+
type: 'object',
|
|
314
|
+
properties: {
|
|
315
|
+
'test-1': { $ref: 'common.schema.json#' },
|
|
316
|
+
'test-2': { $ref: 'common.schema.json#/definitions/known-product' },
|
|
317
|
+
'test-3': {
|
|
318
|
+
type: 'object',
|
|
319
|
+
properties: {
|
|
320
|
+
Product: { $ref: 'common.schema.json#/definitions/known-product' }
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const schema2 = {
|
|
326
|
+
definitions: {
|
|
327
|
+
'known-product': {
|
|
328
|
+
title: 'product',
|
|
329
|
+
type: 'string',
|
|
330
|
+
enum: [ 'power', 'hydrogen', 'heat' ]
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
title: 'test',
|
|
334
|
+
properties: {
|
|
335
|
+
customer: { type: 'string' },
|
|
336
|
+
product: { $ref: '#/definitions/known-product' }
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const server = createFakeServer()
|
|
340
|
+
server.autoRespond = true
|
|
341
|
+
window.XMLHttpRequest = server.xhr
|
|
342
|
+
server.respondWith('/common.schema.json', [
|
|
343
|
+
200,
|
|
344
|
+
{ 'Content-Type': 'application/json' },
|
|
345
|
+
JSON.stringify(schema2)
|
|
346
|
+
])
|
|
347
|
+
fetchUrl =
|
|
348
|
+
document.location.origin + document.location.pathname.toString()
|
|
349
|
+
loader = new SchemaLoader({ ajax: true })
|
|
350
|
+
fileBase = loader._getFileBase(document.location.toString())
|
|
351
|
+
loader.load(
|
|
352
|
+
schema1,
|
|
353
|
+
schema => {
|
|
354
|
+
console.log(loader.refs)
|
|
355
|
+
expect(Object.keys(loader.refs).length).toBe(2)
|
|
356
|
+
done()
|
|
357
|
+
server.restore()
|
|
358
|
+
},
|
|
359
|
+
fetchUrl,
|
|
360
|
+
fileBase
|
|
361
|
+
)
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
describe('when external ref exists with json pointer', () => {
|
|
366
|
+
it('should get ref and resolve json pointer', done => {
|
|
367
|
+
const response = {
|
|
368
|
+
definitions: {
|
|
369
|
+
fruits: {
|
|
370
|
+
enum: [
|
|
371
|
+
'apple',
|
|
372
|
+
'banana',
|
|
373
|
+
'cherry'
|
|
374
|
+
]
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const server = createFakeServer()
|
|
379
|
+
server.autoRespond = true
|
|
380
|
+
window.XMLHttpRequest = server.xhr
|
|
381
|
+
server.respondWith([
|
|
382
|
+
200,
|
|
383
|
+
{ 'Content-Type': 'application/json' },
|
|
384
|
+
JSON.stringify(response)
|
|
385
|
+
])
|
|
386
|
+
fetchUrl =
|
|
387
|
+
document.location.origin + document.location.pathname.toString()
|
|
388
|
+
loader = new SchemaLoader({ ajax: true })
|
|
389
|
+
fileBase = loader._getFileBase(document.location.toString())
|
|
390
|
+
|
|
391
|
+
const schema = {
|
|
392
|
+
type: 'object',
|
|
393
|
+
properties: {
|
|
394
|
+
fruits: { $ref: '/fruits.json#/definitions/fruits' }
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
loader.load(
|
|
398
|
+
schema,
|
|
399
|
+
schema => {
|
|
400
|
+
const urls = Object.keys(loader.refs)
|
|
401
|
+
expect(urls.length).toEqual(1)
|
|
402
|
+
expect(urls[0]).toEqual('/fruits.json#/definitions/fruits')
|
|
403
|
+
expect(loader.refs['/fruits.json#/definitions/fruits']).toEqual({ enum: ['apple', 'banana', 'cherry'] })
|
|
404
|
+
done()
|
|
405
|
+
server.restore()
|
|
406
|
+
},
|
|
407
|
+
fetchUrl,
|
|
408
|
+
fileBase
|
|
409
|
+
)
|
|
410
|
+
})
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
describe('when resolving undeclared URN $ref', () => {
|
|
414
|
+
it('can get refs recursively', done => {
|
|
415
|
+
const schema1 = {
|
|
416
|
+
type: 'object',
|
|
417
|
+
properties: {
|
|
418
|
+
fname: { $ref: 'urn:main' },
|
|
419
|
+
lname: { $ref: 'urn:sub' }
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const schema2 = {
|
|
423
|
+
definitions: {
|
|
424
|
+
name: {
|
|
425
|
+
id: 'urn:main',
|
|
426
|
+
$ref: 'urn:sub'
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const schema3 = {
|
|
431
|
+
definitions: {
|
|
432
|
+
name: {
|
|
433
|
+
$id: 'urn:sub',
|
|
434
|
+
type: 'string',
|
|
435
|
+
default: 'Waldo',
|
|
436
|
+
minLength: 4
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
loader = new SchemaLoader({ urn_resolver: (urn, callback) => {
|
|
441
|
+
if (urn === 'urn:main') {
|
|
442
|
+
callback(JSON.stringify(schema2))
|
|
443
|
+
return true
|
|
444
|
+
}
|
|
445
|
+
if (urn === 'urn:sub') {
|
|
446
|
+
callback(JSON.stringify(schema3))
|
|
447
|
+
return true
|
|
448
|
+
}
|
|
449
|
+
return false
|
|
450
|
+
}})
|
|
451
|
+
loader.load(
|
|
452
|
+
schema1,
|
|
453
|
+
schema => {
|
|
454
|
+
console.log(loader.refs_with_info)
|
|
455
|
+
expect(Object.keys(loader.refs).length).toBe(4)
|
|
456
|
+
done()
|
|
457
|
+
}
|
|
458
|
+
)
|
|
459
|
+
})
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
describe('when resolving undeclared URN $ref with fragment', () => {
|
|
463
|
+
it('can get refs recursively', done => {
|
|
464
|
+
const schema1 = {
|
|
465
|
+
type: 'object',
|
|
466
|
+
properties: {
|
|
467
|
+
fname: { $ref: 'urn:main#/definitions/name' },
|
|
468
|
+
lname: { $ref: 'urn:main#/definitions/name' }
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const schema2 = {
|
|
472
|
+
definitions: {
|
|
473
|
+
name: {
|
|
474
|
+
$id: 'urn:main',
|
|
475
|
+
type: 'string',
|
|
476
|
+
default: 'Waldo',
|
|
477
|
+
minLength: 4
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
loader = new SchemaLoader({ urn_resolver: (urn, callback) => {
|
|
482
|
+
if (urn === 'urn:main') {
|
|
483
|
+
callback(JSON.stringify(schema2))
|
|
484
|
+
return true
|
|
485
|
+
}
|
|
486
|
+
return false
|
|
487
|
+
}})
|
|
488
|
+
loader.load(
|
|
489
|
+
schema1,
|
|
490
|
+
schema => {
|
|
491
|
+
console.log(loader.refs_with_info)
|
|
492
|
+
expect(Object.keys(loader.refs).length).toBe(2)
|
|
493
|
+
done()
|
|
494
|
+
}
|
|
495
|
+
)
|
|
496
|
+
})
|
|
497
|
+
})
|
|
498
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* global describe beforeAll beforeEach afterEach afterAll it expect */
|
|
2
|
+
|
|
3
|
+
import { JSONEditor } from '../../src/core'
|
|
4
|
+
import { Validator } from '../../src/validator'
|
|
5
|
+
import { defaults } from '../../src/defaults'
|
|
6
|
+
import fixture from '../fixtures/validation.json'
|
|
7
|
+
import fixtureString from '../fixtures/string.json'
|
|
8
|
+
import fixtureRecursive from '../fixtures/recursive.json'
|
|
9
|
+
import * as math from 'mathjs'
|
|
10
|
+
import { createFakeServer } from 'sinon'
|
|
11
|
+
|
|
12
|
+
describe('Validator', () => {
|
|
13
|
+
it('mathjs test', () => {
|
|
14
|
+
window.math = math
|
|
15
|
+
expect(window.math.mod(window.math.bignumber(1), window.math.bignumber(0.01))).toEqual(window.math.bignumber(0))
|
|
16
|
+
})
|
|
17
|
+
it('should exist', () => {
|
|
18
|
+
expect(Validator).toBeTruthy()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
describe('Constructor()', () => {
|
|
22
|
+
it('should create a new object', () => {
|
|
23
|
+
const jsonEditor = {}
|
|
24
|
+
const schema = {}
|
|
25
|
+
const options = {}
|
|
26
|
+
const instance = new Validator(jsonEditor, schema, options, defaults)
|
|
27
|
+
expect(instance).toBeTruthy()
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
describe('Validation Test', () => {
|
|
33
|
+
let element
|
|
34
|
+
let server
|
|
35
|
+
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
server = createFakeServer()
|
|
38
|
+
server.autoRespond = true
|
|
39
|
+
window.XMLHttpRequest = server.xhr
|
|
40
|
+
const response = {
|
|
41
|
+
string: fixtureString,
|
|
42
|
+
recursive: fixtureRecursive
|
|
43
|
+
}
|
|
44
|
+
server.respondWith(/(\w+)\.json/, (xhr, name) => {
|
|
45
|
+
xhr.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(response[name]))
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
afterAll(() => {
|
|
50
|
+
server.restore()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
window.math = math
|
|
55
|
+
document.body.insertAdjacentHTML(
|
|
56
|
+
'afterbegin',
|
|
57
|
+
'<div id="fixture"></div>')
|
|
58
|
+
element = document.getElementById('fixture')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
Object.entries(fixture).forEach(([subject, spec]) => {
|
|
62
|
+
describe(subject, () => {
|
|
63
|
+
let editor
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
editor = new JSONEditor(element, {
|
|
66
|
+
schema: spec.schema,
|
|
67
|
+
ajax: true
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
afterEach(() => {
|
|
72
|
+
editor.destroy()
|
|
73
|
+
})
|
|
74
|
+
spec.valid.forEach((v, i) => {
|
|
75
|
+
it(`valid data ${i + 1}`, (done) => {
|
|
76
|
+
editor.on('ready', () => {
|
|
77
|
+
const result = editor.validate(v)
|
|
78
|
+
expect(result.length).toBe(0)
|
|
79
|
+
done()
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
spec.invalid.forEach((v, i) => {
|
|
84
|
+
it(`invalid data ${i + 1}`, (done) => {
|
|
85
|
+
editor.on('ready', () => {
|
|
86
|
+
const result = editor.validate(v)
|
|
87
|
+
expect(result.length).toBeGreaterThan(0)
|
|
88
|
+
done()
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
})
|