// LessonPlanReadonlyView 组件单测
// 依据：02-architecture-design.md §15 组件设计
// 覆盖：基本信息 / 教学目标 / 教学重点 / 教学难点 / 教学内容 / 作业说明（可选）/ 空列表

import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import { LessonPlanReadonlyView } from "./LessonPlanReadonlyView";
import type { LessonPlanDetail } from "@/types";

const fullDetail: LessonPlanDetail = {
  id: "lp-002",
  title: "配方法解一元二次方程",
  subject: "数学",
  className: "初一(1)班",
  teacherName: "王老师",
  textbookTitle: "人教版七年级数学下册",
  chapterTitle: "第一章 一元二次方程",
  status: "published",
  publishedAt: "2026-02-22T10:00:00Z",
  estimatedMinutes: 45,
  objectives: [
    "理解配方法的几何意义",
    "掌握用配方法解一元二次方程的步骤",
  ],
  keyPoints: ["配方法的核心步骤", "完全平方式的应用"],
  difficultPoints: ["配方时如何确定常数项", "二次项系数不为 1 时的处理"],
  content: "本节课主要讲解配方法解一元二次方程的完整步骤。",
  homeworkDescription: "课本第 25 页练习 1-4 题。",
};

describe("LessonPlanReadonlyView 完整内容", () => {
  it("渲染标题与学科", () => {
    render(<LessonPlanReadonlyView lessonPlan={fullDetail} />);
    expect(screen.getByText("配方法解一元二次方程")).toBeInTheDocument();
    expect(screen.getByText("数学")).toBeInTheDocument();
  });

  it("渲染基本信息（班级/教师/教材/章节）", () => {
    render(<LessonPlanReadonlyView lessonPlan={fullDetail} />);
    expect(screen.getByText("初一(1)班")).toBeInTheDocument();
    expect(screen.getByText("王老师")).toBeInTheDocument();
    expect(screen.getByText("人教版七年级数学下册")).toBeInTheDocument();
    expect(screen.getByText("第一章 一元二次方程")).toBeInTheDocument();
  });

  it("渲染教学目标列表", () => {
    render(<LessonPlanReadonlyView lessonPlan={fullDetail} />);
    expect(
      screen.getByText("理解配方法的几何意义"),
    ).toBeInTheDocument();
    expect(
      screen.getByText("掌握用配方法解一元二次方程的步骤"),
    ).toBeInTheDocument();
  });

  it("渲染教学重点列表", () => {
    render(<LessonPlanReadonlyView lessonPlan={fullDetail} />);
    expect(screen.getByText("配方法的核心步骤")).toBeInTheDocument();
    expect(screen.getByText("完全平方式的应用")).toBeInTheDocument();
  });

  it("渲染教学难点列表", () => {
    render(<LessonPlanReadonlyView lessonPlan={fullDetail} />);
    expect(
      screen.getByText("配方时如何确定常数项"),
    ).toBeInTheDocument();
    expect(
      screen.getByText("二次项系数不为 1 时的处理"),
    ).toBeInTheDocument();
  });

  it("渲染教学内容文本", () => {
    render(<LessonPlanReadonlyView lessonPlan={fullDetail} />);
    expect(
      screen.getByText(
        "本节课主要讲解配方法解一元二次方程的完整步骤。",
      ),
    ).toBeInTheDocument();
  });

  it("渲染作业说明（当存在时）", () => {
    render(<LessonPlanReadonlyView lessonPlan={fullDetail} />);
    expect(screen.getByText("课本第 25 页练习 1-4 题。")).toBeInTheDocument();
  });
});

describe("LessonPlanReadonlyView 作业说明可选", () => {
  it("无作业说明时不渲染作业说明区块", () => {
    const noHomework: LessonPlanDetail = {
      ...fullDetail,
      homeworkDescription: undefined,
    };
    render(<LessonPlanReadonlyView lessonPlan={noHomework} />);
    // "作业说明" 标题不应出现
    const headings = screen.queryAllByText("作业说明");
    expect(headings).toHaveLength(0);
  });
});

describe("LessonPlanReadonlyView 空列表", () => {
  it("教学目标为空时显示空态文案", () => {
    const emptyObjectives: LessonPlanDetail = {
      ...fullDetail,
      objectives: [],
    };
    render(<LessonPlanReadonlyView lessonPlan={emptyObjectives} />);
    expect(screen.getByText("暂无教学目标")).toBeInTheDocument();
  });

  it("教学重点为空时显示空态文案", () => {
    const emptyKeyPoints: LessonPlanDetail = {
      ...fullDetail,
      keyPoints: [],
    };
    render(<LessonPlanReadonlyView lessonPlan={emptyKeyPoints} />);
    expect(screen.getByText("暂无教学重点")).toBeInTheDocument();
  });

  it("教学难点为空时显示空态文案", () => {
    const emptyDifficult: LessonPlanDetail = {
      ...fullDetail,
      difficultPoints: [],
    };
    render(<LessonPlanReadonlyView lessonPlan={emptyDifficult} />);
    expect(screen.getByText("暂无教学难点")).toBeInTheDocument();
  });
});
