|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { detectTextAlignment, getTextAlignmentClasses } from "../textAlignment"; |
| 3 | + |
| 4 | +describe("textAlignment", () => { |
| 5 | + describe("detectTextAlignment", () => { |
| 6 | + it("should detect English as LTR", () => { |
| 7 | + const result = detectTextAlignment( |
| 8 | + "This is a test in English with multiple sentences to make it long enough for reliable detection.", |
| 9 | + ); |
| 10 | + |
| 11 | + expect(result.language).toBe("eng"); |
| 12 | + expect(result.direction).toBe("ltr"); |
| 13 | + expect(result.textAlign).toBe("left"); |
| 14 | + }); |
| 15 | + |
| 16 | + it("should detect Arabic as RTL", () => { |
| 17 | + const result = detectTextAlignment( |
| 18 | + "هذا نص تجريبي باللغة العربية لاختبار اكتشاف اللغة والمحاذاة بشكل صحيح", |
| 19 | + ); |
| 20 | + |
| 21 | + expect(result.language).toBe("arb"); |
| 22 | + expect(result.direction).toBe("rtl"); |
| 23 | + expect(result.textAlign).toBe("right"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should detect Hebrew as RTL", () => { |
| 27 | + const result = detectTextAlignment( |
| 28 | + "זהו טקסט לבדיקה בעברית כדי לבדוק זיהוי שפה ויישור בצורה נכונה", |
| 29 | + ); |
| 30 | + |
| 31 | + expect(result.language).toBe("heb"); |
| 32 | + expect(result.direction).toBe("rtl"); |
| 33 | + expect(result.textAlign).toBe("right"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should handle short text with default values", () => { |
| 37 | + const result = detectTextAlignment("Hi"); |
| 38 | + |
| 39 | + expect(result.language).toBe("und"); |
| 40 | + expect(result.direction).toBe("ltr"); |
| 41 | + expect(result.textAlign).toBe("left"); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should handle empty text", () => { |
| 45 | + const result = detectTextAlignment(""); |
| 46 | + |
| 47 | + expect(result.language).toBe("und"); |
| 48 | + expect(result.direction).toBe("ltr"); |
| 49 | + expect(result.textAlign).toBe("left"); |
| 50 | + }); |
| 51 | + |
| 52 | + it("should ignore markdown syntax when detecting language", () => { |
| 53 | + const result = detectTextAlignment( |
| 54 | + "# This is a **heading** in English with _emphasis_ and `code` blocks for testing language detection", |
| 55 | + ); |
| 56 | + |
| 57 | + expect(result.language).toBe("eng"); |
| 58 | + expect(result.direction).toBe("ltr"); |
| 59 | + expect(result.textAlign).toBe("left"); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe("getTextAlignmentClasses", () => { |
| 64 | + it("should return LTR classes for English text", () => { |
| 65 | + const classes = getTextAlignmentClasses( |
| 66 | + "This is English text that should be left-aligned with LTR direction.", |
| 67 | + ); |
| 68 | + |
| 69 | + expect(classes).toBe("ltr text-left"); |
| 70 | + }); |
| 71 | + |
| 72 | + it("should return RTL classes for Arabic text", () => { |
| 73 | + const classes = getTextAlignmentClasses( |
| 74 | + "هذا نص عربي يجب أن يكون محاذي لليمين مع اتجاه من اليمين لليسار", |
| 75 | + ); |
| 76 | + |
| 77 | + expect(classes).toBe("rtl text-right"); |
| 78 | + }); |
| 79 | + |
| 80 | + it("should return RTL classes for Hebrew text", () => { |
| 81 | + const classes = getTextAlignmentClasses( |
| 82 | + "זה טקסט עברי שצריך להיות מיושר לימין עם כיוון מימין לשמאל", |
| 83 | + ); |
| 84 | + |
| 85 | + expect(classes).toBe("rtl text-right"); |
| 86 | + }); |
| 87 | + |
| 88 | + it("should return default LTR classes for short text", () => { |
| 89 | + const classes = getTextAlignmentClasses("Hi"); |
| 90 | + |
| 91 | + expect(classes).toBe("ltr text-left"); |
| 92 | + }); |
| 93 | + }); |
| 94 | +}); |
0 commit comments