PocketBase gains optional, manually-authored English fields on articles and categories (same record, same slug), and the frontend serves an /en counterpart of every dynamic route via thin page wrappers around shared view components — no i18n library, consistent with the project's existing minimalism stance for a two-locale site with ~20 UI strings. An article/category with no translation 404s cleanly on its own /en detail page and is filtered out of /en listings, and the header's language-switch link falls back to the English blog index rather than a dead link; resolving that requires a global route middleware, since the layout's header renders before the page content in document order and so can't react to state a page component sets during its own async setup.
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { PAGE_SIZE, langParam, pageParam, pagination, quote } from '../../frontend/server/utils/queries'
|
|
|
|
describe('pagination', () => {
|
|
it('defaults to PAGE_SIZE', () => {
|
|
expect(pagination(2)).toBe(`page=2&perPage=${PAGE_SIZE}`)
|
|
})
|
|
|
|
it('accepts a custom page size', () => {
|
|
expect(pagination(1, 5)).toBe('page=1&perPage=5')
|
|
})
|
|
})
|
|
|
|
describe('pageParam', () => {
|
|
it('accepts a positive integer', () => {
|
|
expect(pageParam('3')).toBe(3)
|
|
expect(pageParam(3)).toBe(3)
|
|
})
|
|
|
|
it.each([undefined, null, '', 'abc', '0', '-1', '1.5', NaN])(
|
|
'falls back to 1 for invalid input %p',
|
|
(value) => {
|
|
expect(pageParam(value)).toBe(1)
|
|
}
|
|
)
|
|
})
|
|
|
|
describe('langParam', () => {
|
|
it('accepts "en"', () => {
|
|
expect(langParam('en')).toBe('en')
|
|
})
|
|
|
|
it.each([undefined, null, '', 'it', 'fr', 123])('falls back to "it" for %p', (value) => {
|
|
expect(langParam(value)).toBe('it')
|
|
})
|
|
})
|
|
|
|
describe('quote', () => {
|
|
it('wraps a plain value in double quotes', () => {
|
|
expect(quote('economia')).toBe('"economia"')
|
|
})
|
|
|
|
it('escapes embedded double quotes', () => {
|
|
expect(quote('la "crisi"')).toBe('"la \\"crisi\\""')
|
|
})
|
|
})
|