import { describe, expect, it } from 'vitest'

import { isId } from '../../components/Breadcrumbs.js'

/**
 * `isId` decides whether a path segment is a document id (shown as "Edit ...")
 * versus a human-readable route segment (title-cased). Prisma uses
 * `@default(cuid())`, so the regression here is CUIDs being mistaken for slugs
 * and rendered raw in the breadcrumb trail.
 */
describe('Breadcrumbs.isId', () => {
  it('recognizes cuid ids (Prisma @default(cuid()))', () => {
    expect(isId('clp1q2w3e4r5t6y7u8i9o0p1a')).toBe(true)
    expect(isId('cm5xk3a9b0001qz8f4g7h2j6k')).toBe(true)
  })

  it('recognizes cuid2 / long base36 token ids', () => {
    expect(isId('tz4a8f5d2e9b1c6h3k7m0p2q')).toBe(true)
  })

  it('still recognizes numeric and hex ids', () => {
    expect(isId('12345')).toBe(true)
    expect(isId('a1b2c3d4e5f6')).toBe(true)
  })

  it('does not treat human-readable slugs as ids', () => {
    expect(isId('about')).toBe(false)
    expect(isId('contact-us')).toBe(false)
    expect(isId('new')).toBe(false)
    expect(isId('page-builder')).toBe(false)
  })
})
