- Statistics view: the browser-tab title follows the admin language.
Payload's custom-view meta.title is one plain string and its custom-view
metadata ignores i18n, so the view renders <DocumentTitle> (/admin) with the
translated title; it re-applies the title while the view is open because
Next streams the English metadata in after hydration. adminDocumentTitle()
adds admin.meta.titleSuffix the way Payload does.
- Cookie scanner: CookieIntegration.label may be { en, pl, ... }. The built-in
names without a product name come from the shared admin texts
(cookieIntegration*, cookieSourceProject); the scan endpoint answers in the
request's admin language and stored source names use the scanning editor's.
- Maintenance notice: getConstructionMode(locale) returns `locale`; the "x"
close button gets a screen-reader name "Close" / "Zamknij" (locale and
closeLabel props; constructionCloseLabel exported).
- Favicon: FaviconCheck (/admin, afterInput on Site settings -> Site icon)
warns in the admin language when the image is under 48x48 or not square,
without blocking the save; validateFaviconField shares faviconProblems().
- Docs, AGENT.md and skills: the above, plus Next.js 16.4.1 or later as the
minimum safe version (AGENT.md 4.11, ipal-setup, ipal-upgrade).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
116 lines
6.5 KiB
TypeScript
116 lines
6.5 KiB
TypeScript
import type { BasePayload, Config, Field, GlobalConfig, PayloadRequest } from 'payload'
|
||
|
||
import { describe, expect, test, vi } from 'vitest'
|
||
|
||
import { adminDocumentTitle, adminTexts, ipalT } from '../src/modules/admin-i18n/index.js'
|
||
import { buildCookieScanEndpoints } from '../src/modules/consent/scanner/endpoint.js'
|
||
import { DEFAULT_COOKIE_INTEGRATIONS, integrationLabel } from '../src/modules/consent/scanner/integrations.js'
|
||
import { collectCookieFindings } from '../src/modules/consent/scanner/scan.js'
|
||
import { constructionCloseLabel } from '../src/modules/construction/texts.js'
|
||
import { faviconProblems } from '../src/modules/seo/faviconProblems.js'
|
||
import { ipalKit } from '../src/plugin.js'
|
||
|
||
vi.mock('server-only', () => ({}))
|
||
|
||
/** Payload's `t` over the plugin texts, for one language. */
|
||
const tFor = (lang: 'en' | 'pl') =>
|
||
((key: string, vars?: Record<string, unknown>) =>
|
||
((adminTexts[lang] as Record<string, string>)[key.replace(/^ipal:/, '')] ?? key).replace(/\{\{(\w+)\}\}/g, (_, n: string) =>
|
||
String((vars?.[n] as number | string | undefined) ?? ''),
|
||
)) as never
|
||
|
||
const fakePayload = (integrations: Record<string, unknown> = {}) =>
|
||
({
|
||
config: { cookiePrefix: 'payload' },
|
||
findGlobal: vi.fn(async () => integrations),
|
||
logger: { error: vi.fn(), info: vi.fn(), warn: vi.fn() },
|
||
}) as unknown as BasePayload
|
||
|
||
describe('statistics page title', () => {
|
||
test('tab title in the admin language, with the title suffix', () => {
|
||
expect(adminDocumentTitle(ipalT(tFor('pl'), 'statsTitle'), '- Payload')).toBe('Statystyki - Payload')
|
||
expect(adminDocumentTitle(ipalT(tFor('en'), 'statsTitle'), '- Acme')).toBe('Statistics - Acme')
|
||
expect(adminDocumentTitle('Statystyki', '')).toBe('Statystyki')
|
||
})
|
||
})
|
||
|
||
describe('cookie scanner integration names', () => {
|
||
test('built-in names come from the shared admin texts, in English and Polish', () => {
|
||
const admin = DEFAULT_COOKIE_INTEGRATIONS.find((i) => i.key === 'admin')!
|
||
expect(admin.label).toEqual({ en: adminTexts.en.cookieIntegrationAdmin, pl: adminTexts.pl.cookieIntegrationAdmin })
|
||
expect(integrationLabel(admin, 'pl')).toBe('Logowanie do panelu')
|
||
expect(integrationLabel(admin, 'en')).toBe('Admin panel login')
|
||
// a language without its own text falls back to English
|
||
expect(integrationLabel(admin, 'de')).toBe('Admin panel login')
|
||
// product names stay one string for every language
|
||
expect(integrationLabel(DEFAULT_COOKIE_INTEGRATIONS.find((i) => i.key === 'ga4')!, 'pl')).toBe('Google Analytics 4')
|
||
// a project's own integration may still use a plain string
|
||
expect(integrationLabel({ label: 'Chat' }, 'pl')).toBe('Chat')
|
||
})
|
||
|
||
test('the scan endpoint answers in the admin language of the request', async () => {
|
||
const [get] = buildCookieScanEndpoints({ access: () => true }, { localeCount: 2, stats: true })
|
||
const ask = async (language: string) => {
|
||
const req = { i18n: { language }, payload: fakePayload() } as unknown as PayloadRequest
|
||
return ((await (await get.handler(req)).json()) as { integrations: { key: string; label: string }[] }).integrations
|
||
}
|
||
expect(await ask('pl')).toEqual([
|
||
{ key: 'consent', label: 'Baner cookies' },
|
||
{ key: 'admin', label: 'Logowanie do panelu' },
|
||
{ key: 'locale', label: 'Wybór języka' },
|
||
{ key: 'stats', label: 'Wbudowane statystyki' },
|
||
])
|
||
expect((await ask('en')).map((i) => i.label)).toEqual(['Cookie banner', 'Admin panel login', 'Language choice', 'Built-in statistics'])
|
||
})
|
||
|
||
test("source names stored by a scan follow the scanning editor's language", async () => {
|
||
const ctx = { integrations: {}, language: 'pl', payload: fakePayload(), plugin: { localeCount: 1, stats: true } }
|
||
const declarations = [{ name: 'chat', category: 'functional' as const, purpose: 'Chat', retention: '1 day', setBeforeConsent: false, vendor: 'Chat' }]
|
||
const { findings } = await collectCookieFindings({ ctx, database: false, declarations })
|
||
expect(findings.find((f) => f.name === 'chat')?.sourceDetail).toBe('Projekt')
|
||
expect(findings.find((f) => f.name === 'ipal_vid')?.sourceDetail).toBe('Wbudowane statystyki')
|
||
})
|
||
})
|
||
|
||
describe('maintenance notice close button', () => {
|
||
test('screen-reader name in the page language', () => {
|
||
expect(constructionCloseLabel('pl')).toBe('Zamknij')
|
||
expect(constructionCloseLabel('pl-PL')).toBe('Zamknij')
|
||
expect(constructionCloseLabel('en')).toBe('Close')
|
||
expect(constructionCloseLabel('de')).toBe('Close')
|
||
expect(constructionCloseLabel()).toBe('Close')
|
||
})
|
||
})
|
||
|
||
describe('favicon check', () => {
|
||
test('too small, not square, or fine; SVG and unknown sizes pass', () => {
|
||
expect(faviconProblems({ height: 32, mimeType: 'image/png', width: 32 })).toEqual([{ height: 32, key: 'faviconTooSmall', width: 32 }])
|
||
expect(faviconProblems({ height: 96, mimeType: 'image/png', width: 192 })).toEqual([{ height: 96, key: 'faviconNotSquare', width: 192 }])
|
||
expect(faviconProblems({ height: 40, width: 30 }).map((p) => p.key)).toEqual(['faviconTooSmall', 'faviconNotSquare'])
|
||
expect(faviconProblems({ height: 192, mimeType: 'image/png', width: 192 })).toEqual([])
|
||
expect(faviconProblems({ height: 16, mimeType: 'image/svg+xml', width: 16 })).toEqual([])
|
||
expect(faviconProblems({ mimeType: 'image/png' })).toEqual([])
|
||
})
|
||
|
||
test('warnings read in both admin languages with the size filled in', () => {
|
||
expect(ipalT(tFor('en'), 'faviconTooSmall', { height: 32, width: 32 })).toContain('32×32 px')
|
||
expect(ipalT(tFor('pl'), 'faviconTooSmall', { height: 32, width: 32 })).toBe('Ikona ma 32×32 px. Google pokazuje ikony od 48×48 px; wgraj większą.')
|
||
expect(ipalT(tFor('pl'), 'faviconNotSquare', { height: 96, width: 192 })).toContain('192×96 px')
|
||
})
|
||
|
||
test('Site settings shows the check under the site icon', async () => {
|
||
const i18n = { defaultLocale: 'en', locales: [{ code: 'en', label: 'English' }] }
|
||
const config = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: false } as never)({
|
||
collections: [
|
||
{ slug: 'users', auth: true, fields: [] },
|
||
{ slug: 'media', fields: [], upload: true },
|
||
],
|
||
secret: 'test',
|
||
} as unknown as Config)
|
||
const settings = config.globals!.find((g) => g.slug === 'site-settings') as GlobalConfig
|
||
const general = (settings.fields[0] as { tabs: { fields: Field[] }[] }).tabs[0].fields
|
||
const favicon = general.find((f) => 'name' in f && f.name === 'favicon') as { admin: { components: { afterInput: unknown[] } } }
|
||
expect(favicon.admin.components.afterInput).toEqual(['@intecion/ipal-kit/admin#FaviconCheck'])
|
||
})
|
||
})
|