test(16.2-06): admin SPA coverage of plugin field types and View site
- fieldTypes: one load per script URL, failed and refused scripts reported, global styles enabled on every screen, empty list on failure - registry, formState, FormField and ListView: plugin renderers, locale maps, notices as literal text, unknown column types as text - AppShell: the View site link's href, target, rel and en/pl label
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
fieldErrors,
|
||||
focusField,
|
||||
initialValues,
|
||||
isMLField,
|
||||
mergeMLValue,
|
||||
noticeLines,
|
||||
panelDomId,
|
||||
@@ -324,3 +325,45 @@ describe('noticeLines', () => {
|
||||
expect(noticeLines([{ field: 'x', message: '' }])).toEqual({})
|
||||
})
|
||||
})
|
||||
|
||||
describe('plugin field values (Phase 16.2)', () => {
|
||||
const plain: FormField = { name: 'notes', type: 'notes', element: 'acme-demo-notes' }
|
||||
const translatable: FormField = { name: 'body', type: 'notesml', element: 'acme-demo-notesml', translatable: true }
|
||||
|
||||
it('treats only a translatable plugin field as a locale map', () => {
|
||||
expect(isMLField(translatable)).toBe(true)
|
||||
expect(isMLField(plain)).toBe(false)
|
||||
expect(isMLField({ type: 'notesml', translatable: true })).toBe(false)
|
||||
expect(isMLField({ type: 'mltext' })).toBe(true)
|
||||
expect(isMLField(undefined)).toBe(false)
|
||||
})
|
||||
|
||||
it('seeds a translatable plugin field with every enabled locale, a plain one with nothing', () => {
|
||||
expect(initialValues([translatable, plain], ['pl', 'en'])).toEqual({ body: { pl: '', en: '' } })
|
||||
expect(initialValues([{ ...plain, default: '<p>x</p>' }], ['pl'])).toEqual({ notes: '<p>x</p>' })
|
||||
})
|
||||
|
||||
it('sends a translatable value as a locale record and a plain value as it is', () => {
|
||||
const values = { body: { pl: '<p>P</p>', en: '<p>E</p>', de: 7 }, notes: { blocks: [1] }, other: 'x' }
|
||||
expect(editablePayload([translatable, plain], values)).toEqual({ body: { pl: '<p>P</p>', en: '<p>E</p>' }, notes: { blocks: [1] } })
|
||||
expect(editablePayload([{ ...plain, readOnly: true }], values)).toEqual({})
|
||||
expect(editablePayload([plain], {})).toEqual({})
|
||||
})
|
||||
|
||||
it('groups notices per field, keeping their order, and skips malformed ones', () => {
|
||||
const lines = noticeLines([
|
||||
{ field: 'body', locale: 'en', message: 'second locale first' },
|
||||
{ field: 'body', locale: 'pl', message: '1 element was removed: style' },
|
||||
{ field: 'body', message: 'no locale' },
|
||||
{ field: 'notes', locale: '', message: 'empty locale' },
|
||||
{ field: '', message: 'no field name' },
|
||||
null as unknown as { field: string; message: string },
|
||||
{ field: 'notes', message: 42 as unknown as string },
|
||||
])
|
||||
expect(lines).toEqual({
|
||||
body: ['EN: second locale first', 'PL: 1 element was removed: style', 'no locale'],
|
||||
notes: ['empty locale'],
|
||||
'': ['no field name'],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user