Files
summercms/admin/tests/form/FormGrid.test.ts
Jakub Zych 1c2a66df45 test(10-05): bring every SPA module, composable and component under Vitest
- 41 unit and component suites under admin/tests/{app,state,shell,list,form,relation,views,ui}
  covering states and a11y roles; every src module is imported by a test
- typed fixture helper assigns each JSON fixture to its generated OpenAPI type
- fix: iconFor ignores inherited object members such as "constructor"
- fix: field controls import ./control instead of the registry (import cycle
  left a renderer unregistered depending on module load order)
- fix: dropdown shows the placeholder for an unknown stored value next to an emptyOption
- fix: list announces a failed schema load even when the rows arrive after it
- tailwind no longer scans admin/tests; boardwalk/dist rebuilt
2026-09-27 17:53:57 +02:00

53 lines
2.1 KiB
TypeScript

import { beforeEach, describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import FormGrid from '../../src/components/form/FormGrid.vue'
import { formField } from '../fixtures/typed'
import { resetState } from '../helpers'
beforeEach(() => {
resetState()
})
describe('form grid', () => {
it('places fields by span: left, right, full by default, auto and row in the next slot', () => {
const fields = [
formField('name'),
formField('code'),
formField('notes'),
{ ...formField('weight'), span: 'auto' },
{ ...formField('size'), span: 'row' },
{ ...formField('serial'), span: undefined },
formField('members'),
]
const wrapper = mount(FormGrid, { props: { fields, values: {}, errors: {}, source: null, idPrefix: 'grid' } })
const classes = (name: string) => wrapper.find(`[data-field="${name}"]`).classes()
expect(classes('name')).toContain('min-[600px]:col-start-1')
expect(classes('code')).toContain('min-[600px]:col-start-2')
expect(classes('notes')).toContain('col-span-full')
expect(classes('weight')).not.toContain('col-span-full')
expect(classes('size')).not.toContain('col-span-full')
expect(classes('serial')).toContain('col-span-full')
// The relation manager always takes the whole row.
expect(classes('members')).toContain('col-span-full')
})
it('passes values, errors and labels down and emits updates by field name', async () => {
const wrapper = mount(FormGrid, {
props: {
fields: [formField('name'), formField('owner')],
values: { name: 'Blue', owner: 5 },
errors: { name: ['Required'] },
labels: { owner: [{ value: 5, label: 'dana@example.test' }] },
source: null,
idPrefix: 'grid',
},
})
const input = wrapper.find('#grid-name')
expect((input.element as HTMLInputElement).value).toBe('Blue')
expect(input.attributes('aria-invalid')).toBe('true')
expect(wrapper.find('#grid-owner').text()).toBe('dana@example.test')
await input.setValue('Red')
expect(wrapper.emitted('update')).toEqual([['name', 'Red']])
})
})