This repository has been archived by the owner on Mar 9, 2018. It is now read-only.
/
create-new-form.js
104 lines (74 loc) · 2.69 KB
/
create-new-form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
const Code = require('code');
const Lab = require('lab');
const Proxyquire = require('proxyquire');
const React = require('react');
const ReactDOM = require('react-dom');
const ReactTestUtils = require('react-dom/test-utils');
const lab = exports.lab = Lab.script();
const stub = {
Actions: {}
};
const Form = Proxyquire('../../../../../../client/pages/admin/admins/search/create-new-form.jsx', {
'./actions': stub.Actions
});
const defaultProps = {
ref: function () {
if (defaultProps.ref.impl) {
defaultProps.ref.impl.apply(null, arguments);
}
},
hasError: {},
help: {}
};
lab.experiment('Admin Admins Create New Form', () => {
lab.test('it renders', (done) => {
const FormEl = React.createElement(Form, defaultProps);
const form = ReactTestUtils.renderIntoDocument(FormEl);
Code.expect(form).to.exist();
done();
});
lab.test('it focuses on the name field when the component is update and showing', (done) => {
const container = document.createElement('div');
defaultProps.ref.impl = function (form) {
defaultProps.ref.impl = undefined;
form.els.name.input.onfocus = function () {
done();
};
};
// initial render
let FormEl = React.createElement(Form, defaultProps);
ReactDOM.render(FormEl, container);
// update props and render again
let props = Object.assign({}, defaultProps, {
show: false
});
FormEl = React.createElement(Form, props);
ReactDOM.render(FormEl, container);
// update props and render again
props = Object.assign({}, defaultProps, {
show: true
});
FormEl = React.createElement(Form, props);
ReactDOM.render(FormEl, container);
});
lab.test('it handles a submit event', (done) => {
stub.Actions.createNew = function () {
done();
};
const FormEl = React.createElement(Form, defaultProps);
const form = ReactTestUtils.renderIntoDocument(FormEl);
const formTag = ReactTestUtils.findRenderedDOMComponentWithTag(form, 'form');
ReactTestUtils.Simulate.submit(formTag);
});
lab.test('it renders showing error alert', (done) => {
const props = Object.assign({}, defaultProps, {
error: 'sorry pal'
});
const FormEl = React.createElement(Form, props);
const form = ReactTestUtils.renderIntoDocument(FormEl);
const alerts = ReactTestUtils.scryRenderedDOMComponentsWithClass(form, 'alert-danger');
Code.expect(alerts).to.have.length(1);
done();
});
});