Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): keep converter selection during conversion

Aditya Garudebc9cdec3364
diff --git a/apps/web/__tests__/unit/media-format-converter-selection.test.ts b/apps/web/__tests__/unit/media-format-converter-selection.test.ts
index 7b4fc7862..e867ed7f1 100644
--- a/apps/web/__tests__/unit/media-format-converter-selection.test.ts
+++ b/apps/web/__tests__/unit/media-format-converter-selection.test.ts
@@ -18,6 +18,11 @@ vi.mock("next/navigation", () => ({
useRouter: () => ({ push: vi.fn() }),
}));
vi.mock("@/app/utils/analytics", () => ({ trackEvent: vi.fn() }));
+vi.mock("@remotion/media-parser", () => ({
+ mediaParserController: () => ({ abort: vi.fn() }),
+ parseMedia: () => Promise.resolve({ durationInSeconds: 1 }),
+}));
+vi.mock("@remotion/webcodecs", () => ({ convertMedia: vi.fn() }));
describe("media converter file selection", () => {
let container: HTMLDivElement;
@@ -41,6 +46,7 @@ describe("media converter file selection", () => {
afterEach(async () => {
await act(async () => root.unmount());
container.remove();
+ delete (ArrayBuffer.prototype as { resize?: () => void }).resize;
vi.unstubAllGlobals();
});
@@ -77,4 +83,58 @@ describe("media converter file selection", () => {
expect(container.textContent).not.toContain("Convert to WEBM");
},
);
+
+ it("keeps the active file when an invalid replacement is dropped during conversion", async () => {
+ const { convertMedia } = await import("@remotion/webcodecs");
+ let finishConversion: (blob: Blob) => void = () => {};
+ vi.mocked(convertMedia).mockResolvedValueOnce({
+ save: () =>
+ new Promise<Blob>((resolve) => {
+ finishConversion = resolve;
+ }),
+ } as Awaited<ReturnType<typeof convertMedia>>);
+ vi.stubGlobal("VideoDecoder", class {});
+ vi.stubGlobal("AudioDecoder", class {});
+ Object.defineProperty(ArrayBuffer.prototype, "resize", {
+ configurable: true,
+ value: vi.fn(),
+ });
+ vi.stubGlobal(
+ "URL",
+ class extends URL {
+ static createObjectURL = vi.fn(() => "blob:converted");
+ static revokeObjectURL = vi.fn();
+ },
+ );
+
+ await selectFile(
+ container,
+ new File(["video"], "first.mp4", { type: "video/mp4" }),
+ );
+ const convertButton = [...container.querySelectorAll("button")].find(
+ (button) => button.textContent?.includes("Convert to WEBM"),
+ );
+ await act(async () => {
+ convertButton?.click();
+ });
+ expect(container.textContent).toContain("Converting...");
+
+ const dropZone = container.querySelector("[class*='border-dashed']");
+ if (!dropZone) throw new Error("Missing drop zone");
+ const drop = new Event("drop", { bubbles: true });
+ Object.defineProperty(drop, "dataTransfer", {
+ value: {
+ files: [new File(["wrong"], "notes.txt", { type: "text/plain" })],
+ },
+ });
+ await act(async () => dropZone.dispatchEvent(drop));
+ await act(async () =>
+ finishConversion(new Blob(["converted"], { type: "video/webm" })),
+ );
+
+ expect(container.textContent).toContain("first.mp4");
+ expect(container.textContent).toContain("Conversion complete!");
+ expect(container.textContent).toContain("Download WEBM");
+ expect(container.textContent).not.toContain("Please select a MP4 file.");
+ });
});
diff --git a/apps/web/components/tools/MediaFormatConverter.tsx b/apps/web/components/tools/MediaFormatConverter.tsx
index 42edec693..e3f4855a3 100644
--- a/apps/web/components/tools/MediaFormatConverter.tsx
+++ b/apps/web/components/tools/MediaFormatConverter.tsx
@@ -252,6 +252,8 @@ export const MediaFormatConverter = ({
};
const validateAndSetFile = (selectedFile: File) => {
+ if (isConverting) return;
+
setError(null);
setFile(null);
if (outputUrl) {
@@ -985,6 +987,7 @@ export const MediaFormatConverter = ({
<input
type="file"
accept={getAcceptAttribute(currentSourceFormat)}
+ disabled={isConverting}
className="hidden"
onChange={handleFileChange}
ref={fileInputRef}