Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
nacmartin committed Dec 1, 2017
1 parent 802c30e commit 1b53a4d
Show file tree
Hide file tree
Showing 57 changed files with 2,488 additions and 2,298 deletions.
170 changes: 92 additions & 78 deletions src/__tests__/buildSyncValidation.spec.js
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");
});
});
45 changes: 21 additions & 24 deletions src/__tests__/compileSchema.spec.js
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");
});
});
136 changes: 64 additions & 72 deletions src/__tests__/createLiformSpec.spec.js
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);
});
});
Loading

0 comments on commit 1b53a4d

Please sign in to comment.