Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pierre-icons.test.ts

67 lines2.2 KB

1import { assert, describe, it } from "vite-plus/test";
2​
3import {
4 hasSpecificPierreIconForFileName,
5 resolvePierreIconForEntry,
6 T3_PIERRE_ICONS,
7} from "./pierre-icons";
8​
9describe("Pierre file icons", () => {
10 it.each(["photo.heic", "photo.heif", "PHOTO.HEIC", "folder/photo.HEIF"])(
11 "uses the image icon for %s",
12 (name) => {
13 assert.equal(resolvePierreIconForEntry(name, "file")?.token, "image");
14 assert.isTrue(hasSpecificPierreIconForFileName(name));
15 },
16 );
17 it("uses detected types for extensionless files while keeping known filename icons", () => {
18 assert.equal(
19 resolvePierreIconForEntry("custom-script", "file", "text/x-python")?.token,
20 "python",
21 );
22 assert.equal(resolvePierreIconForEntry("image", "file", "image/png")?.token, "image");
23 assert.equal(
24 resolvePierreIconForEntry("Dockerfile", "file", "text/x-shellscript")?.token,
25 "docker",
26 );
27 assert.isNull(resolvePierreIconForEntry("folder.png", "directory", "image/png"));
28 assert.equal(
29 resolvePierreIconForEntry("unknown", "file", "application/octet-stream")?.token,
30 "default",
31 );
32 });
33​
34 it.each([
35 ["pdf", "pdf"],
36 ["doc", "word"],
37 ["docx", "word"],
38 ["odt", "word"],
39 ["rtf", "word"],
40 ["xls", "spreadsheet"],
41 ["xlsx", "spreadsheet"],
42 ["ods", "spreadsheet"],
43 ["csv", "spreadsheet"],
44 ["tsv", "spreadsheet"],
45 ["ppt", "slides"],
46 ["pptx", "slides"],
47 ["odp", "slides"],
48 ["epub", "epub"],
49 ])("uses the document family icon for %s", (extension, family) => {
50 for (const path of [`report.${extension}`, `folder/REPORT.${extension.toUpperCase()}`]) {
51 assert.equal(resolvePierreIconForEntry(path, "file")?.name, `t3-file-icon-${family}`);
52 assert.isTrue(hasSpecificPierreIconForFileName(path));
53 }
54 });
55​
56 it("ships every custom icon referenced by the extended resolver", () => {
57 const customIconNames = new Set(
58 [
59 ...Object.values(T3_PIERRE_ICONS.byFileName),
60 ...Object.values(T3_PIERRE_ICONS.byFileExtension),
61 ].filter((name) => name.startsWith("t3-")),
62 );
63 for (const iconName of customIconNames) {
64 assert.include(T3_PIERRE_ICONS.spriteSheet, `id="${iconName}"`);
65 }
66 });
67});