@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 62 lines 1.91 KB
Raw
1 import { getSchemaByResolvedExtensions, resolveExtensions } from "@tiptap/core";
2 import { Node as ProseMirrorNode } from "@tiptap/pm/model";
3 import StarterKit from "@tiptap/starter-kit";
4 import { describe, expect, it } from "vite-plus/test";
5
6 import {
7 buildDocJson,
8 ComposerBlockExtensions,
9 ComposerCodeBlockExtension,
10 ComposerCodeExtension,
11 ComposerListExtensions,
12 } from "./composer-rich-text-doc";
13 import { composerTextDirections } from "./composer-text-direction";
14
15 const schema = getSchemaByResolvedExtensions(
16 resolveExtensions([
17 StarterKit.configure({
18 blockquote: false,
19 bulletList: false,
20 codeBlock: false,
21 heading: false,
22 horizontalRule: false,
23 listItem: false,
24 orderedList: false,
25 code: false,
26 }),
27 ComposerCodeExtension,
28 ComposerCodeBlockExtension,
29 ...ComposerListExtensions,
30 ...ComposerBlockExtensions,
31 ]),
32 );
33
34 function directions(value: string) {
35 const doc = ProseMirrorNode.fromJSON(
36 schema,
37 buildDocJson(value, (name) => ({ label: name, description: null })),
38 );
39 return composerTextDirections(doc).blocks;
40 }
41
42 describe("composerTextDirections", () => {
43 it("does not count inline code toward a line's direction", () => {
44 expect(directions("`useEffect` و `useLayoutEffect` في `React`")).toEqual(["rtl"]);
45 });
46
47 it("gives a list one direction, from all of its items", () => {
48 expect(directions("- Vitest\n- اختبر الدالة الجديدة\n- وأضف تعليق")).toEqual(["rtl"]);
49 });
50
51 it("continues the line above until a line has letters", () => {
52 expect(directions("اكتب الدالة\n\n42\nfix it")).toEqual(["rtl", "rtl", "rtl", "ltr"]);
53 });
54
55 it("keeps a code block left to right inside Arabic text", () => {
56 expect(directions("اكتب الدالة\n```\n// احسب مجموع القيم هنا\n```\nثم اختبرها")).toEqual([
57 "rtl",
58 "ltr",
59 "rtl",
60 ]);
61 });
62 });