import { describe, it, expect } from "vitest"; import { render, screen } from "@testing-library/react"; import { WorkflowResultsTab } from "./WorkflowResultsTab"; import type { WorkflowStepResult } from "@fusion/core"; describe("WorkflowResultsTab", () => { const mockResults: WorkflowStepResult[] = [ { workflowStepId: "WS-001", workflowStepName: "QA Check", status: "passed", output: "All tests passed successfully.", startedAt: "2026-03-31T10:00:00Z", completedAt: "2026-03-31T10:02:30Z", }, { workflowStepId: "WS-002", workflowStepName: "Security Audit", status: "failed", output: "Found 2 security issues in auth.ts", startedAt: "2026-03-31T10:02:35Z", completedAt: "2026-03-31T10:03:15Z", }, { workflowStepId: "WS-003", workflowStepName: "Documentation Review", status: "skipped", output: undefined, startedAt: undefined, completedAt: undefined, }, { workflowStepId: "WS-004", workflowStepName: "Performance Check", status: "pending", output: undefined, startedAt: "2026-03-31T10:03:20Z", completedAt: undefined, }, ]; it("renders list of workflow step results", () => { render(); expect(screen.getByTestId("workflow-results-list")).toBeInTheDocument(); expect(screen.getByText("QA Check")).toBeInTheDocument(); expect(screen.getByText("Security Audit")).toBeInTheDocument(); expect(screen.getByText("Documentation Review")).toBeInTheDocument(); expect(screen.getByText("Performance Check")).toBeInTheDocument(); }); it("renders correct status badges for each result", () => { render(); // Passed badge const passedBadge = screen.getByTestId("workflow-result-badge-WS-001"); expect(passedBadge).toHaveTextContent("Passed"); expect(passedBadge).toHaveStyle({ backgroundColor: "var(--color-success, #3fb950)" }); // Failed badge const failedBadge = screen.getByTestId("workflow-result-badge-WS-002"); expect(failedBadge).toHaveTextContent("Failed"); expect(failedBadge).toHaveStyle({ backgroundColor: "var(--color-error, #f85149)" }); // Skipped badge const skippedBadge = screen.getByTestId("workflow-result-badge-WS-003"); expect(skippedBadge).toHaveTextContent("Skipped"); // Pending badge const pendingBadge = screen.getByTestId("workflow-result-badge-WS-004"); expect(pendingBadge).toHaveTextContent("Running…"); expect(pendingBadge).toHaveStyle({ backgroundColor: "var(--todo, #58a6ff)" }); }); it("shows output content for each result", () => { render(); expect(screen.getByTestId("workflow-result-output-WS-001")).toHaveTextContent( "All tests passed successfully." ); expect(screen.getByTestId("workflow-result-output-WS-002")).toHaveTextContent( "Found 2 security issues in auth.ts" ); }); it("handles results without output gracefully", () => { render(); // WS-003 and WS-004 have no output, so output elements should not be rendered expect(screen.queryByTestId("workflow-result-output-WS-003")).not.toBeInTheDocument(); expect(screen.queryByTestId("workflow-result-output-WS-004")).not.toBeInTheDocument(); }); it("shows empty state when no results", () => { render(); expect(screen.getByTestId("workflow-results-empty")).toBeInTheDocument(); expect(screen.getByText("No workflow steps have run yet.")).toBeInTheDocument(); }); it("shows loading state when loading prop is true", () => { render(); expect(screen.getByTestId("workflow-results-loading")).toBeInTheDocument(); expect(screen.getByText("Loading workflow results…")).toBeInTheDocument(); }); it("displays execution timestamps when available", () => { render(); // Check that timestamps are displayed for results that have them const timestamps = screen.getAllByText(/Started:/); expect(timestamps.length).toBeGreaterThanOrEqual(3); // 3 results have startedAt }); it("displays duration when start and end times are available", () => { render(); // The first result has a 2m 30s duration expect(screen.getByText("2m 30s")).toBeInTheDocument(); }); it("handles results with missing timestamps gracefully", () => { const resultsWithoutTimestamps: WorkflowStepResult[] = [ { workflowStepId: "WS-005", workflowStepName: "Simple Check", status: "passed", output: "Done", }, ]; render(); expect(screen.getByText("Simple Check")).toBeInTheDocument(); // Should not crash without timestamps }); });