|
| 1 | +import type { ReactNode } from "react"; |
| 2 | +import { render, screen } from "@testing-library/react"; |
| 3 | +import { describe, expect, it, vi } from "vitest"; |
| 4 | +import type { SkillSpec } from "../../../../api/types"; |
| 5 | + |
| 6 | +vi.mock("@agentscope-ai/design", () => { |
| 7 | + const Container = ({ children }: { children?: ReactNode }) => ( |
| 8 | + <div>{children}</div> |
| 9 | + ); |
| 10 | + return { |
| 11 | + Button: Container, |
| 12 | + Card: Container, |
| 13 | + Checkbox: Container, |
| 14 | + Switch: Container, |
| 15 | + Tooltip: Container, |
| 16 | + }; |
| 17 | +}); |
| 18 | + |
| 19 | +vi.mock("@ant-design/icons", () => { |
| 20 | + const Icon = () => <span />; |
| 21 | + return { |
| 22 | + CalendarFilled: Icon, |
| 23 | + FileTextFilled: Icon, |
| 24 | + FileZipFilled: Icon, |
| 25 | + FilePdfFilled: Icon, |
| 26 | + FileWordFilled: Icon, |
| 27 | + FileExcelFilled: Icon, |
| 28 | + FilePptFilled: Icon, |
| 29 | + FileImageFilled: Icon, |
| 30 | + CodeFilled: Icon, |
| 31 | + EyeOutlined: Icon, |
| 32 | + EyeInvisibleOutlined: Icon, |
| 33 | + }; |
| 34 | +}); |
| 35 | + |
| 36 | +vi.mock("react-i18next", () => ({ |
| 37 | + useTranslation: () => ({ t: (key: string) => key }), |
| 38 | +})); |
| 39 | + |
| 40 | +vi.mock("@/utils/skill", () => ({ |
| 41 | + isSkillBuiltin: () => false, |
| 42 | +})); |
| 43 | + |
| 44 | +import { SkillCard } from "./SkillCard"; |
| 45 | +import { SkillListItem } from "./SkillListItem"; |
| 46 | + |
| 47 | +const makeSkill = (enabled: boolean, preload: boolean): SkillSpec => ({ |
| 48 | + name: "resident", |
| 49 | + description: "test", |
| 50 | + source: "customized", |
| 51 | + enabled, |
| 52 | + load_policy: preload ? "preload" : "on_demand", |
| 53 | + channels: ["all"], |
| 54 | +}); |
| 55 | + |
| 56 | +describe("preloaded badge", () => { |
| 57 | + it.each([ |
| 58 | + ["card", SkillCard], |
| 59 | + ["list", SkillListItem], |
| 60 | + ])("shows only for an enabled preloaded %s Skill", (_name, Component) => { |
| 61 | + const commonProps = { |
| 62 | + onClick: vi.fn(), |
| 63 | + onToggleEnabled: vi.fn(), |
| 64 | + onDelete: vi.fn(), |
| 65 | + }; |
| 66 | + const renderComponent = (skill: SkillSpec) => |
| 67 | + Component === SkillCard ? ( |
| 68 | + <SkillCard skill={skill} {...commonProps} /> |
| 69 | + ) : ( |
| 70 | + <SkillListItem |
| 71 | + skill={skill} |
| 72 | + batchModeEnabled={false} |
| 73 | + isSelected={false} |
| 74 | + onSelect={vi.fn()} |
| 75 | + {...commonProps} |
| 76 | + /> |
| 77 | + ); |
| 78 | + const { rerender } = render(renderComponent(makeSkill(false, true))); |
| 79 | + |
| 80 | + expect(screen.queryByText("skills.preloadedBadge")).toBeNull(); |
| 81 | + rerender(renderComponent(makeSkill(true, false))); |
| 82 | + expect(screen.queryByText("skills.preloadedBadge")).toBeNull(); |
| 83 | + rerender(renderComponent(makeSkill(true, true))); |
| 84 | + expect(screen.getByText("skills.preloadedBadge")).toBeInTheDocument(); |
| 85 | + }); |
| 86 | +}); |
0 commit comments