Admin panel in English and Polish, reworded per docs/dev/admin-ux.md

- admin-i18n module: AdminText { en, pl }, component texts under the ipal
  namespace (project translations win), en + pl admin languages when the
  project sets none (project's supportedLanguages wins)
- every plugin label, description, option, tab and group as { en, pl };
  explicit labels instead of auto-labels; sentence case; glossary terms
- visible renames (slugs, names, data unchanged): Cookie banner, Form
  messages, Privacy group, Search engines, Maintenance, Spam protection,
  E-mail sending, stats nav link Overview (hidden without access)
- Polish visitor defaults by page locale: cookie banner, form messages,
  validators, lightbox, accessibility widget; {field} uses the label
- fixes: e-mail status banner used Turnstile wording; developer words and
  env var names out of editor messages; stats numbers/dates in the admin
  language; test e-mail no longer says ipal-kit
- test/adminUx.test.ts: length limits, en + pl present, no developer words

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-27 15:46:25 +01:00
co-authored by Claude Opus 5.5
parent eeac33ed2f
commit 6b46bc0c14
108 changed files with 2806 additions and 981 deletions
+237
View File
@@ -0,0 +1,237 @@
import type { CollectionConfig, Config, Field, GlobalConfig } from 'payload'
import { describe, expect, test } from 'vitest'
import { applyAdminI18n } from '../src/modules/admin-i18n/apply.js'
import { adminTexts } from '../src/modules/admin-i18n/index.js'
import { ipalKit } from '../src/plugin.js'
/**
* docs/dev/admin-ux.md, enforced: every admin string the plugin adds has an
* explicit English and Polish text, within the length limits, without
* developer words.
*/
const LABEL_MAX = 30
const DESCRIPTION_MAX = 120
const OPTION_MAX = 40
const TEXT_MAX = 160
// Product names may push a label past 3 words ("LinkedIn Insight Tag ID").
const PRODUCTS = /Google|Meta|Microsoft|LinkedIn|TikTok|Cloudflare|Bing|Yandex|IndexNow|Search Console|Turnstile|Clarity|Pixel/
// Function calls, JSX tags, ENV_VARS, camelCase words, package/vendor names, "Empty →".
const JARGON = /\w\(|<[A-Z]|\b[A-Z][A-Z0-9]*_[A-Z0-9_]+\b|\b[a-z]+[A-Z][a-z][A-Za-z]*\b|ipal-|Intecion|→/
// Abbreviations that end in a dot but don't end a sentence.
const ABBREVIATIONS = /\b(e\.g|i\.e|np|m\.in|tzw|ok|min|maks|max|etc)\./gi
const i18n = {
defaultLocale: 'pl',
locales: [
{ code: 'pl', label: 'Polski' },
{ code: 'en', label: 'English' },
],
}
const t = (en: string, pl: string) => ({ en, pl })
const project = (): Config =>
({
collections: [
{ slug: 'users', auth: true, fields: [] },
{ slug: 'pages', fields: [{ name: 'title', type: 'text', label: t('Title', 'Tytuł') }] },
{ slug: 'posts', fields: [{ name: 'title', type: 'text', label: t('Title', 'Tytuł') }] },
{ slug: 'media', fields: [], upload: true },
],
secret: 'test',
}) as unknown as Config
const fullConfig = () =>
ipalKit({
access: { authCollection: 'users' },
consentLog: true,
content: { collections: [{ slug: 'posts' }] },
cookieScanner: { crawl: { serviceUrl: 'http://crawler.test', siteUrl: 'http://site.test', token: 'x' } },
forms: { emailLayout: true },
i18n,
indexNow: true,
lightbox: true,
pages: { slug: 'pages' },
seo: { collections: ['pages', 'posts'] },
stats: true,
twoFactor: false,
} as never)(project())
type Problem = string
type Text = unknown
const isText = (v: Text): v is { en: string; pl: string } =>
typeof v === 'object' && v !== null && typeof (v as { en?: unknown }).en === 'string' && typeof (v as { pl?: unknown }).pl === 'string'
const sentences = (s: string) => s.replace(ABBREVIATIONS, '$1').split(/[.!?](?:\s|$)/).filter((p) => p.trim()).length
function checkText(where: string, kind: 'description' | 'label' | 'option', value: Text, problems: Problem[]) {
if (!isText(value)) {
problems.push(`${where}: ${kind} is not { en, pl } (${JSON.stringify(value)})`)
return
}
for (const lang of ['en', 'pl'] as const) {
const s = value[lang].trim()
if (!s) {problems.push(`${where}: empty ${kind} (${lang})`)}
if (JARGON.test(s)) {problems.push(`${where}: developer words in ${kind} (${lang}): "${s}"`)}
if (kind === 'label') {
const words = s.split(/\s+/).length
if (s.length > LABEL_MAX) {problems.push(`${where}: label over ${LABEL_MAX} chars (${lang}): "${s}"`)}
if (words > (PRODUCTS.test(s) ? 5 : 3)) {problems.push(`${where}: label over 3 words (${lang}): "${s}"`)}
}
if (kind === 'option' && s.length > OPTION_MAX) {problems.push(`${where}: option over ${OPTION_MAX} chars (${lang}): "${s}"`)}
if (kind === 'description') {
if (s.length > DESCRIPTION_MAX) {problems.push(`${where}: description over ${DESCRIPTION_MAX} chars (${lang}): "${s}"`)}
if (sentences(s) > 1) {problems.push(`${where}: description longer than one sentence (${lang}): "${s}"`)}
}
}
}
function walk(fields: Field[], path: string, problems: Problem[]) {
for (const field of fields) {
const f = field as { admin?: Record<string, unknown> } & Field & Record<string, unknown>
const where = `${path}.${'name' in f && f.name ? String(f.name) : f.type}`
if (f.hidden || f.admin?.hidden || f.admin?.disabled) {continue}
if (f.type === 'tabs') {
for (const tab of (f as unknown as { tabs: ({ fields: Field[] } & Record<string, unknown>)[] }).tabs) {
const tabWhere = `${path}.tab(${String(tab.name ?? JSON.stringify(tab.label))})`
checkText(tabWhere, 'label', tab.label, problems)
if (tab.description) {checkText(tabWhere, 'description', tab.description, problems)}
walk(tab.fields, tabWhere, problems)
}
continue
}
if (f.type === 'row') {
walk(f.fields, path, problems)
continue
}
const visibleUi = f.type === 'ui' ? Boolean(f.label) : true
if (visibleUi && f.label !== false) {checkText(where, 'label', f.label, problems)}
if (f.admin?.description && typeof f.admin.description !== 'function') {checkText(where, 'description', f.admin.description, problems)}
if (Array.isArray(f.options)) {
for (const o of f.options as unknown[]) {
if (typeof o === 'object' && o) {checkText(`${where}[${String((o as { value: string }).value)}]`, 'option', (o as { label: Text }).label, problems)}
else {problems.push(`${where}: option "${String(o)}" has no label`)}
}
}
if (f.type === 'array') {
const labels = f.labels as { plural?: Text; singular?: Text } | undefined
checkText(`${where}.labels.singular`, 'label', labels?.singular, problems)
checkText(`${where}.labels.plural`, 'label', labels?.plural, problems)
}
if (f.type === 'blocks') {
for (const block of f.blocks as { fields: Field[]; labels?: { plural?: Text; singular?: Text }; slug: string }[]) {
checkText(`${where}.${block.slug}.labels.singular`, 'label', block.labels?.singular, problems)
checkText(`${where}.${block.slug}.labels.plural`, 'label', block.labels?.plural, problems)
walk(block.fields, `${where}.${block.slug}`, problems)
}
}
if ('fields' in f && Array.isArray(f.fields) && f.type !== 'blocks') {walk(f.fields as Field[], where, problems)}
}
}
function checkGlobal(global: GlobalConfig, problems: Problem[]) {
checkText(`global ${global.slug}`, 'label', global.label, problems)
if (global.admin?.group) {checkText(`global ${global.slug} group`, 'label', global.admin.group, problems)}
if (global.admin?.description && typeof global.admin.description !== 'function') {checkText(`global ${global.slug}`, 'description', global.admin.description, problems)}
walk(global.fields, global.slug, problems)
}
function checkCollection(collection: CollectionConfig, problems: Problem[]) {
checkText(`collection ${collection.slug} singular`, 'label', collection.labels?.singular, problems)
checkText(`collection ${collection.slug} plural`, 'label', collection.labels?.plural, problems)
if (collection.admin?.group) {checkText(`collection ${collection.slug} group`, 'label', collection.admin.group, problems)}
if (collection.admin?.description && typeof collection.admin.description !== 'function') {checkText(`collection ${collection.slug}`, 'description', collection.admin.description, problems)}
walk(collection.fields, collection.slug, problems)
}
// Collections the plugin creates; fields of other plugins (form-builder, plugin-seo) are checked where ipal-kit sets them.
const PLUGIN_COLLECTIONS = ['consent-records', 'cookie-review', 'stats-visits']
describe('admin wording (docs/dev/admin-ux.md)', () => {
test('plugin globals: every visible text in en + pl, within limits', async () => {
const config = await fullConfig()
const problems: Problem[] = []
for (const global of config.globals ?? []) {checkGlobal(global, problems)}
expect(problems).toEqual([])
})
test('plugin collections: every visible text in en + pl, within limits', async () => {
const config = await fullConfig()
const problems: Problem[] = []
const slugs = (config.collections ?? []).map((c) => c.slug)
for (const slug of PLUGIN_COLLECTIONS) {
const collection = config.collections?.find((c) => c.slug === slug || c.slug.startsWith(slug))
expect(collection, `${slug} in ${slugs.join(', ')}`).toBeTruthy()
checkCollection(collection!, problems)
}
expect(problems).toEqual([])
})
test('fields injected into project collections: en + pl, within limits', async () => {
const config = await fullConfig()
const problems: Problem[] = []
for (const slug of ['users', 'pages', 'posts']) {
const collection = config.collections!.find((c) => c.slug === slug)!
walk(collection.fields, slug, problems)
}
expect(problems).toEqual([])
})
test('form builder: blocks the plugin defines, en + pl, within limits', async () => {
const config = await fullConfig()
const problems: Problem[] = []
const forms = config.collections!.find((c) => c.slug === 'forms')!
checkText('collection forms singular', 'label', forms.labels?.singular, problems)
checkText('collection forms plural', 'label', forms.labels?.plural, problems)
const blocksField = forms.fields.find((f) => 'name' in f && f.name === 'fields') as { blocks: { fields: Field[]; labels?: { plural?: Text; singular?: Text }; slug: string }[] }
for (const block of blocksField.blocks) {
checkText(`forms.fields.${block.slug}.labels.singular`, 'label', block.labels?.singular, problems)
walk(block.fields, `forms.fields.${block.slug}`, problems)
}
expect(problems).toEqual([])
})
test('component texts: same keys in en and pl, none empty, no developer words', () => {
const en = adminTexts.en as Record<string, string>
const pl = adminTexts.pl as Record<string, string>
expect(Object.keys(pl).sort()).toEqual(Object.keys(en).sort())
const problems: Problem[] = []
for (const [lang, texts] of Object.entries({ en, pl })) {
for (const [key, s] of Object.entries(texts)) {
if (!s.trim()) {problems.push(`${key} (${lang}) is empty`)}
if (s.length > TEXT_MAX) {problems.push(`${key} (${lang}) over ${TEXT_MAX} chars`)}
// The vendor credit (whiteLabel.credit) is the one place that names the vendor.
if (key !== 'brandingCredit' && JARGON.test(s.replace(/\{\{\w+\}\}/g, ''))) {problems.push(`${key} (${lang}) has developer words: "${s}"`)}
}
}
expect(problems).toEqual([])
})
})
describe('admin languages', () => {
test('English and Polish by default, with the plugin texts', async () => {
const config = await fullConfig()
expect(Object.keys(config.i18n?.supportedLanguages ?? {}).sort()).toEqual(['en', 'pl'])
const translations = config.i18n?.translations as Record<string, { ipal: Record<string, string> }>
expect(translations.pl.ipal).toEqual(adminTexts.pl)
expect(translations.en.ipal).toEqual(adminTexts.en)
})
test("the project's languages and translations win", () => {
const de = { dateFNSKey: 'de', translations: {} }
const key = Object.keys(adminTexts.en)[0]
const config = applyAdminI18n({
i18n: { supportedLanguages: { de } as never, translations: { de: { ipal: { [key]: 'Eigener Text' } } } as never },
} as Config)
expect(Object.keys(config.i18n!.supportedLanguages!)).toEqual(['de'])
const translations = config.i18n!.translations as Record<string, { ipal: Record<string, string> }>
expect(translations.de.ipal[key]).toBe('Eigener Text')
// Another key falls back to English, not to the raw key.
const other = Object.keys(adminTexts.en)[1]
expect(translations.de.ipal[other]).toBe((adminTexts.en as Record<string, string>)[other])
})
})
+1 -1
View File
@@ -83,7 +83,7 @@ describe('noindex protection', () => {
const home = await payload.create({ collection: 'pages' as never, data: { slug: 'start', _status: 'published', title: 'Start' } as never })
const other = await payload.create({ collection: 'pages' as never, data: { slug: 'dziekujemy', _status: 'published', title: 'Dziękujemy' } as never })
await payload.updateGlobal({ slug: 'site-settings' as never, data: { homepage: home.id, siteName: 'Acme' } as never })
await expect(payload.update({ id: home.id, collection: 'pages' as never, data: { noindex: true } as never })).rejects.toThrow(/Exclude from indexing/)
await expect(payload.update({ id: home.id, collection: 'pages' as never, data: { noindex: true } as never })).rejects.toThrow(/Hide from search engines/)
const updated = (await payload.update({ id: other.id, collection: 'pages' as never, data: { noindex: true } as never })) as { noindex?: boolean }
expect(updated.noindex).toBe(true)
})
+7 -5
View File
@@ -224,8 +224,9 @@ describe('one-call helpers — layout, page, GEO routes', () => {
const shell = await h().getSiteShell('pl')
expect(shell.turnstileSiteKey).toBeNull()
expect(shell.consent.buttons.acceptAll).toEqual(expect.any(String))
expect(shell.formTexts).toMatchObject({ next: 'Next', stepOf: 'Step {current} of {total}' })
expect(shell.lightboxTexts).toMatchObject({ close: 'Close', counter: '{current} / {total}' })
// a Polish page gets the Polish defaults while the panel is empty
expect(shell.formTexts).toMatchObject({ next: 'Dalej', stepOf: 'Krok {current} z {total}' })
expect(shell.lightboxTexts).toMatchObject({ close: 'Zamknij', counter: '{current} / {total}' })
expect(shell.jsonLd.map((n) => n['@type'])).toEqual(['WebSite', 'Organization'])
expect(shell.jsonLd.every((n) => !('@context' in n))).toBe(true)
const custom = createContentHelpers({ baseUrl: 'https://acme.pl', config: configPromise, i18n, siteJsonLd: false })
@@ -319,7 +320,8 @@ describe('consent texts', () => {
expect(empty.title).toBeUndefined()
expect(empty.settingsDescription).toBeUndefined()
expect(empty.alwaysActiveLabel).toBeUndefined()
expect(empty.buttons.close).toBe('Close')
expect(empty.buttons.close).toBe('Zamknij') // Polish default on a Polish page
expect((await getConsentTexts({ config, locale: 'en', payload, privacyPolicy: false })).buttons.close).toBe('Close')
await payload.updateGlobal({
slug: 'cookie-settings' as never,
@@ -354,10 +356,10 @@ describe('cookie table', () => {
{ name: '_ga', category: 'analytics', duration: '2 lata', provider: 'Google', purpose: 'Statystyki' },
])
// the same rows feed the detailed settings window, with English labels until the panel has them
// the same rows feed the detailed settings window, with the page language's default labels until the panel has them
const texts = await getConsentTexts({ config: { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] }, locale: 'pl', payload, privacyPolicy: false })
expect(texts.cookies).toEqual([{ name: '_ga', category: 'analytics', duration: '2 lata', provider: 'Google', purpose: 'Statystyki' }])
expect(texts.details).toEqual({ cookies: 'Cookies used', duration: 'Duration', provider: 'Provider', purpose: 'Purpose' })
expect(texts.details).toEqual({ cookies: 'Używane cookies', duration: 'Okres', provider: 'Dostawca', purpose: 'Cel' })
await payload.updateGlobal({
slug: 'cookie-settings' as never,
+3
View File
@@ -94,6 +94,9 @@ describe('lightbox helpers', () => {
expect(lightboxIndex(0, -1, 3, false)).toBe(0)
expect(formatLightboxCounter('{current} z {total}', 2, 5)).toBe('2 z 5')
expect(resolveLightboxTexts({ close: 'Zamknij', next: ' ', previous: null })).toEqual({ ...LIGHTBOX_FALLBACK, close: 'Zamknij' })
// a Polish page falls back to Polish, any other language to English
expect(resolveLightboxTexts({ close: 'X' }, 'pl')).toMatchObject({ close: 'X', next: 'Następne zdjęcie' })
expect(resolveLightboxTexts(null, 'de').next).toBe(LIGHTBOX_FALLBACK.next)
})
test('Notifications gets the Lightbox group only when asked', () => {
+5 -1
View File
@@ -94,7 +94,11 @@ describe('project-defined link styles', () => {
const { buildLinkField } = await import('../src/modules/links/buildLinkField.js')
const field = buildLinkField({ appearances: ['primary', { label: 'Highlighted', value: 'highlight' }] })
const select = field.fields.find((f) => 'name' in f && f.name === 'appearance') as { defaultValue: string; options: unknown[] }
expect(select.options).toEqual([{ label: 'primary', value: 'primary' }, { label: 'Highlighted', value: 'highlight' }])
// a default style named by value gets its panel label; the project's own label is kept
expect(select.options).toEqual([
{ label: { en: 'Main button', pl: 'Przycisk główny' }, value: 'primary' },
{ label: 'Highlighted', value: 'highlight' },
])
expect(select.defaultValue).toBe('primary')
expect(resolveLink({ ...page('oferta'), appearance: 'highlight' }, opts)?.appearance).toBe('highlight')
})
+6 -6
View File
@@ -148,12 +148,12 @@ describe('gap fixes: searchSettings, collection overrides', () => {
const tabsOf = (config: Config) => {
const settings = config.globals!.find((g) => g.slug === 'site-settings')!
const tabs = settings.fields.find((f) => f.type === 'tabs') as { tabs: { label?: unknown }[] }
return tabs.tabs.map((t) => String(t.label))
return tabs.tabs.map((t) => (t.label as { en?: string } | undefined)?.en ?? String(t.label))
}
test('searchSettings: false removes the Search & AI tab without `seo`', async () => {
expect(tabsOf(await ipalKit({ i18n, twoFactor: false })(base()))).toContain('Search & AI')
expect(tabsOf(await ipalKit({ i18n, searchSettings: false, twoFactor: false })(base()))).not.toContain('Search & AI')
test('searchSettings: false removes the Search engines tab without `seo`', async () => {
expect(tabsOf(await ipalKit({ i18n, twoFactor: false })(base()))).toContain('Search engines')
expect(tabsOf(await ipalKit({ i18n, searchSettings: false, twoFactor: false })(base()))).not.toContain('Search engines')
})
test('searchSettings: a function shapes the fields; the top-level option wins over seo.searchSettings', async () => {
@@ -165,11 +165,11 @@ describe('gap fixes: searchSettings, collection overrides', () => {
})(base())
const settings = config.globals!.find((g) => g.slug === 'site-settings')!
const tab = (settings.fields.find((f) => f.type === 'tabs') as { tabs: { fields: { name?: string }[]; label?: unknown }[] }).tabs.find(
(t) => t.label === 'Search & AI',
(t) => (t.label as { en?: string } | undefined)?.en === 'Search engines',
)!
expect(tab.fields.map((f) => f.name)).toEqual(['llmsIntro'])
// the older seo.searchSettings still works alone
expect(tabsOf(await ipalKit({ i18n, seo: { collections: [], searchSettings: false }, twoFactor: false })(base()))).not.toContain('Search & AI')
expect(tabsOf(await ipalKit({ i18n, seo: { collections: [], searchSettings: false }, twoFactor: false })(base()))).not.toContain('Search engines')
})
test('consentLog / stats collectionOverrides: an object merges access, a function takes over', async () => {
+7 -7
View File
@@ -32,7 +32,7 @@ afterEach(() => {
vi.unstubAllEnvs()
})
describe('search verification (Site Settings → Search & AI)', () => {
describe('search verification (Site settings → Search engines)', () => {
test('keeps the code from a bare value or a pasted <meta> tag', () => {
expect(normalizeVerificationToken(' abc-123_XYZ ')).toBe('abc-123_XYZ')
expect(normalizeVerificationToken('<meta name="google-site-verification" content="Tok_9-x" />')).toBe('Tok_9-x')
@@ -289,24 +289,24 @@ describe('collectSiteIndex and llms.txt', () => {
})
})
describe('plugin: Search & AI tab', () => {
describe('plugin: Search engines tab', () => {
const base = (): Config => ({ collections: [{ slug: 'users', auth: true, fields: [] }], secret: 'test' }) as unknown as Config
const tabs = (c: Config) => {
const settings = c.globals?.find((g) => g.slug === 'site-settings')
const field = settings?.fields[0] as { tabs: { label: string }[] }
return field.tabs.map((t) => t.label)
const field = settings?.fields[0] as { tabs: { label: { en: string } }[] }
return field.tabs.map((t) => t.label.en)
}
test('on by default, off with seo.searchSettings: false', async () => {
const on = await ipalKit({ access: { authCollection: 'users' }, i18n: config, twoFactor: false })(base())
expect(tabs(on)).toContain('Search & AI')
expect(tabs(on)).toContain('Search engines')
const off = await ipalKit({
access: { authCollection: 'users' },
i18n: config,
seo: { collections: [], searchSettings: false },
twoFactor: false,
})(base())
expect(tabs(off)).not.toContain('Search & AI')
expect(tabs(off)).not.toContain('Search engines')
const custom = await ipalKit({
access: { authCollection: 'users' },
i18n: config,
@@ -314,7 +314,7 @@ describe('plugin: Search & AI tab', () => {
twoFactor: false,
})(base())
const settings = custom.globals?.find((g) => g.slug === 'site-settings')
const tab = (settings?.fields[0] as { tabs: { fields: { name?: string }[]; label: string }[] }).tabs.find((t) => t.label === 'Search & AI')
const tab = (settings?.fields[0] as { tabs: { fields: { name?: string }[]; label: { en: string } }[] }).tabs.find((t) => t.label.en === 'Search engines')
expect(tab?.fields.map((f) => f.name)).toEqual(['searchVerification', 'aiCrawlers'])
})
})
+2 -2
View File
@@ -87,8 +87,8 @@ describe('buildR2Storage — read-only media (R2_PUBLIC_URL only, outside produc
test('uploads and deletes are refused, metadata edits pass', async () => {
const hooks = await mediaHooks({ NODE_ENV: 'development', R2_PUBLIC_URL: 'https://media.acme.pl' })
const guard = hooks!.beforeOperation[0]
expect(() => guard({ args: { req: { file: {} } }, operation: 'create' })).toThrow(/read-only/)
expect(() => guard({ args: { req: {} }, operation: 'delete' })).toThrow(/read-only/)
expect(() => guard({ args: { req: { file: {} } }, operation: 'create' })).toThrow(/cannot be uploaded or deleted/)
expect(() => guard({ args: { req: {} }, operation: 'delete' })).toThrow(/cannot be uploaded or deleted/)
expect(() => guard({ args: { req: {} }, operation: 'update' })).not.toThrow()
})
+24 -2
View File
@@ -1,6 +1,9 @@
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { submitForm } from '../src/modules/forms/submitForm.js'
import { localizedRules, minLength, required } from '../src/modules/forms/validators.js'
import { notificationFallback } from '../src/modules/notifications/defaults.js'
import { resolveFormMessage } from '../src/modules/notifications/resolveFormMessage.js'
import { UNKNOWN_IP_FACTOR } from '../src/modules/shared/rateLimit.js'
import { fakePayload } from './helpers.js'
@@ -171,6 +174,25 @@ describe('submitForm — other gates', () => {
})
})
test('a validation message names the field by its label, in the page language', async () => {
const { payload } = fakePayload({ forms: { f: { fields: [{ name: 'email', blockType: 'email', label: 'Adres e-mail', required: true }] } } })
const result = await submitForm({ data: { email: 'nope' }, formId: 'f', ip: nextIp(), locale: 'pl', maxPerMinute: 0, payload })
expect(result).toEqual({ field: 'email', kind: 'invalid_format', label: 'Adres e-mail', reason: 'validation', success: false })
expect(resolveFormMessage(result, notificationFallback('pl').form)).toBe('Sprawdź pole „Adres e-mail”.')
// no single field at fault → the generic error, never an empty {field}
expect(resolveFormMessage({ kind: 'unknown_fields', reason: 'validation', success: false }, notificationFallback('en').form)).toBe(notificationFallback('en').form.error)
})
test('validator messages: full sentences, Polish via localizedRules, own message wins', () => {
expect(required()('')).toBe('Fill in this field.')
expect(minLength(10)('abc')).toBe('Enter at least 10 characters.')
const pl = localizedRules('pl-PL')
expect(pl.required()('')).toBe('Uzupełnij to pole.')
expect(pl.minLength(2)('a')).toBe('Wpisz co najmniej 2 znaki.')
expect(pl.minLength(5)('a')).toBe('Wpisz co najmniej 5 znaków.')
expect(pl.email('Mój tekst')('x')).toBe('Mój tekst')
})
test('the captcha field injected by the widget is not an unknown key', async () => {
const { create, payload } = fakePayload({ forms })
const result = await submitForm({
@@ -200,8 +222,8 @@ describe('turnstileKeyProblem', () => {
const { turnstileKeyProblem } = await import('../src/modules/turnstile/config.js')
expect(turnstileKeyProblem({})).toBeNull()
expect(turnstileKeyProblem({ turnstileSecretKey: 's', turnstileSiteKey: 'k' })).toBeNull()
expect(turnstileKeyProblem({ turnstileSiteKey: 'k' })).toMatch(/Secret key is missing/)
expect(turnstileKeyProblem({ turnstileSecretKey: 's' })).toMatch(/Site key is missing/)
expect(turnstileKeyProblem({ turnstileSiteKey: 'k' })).toMatch(/secret key is missing/)
expect(turnstileKeyProblem({ turnstileSecretKey: 's' })).toMatch(/site key is missing/)
vi.stubEnv('TURNSTILE_SECRET_KEY', 's')
expect(turnstileKeyProblem({ turnstileSiteKey: 'k' })).toBeNull()
})