import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')

test('category tree owns a bounded scroll area inside the skills layout', () => {
  const tree = fs.readFileSync(path.join(ROOT, 'src/components/CategoryTree.jsx'), 'utf8')
  const skills = fs.readFileSync(path.join(ROOT, 'src/pages/AllSkills.jsx'), 'utf8')

  assert.match(tree, /w-64[^"']*h-full[^"']*min-h-0/)
  assert.match(tree, /flex-1 min-h-0 overflow-y-auto/)
  assert.match(skills, /hidden lg:block h-full min-h-0/)
})

test('category mutations wait for the server and surface failures without hiding controls', () => {
  const tree = fs.readFileSync(path.join(ROOT, 'src/components/CategoryTree.jsx'), 'utf8')

  assert.match(tree, /const handleCommitAdd = async/)
  assert.match(tree, /await addNode\(parentId, label\)/)
  assert.match(tree, /const handleCommitEdit = async/)
  assert.match(tree, /await updateNode\(id, label\)/)
  assert.match(tree, /mutationError/)
  assert.match(tree, /active \? 'opacity-100'/)
})
