|
| 1 | +import { readFileSync } from "node:fs"; |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import { getAvailableLocales, translate } from "@/i18n/loader"; |
| 4 | +import { exportErrorMessage } from "./exportError"; |
| 5 | + |
| 6 | +const cases = [ |
| 7 | + [ |
| 8 | + "No video frames were exported. Check that the clips contain readable video before exporting again.", |
| 9 | + "noReadableFrames", |
| 10 | + ], |
| 11 | + [ |
| 12 | + "Cannot export clip 12: the camera video ends before this clip starts. Record the camera again or remove its track before exporting.", |
| 13 | + "cameraEnded", |
| 14 | + ], |
| 15 | + [ |
| 16 | + "Cannot export clip 12: the camera video has no readable frame at the clip's start. Record the camera again or remove its track before exporting.", |
| 17 | + "cameraUnreadable", |
| 18 | + ], |
| 19 | + [ |
| 20 | + "Cannot export clip 12: the screen video has no readable frame at the clip's start.", |
| 21 | + "screenUnreadable", |
| 22 | + ], |
| 23 | + ["Cannot export clip 12: could not read the screen video.", "screenUnreadable"], |
| 24 | +] as const; |
| 25 | + |
| 26 | +describe("native export error presentation", () => { |
| 27 | + it.each(cases)("localizes %s in every supported language", (message, key) => { |
| 28 | + const native = readFileSync("crates/compositor/src/timeline_walk.rs", "utf8"); |
| 29 | + // The bridge currently carries anyhow text. Catch native wording drift here. |
| 30 | + expect(native).toContain(message.replace("clip 12:", "clip {}:")); |
| 31 | + for (const locale of getAvailableLocales()) { |
| 32 | + const t = (key: string, vars?: Record<string, string | number>) => |
| 33 | + translate(locale, "editor", key, vars); |
| 34 | + const expected = t(`exportDialog.${key}`, { clip: 12 }); |
| 35 | + expect(exportErrorMessage(message, t)).toBe(expected); |
| 36 | + expect(expected).not.toContain("exportDialog."); |
| 37 | + expect(expected).not.toContain("{{"); |
| 38 | + if (key !== "noReadableFrames") expect(expected).toContain("12"); |
| 39 | + if (locale !== "en") |
| 40 | + expect(expected).not.toBe(translate("en", "editor", `exportDialog.${key}`, { clip: 12 })); |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + it("translates recognized context chains without exposing decoder internals", () => { |
| 45 | + const t = (key: string, vars?: Record<string, string | number>) => |
| 46 | + translate("zh-CN", "editor", key, vars); |
| 47 | + for (const [message, key] of cases.slice(2)) { |
| 48 | + expect(exportErrorMessage(`${message}: decoder failed: invalid data`, t)).toBe( |
| 49 | + t(`exportDialog.${key}`, { clip: 12 }), |
| 50 | + ); |
| 51 | + } |
| 52 | + for (const detail of [ |
| 53 | + "No decoder is available for the exported video.", |
| 54 | + "open exported video: invalid data", |
| 55 | + "The exported video has no decodable displayable frames. The destination has not been replaced.", |
| 56 | + ]) { |
| 57 | + for (const locale of getAvailableLocales()) { |
| 58 | + const scoped = (key: string) => translate(locale, "editor", key); |
| 59 | + expect(exportErrorMessage(`validating exported video: ${detail}`, scoped)).toBe( |
| 60 | + scoped("exportDialog.validationFailed"), |
| 61 | + ); |
| 62 | + } |
| 63 | + } |
| 64 | + }); |
| 65 | + |
| 66 | + it.each([ |
| 67 | + "disk full", |
| 68 | + "Cannot export clip 12: unknown encoder error", |
| 69 | + "cleanup failed: validating exported video: invalid data", |
| 70 | + "[pipeline] warning: shortened clip", |
| 71 | + "Cannot export clip 0: could not read the screen video.", |
| 72 | + ])("preserves unrelated errors: %s", (message) => { |
| 73 | + expect(exportErrorMessage(message, () => "wrong diagnosis")).toBe(message); |
| 74 | + }); |
| 75 | +}); |
0 commit comments