fix(admin): restore suite after colorpicker and codeeditor registration

- Expect colorpicker/codeeditor as registered controls; use notatype for unsupported cases
- Seed DatePicker placeholder from the model value so the calendar opens on that month
- Make CodeEditor chunk-failure mock reject the dynamic import

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-13 13:53:44 +01:00
parent 5f62cd6b92
commit e81cfde7b2
6 changed files with 32 additions and 16 deletions

View File

@@ -269,7 +269,7 @@ const iconButton =
v-else v-else
:id="controlId" :id="controlId"
:model-value="dateValue" :model-value="dateValue"
:default-placeholder="placeholderValue" :default-placeholder="dateValue ?? placeholderValue"
:locale="locale" :locale="locale"
:granularity="granularity" :granularity="granularity"
:hour-cycle="hourCycle" :hour-cycle="hourCycle"

View File

@@ -164,7 +164,9 @@ describe('field renderer', () => {
}) })
it('renders the unsupported box for an unknown type', () => { it('renders the unsupported box for an unknown type', () => {
const wrapper = mount(FieldRenderer, { props: { field: formField('color'), modelValue: '#fff', controlId: 'c' } }) const wrapper = mount(FieldRenderer, {
props: { field: { ...formField('color'), type: 'notatype' }, modelValue: '#fff', controlId: 'c' },
})
expect(wrapper.find('[data-unsupported-field]').exists()).toBe(true) expect(wrapper.find('[data-unsupported-field]').exists()).toBe(true)
}) })
}) })

View File

@@ -55,7 +55,9 @@ describe('form state helpers', () => {
active: false, active: false,
unknown_key: 'x', unknown_key: 'x',
}) })
expect(body).toEqual({ name: 'Blue', tags: [3], active: false }) // colorpicker is a registered control (Phase 35); owner is read-only and
// members is a relation manager (not sent here).
expect(body).toEqual({ name: 'Blue', color: '#fff', tags: [3], active: false })
}) })
it('never sends widget or partial fields, even with a value under their name', () => { it('never sends widget or partial fields, even with a value under their name', () => {

View File

@@ -442,12 +442,12 @@ describe('CodeEditorField chunk failure', () => {
it('shows the load_failed note and a monospace textarea that still emits', async () => { it('shows the load_failed note and a monospace textarea that still emits', async () => {
vi.resetModules() vi.resetModules()
vi.unmock('../../src/components/form/codeeditor/editor') vi.doUnmock('../../src/components/form/codeeditor/editor')
vi.doMock('../../src/components/form/codeeditor/editor', () => ({ // Reject the dynamic import itself so a prior suite that already
createCodeEditor: () => { // evaluated the real editor chunk cannot keep createCodeEditor working.
throw new Error('chunk failed') vi.doMock('../../src/components/form/codeeditor/editor', () => {
}, throw new Error('chunk failed')
})) })
;(await import('../../src/app/i18n')).setBundle({ ...mailPreviewBundle, ...codeeditorBundle }, 'en') ;(await import('../../src/app/i18n')).setBundle({ ...mailPreviewBundle, ...codeeditorBundle }, 'en')
const Field = (await import('../../src/components/form/fields/CodeEditorField.vue')).default const Field = (await import('../../src/components/form/fields/CodeEditorField.vue')).default
const wrapper = mount(Field, { const wrapper = mount(Field, {

View File

@@ -13,6 +13,8 @@ import MLTextareaField from '../../src/components/form/fields/MLTextareaField.vu
import MLTextField from '../../src/components/form/fields/MLTextField.vue' import MLTextField from '../../src/components/form/fields/MLTextField.vue'
import PasswordField from '../../src/components/form/fields/PasswordField.vue' import PasswordField from '../../src/components/form/fields/PasswordField.vue'
import PermissionEditorField from '../../src/components/form/fields/PermissionEditorField.vue' import PermissionEditorField from '../../src/components/form/fields/PermissionEditorField.vue'
import ColorPickerField from '../../src/components/form/fields/ColorPickerField.vue'
import CodeEditorField from '../../src/components/form/fields/CodeEditorField.vue'
import UnsupportedField from '../../src/components/form/fields/UnsupportedField.vue' import UnsupportedField from '../../src/components/form/fields/UnsupportedField.vue'
import WidgetField from '../../src/components/form/fields/WidgetField.vue' import WidgetField from '../../src/components/form/fields/WidgetField.vue'
import MLPluginField from '../../src/components/form/fields/MLPluginField.vue' import MLPluginField from '../../src/components/form/fields/MLPluginField.vue'
@@ -45,19 +47,21 @@ describe('field renderer registry (D-05)', () => {
['switch', SwitchField], ['switch', SwitchField],
['checkbox', CheckboxField], ['checkbox', CheckboxField],
['relation', RelationField], ['relation', RelationField],
['colorpicker', ColorPickerField],
['codeeditor', CodeEditorField],
[RELATION_MANAGER, RelationManager], [RELATION_MANAGER, RelationManager],
])('renders %s with its control', (type, component) => { ])('renders %s with its control', (type, component) => {
expect(rendererFor(type)).toBe(component) expect(rendererFor(type)).toBe(component)
}) })
it.each(['colorpicker', 'codeeditor', '', 'TEXT', 'constructor'])('falls back to UnsupportedField for %j', (type) => { it.each(['notatype', '', 'TEXT', 'constructor'])('falls back to UnsupportedField for %j', (type) => {
expect(rendererFor(type)).toBe(UnsupportedField) expect(rendererFor(type)).toBe(UnsupportedField)
expect(isRegistered(type)).toBe(false) expect(isRegistered(type)).toBe(false)
}) })
it('edits values of every control type except the record-bound relation manager', () => { it('edits values of every control type except the record-bound relation manager', () => {
expect(RELATION_MANAGER).toBe('relation-manager') expect(RELATION_MANAGER).toBe('relation-manager')
for (const type of ['text', 'textarea', 'number', 'dropdown', 'switch', 'checkbox', 'relation']) { for (const type of ['text', 'textarea', 'number', 'dropdown', 'switch', 'checkbox', 'relation', 'colorpicker', 'codeeditor']) {
expect(isRegistered(type), type).toBe(true) expect(isRegistered(type), type).toBe(true)
expect(needsRecord(type), type).toBe(false) expect(needsRecord(type), type).toBe(false)
} }

View File

@@ -129,8 +129,8 @@ describe('edit a record', () => {
const [put] = requestsTo(calls, 'PUT', RECORD) const [put] = requestsTo(calls, 'PUT', RECORD)
expect(put).toBeDefined() expect(put).toBeDefined()
expect(put!.headers.get('X-Requested-With')).toBe('XMLHttpRequest') expect(put!.headers.get('X-Requested-With')).toBe('XMLHttpRequest')
// Every editable, context-allowed field; not the unsupported colorpicker, // Every editable, context-allowed field; not the read-only owner or the
// the read-only owner or the relation manager. // relation manager. colorpicker is a registered control (Phase 35).
expect(await put!.json()).toEqual({ expect(await put!.json()).toEqual({
name: 'Red widget', name: 'Red widget',
code: 'W-01', code: 'W-01',
@@ -142,6 +142,7 @@ describe('edit a record', () => {
maker: 2, maker: 2,
tags: [3, 1], tags: [3, 1],
serial: 'SN-1', serial: 'SN-1',
color: '#0000ff',
}) })
const toast = wrapper.find('[role="status"]') const toast = wrapper.find('[role="status"]')
expect(toast.text()).toContain('Widget „Red widget” saved') expect(toast.text()).toContain('Widget „Red widget” saved')
@@ -209,12 +210,19 @@ describe('edit a record', () => {
}) })
it('renders an unknown field type as the unsupported box instead of breaking the form', async () => { it('renders an unknown field type as the unsupported box instead of breaking the form', async () => {
const { wrapper } = await mountApp('/acme/demo/widgets/1', formRoutes) const schema = JSON.parse(JSON.stringify(formSchema)) as typeof formSchema
const color = schema.data.fields.find((field) => field.name === 'color')
expect(color).toBeDefined()
color!.type = 'notatype'
const { wrapper } = await mountApp('/acme/demo/widgets/1', {
...formRoutes,
[`GET ${API}/acme/demo/widgets/schema/form`]: { body: schema },
})
const box = wrapper.find('[data-unsupported-field]') const box = wrapper.find('[data-unsupported-field]')
expect(box.exists()).toBe(true) expect(box.exists()).toBe(true)
expect(box.text()).toBe('Nieobsługiwany typ pola: colorpicker') expect(box.text()).toBe('Nieobsługiwany typ pola: notatype')
expect(box.find('code').text()).toBe('colorpicker') expect(box.find('code').text()).toBe('notatype')
expect(box.find('code').classes()).toContain('font-mono') expect(box.find('code').classes()).toContain('font-mono')
expect(box.find('svg').exists()).toBe(true) expect(box.find('svg').exists()).toBe(true)
expect(wrapper.find('label[for="field-color"]').text()).toBe('Colour') expect(wrapper.find('label[for="field-color"]').text()).toBe('Colour')