Files
edgeever/packages/shared/src/mobile-editor.test.mjs
T
tianma-if 4878298592 feat(mobile): add undo and redo to phone editors
Android web, the Android app, and iOS share the same toolbar. Loading a note clears that replacement from history so the first undo does not wipe the document.
2026-09-28 15:15:47 +08:00

58 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, test } from "bun:test";
import {
MOBILE_EDITOR_ACTIVE_FLAGS,
MOBILE_EDITOR_TOOLBAR_ACTIONS,
getMobileEditorInputAttributes,
getMobileEditorImageScaleLabel,
getMobileEditorImageWidthPresetLabel,
getMobileEditorPlaceholder,
getMobileEditorToolbarActionLabel,
getMobileEditorToolbarLabel,
} from "./mobile-editor.ts";
describe("mobile editor contract", () => {
test("keeps undo and redo at the start of the mobile toolbar", () => {
expect(MOBILE_EDITOR_TOOLBAR_ACTIONS.map(({ id }) => id)).toEqual([
"undo",
"redo",
"image",
"bold",
"bulletList",
"taskList",
"increaseListIndent",
"decreaseListIndent",
"blockquote",
"horizontalRule",
]);
expect(MOBILE_EDITOR_TOOLBAR_ACTIONS.find(({ id }) => id === "bold")?.activeFlag).toBe(
MOBILE_EDITOR_ACTIVE_FLAGS.bold
);
});
test("provides the same localized copy to both mobile clients", () => {
expect(getMobileEditorPlaceholder("zh-CN")).toBe("开始记录...");
expect(getMobileEditorPlaceholder("en-US")).toBe("Start writing...");
expect(getMobileEditorToolbarLabel("zh-CN")).toBe("编辑器工具栏");
expect(getMobileEditorToolbarActionLabel("undo", "zh-CN")).toBe("撤销");
expect(getMobileEditorToolbarActionLabel("redo", "en-US")).toBe("Redo");
expect(getMobileEditorToolbarActionLabel("undo", "ja")).toBe("元に戻す");
expect(getMobileEditorToolbarActionLabel("bulletList", "en-US")).toBe("Bullet list");
expect(getMobileEditorToolbarActionLabel("taskList", "zh-CN")).toBe("任务清单");
expect(getMobileEditorToolbarActionLabel("increaseListIndent", "zh-CN")).toBe("增加列表层级(Tab)");
expect(getMobileEditorToolbarActionLabel("decreaseListIndent", "en-US")).toBe("Decrease list level (Shift + Tab)");
expect(getMobileEditorImageScaleLabel("zh-CN")).toBe("图片显示尺寸");
expect(getMobileEditorImageWidthPresetLabel("medium", "en-US")).toBe("Medium");
});
test("keeps mobile typing assistance enabled", () => {
expect(getMobileEditorInputAttributes("editor-content")).toEqual({
autocapitalize: "sentences",
autocomplete: "on",
autocorrect: "on",
class: "editor-content",
inputmode: "text",
spellcheck: "true",
});
});
});