1
0
mirror of synced 2024-11-22 21:36:04 +03:00
vue-formulario/test/unit/PathRegistry.test.js
2021-06-14 14:02:10 +03:00

51 lines
1.4 KiB
JavaScript

import PathRegistry from '@/PathRegistry'
describe('PathRegistry', () => {
test('subset structure', () => {
const registry = new PathRegistry()
const paths = path => Array.from(registry.getSubset(path).paths())
registry.add('name', null)
registry.add('address', [])
registry.add('address[0]', {})
registry.add('address[0].street', 'Baker Street')
registry.add('address[0].building', '221b')
registry.add('address[1]', {})
registry.add('address[1].street', '')
registry.add('address[1].building', '')
expect(paths('name')).toEqual(['name'])
expect(paths('address')).toEqual([
'address',
'address[0]',
'address[0].street',
'address[0].building',
'address[1]',
'address[1].street',
'address[1].building',
])
expect(paths('address[1]')).toEqual([
'address[1]',
'address[1].street',
'address[1].building',
])
registry.remove('address[1]')
expect(paths('address')).toEqual([
'address',
'address[0]',
'address[0].street',
'address[0].building',
'address[1].street',
'address[1].building',
])
expect(paths('address[1]')).toEqual([
'address[1].street',
'address[1].building',
])
})
})