Skip to content

Commit fdbb30a

Browse files
committed
adding components
1 parent d732eb7 commit fdbb30a

File tree

7 files changed

+104
-30
lines changed

7 files changed

+104
-30
lines changed

src/components.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/components/FormlyField.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<component :is="schema.type" :model="model"></component>
3+
</template>
4+
5+
<script>
6+
export default {
7+
props: ['schema', 'model']
8+
}
9+
</script>

src/components/FormlyForm.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<fieldset>
3+
4+
</fieldset>
5+
</template>
6+
7+
<script>
8+
export default{
9+
10+
}
11+
</script>

src/components/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import FormlyForm from './FormlyForm.vue';
2+
import FormlyField from './FormlyField.vue';
3+
4+
export default function(Vue){
5+
Vue.component('FormlyForm', FormlyForm);
6+
Vue.component('FormlyField', FormlyField);
7+
}

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Formly.install = function(Vue, options){
99
return;
1010
}
1111

12+
Components(Vue);
13+
1214
Vue.$formly = {
1315

1416
fields: {},

test/unit/specs/FormlyField.spec.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import chai from 'chai';
2+
const expect = chai.expect;
3+
import sinonChai from 'sinon-chai';
4+
import sinon from 'sinon';
5+
import Vue from 'vue';
6+
import VueFormly from 'src/index';
7+
Vue.use(VueFormly);
8+
chai.use(sinonChai);
9+
10+
let el, vm;
11+
12+
function createForm(template, data){
13+
el = document.createElement('div');
14+
el.innerHTML = template;
15+
vm = new Vue({
16+
el: el,
17+
data: data
18+
});
19+
20+
return [el, vm];
21+
}
22+
23+
describe('FormlyField', () => {
24+
25+
it('should take on the type of another component', () => {
26+
27+
Vue.component('test', {
28+
template: '<div id="testComponent">Hello World</div>'
29+
});
30+
31+
let data = {
32+
schema:{
33+
type: 'test'
34+
}
35+
};
36+
37+
createForm('<formly-field :schema="schema"></formly-field>', data);
38+
39+
let innerElem = vm.$el.querySelector('#testComponent');
40+
41+
expect(innerElem.textContent).to.contain('Hello World');
42+
43+
});
44+
45+
it('should mimic the model of the parent', (done) => {
46+
47+
Vue.component('test', {
48+
props: ['model'],
49+
template: '<input type="text" id="testInput" v-model="model">'
50+
});
51+
52+
let data = {
53+
schema: {
54+
type: 'test'
55+
},
56+
testModel: 'foo'
57+
};
58+
59+
createForm('<formly-field :schema="schema" :model.sync="testModel"></formly-field>', data);
60+
61+
let input = vm.$el.querySelector('#testInput');
62+
63+
expect(input.value).to.contain('foo');
64+
65+
//change the value and expect a change
66+
vm.testModel = 'bar';
67+
68+
setTimeout(() => {
69+
expect(input.value).to.equal('bar');
70+
done();
71+
}, 0);
72+
73+
});
74+
75+
});

test/unit/specs/VueFormly.spec.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)