|
1 | | -import { describe, it, expect, beforeEach } from "vitest"; |
2 | | -import { getSimulatedInput } from "../../../src/ts/test/events/helpers"; |
| 1 | +import { describe, it, expect, beforeEach, vi } from "vitest"; |
| 2 | + |
| 3 | +const mockConfig = vi.hoisted(() => ({ funbox: "" })); |
| 4 | +vi.mock("../../../src/ts/config/store", () => ({ |
| 5 | + Config: mockConfig, |
| 6 | +})); |
| 7 | + |
| 8 | +import { |
| 9 | + getSimulatedInput, |
| 10 | + getTestEventCode, |
| 11 | +} from "../../../src/ts/test/events/helpers"; |
3 | 12 | import type { InputEvent } from "../../../src/ts/test/events/types"; |
4 | 13 | import type { InsertInputType } from "../../../src/ts/input/helpers/input-type"; |
5 | 14 |
|
@@ -165,3 +174,62 @@ describe("getSimulatedInput", () => { |
165 | 174 | // expect(getSimulatedInput(events)).toBe("kab"); |
166 | 175 | // }); |
167 | 176 | }); |
| 177 | + |
| 178 | +function kbd(code: string, key?: string): KeyboardEvent { |
| 179 | + return { code, key: key ?? "" } as KeyboardEvent; |
| 180 | +} |
| 181 | + |
| 182 | +describe("getTestEventCode", () => { |
| 183 | + beforeEach(() => { |
| 184 | + mockConfig.funbox = ""; |
| 185 | + }); |
| 186 | + |
| 187 | + it("returns the event code as-is for normal keys", () => { |
| 188 | + expect(getTestEventCode(kbd("KeyA"))).toBe("KeyA"); |
| 189 | + expect(getTestEventCode(kbd("Space"))).toBe("Space"); |
| 190 | + expect(getTestEventCode(kbd("Digit1"))).toBe("Digit1"); |
| 191 | + }); |
| 192 | + |
| 193 | + it("returns NoCode when code is empty string", () => { |
| 194 | + expect(getTestEventCode(kbd(""))).toBe("NoCode"); |
| 195 | + }); |
| 196 | + |
| 197 | + it("returns NoCode when key is Unidentified even with a valid code", () => { |
| 198 | + expect(getTestEventCode(kbd("Semicolon", "Unidentified"))).toBe("NoCode"); |
| 199 | + }); |
| 200 | + |
| 201 | + it("returns NoCode when key is Unidentified", () => { |
| 202 | + expect(getTestEventCode(kbd("KeyA", "Unidentified"))).toBe("NoCode"); |
| 203 | + }); |
| 204 | + |
| 205 | + it("returns Space for NumpadEnter when 58008 funbox is active", () => { |
| 206 | + mockConfig.funbox = "58008"; |
| 207 | + expect(getTestEventCode(kbd("NumpadEnter"))).toBe("Space"); |
| 208 | + }); |
| 209 | + |
| 210 | + it("does not remap NumpadEnter without 58008 funbox", () => { |
| 211 | + expect(getTestEventCode(kbd("NumpadEnter"))).toBe("NumpadEnter"); |
| 212 | + }); |
| 213 | + |
| 214 | + it("returns NoCode for arrow keys when arrows funbox is active", () => { |
| 215 | + mockConfig.funbox = "arrows"; |
| 216 | + expect(getTestEventCode(kbd("ArrowUp"))).toBe("NoCode"); |
| 217 | + expect(getTestEventCode(kbd("ArrowDown"))).toBe("NoCode"); |
| 218 | + expect(getTestEventCode(kbd("ArrowLeft"))).toBe("NoCode"); |
| 219 | + expect(getTestEventCode(kbd("ArrowRight"))).toBe("NoCode"); |
| 220 | + }); |
| 221 | + |
| 222 | + it("does not remap arrow keys without arrows funbox", () => { |
| 223 | + expect(getTestEventCode(kbd("ArrowUp"))).toBe("ArrowUp"); |
| 224 | + }); |
| 225 | + |
| 226 | + it("handles 58008 funbox combined with other funboxes", () => { |
| 227 | + mockConfig.funbox = "other#58008"; |
| 228 | + expect(getTestEventCode(kbd("NumpadEnter"))).toBe("Space"); |
| 229 | + }); |
| 230 | + |
| 231 | + it("handles arrows funbox combined with other funboxes", () => { |
| 232 | + mockConfig.funbox = "arrows#other"; |
| 233 | + expect(getTestEventCode(kbd("ArrowLeft"))).toBe("NoCode"); |
| 234 | + }); |
| 235 | +}); |
0 commit comments