Build image / build-and-push (push) Successful in 16s
Co-authored-by: Steve Dudenhoeffer <[email protected]>
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { defaultCopyName } from './gardens'
|
|
|
|
// The server caps a garden name at 200 BYTES and derives a copy's name the same
|
|
// way (copyName in internal/service/gardens.go). These cases pin the mirror: an
|
|
// over-long prefill would come back as a 400 rather than a copy.
|
|
describe('defaultCopyName', () => {
|
|
it('appends the suffix to a short name', () => {
|
|
expect(defaultCopyName('Home')).toBe('Home (copy)')
|
|
})
|
|
|
|
it('keeps a derived name within the 200-byte cap', () => {
|
|
const name = 'a'.repeat(200)
|
|
const derived = defaultCopyName(name)
|
|
expect(new TextEncoder().encode(derived).length).toBeLessThanOrEqual(200)
|
|
expect(derived.endsWith(' (copy)')).toBe(true)
|
|
})
|
|
|
|
it('truncates multi-byte names on a code-point boundary', () => {
|
|
const name = 'é'.repeat(100) // 200 bytes, exactly at the cap
|
|
const derived = defaultCopyName(name)
|
|
expect(new TextEncoder().encode(derived).length).toBeLessThanOrEqual(200)
|
|
// No replacement character: nothing was cut mid-code-point.
|
|
expect(derived).not.toContain('�')
|
|
})
|
|
|
|
it('does not leave a dangling space before the suffix', () => {
|
|
const name = 'x'.repeat(192) + ' y' // truncation lands on the space
|
|
expect(defaultCopyName(name)).toBe('x'.repeat(192) + ' (copy)')
|
|
})
|
|
})
|