forked from formio/formio.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebformBuilder.unit.js
63 lines (57 loc) · 2.47 KB
/
WebformBuilder.unit.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
import assert from 'power-assert';
import Harness from '../test/harness';
import WebformBuilder from './WebformBuilder';
import { uniqueApiKeys, uniqueApiKeysLayout, uniqueApiKeysSameLevel, columnsForm } from '../test/formtest';
describe('WebformBuilder tests', function() {
this.retries(3);
before((done) => Harness.builderBefore(done));
afterEach(() => Harness.getBuilder().setForm({ display: 'form', components: [] }));
after((done) => Harness.builderAfter(done));
it('Should create a new form builder class', (done) => {
const builder = Harness.getBuilder();
assert(builder instanceof WebformBuilder, 'Builder must be an instance of FormioFormBuilder');
done();
});
it('Should not show unique API error when components with same keys are inside and outside of the Data component', (done) => {
const builder = Harness.getBuilder();
builder.webform.setForm(uniqueApiKeys).then(() => {
builder.highlightInvalidComponents();
const component = builder.webform.getComponent(['textField']);
assert.equal(component.errors.length, 0);
done();
}).catch(done);
});
it('Should show unique API error when components inside and outside of the Layout component have same keys', (done) => {
const builder = Harness.getBuilder();
builder.webform.setForm(uniqueApiKeysLayout).then(() => {
builder.highlightInvalidComponents();
const component = builder.webform.getComponent(['textField']);
assert.equal(component.errors.length, 1);
done();
}).catch(done);
});
it('Should allow add components', function(done) {
const builder = Harness.getBuilder();
builder.setForm(columnsForm).then(() => {
const column1 = builder.webform.element.querySelector('[ref="columns-container"]');
Harness.buildComponent('textfield', column1);
setTimeout(() => {
Harness.saveComponent();
setTimeout(() => {
const columns = builder.webform.getComponent('columns');
assert.equal(columns.columns[0].length, 1);
done();
}, 150);
}, 150);
}).catch(done);
});
it('Should show unique API error when components on the same level have same keys', (done) => {
const builder = Harness.getBuilder();
builder.webform.setForm(uniqueApiKeysSameLevel).then(() => {
builder.highlightInvalidComponents();
const component = builder.webform.getComponent(['textField']);
assert.equal(component.errors.length, 1);
done();
}).catch(done);
});
});