library
Prebuilt pebble components: drop-in custom elements, no compiler needed
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runAucun
0Étoiles
0Forks
2Issues
| 1 | // CAPABILITY PROBE — what happy-dom 17 gives the tablet element tests. |
| 2 | // The engine owns editing, so the tests drive synthetic events; this probe |
| 3 | // pins down which DOM APIs the synthetic path can rely on. Anything missing |
| 4 | // here gets the thinnest mock seam in the element tests, and the Chromium |
| 5 | // smoke (examples/tablet-smoke.ts) owns true typing. |
| 6 | import { expect, test } from "bun:test"; |
| 7 | |
| 8 | test("probe: InputEvent carries inputType/data and is cancelable", () => { |
| 9 | const field = document.createElement("textarea"); |
| 10 | document.body.appendChild(field); |
| 11 | const event = new InputEvent("beforeinput", { inputType: "insertText", data: "x", bubbles: true, cancelable: true }); |
| 12 | field.dispatchEvent(event); |
| 13 | expect(event.inputType).toBe("insertText"); |
| 14 | expect(event.data).toBe("x"); |
| 15 | expect(event.defaultPrevented).toBe(false); |
| 16 | document.body.textContent = ""; |
| 17 | }); |
| 18 | |
| 19 | test("probe: preventDefault on beforeinput is visible synchronously", () => { |
| 20 | const field = document.createElement("textarea"); |
| 21 | document.body.appendChild(field); |
| 22 | field.addEventListener("beforeinput", event => event.preventDefault()); |
| 23 | const event = new InputEvent("beforeinput", { inputType: "deleteContentBackward", bubbles: true, cancelable: true }); |
| 24 | field.dispatchEvent(event); |
| 25 | expect(event.defaultPrevented).toBe(true); |
| 26 | document.body.textContent = ""; |
| 27 | }); |
| 28 | |
| 29 | test("probe: CompositionEvent constructs and dispatches", () => { |
| 30 | const field = document.createElement("textarea"); |
| 31 | document.body.appendChild(field); |
| 32 | const seen: string[] = []; |
| 33 | field.addEventListener("compositionstart", () => seen.push("start")); |
| 34 | field.addEventListener("compositionend", () => seen.push("end")); |
| 35 | field.dispatchEvent(new CompositionEvent("compositionstart", { bubbles: true })); |
| 36 | field.dispatchEvent(new CompositionEvent("compositionend", { bubbles: true })); |
| 37 | expect(seen).toEqual(["start", "end"]); |
| 38 | // Gap: happy-dom's CompositionEvent ignores the `data` init. No seam |
| 39 | // needed — the element never reads it: the compose action folds in |
| 40 | // field.value, which happy-dom sets fine. |
| 41 | document.body.textContent = ""; |
| 42 | }); |
| 43 | |
| 44 | test("probe: textarea selection APIs (selectionStart/End, setSelectionRange, direction)", () => { |
| 45 | const field = document.createElement("textarea"); |
| 46 | field.value = "hello world"; |
| 47 | document.body.appendChild(field); |
| 48 | field.selectionStart = 6; |
| 49 | field.selectionEnd = 11; |
| 50 | expect(field.selectionStart).toBe(6); |
| 51 | expect(field.selectionEnd).toBe(11); |
| 52 | // start <= end always (the engine projects min/max + direction, never a |
| 53 | // reversed pair — happy-dom collapses a reversed pair, Chromium swaps it). |
| 54 | field.setSelectionRange(6, 11, "backward"); |
| 55 | expect(field.selectionStart).toBe(6); |
| 56 | expect(field.selectionEnd).toBe(11); |
| 57 | expect(field.selectionDirection).toBe("backward"); |
| 58 | document.body.textContent = ""; |
| 59 | }); |
| 60 | |
| 61 | test("probe: focus() sets document.activeElement; selectionchange dispatches on document", () => { |
| 62 | const field = document.createElement("textarea"); |
| 63 | document.body.appendChild(field); |
| 64 | field.focus(); |
| 65 | expect(document.activeElement).toBe(field); |
| 66 | let fired = 0; |
| 67 | const listener = () => (fired += 1); |
| 68 | document.addEventListener("selectionchange", listener); |
| 69 | document.dispatchEvent(new Event("selectionchange")); |
| 70 | document.removeEventListener("selectionchange", listener); |
| 71 | expect(fired).toBe(1); |
| 72 | document.body.textContent = ""; |
| 73 | }); |
| 74 | |
| 75 | test("probe: ClipboardEvent with a clipboardData payload", () => { |
| 76 | const field = document.createElement("textarea"); |
| 77 | document.body.appendChild(field); |
| 78 | // happy-dom 17 has no DataTransfer-in-ClipboardEvent constructor support; |
| 79 | // the thinnest seam: assign a clipboardData-shaped stub before dispatch. |
| 80 | const event = new ClipboardEvent("paste", { bubbles: true, cancelable: true }); |
| 81 | const store = new Map([["text/plain", "pasted text"]]); |
| 82 | Object.defineProperty(event, "clipboardData", { |
| 83 | value: { getData: (type: string) => store.get(type) ?? "", setData: (type: string, text: string) => void store.set(type, text) }, |
| 84 | }); |
| 85 | field.dispatchEvent(event); |
| 86 | expect((event as unknown as { clipboardData: { getData(t: string): string } }).clipboardData.getData("text/plain")).toBe("pasted text"); |
| 87 | document.body.textContent = ""; |
| 88 | }); |
| 89 | |
| 90 | test("probe: KeyboardEvent isComposing flag survives construction", () => { |
| 91 | const event = new KeyboardEvent("keydown", { key: "s", ctrlKey: true, isComposing: true, bubbles: true, cancelable: true }); |
| 92 | expect(event.isComposing).toBe(true); |
| 93 | }); |
| 94 | |
| 95 | test("probe: event.timeStamp is a number the history grouper can use", () => { |
| 96 | const event = new InputEvent("beforeinput", { inputType: "insertText", data: "x" }); |
| 97 | expect(typeof event.timeStamp).toBe("number"); |
| 98 | }); |