package com.correx.apps.cli.commands

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class TaskRenderTest {

    private val task = TaskRow(
        id = "auth-1",
        key = "auth-1",
        status = "IN_PROGRESS",
        title = "JWT refresh",
        goal = "users stay authenticated",
        acceptanceCriteria = listOf("rotates"),
        affectedPaths = listOf("backend/auth/**"),
        claimant = "claude-opus",
        links = listOf(TaskLinkRow("adr-7", "IMPLEMENTS", "DOC")),
        notes = listOf(TaskNoteRow("AGENT", "kickoff")),
    )

    @Test
    fun `renderTaskList shows one line per task with id, status, title`() {
        val out = renderTaskList(listOf(task, TaskRow(id = "billing-3", status = "DONE", title = "Invoice")))
        val lines = out.lines()
        assertEquals(2, lines.size)
        assertTrue(lines[0].startsWith("auth-1"))
        assertTrue(
            lines[0].contains("IN_PROGRESS") && lines[0].contains("JWT refresh") && lines[0].contains("@claude-opus"),
        )
        assertTrue(lines[1].contains("billing-3") && lines[1].contains("DONE"))
    }

    @Test
    fun `renderTaskList reports empty`() {
        assertEquals("no tasks", renderTaskList(emptyList()))
    }

    @Test
    fun `renderTaskDetail includes goal, criteria, links and notes`() {
        val out = renderTaskDetail(task)
        assertTrue(out.startsWith("task auth-1 [IN_PROGRESS] JWT refresh"))
        val wants = listOf(
            "goal: users stay authenticated",
            "- rotates",
            "backend/auth/**",
            "adr-7 (IMPLEMENTS -> DOC)",
            "[AGENT] kickoff",
        )
        for (want in wants) {
            assertTrue(out.contains(want), "detail missing: $want")
        }
    }
}
