lihongyuan99 241a7b3b9b
fix(frontend): key the Julia entry of extensionMap by its extension (#6130)
extensionMap is keyed by extension and valued by language, but the Julia row
was written backwards as `julia: "jl"`. checkCodeFile tests membership with
`extension in extensionMap`, so ".jl" never matched and a Julia artifact was
not a code file at all, while ".julia" resolved to a language named "jl".

Add both `jl: "julia"` and `julia: "julia"`, the same pair form the map already
uses for haskell/hs and elixir/ex, so no extension that classified before stops
classifying.
2026-10-01 09:58:23 +08:00

47 lines
1.3 KiB
TypeScript

import { expect, test } from "@rstest/core";
import { FilePlayIcon, FileTextIcon, ImageIcon } from "lucide-react";
import {
canBrowserPreviewFile,
checkCodeFile,
getFileIcon,
} from "@/core/utils/files";
test.each([
["animation.apng", ImageIcon],
["photo.avif", ImageIcon],
["clip.webm", FilePlayIcon],
])("uses a media icon for previewable %s", (filepath, icon) => {
expect(canBrowserPreviewFile(filepath)).toBe(true);
expect(getFileIcon(filepath).type).toBe(icon);
});
test("keeps the document icon for an unknown extension", () => {
expect(getFileIcon("data.unknown").type).toBe(FileTextIcon);
});
// `extensionMap` maps a file extension to a language name. Both halves of that
// direction matter: `checkCodeFile` tests extension membership, and the language
// is what the editor and previewers receive.
test("resolves a language from its extension", () => {
expect(checkCodeFile("script.hs")).toEqual({
isCodeFile: true,
language: "haskell",
});
expect(checkCodeFile("deploy.ex")).toEqual({
isCodeFile: true,
language: "elixir",
});
expect(checkCodeFile("analysis.jl")).toEqual({
isCodeFile: true,
language: "julia",
});
});
test("values the language name, never the extension it came from", () => {
expect(checkCodeFile("notes.julia")).toEqual({
isCodeFile: true,
language: "julia",
});
});