Files
ipal-kit/test/adminUxFollowUps.test.ts
Radosław SmolińskiandClaude Fable 5.2 0a4f001797 IAPL rename, scripted: preferred names in src, bin, scripts, services, tests; bin files and skill folders moved
Replaced by an explicit list of forms only (ten exported names, runtime env names, project file
names and marks, commands, skill names, the log prefix, the brand in prose). Package name, import
paths, routes, CSS tokens, data attributes, custom keys, context flags, the cookie and kv keys are
not touched. package.json keeps the five old bin names beside the five new ones.
The old names stop working in this commit and come back as aliases in the next; docs follow.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 17:24:21 +01:00

116 lines
6.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { BasePayload, Config, Field, GlobalConfig, PayloadRequest } from 'payload'
import { describe, expect, test, vi } from 'vitest'
import { adminDocumentTitle, adminTexts, iaplT } 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 { iapl } 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(iaplT(tFor('pl'), 'statsTitle'), '- Payload')).toBe('Statystyki - Payload')
expect(adminDocumentTitle(iaplT(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(iaplT(tFor('en'), 'faviconTooSmall', { height: 32, width: 32 })).toContain('32×32 px')
expect(iaplT(tFor('pl'), 'faviconTooSmall', { height: 32, width: 32 })).toBe('Ikona ma 32×32 px. Google pokazuje ikony od 48×48 px; wgraj większą.')
expect(iaplT(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 iapl({ 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'])
})
})