// Lichte regressie-tests voor de mobile backlog-page. Server-component render
// vereist te veel mocking; we asserten op statische source-eigenschappen die
// kritisch zijn voor de mobile-shell (cookie-key gescheiden, /m/-paden).
import { describe, it, expect } from 'vitest'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'

const PAGE = resolve(process.cwd(), 'app/(mobile)/m/products/[id]/page.tsx')
const src = readFileSync(PAGE, 'utf-8')

describe('mobile backlog page (ST-1137)', () => {
  it('gebruikt gescheiden cookie-key (backlog-{id}-mobile)', () => {
    // Beslissing C: tab-mode-gebruikers vervuilen desktop-split niet.
    expect(src).toMatch(/cookieKey=\{`backlog-\$\{id\}-mobile`\}/)
  })

  it('closePath en TaskDialog redirect blijven onder /m/products/', () => {
    expect(src).toContain('const closePath = `/m/products/${id}`')
  })

  it('hergebruikt BacklogHydrationWrapper + BacklogSplitPane (geen content-componenten dupliceren)', () => {
    expect(src).toContain('BacklogHydrationWrapper')
    expect(src).toContain('BacklogSplitPane')
    expect(src).toContain('PbiList')
    expect(src).toContain('StoryPanel')
    expect(src).toContain('TaskPanel')
  })

  it('auth via requireSession() (gedeelde guard)', () => {
    expect(src).toContain("from '@/lib/auth-guard'")
    expect(src).toContain('requireSession()')
  })

  it('rendert TaskDialog op ?newTask en EditTaskLoader op ?editTask', () => {
    expect(src).toContain('{newTask &&')
    expect(src).toContain('{editTask && !newTask &&')
  })
})
