File size: 1,742 Bytes
4e7644b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { describe, it, expect } from "vitest";
import { render } from "@testing-library/react";
import { SkillVisual, getFileIcon } from "./index";

describe("SkillVisual", () => {
  it("renders emoji when provided", () => {
    const { container } = render(<SkillVisual name="my-skill" emoji="🤖" />);
    expect(container.textContent).toBe("🤖");
  });

  it("applies emojiClassName to emoji wrapper", () => {
    const { container } = render(
      <SkillVisual name="skill" emoji="⚡" emojiClassName="emoji-cls" />,
    );
    expect(container.querySelector(".emoji-cls")).toBeInTheDocument();
  });

  it("renders file icon when no emoji provided", () => {
    const { container } = render(<SkillVisual name="report.pdf" />);
    expect(container.querySelector("[role='img']")).toBeInTheDocument();
  });
});

describe("getFileIcon", () => {
  const cases: [string, string][] = [
    ["file_reader", "FileTextFilled"],
    ["news", "FileTextFilled"],
    ["docx", "FileWordFilled"],
    ["xlsx", "FileExcelFilled"],
    ["pptx", "FilePptFilled"],
    ["pdf", "FilePdfFilled"],
    ["cron", "CalendarFilled"],
    ["report.txt", "FileTextFilled"],
    ["archive.zip", "FileZipFilled"],
    ["photo.jpg", "FileImageFilled"],
    ["script.py", "CodeFilled"],
    ["unknown.xyz", "FileTextFilled"],
  ];

  it.each(cases)("getFileIcon('%s') renders correct icon", (input) => {
    const { container } = render(<>{getFileIcon(input)}</>);
    expect(container.querySelector("[role='img']")).toBeInTheDocument();
  });

  it("handles extra whitespace and mixed case in skill key", () => {
    const { container } = render(<>{getFileIcon("  CRON  ")}</>);
    expect(container.querySelector("[role='img']")).toBeInTheDocument();
  });
});