-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
2,488 additions
and
2,298 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,101 @@ | ||
import expect from 'expect' | ||
import buildSyncValidation, { setError } from '../buildSyncValidation.js' | ||
import Ajv from 'ajv' | ||
import expect from "expect"; | ||
import buildSyncValidation, { setError } from "../buildSyncValidation.js"; | ||
import Ajv from "ajv"; | ||
|
||
describe('sync validation', () => { | ||
|
||
it('Works with basic objects', () => { | ||
let schema = { | ||
properties: { | ||
name : { | ||
type: 'string', | ||
minLength: 3, | ||
}, | ||
}, | ||
required:["name"] | ||
describe("sync validation", () => { | ||
it("Works with basic objects", () => { | ||
let schema = { | ||
properties: { | ||
name: { | ||
type: "string", | ||
minLength: 3 | ||
} | ||
}, | ||
required: ["name"] | ||
}; | ||
|
||
let values = {} | ||
let errors = buildSyncValidation(schema)(values) | ||
expect(errors).toBeA('object').toIncludeKey('name') | ||
}) | ||
it('Errors on arrays are in _error key of the array', () => { | ||
let schema = { | ||
properties: { | ||
columns: { | ||
type: "array", | ||
minItems: 1, | ||
items: { | ||
type: "string" | ||
} | ||
}, | ||
}, | ||
required:["columns"] | ||
let values = {}; | ||
let errors = buildSyncValidation(schema)(values); | ||
expect(errors) | ||
.toBeA("object") | ||
.toIncludeKey("name"); | ||
}); | ||
it("Errors on arrays are in _error key of the array", () => { | ||
let schema = { | ||
properties: { | ||
columns: { | ||
type: "array", | ||
minItems: 1, | ||
items: { | ||
type: "string" | ||
} | ||
} | ||
}, | ||
required: ["columns"] | ||
}; | ||
|
||
let values = {} | ||
let errors = buildSyncValidation(schema)(values) | ||
expect(errors).toBeA('object').toIncludeKey('columns') | ||
expect(errors.columns).toBeA('object').toIncludeKey('_error') | ||
}) | ||
it('Works with array elements', () => { | ||
let schema = { | ||
properties: { | ||
columns: { | ||
type: "array", | ||
minItems: 1, | ||
items: { | ||
type: "string", | ||
minLength: 3 | ||
} | ||
}, | ||
}, | ||
required:["columns"] | ||
let values = {}; | ||
let errors = buildSyncValidation(schema)(values); | ||
expect(errors) | ||
.toBeA("object") | ||
.toIncludeKey("columns"); | ||
expect(errors.columns) | ||
.toBeA("object") | ||
.toIncludeKey("_error"); | ||
}); | ||
it("Works with array elements", () => { | ||
let schema = { | ||
properties: { | ||
columns: { | ||
type: "array", | ||
minItems: 1, | ||
items: { | ||
type: "string", | ||
minLength: 3 | ||
} | ||
} | ||
}, | ||
required: ["columns"] | ||
}; | ||
|
||
let values = {columns: ['a']} | ||
let errors = buildSyncValidation(schema)(values) | ||
expect(errors).toBeA('object').toIncludeKey('columns') | ||
expect(errors.columns).toBeA('object').toIncludeKey('0') | ||
}) | ||
it('Works with several errors', () => { | ||
let schema = { | ||
properties: { | ||
name: { | ||
type: "string", | ||
minLength: 3, | ||
}, | ||
columns: { | ||
type: "array", | ||
minItems: 1, | ||
items: { | ||
type: "string", | ||
minLength: 3 | ||
} | ||
}, | ||
}, | ||
required:["columns", "name"] | ||
let values = { columns: ["a"] }; | ||
let errors = buildSyncValidation(schema)(values); | ||
expect(errors) | ||
.toBeA("object") | ||
.toIncludeKey("columns"); | ||
expect(errors.columns) | ||
.toBeA("object") | ||
.toIncludeKey("0"); | ||
}); | ||
it("Works with several errors", () => { | ||
let schema = { | ||
properties: { | ||
name: { | ||
type: "string", | ||
minLength: 3 | ||
}, | ||
columns: { | ||
type: "array", | ||
minItems: 1, | ||
items: { | ||
type: "string", | ||
minLength: 3 | ||
} | ||
} | ||
}, | ||
required: ["columns", "name"] | ||
}; | ||
|
||
let values = {columns: ['a'], name: 'aa'} | ||
let errors = buildSyncValidation(schema)(values) | ||
expect(errors).toBeA('object').toIncludeKey('columns') | ||
expect(errors).toBeA('object').toIncludeKey('name') | ||
expect(errors.columns).toBeA('object').toIncludeKey('0') | ||
}) | ||
}) | ||
|
||
let values = { columns: ["a"], name: "aa" }; | ||
let errors = buildSyncValidation(schema)(values); | ||
expect(errors) | ||
.toBeA("object") | ||
.toIncludeKey("columns"); | ||
expect(errors) | ||
.toBeA("object") | ||
.toIncludeKey("name"); | ||
expect(errors.columns) | ||
.toBeA("object") | ||
.toIncludeKey("0"); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,27 +1,24 @@ | ||
import expect from 'expect' | ||
import compileSchema from '../compileSchema' | ||
import expect from "expect"; | ||
import compileSchema from "../compileSchema"; | ||
|
||
|
||
describe('createLiform', () => { | ||
const schema = { | ||
definitions: { | ||
nameref: { | ||
type: 'string' | ||
} | ||
}, | ||
title: 'A schema', | ||
properties: { | ||
name : { | ||
'$ref': '#/definitions/nameref', | ||
} | ||
} | ||
describe("createLiform", () => { | ||
const schema = { | ||
definitions: { | ||
nameref: { | ||
type: "string" | ||
} | ||
}, | ||
title: "A schema", | ||
properties: { | ||
name: { | ||
$ref: "#/definitions/nameref" | ||
} | ||
} | ||
}; | ||
|
||
it('should resolve $refs', () => { | ||
|
||
const schemaCompiled = compileSchema(schema) | ||
expect(schemaCompiled.properties.name.type).toExist(); | ||
expect(schemaCompiled.properties.name.type).toEqual('string'); | ||
|
||
}) | ||
}) | ||
it("should resolve $refs", () => { | ||
const schemaCompiled = compileSchema(schema); | ||
expect(schemaCompiled.properties.name.type).toExist(); | ||
expect(schemaCompiled.properties.name.type).toEqual("string"); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,79 +1,71 @@ | ||
import expect from 'expect' | ||
import React from 'react' | ||
import TestUtils from 'react-addons-test-utils' | ||
import Liform, { DefaultTheme } from '../' | ||
import { Provider } from 'react-redux' | ||
import { createStore, combineReducers } from 'redux' | ||
import { reducer as formReducer } from 'redux-form' | ||
import { shallow, mount, render } from 'enzyme' | ||
import { FormFrame } from './test-utils' | ||
import { Field } from 'redux-form' | ||
import sinon from 'sinon' | ||
import expect from "expect"; | ||
import React from "react"; | ||
import TestUtils from "react-addons-test-utils"; | ||
import Liform, { DefaultTheme } from "../"; | ||
import { Provider } from "react-redux"; | ||
import { createStore, combineReducers } from "redux"; | ||
import { reducer as formReducer } from "redux-form"; | ||
import { shallow, mount, render } from "enzyme"; | ||
import { FormFrame } from "./test-utils"; | ||
import { Field } from "redux-form"; | ||
import sinon from "sinon"; | ||
|
||
|
||
|
||
describe('createLiform', () => { | ||
const schema = { | ||
title: 'A schema', | ||
properties: { | ||
'name' : { | ||
type: 'string', | ||
} | ||
} | ||
describe("createLiform", () => { | ||
const schema = { | ||
title: "A schema", | ||
properties: { | ||
name: { | ||
type: "string" | ||
} | ||
} | ||
}; | ||
|
||
//const schemaWrong = { | ||
// title: 'A schema', | ||
// properties: { | ||
// 'name' : { | ||
// type: 'asdf', | ||
// } | ||
// } | ||
//} | ||
|
||
//const schemaWrong = { | ||
// title: 'A schema', | ||
// properties: { | ||
// 'name' : { | ||
// type: 'asdf', | ||
// } | ||
// } | ||
//} | ||
|
||
it('should render a form', () => { | ||
|
||
const Component = ( | ||
<FormFrame> | ||
<Liform schema={schema} /> | ||
</FormFrame> | ||
) | ||
const wrapper = render(Component) | ||
//console.log(render( Component).html()); | ||
expect(wrapper.find('form').length).toEqual(1); | ||
|
||
}) | ||
|
||
it('can pass a context', () => { | ||
const CustomString = field => { | ||
const { fun } = field.context | ||
fun() | ||
return ( | ||
<input {...field.input} className="form-control" type="email"/> | ||
) | ||
} | ||
const CustomWidget = (props) => { | ||
return ( | ||
<Field | ||
component={CustomString} | ||
name={props.fieldName} | ||
context={props.context} | ||
/> | ||
) | ||
} | ||
const myTheme = { ...DefaultTheme, 'string': CustomWidget } | ||
it("should render a form", () => { | ||
const Component = ( | ||
<FormFrame> | ||
<Liform schema={schema} /> | ||
</FormFrame> | ||
); | ||
const wrapper = render(Component); | ||
//console.log(render( Component).html()); | ||
expect(wrapper.find("form").length).toEqual(1); | ||
}); | ||
|
||
let fun = sinon.spy(); | ||
it("can pass a context", () => { | ||
const CustomString = field => { | ||
const { fun } = field.context; | ||
fun(); | ||
return <input {...field.input} className="form-control" type="email" />; | ||
}; | ||
const CustomWidget = props => { | ||
return ( | ||
<Field | ||
component={CustomString} | ||
name={props.fieldName} | ||
context={props.context} | ||
/> | ||
); | ||
}; | ||
const myTheme = { ...DefaultTheme, string: CustomWidget }; | ||
|
||
const Component = ( | ||
<FormFrame> | ||
<Liform schema={schema} context={{fun}} theme={myTheme}/> | ||
</FormFrame> | ||
) | ||
const wrapper = render(Component) | ||
sinon.assert.calledOnce(fun); | ||
expect(wrapper.find('form').length).toEqual(1); | ||
}) | ||
let fun = sinon.spy(); | ||
|
||
}) | ||
const Component = ( | ||
<FormFrame> | ||
<Liform schema={schema} context={{ fun }} theme={myTheme} /> | ||
</FormFrame> | ||
); | ||
const wrapper = render(Component); | ||
sinon.assert.calledOnce(fun); | ||
expect(wrapper.find("form").length).toEqual(1); | ||
}); | ||
}); |
Oops, something went wrong.