Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Train fix (#7885): test that a selection becomes a highlight as the pointer lifts

milind-soni87d83115c5df
diff --git a/shared/app-frame/point.test.ts b/shared/app-frame/point.test.ts
index a36fe9c533..526f8bf8cb 100644
--- a/shared/app-frame/point.test.ts
+++ b/shared/app-frame/point.test.ts
@@ -170,6 +170,33 @@ describe("the page's point script", () => {
expect(document.querySelector("[data-mausbot-point=mark]")).toBeNull();
});
+ it("turns a selection into a highlight as the pointer lifts while Point is on, and a plain click still picks the element", async () => {
+ const { say } = boot();
+ document.body.innerHTML = `<p id="total">42 <b>units</b> left</p>`;
+ const paragraph = document.querySelector("p")!;
+ const lift = async () => {
+ paragraph.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true }));
+ await new Promise((done) => setTimeout(done, 0));
+ };
+ const range = document.createRange();
+ range.setStart(paragraph.firstChild!, 0);
+ range.setEnd(paragraph.querySelector("b")!.firstChild!, 5);
+ document.getSelection()!.addRange(range);
+ await lift();
+ expect(posted).toEqual([]);
+ say(pointMessage(true));
+ document.getSelection()!.removeAllRanges();
+ document.getSelection()!.addRange(range);
+ await lift();
+ const picked = posted.map((data) => readPointEvent({ source: frame, data }, frame)).filter((event) => event?.kind === "pointed");
+ expect(picked).toEqual([expect.objectContaining({ part: expect.objectContaining({ text: "42 units", selector: "#total", range: expect.objectContaining({ start: 0, end: 8 }) }) })]);
+ expect(document.getSelection()!.rangeCount).toBe(0);
+ posted.length = 0;
+ await lift();
+ click(paragraph);
+ expect(posted.map((data) => readPointEvent({ source: frame, data }, frame))).toEqual([expect.objectContaining({ part: expect.objectContaining({ tag: "p", selector: "#total" }) })]);
+ });
+
it("offers a shorter selection when a highlighted passage would exceed the send limit", () => {
const { say } = boot();
const paragraph = document.createElement("p");