Tests: fix test-project typecheck (casts, Rule arity) and base-to-string lint warnings
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a92bc51814
commit
2dafcd0852
@@ -92,12 +92,12 @@ function checkText(where: string, kind: 'description' | 'label' | 'option', valu
|
|||||||
function walk(fields: Field[], path: string, problems: Problem[]) {
|
function walk(fields: Field[], path: string, problems: Problem[]) {
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
const f = field as { admin?: Record<string, unknown> } & Field & Record<string, unknown>
|
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}`
|
const where = `${path}.${'name' in f && typeof f.name === 'string' && f.name ? f.name : f.type}`
|
||||||
if (f.hidden || f.admin?.hidden || f.admin?.disabled) {continue}
|
if (f.hidden || f.admin?.hidden || f.admin?.disabled) {continue}
|
||||||
|
|
||||||
if (f.type === 'tabs') {
|
if (f.type === 'tabs') {
|
||||||
for (const tab of (f as unknown as { tabs: ({ fields: Field[] } & Record<string, unknown>)[] }).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))})`
|
const tabWhere = `${path}.tab(${typeof tab.name === 'string' ? tab.name : JSON.stringify(tab.label)})`
|
||||||
checkText(tabWhere, 'label', tab.label, problems)
|
checkText(tabWhere, 'label', tab.label, problems)
|
||||||
if (tab.description) {checkText(tabWhere, 'description', tab.description, problems)}
|
if (tab.description) {checkText(tabWhere, 'description', tab.description, problems)}
|
||||||
walk(tab.fields, tabWhere, problems)
|
walk(tab.fields, tabWhere, problems)
|
||||||
@@ -226,7 +226,7 @@ describe('admin languages', () => {
|
|||||||
const key = Object.keys(adminTexts.en)[0]
|
const key = Object.keys(adminTexts.en)[0]
|
||||||
const config = applyAdminI18n({
|
const config = applyAdminI18n({
|
||||||
i18n: { supportedLanguages: { de } as never, translations: { de: { ipal: { [key]: 'Eigener Text' } } } as never },
|
i18n: { supportedLanguages: { de } as never, translations: { de: { ipal: { [key]: 'Eigener Text' } } } as never },
|
||||||
} as Config)
|
} as unknown as Config)
|
||||||
expect(Object.keys(config.i18n!.supportedLanguages!)).toEqual(['de'])
|
expect(Object.keys(config.i18n!.supportedLanguages!)).toEqual(['de'])
|
||||||
const translations = config.i18n!.translations as Record<string, { ipal: Record<string, string> }>
|
const translations = config.i18n!.translations as Record<string, { ipal: Record<string, string> }>
|
||||||
expect(translations.de.ipal[key]).toBe('Eigener Text')
|
expect(translations.de.ipal[key]).toBe('Eigener Text')
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ describe('plugin: Search engines tab', () => {
|
|||||||
const base = (): Config => ({ collections: [{ slug: 'users', auth: true, fields: [] }], secret: 'test' }) as unknown as Config
|
const base = (): Config => ({ collections: [{ slug: 'users', auth: true, fields: [] }], secret: 'test' }) as unknown as Config
|
||||||
const tabs = (c: Config) => {
|
const tabs = (c: Config) => {
|
||||||
const settings = c.globals?.find((g) => g.slug === 'site-settings')
|
const settings = c.globals?.find((g) => g.slug === 'site-settings')
|
||||||
const field = settings?.fields[0] as { tabs: { label: { en: string } }[] }
|
const field = settings?.fields[0] as unknown as { tabs: { label: { en: string } }[] }
|
||||||
return field.tabs.map((t) => t.label.en)
|
return field.tabs.map((t) => t.label.en)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,7 +314,7 @@ describe('plugin: Search engines tab', () => {
|
|||||||
twoFactor: false,
|
twoFactor: false,
|
||||||
})(base())
|
})(base())
|
||||||
const settings = custom.globals?.find((g) => g.slug === 'site-settings')
|
const settings = custom.globals?.find((g) => g.slug === 'site-settings')
|
||||||
const tab = (settings?.fields[0] as { tabs: { fields: { name?: string }[]; label: { en: string } }[] }).tabs.find((t) => t.label.en === 'Search engines')
|
const tab = (settings?.fields[0] as unknown 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'])
|
expect(tab?.fields.map((f) => f.name)).toEqual(['searchVerification', 'aiCrawlers'])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -184,13 +184,13 @@ describe('submitForm — other gates', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('validator messages: full sentences, Polish via localizedRules, own message wins', () => {
|
test('validator messages: full sentences, Polish via localizedRules, own message wins', () => {
|
||||||
expect(required()('')).toBe('Fill in this field.')
|
expect(required()('', {})).toBe('Fill in this field.')
|
||||||
expect(minLength(10)('abc')).toBe('Enter at least 10 characters.')
|
expect(minLength(10)('abc', {})).toBe('Enter at least 10 characters.')
|
||||||
const pl = localizedRules('pl-PL')
|
const pl = localizedRules('pl-PL')
|
||||||
expect(pl.required()('')).toBe('Uzupełnij to pole.')
|
expect(pl.required()('', {})).toBe('Uzupełnij to pole.')
|
||||||
expect(pl.minLength(2)('a')).toBe('Wpisz co najmniej 2 znaki.')
|
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.minLength(5)('a', {})).toBe('Wpisz co najmniej 5 znaków.')
|
||||||
expect(pl.email('Mój tekst')('x')).toBe('Mój tekst')
|
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 () => {
|
test('the captcha field injected by the widget is not an unknown key', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user