adf8299a33
* Adds support form FormulateError form errors * Adds support for form-errors prop Also includes tests for both named-form-errors as well, form-errors prop, positioning form errors with the <FormulateErrors /> component, and allowing multiple <FormulateErrors /> * Adds form error support, error handling, and supporting tests * Remove unused util functions * fixes bug that resulted in validation failing if run more than once Credit to @luan-nk-nguyen for discovering the bug Co-authored-by: Andrew Boyd <andrew@wearebraid.com>
102 lines
1.9 KiB
JavaScript
102 lines
1.9 KiB
JavaScript
import Formulate from '../src/Formulate.js'
|
|
|
|
test('can merge simple object', () => {
|
|
let a = {
|
|
optionA: true,
|
|
optionB: '1234'
|
|
}
|
|
let b = {
|
|
optionA: false
|
|
}
|
|
expect(Formulate.merge(a, b)).toEqual({
|
|
optionA: false,
|
|
optionB: '1234'
|
|
})
|
|
})
|
|
|
|
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']
|
|
})
|
|
})
|
|
|
|
test('can merge recursively', () => {
|
|
let a = {
|
|
optionA: true,
|
|
optionC: {
|
|
first: '123',
|
|
third: {
|
|
a: 'b'
|
|
}
|
|
},
|
|
optionB: '1234'
|
|
}
|
|
let b = {
|
|
optionB: '567',
|
|
optionC: {
|
|
first: '1234',
|
|
second: '789',
|
|
}
|
|
}
|
|
expect(Formulate.merge(a, b)).toEqual({
|
|
optionA: true,
|
|
optionC: {
|
|
first: '1234',
|
|
third: {
|
|
a: 'b'
|
|
},
|
|
second: '789'
|
|
},
|
|
optionB: '567'
|
|
})
|
|
})
|
|
|
|
test('installs on vue instance', () => {
|
|
const components = [
|
|
'FormulateForm',
|
|
'FormulateInput',
|
|
'FormulateErrors',
|
|
'FormulateInputBox',
|
|
'FormulateInputText',
|
|
'FormulateInputFile',
|
|
'FormulateInputGroup',
|
|
'FormulateInputButton',
|
|
'FormulateInputSelect',
|
|
'FormulateInputSlider',
|
|
'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)
|
|
})
|
|
|
|
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')
|
|
})
|