|
| 1 | +import { |
| 2 | + generateKeyVariants, |
| 3 | + findMatchingShortcut, |
| 4 | +} from "./keyboard-layout-converter"; |
| 5 | + |
| 6 | +describe("generateKeyVariants", () => { |
| 7 | + it("should return input key with case variations for single character", () => { |
| 8 | + const variants = generateKeyVariants("q"); |
| 9 | + expect(variants).toContain("q"); |
| 10 | + expect(variants).toContain("Q"); |
| 11 | + }); |
| 12 | + |
| 13 | + it("should include Korean conversion for q key", () => { |
| 14 | + const variants = generateKeyVariants("q"); |
| 15 | + expect(variants).toContain("ㅂ"); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should include English conversion for Korean key", () => { |
| 19 | + const variants = generateKeyVariants("ㅂ"); |
| 20 | + expect(variants).toContain("q"); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should return original input for non-single character input", () => { |
| 24 | + const variants = generateKeyVariants("abc"); |
| 25 | + expect(variants).toEqual(["abc"]); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should return original input for empty string", () => { |
| 29 | + const variants = generateKeyVariants(""); |
| 30 | + expect(variants).toEqual([""]); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should handle Russian characters", () => { |
| 34 | + const variants = generateKeyVariants("й"); |
| 35 | + expect(variants).toContain("q"); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should handle Arabic characters", () => { |
| 39 | + const variants = generateKeyVariants("ض"); |
| 40 | + expect(variants).toContain("z"); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should handle Hebrew characters", () => { |
| 44 | + const variants = generateKeyVariants("ק"); |
| 45 | + expect(variants).toContain("e"); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should handle German characters", () => { |
| 49 | + const variants = generateKeyVariants("ü"); |
| 50 | + expect(variants).toContain("["); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should handle Spanish characters", () => { |
| 54 | + const variants = generateKeyVariants("ñ"); |
| 55 | + expect(variants).toContain(";"); |
| 56 | + }); |
| 57 | + |
| 58 | + it("should handle Greek characters", () => { |
| 59 | + const variants = generateKeyVariants("θ"); |
| 60 | + expect(variants).toContain("u"); |
| 61 | + }); |
| 62 | + |
| 63 | + it("should handle Japanese hiragana characters", () => { |
| 64 | + const variants = generateKeyVariants("あ"); |
| 65 | + expect(variants).toContain("a"); |
| 66 | + }); |
| 67 | + |
| 68 | + it("should handle Japanese katakana characters", () => { |
| 69 | + const variants = generateKeyVariants("ア"); |
| 70 | + expect(variants).toContain("a"); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should handle Chinese characters", () => { |
| 74 | + const variants = generateKeyVariants("你"); |
| 75 | + expect(variants).toContain("你"); |
| 76 | + }); |
| 77 | + |
| 78 | + it("should handle Hindi Devanagari characters", () => { |
| 79 | + const variants = generateKeyVariants("अ"); |
| 80 | + expect(variants).toContain("a"); |
| 81 | + }); |
| 82 | + |
| 83 | + it("should handle numbers and special characters", () => { |
| 84 | + const variants = generateKeyVariants("1"); |
| 85 | + expect(variants).toContain("1"); |
| 86 | + }); |
| 87 | +}); |
| 88 | + |
| 89 | +describe("findMatchingShortcut", () => { |
| 90 | + const shortcuts = ["q", "t", "g", "n"]; |
| 91 | + |
| 92 | + it("should find exact match for English character", () => { |
| 93 | + const result = findMatchingShortcut("q", shortcuts); |
| 94 | + expect(result).toBe("q"); |
| 95 | + }); |
| 96 | + |
| 97 | + it("should find match for Korean character mapping to English", () => { |
| 98 | + const result = findMatchingShortcut("ㅂ", shortcuts); |
| 99 | + expect(result).toBe("q"); |
| 100 | + }); |
| 101 | + |
| 102 | + it("should find match for Russian character mapping to English", () => { |
| 103 | + const result = findMatchingShortcut("й", shortcuts); |
| 104 | + expect(result).toBe("q"); |
| 105 | + }); |
| 106 | + |
| 107 | + it("should return undefined for non-matching character", () => { |
| 108 | + const result = findMatchingShortcut("x", shortcuts); |
| 109 | + expect(result).toBeUndefined(); |
| 110 | + }); |
| 111 | + |
| 112 | + it("should return undefined for multi-character input", () => { |
| 113 | + const result = findMatchingShortcut("qt", shortcuts); |
| 114 | + expect(result).toBeUndefined(); |
| 115 | + }); |
| 116 | + |
| 117 | + it("should handle case insensitive matching", () => { |
| 118 | + const result = findMatchingShortcut("Q", shortcuts); |
| 119 | + expect(result).toBe("q"); |
| 120 | + }); |
| 121 | + |
| 122 | + it("should handle empty shortcuts array", () => { |
| 123 | + const result = findMatchingShortcut("q", []); |
| 124 | + expect(result).toBeUndefined(); |
| 125 | + }); |
| 126 | + |
| 127 | + it("should handle shortcuts with undefined values", () => { |
| 128 | + const result = findMatchingShortcut("q", ["q", undefined as any, "t"]); |
| 129 | + expect(result).toBe("q"); |
| 130 | + }); |
| 131 | + |
| 132 | + it("should match Korean ㅅ with t shortcut", () => { |
| 133 | + const shortcutsWithT = ["s", "t", "g"]; |
| 134 | + const result = findMatchingShortcut("ㅅ", shortcutsWithT); |
| 135 | + expect(result).toBe("t"); |
| 136 | + }); |
| 137 | + |
| 138 | + it("should match Korean ㄴ with s shortcut", () => { |
| 139 | + const shortcutsWithS = ["s", "t", "g"]; |
| 140 | + const result = findMatchingShortcut("ㄴ", shortcutsWithS); |
| 141 | + expect(result).toBe("s"); |
| 142 | + }); |
| 143 | +}); |
0 commit comments