Skip to content

Commit 4238d6b

Browse files
committed
deps and used jest for testing
1 parent 7703aec commit 4238d6b

20 files changed

+1079
-1087
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"extends": "airbnb",
33
"parser": "babel-eslint",
4-
"rules": {
4+
"globals": {
5+
"it": true,
6+
"expect": true,
7+
"describe": true
58
}
69
}

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ node_js:
33
- iojs
44
- "4"
55
- "5"
6+
- "6"
67
script: npm test
78
notifications:
89
email:
910
recipients:
10-
- zlatkofedor@cherrysro.com
11+
- zlatkofedor@cherryprojects.com
1112
on_success: change
1213
on_failure: always
13-
14-
after_script:
15-
- ./node_modules/.bin/babel-node ./node_modules/.bin/gulp coveralls

__tests__/Array.jsx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
import Form from '../src';
4+
5+
describe('Up', () => {
6+
it('should be able to move item in array', (done) => {
7+
const value = {
8+
items: [1, 2, 3],
9+
};
10+
11+
function onChange(state) {
12+
expect(state.items).toEqual([1, 3, 2]);
13+
done();
14+
}
15+
16+
const wrapper = mount((
17+
<Form value={value} onChange={onChange}>
18+
<fieldset name="items">
19+
<input name="." />
20+
<button type="button" up>Up</button>
21+
</fieldset>
22+
</Form>
23+
));
24+
25+
expect(wrapper.find('input').first().props().value).toBe(1);
26+
27+
wrapper.find('button').last().simulate('click');
28+
});
29+
});
30+
31+
describe('Down', () => {
32+
it('should be able to move item in array', (done) => {
33+
const value = {
34+
items: [1, 2, 3],
35+
};
36+
37+
function onChange(state) {
38+
expect(state.items).toEqual([2, 1, 3]);
39+
done();
40+
}
41+
42+
const wrapper = mount((
43+
<Form value={value} onChange={onChange}>
44+
<fieldset name="items">
45+
<input name="." />
46+
<button type="button" down>Down</button>
47+
</fieldset>
48+
</Form>
49+
));
50+
51+
expect(wrapper.find('input').first().props().value).toBe(1);
52+
53+
wrapper.find('button').first().simulate('click');
54+
});
55+
});
56+
57+
describe('Remove', () => {
58+
it('should be able to move item in array', (done) => {
59+
const value = {
60+
items: [1, 2, 3],
61+
};
62+
63+
function onChange(state) {
64+
expect(state.items).toEqual([2, 3]);
65+
done();
66+
}
67+
68+
const wrapper = mount((
69+
<Form value={value} onChange={onChange}>
70+
<fieldset name="items">
71+
<input name="." />
72+
<button type="button" remove>Remove</button>
73+
</fieldset>
74+
</Form>
75+
));
76+
77+
wrapper.find('button').first().simulate('click');
78+
});
79+
});

__tests__/ErrorAlert.jsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
import Form, {
4+
ErrorAlert,
5+
} from '../src';
6+
7+
describe('ErrorAlert', () => {
8+
it('should be able to create simple instance', (done) => {
9+
const value = {
10+
firstName: 'Zlatko',
11+
};
12+
13+
const schema = {
14+
type: 'object',
15+
properties: {
16+
firstName: {
17+
type: 'string',
18+
},
19+
},
20+
required: ['firstName'],
21+
};
22+
23+
function onSubmit(state) {
24+
expect(state.firstName).toBe('Zlatko');
25+
done();
26+
}
27+
28+
const wrapper = mount((
29+
<Form value={value} schema={schema} onSubmit={onSubmit}>
30+
<input name="firstName" />
31+
<ErrorAlert name="firstName" />
32+
<button type="submit">Submit</button>
33+
</Form>
34+
));
35+
36+
expect(wrapper.find('form').length).toBe(1);
37+
wrapper.find('[type="submit"]').get(0).click();
38+
});
39+
40+
it('should be able to create simple error instance', (done) => {
41+
const value = {
42+
firstName: undefined,
43+
};
44+
45+
const schema = {
46+
type: 'object',
47+
properties: {
48+
firstName: {
49+
type: 'string',
50+
},
51+
},
52+
required: ['firstName'],
53+
};
54+
55+
function onError(errors) {
56+
expect(errors.length).toBe(1);
57+
}
58+
59+
function onSubmit() {
60+
throw new Error('On submit was called');
61+
}
62+
63+
const wrapper = mount((
64+
<Form
65+
value={value}
66+
schema={schema}
67+
onSubmit={onSubmit}
68+
onError={onError}
69+
>
70+
<input name="firstName" />
71+
<ErrorAlert name="firstName" />
72+
<button type="submit">Submit</button>
73+
</Form>
74+
));
75+
76+
expect(wrapper.find('form').length).toBe(1);
77+
wrapper.find('[type="submit"]').get(0).click();
78+
79+
setTimeout(() => {
80+
expect(wrapper.find('.alert').text()).toBe('should have required property \'firstName\'');
81+
done();
82+
}, 0);
83+
});
84+
});

0 commit comments

Comments
 (0)