Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whitphx committed Nov 21, 2024
1 parent 76edbc0 commit 25f783e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/kernel/src/react-helpers/download-button.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, it, expect } from "vitest";
import { getFileNameFromContentDispositionHeader } from "./download-button";

describe("getFileNameFromContentDispositionHeader", () => {
[
{
header: `attachment; filename="StreamlitApp_2022-08-12_14-44-14.bin"`,
expected: "StreamlitApp_2022-08-12_14-44-14.bin",
},
{
header: "attachment; filename*=utf-8''%E3%83%86%E3%82%B9%E3%83%88.png",
expected: "テスト.png",
},
].forEach(({ header, expected }) => {
it(`extracts filename ("${expected}") from the given ContentDisposition header value ("${header}")`, () => {
expect(getFileNameFromContentDispositionHeader(header)).toEqual(expected);
});
});
});
2 changes: 1 addition & 1 deletion packages/kernel/src/react-helpers/download-button.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StliteKernel } from "../kernel";
import { parse } from "@tinyhttp/content-disposition";

function getFileNameFromContentDispositionHeader(
export function getFileNameFromContentDispositionHeader(
contentDisposition: string,
): string | undefined {
const parsed = parse(contentDisposition);
Expand Down

0 comments on commit 25f783e

Please sign in to comment.