import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, expect, test } from "vitest";
import { fixtureTask } from "../fixtures";
import { TurnContent } from "./TurnContent";
afterEach(cleanup);
test("a running request is visible without a stale or placeholder reply", () => {
const task={...fixtureTask(),status:"working" as const,promptExcerpt:"Current **request**",replyExcerpt:null};
render();
expect(screen.getByLabelText("Latest turn request").querySelector('strong')?.textContent).toBe('request');
expect(screen.queryByLabelText("Latest turn response")).toBeNull();
});
test("details use full text, and only actual scheduled input has a clock", () => {
const task={...fixtureTask(),scheduled:true,inputSource:"ordinary" as const,promptExcerpt:"Short",promptText:"Full request",replyExcerpt:"Short result",replyText:"Full result"};
const {rerender}=render();
expect(screen.getByText('Full request')).toBeVisible(); expect(screen.getByText('Full result')).toBeVisible();
expect(screen.queryByLabelText('Scheduled prompt')).toBeNull();
rerender();
expect(screen.getByLabelText('Scheduled prompt')).toBeVisible();
});
test("cards show only the prompt while running and only the response otherwise", () => {
const task={...fixtureTask(),status:"working" as const,promptExcerpt:"Current request",replyExcerpt:"Current response"};
const {rerender}=render();
expect(screen.getByText('Current request')).toBeVisible();expect(screen.queryByText('Current response')).toBeNull();
rerender();
expect(screen.queryByText('Current request')).toBeNull();expect(screen.getByText('Current response')).toBeVisible();
});
test("details hide generated request labels and put worked time before the complete reply", () => {
render();
expect(screen.getByLabelText('Latest turn request')).toHaveTextContent('Please review.');
expect(screen.getByLabelText('Latest turn request')).not.toHaveTextContent('My request:');
expect(screen.getByRole('separator')).toHaveTextContent('Worked for 4m');
expect(screen.getByLabelText('Latest turn response')).toHaveTextContent('Full response.');
});
test("card prompt cleanup does not change response headings", () => {
const task={...fixtureTask(),status:"working" as const,promptExcerpt:"## My request:\nReview this.",replyExcerpt:"## My requests:\nA response section."};
const {rerender}=render();
expect(screen.getByLabelText("Latest turn request")).not.toHaveTextContent("My request:");
rerender();
expect(screen.getByLabelText("Latest turn response")).toHaveTextContent("My requests:");
});