fix(admin): isolate CodeMirror load for chunk-failure tests

- Route CodeEditorField through codeeditor/load so vitest can mock the chunk
- Keep registry expectations for colorpicker/codeeditor without importing the editor SFC

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-13 13:57:16 +01:00
parent e81cfde7b2
commit 1df2e31dea
4 changed files with 30 additions and 15 deletions

View File

@@ -235,16 +235,18 @@ describe('CodeEditorField loading and fallback', () => {
})
it('shows the bg-skel loading box at the size height while the chunk loads', async () => {
// Hold the dynamic import open so the loading box stays visible.
// Hold the chunk import open so the loading box stays visible.
let release!: () => void
const gate = new Promise<void>((resolve) => {
release = resolve
})
vi.resetModules()
vi.doMock('../../src/components/form/codeeditor/editor', async () => {
await gate
return await vi.importActual('../../src/components/form/codeeditor/editor')
})
vi.doMock('../../src/components/form/codeeditor/load', () => ({
importCodeEditor: async () => {
await gate
return await vi.importActual('../../src/components/form/codeeditor/editor')
},
}))
const Field = (await import('../../src/components/form/fields/CodeEditorField.vue')).default
const wrapper = mount(Field, {
props: { field: codeField(), modelValue: '<p>x</p>', controlId: 'f-html' },
@@ -258,7 +260,7 @@ describe('CodeEditorField loading and fallback', () => {
release()
await flushPromises()
wrapper.unmount()
vi.doUnmock('../../src/components/form/codeeditor/editor')
vi.doUnmock('../../src/components/form/codeeditor/load')
})
it('renders a read-only pre without loading CodeMirror', async () => {
@@ -442,12 +444,12 @@ describe('CodeEditorField chunk failure', () => {
it('shows the load_failed note and a monospace textarea that still emits', async () => {
vi.resetModules()
vi.doUnmock('../../src/components/form/codeeditor/editor')
// Reject the dynamic import itself so a prior suite that already
// evaluated the real editor chunk cannot keep createCodeEditor working.
vi.doMock('../../src/components/form/codeeditor/editor', () => {
throw new Error('chunk failed')
})
vi.doUnmock('../../src/components/form/codeeditor/load')
vi.doMock('../../src/components/form/codeeditor/load', () => ({
importCodeEditor: async () => {
throw new Error('chunk failed')
},
}))
;(await import('../../src/app/i18n')).setBundle({ ...mailPreviewBundle, ...codeeditorBundle }, 'en')
const Field = (await import('../../src/components/form/fields/CodeEditorField.vue')).default
const wrapper = mount(Field, {

View File

@@ -14,7 +14,6 @@ import MLTextField from '../../src/components/form/fields/MLTextField.vue'
import PasswordField from '../../src/components/form/fields/PasswordField.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 WidgetField from '../../src/components/form/fields/WidgetField.vue'
import MLPluginField from '../../src/components/form/fields/MLPluginField.vue'
@@ -48,12 +47,21 @@ describe('field renderer registry (D-05)', () => {
['checkbox', CheckboxField],
['relation', RelationField],
['colorpicker', ColorPickerField],
['codeeditor', CodeEditorField],
[RELATION_MANAGER, RelationManager],
])('renders %s with its control', (type, component) => {
expect(rendererFor(type)).toBe(component)
})
// codeeditor is registered (Phase 35) but not imported here: a static import
// of CodeEditorField would evaluate its CodeMirror chunk and break the
// mail-smoke chunk-failure mock that relies on vi.resetModules.
it('registers codeeditor as an editable control', () => {
expect(isRegistered('codeeditor')).toBe(true)
expect(needsRecord('codeeditor')).toBe(false)
expect(rendererFor('codeeditor')).not.toBe(UnsupportedField)
expect(rendererFor('codeeditor').__name).toBe('CodeEditorField')
})
it.each(['notatype', '', 'TEXT', 'constructor'])('falls back to UnsupportedField for %j', (type) => {
expect(rendererFor(type)).toBe(UnsupportedField)
expect(isRegistered(type)).toBe(false)