feat(14.2.1-05): hydrate ML create/GET/save through TranslatedExact

Form schema meta lists enabled locales, Show/save expand mltext maps
without D-11 fallback, and the SPA seeds and adopt-merges every locale.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-10-06 15:37:00 +02:00
parent ed81f2a0c1
commit 0f8d13738d
11 changed files with 309 additions and 34 deletions

View File

@@ -1,10 +1,12 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { enableAutoUnmount, mount } from '@vue/test-utils'
import { ref } from 'vue'
import type { FormField } from '../../src/api/types'
import MarkdownField from '../../src/components/form/fields/MarkdownField.vue'
import MLMarkdownField from '../../src/components/form/fields/MLMarkdownField.vue'
import MLTextField from '../../src/components/form/fields/MLTextField.vue'
import { editablePayload } from '../../src/components/form/formState'
import { FORM_ENABLED_LOCALES } from '../../src/components/form/formContext'
import { editablePayload, initialValues, mergeMLValue } from '../../src/components/form/formState'
import { isRegistered, rendererFor } from '../../src/components/form/registry'
import { resetState } from '../helpers'
@@ -12,8 +14,23 @@ function field(type: string, name = 'title'): FormField {
return { name, label: 'Title', type } as FormField
}
const enabledLocales = ref<readonly string[]>(['en', 'pl'])
function mlMount(component: typeof MLTextField | typeof MLMarkdownField, props: Record<string, unknown>) {
return mount(component, {
props,
attachTo: document.body,
global: {
provide: {
[FORM_ENABLED_LOCALES as symbol]: enabledLocales,
},
},
})
}
beforeEach(() => {
resetState()
enabledLocales.value = ['en', 'pl']
})
afterEach(() => {
@@ -45,13 +62,10 @@ describe('ML field registry and nested save body', () => {
})
it('edits the active locale and copies from another', async () => {
const wrapper = mount(MLTextField, {
props: {
field: field('mltext'),
modelValue: { en: 'Hello', pl: 'Witaj' },
controlId: 'f-title',
},
attachTo: document.body,
const wrapper = mlMount(MLTextField, {
field: field('mltext'),
modelValue: { en: 'Hello', pl: 'Witaj' },
controlId: 'f-title',
})
const input = wrapper.find('input')
expect(input.element.value).toBe('Hello')
@@ -63,13 +77,15 @@ describe('ML field registry and nested save body', () => {
})
it('switches every ML control from one selector', async () => {
const title = mount(MLTextField, {
props: { field: field('mltext'), modelValue: { en: 'Hello', pl: 'Witaj' }, controlId: 'f-title' },
attachTo: document.body,
const title = mlMount(MLTextField, {
field: field('mltext'),
modelValue: { en: 'Hello', pl: 'Witaj' },
controlId: 'f-title',
})
const body = mount(MLMarkdownField, {
props: { field: field('mlmarkdown', 'body'), modelValue: { en: 'EN', pl: 'PL' }, controlId: 'f-body' },
attachTo: document.body,
const body = mlMount(MLMarkdownField, {
field: field('mlmarkdown', 'body'),
modelValue: { en: 'EN', pl: 'PL' },
controlId: 'f-body',
})
expect(body.findComponent(MarkdownField).exists()).toBe(true)
await title.find('[data-ml-locale]').setValue('pl')
@@ -92,4 +108,31 @@ describe('ML field registry and nested save body', () => {
expect((window as unknown as { __ml_xss?: number }).__ml_xss).toBeUndefined()
expect(wrapper.find('[data-markdown-preview-pane]').text()).toContain('<script>')
})
it('seeds empty maps and lists every enabled locale on create', () => {
const fields = [field('mltext')]
const values = initialValues(fields, ['en', 'pl'])
expect(values.title).toEqual({ en: '', pl: '' })
const wrapper = mlMount(MLTextField, {
field: fields[0],
modelValue: values.title,
controlId: 'f-title',
})
expect(wrapper.findAll('[data-ml-locale] option').map((node) => node.text())).toEqual(['en', 'pl'])
})
it('keeps sibling locales when adopt merges a GET host string', async () => {
const fields = [field('mltext')]
const merged = mergeMLValue('Hello', ['en', 'pl'])
expect(merged).toEqual({ en: 'Hello', pl: '' })
const wrapper = mlMount(MLTextField, {
field: fields[0],
modelValue: merged,
controlId: 'f-title',
})
expect(wrapper.findAll('[data-ml-locale] option').map((node) => node.text())).toEqual(['en', 'pl'])
await wrapper.find('[data-ml-locale]').setValue('pl')
await wrapper.find('input').setValue('Witaj')
expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual([{ en: 'Hello', pl: 'Witaj' }])
})
})