Emdash source with visual editor image upload fix

Fixes:
1. media.ts: wrap placeholder generation in try-catch
2. toolbar.ts: check r.ok, display error message in popover
This commit is contained in:
2026-05-03 10:44:54 +07:00
parent 78f81bebb6
commit 2d1be52177
2352 changed files with 662964 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";
import { chunks, SQL_BATCH_SIZE } from "../../../src/utils/chunks.js";
describe("chunks", () => {
it("returns empty array for empty input", () => {
expect(chunks([], 10)).toEqual([]);
});
it("returns single chunk when array fits within size", () => {
expect(chunks([1, 2, 3], 5)).toEqual([[1, 2, 3]]);
});
it("splits array into even chunks", () => {
expect(chunks([1, 2, 3, 4], 2)).toEqual([
[1, 2],
[3, 4],
]);
});
it("handles remainder in last chunk", () => {
expect(chunks([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
});
it("handles chunk size of 1", () => {
expect(chunks([1, 2, 3], 1)).toEqual([[1], [2], [3]]);
});
it("handles array exactly equal to chunk size", () => {
expect(chunks([1, 2, 3], 3)).toEqual([[1, 2, 3]]);
});
});
describe("SQL_BATCH_SIZE", () => {
it("is 50", () => {
expect(SQL_BATCH_SIZE).toBe(50);
});
});

View File

@@ -0,0 +1,46 @@
import { describe, expect, it } from "vitest";
import { isMissingTableError } from "../../../src/utils/db-errors.js";
describe("isMissingTableError", () => {
it("detects SQLite / D1 phrasing", () => {
expect(isMissingTableError(new Error("SQLITE_ERROR: no such table: _emdash_bylines"))).toBe(
true,
);
expect(isMissingTableError(new Error("no such table: content_taxonomies"))).toBe(true);
});
it("detects PostgreSQL relation phrasing", () => {
expect(isMissingTableError(new Error('relation "_emdash_bylines" does not exist'))).toBe(true);
expect(
isMissingTableError(new Error('ERROR: relation "content_taxonomies" does not exist')),
).toBe(true);
});
it("detects PostgreSQL table phrasing", () => {
expect(isMissingTableError(new Error('table "ec_posts" does not exist'))).toBe(true);
});
it("detects MySQL-style doesn't exist phrasing", () => {
expect(isMissingTableError(new Error("Table 'db.foo' doesn't exist"))).toBe(true);
});
it("is case-insensitive", () => {
expect(isMissingTableError(new Error('RELATION "foo" DOES NOT EXIST'))).toBe(true);
});
it("rejects unrelated errors", () => {
expect(isMissingTableError(new Error("column missing"))).toBe(false);
expect(isMissingTableError(new Error("permission denied"))).toBe(false);
expect(isMissingTableError(new Error("does not exist"))).toBe(false); // no table/relation word
expect(isMissingTableError(new Error("syntax error"))).toBe(false);
});
it("handles non-Error inputs safely", () => {
expect(isMissingTableError("no such table: x")).toBe(true);
expect(isMissingTableError(null)).toBe(false);
expect(isMissingTableError(undefined)).toBe(false);
expect(isMissingTableError(42)).toBe(false);
expect(isMissingTableError({})).toBe(false);
});
});