2019-11-01 23:08:18 +03:00
|
|
|
import Formulate from '../src/Formulate.js'
|
2019-10-07 17:24:30 +03:00
|
|
|
|
2020-02-27 22:47:24 +03:00
|
|
|
test('can merge simple object', () => {
|
2019-10-07 17:24:30 +03:00
|
|
|
let a = {
|
|
|
|
optionA: true,
|
|
|
|
optionB: '1234'
|
|
|
|
}
|
|
|
|
let b = {
|
|
|
|
optionA: false
|
|
|
|
}
|
2020-02-27 22:47:24 +03:00
|
|
|
expect(Formulate.merge(a, b)).toEqual({
|
2019-10-07 17:24:30 +03:00
|
|
|
optionA: false,
|
|
|
|
optionB: '1234'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-27 22:47:24 +03:00
|
|
|
test('can add to simple array', () => {
|
|
|
|
let a = {
|
|
|
|
optionA: true,
|
|
|
|
optionB: ['first', 'second']
|
|
|
|
}
|
|
|
|
let b = {
|
|
|
|
optionB: ['third']
|
|
|
|
}
|
|
|
|
expect(Formulate.merge(a, b, true)).toEqual({
|
|
|
|
optionA: true,
|
|
|
|
optionB: ['first', 'second', 'third']
|
|
|
|
})
|
|
|
|
})
|
2019-10-07 17:24:30 +03:00
|
|
|
|
2020-02-27 22:47:24 +03:00
|
|
|
test('can merge recursively', () => {
|
2019-10-07 17:24:30 +03:00
|
|
|
let a = {
|
|
|
|
optionA: true,
|
|
|
|
optionC: {
|
|
|
|
first: '123',
|
|
|
|
third: {
|
|
|
|
a: 'b'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
optionB: '1234'
|
|
|
|
}
|
|
|
|
let b = {
|
|
|
|
optionB: '567',
|
|
|
|
optionC: {
|
|
|
|
first: '1234',
|
|
|
|
second: '789',
|
|
|
|
}
|
|
|
|
}
|
2020-02-27 22:47:24 +03:00
|
|
|
expect(Formulate.merge(a, b)).toEqual({
|
2019-10-07 17:24:30 +03:00
|
|
|
optionA: true,
|
|
|
|
optionC: {
|
|
|
|
first: '1234',
|
|
|
|
third: {
|
|
|
|
a: 'b'
|
|
|
|
},
|
|
|
|
second: '789'
|
|
|
|
},
|
|
|
|
optionB: '567'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('installs on vue instance', () => {
|
|
|
|
const components = [
|
|
|
|
'FormulateForm',
|
|
|
|
'FormulateInput',
|
2019-11-07 01:17:19 +03:00
|
|
|
'FormulateInputErrors',
|
2019-10-07 17:24:30 +03:00
|
|
|
'FormulateInputBox',
|
|
|
|
'FormulateInputText',
|
2019-11-15 22:44:01 +03:00
|
|
|
'FormulateInputFile',
|
2019-10-07 17:24:30 +03:00
|
|
|
'FormulateInputGroup',
|
2020-01-28 20:12:08 +03:00
|
|
|
'FormulateInputButton',
|
2019-10-07 17:24:30 +03:00
|
|
|
'FormulateInputSelect',
|
2019-11-14 09:00:56 +03:00
|
|
|
'FormulateInputSlider',
|
2019-10-07 17:24:30 +03:00
|
|
|
'FormulateInputTextArea'
|
|
|
|
]
|
|
|
|
const registry = []
|
|
|
|
function Vue () {}
|
|
|
|
Vue.component = function (name, instance) {
|
|
|
|
registry.push(name)
|
|
|
|
}
|
|
|
|
Formulate.install(Vue, { extended: true })
|
|
|
|
expect(Vue.prototype.$formulate).toBe(Formulate)
|
|
|
|
expect(registry).toEqual(components)
|
|
|
|
})
|
2020-02-27 22:47:24 +03:00
|
|
|
|
|
|
|
test('can extend instance in a plugin', () => {
|
|
|
|
function Vue () {}
|
|
|
|
Vue.component = function (name, instance) {}
|
|
|
|
const plugin = function (i) {
|
|
|
|
i.extend({
|
|
|
|
rules: {
|
|
|
|
testRule: () => false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
Formulate.install(Vue, {
|
|
|
|
plugins: [ plugin ]
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(typeof Vue.prototype.$formulate.options.rules.testRule).toBe('function')
|
|
|
|
})
|