From 45796d52d8526fc429c156c639f0e5938c918b31 Mon Sep 17 00:00:00 2001 From: andycall Date: Mon, 2 Sep 2024 02:05:12 +0800 Subject: [PATCH] test: add test specs. --- bridge/core/html/html_anchor_element.d.ts | 3 +- .../dom/events/event.ts.31bdc0461.png | Bin 0 -> 5292 bytes integration_tests/specs/dom/events/event.ts | 38 ++++++++++++++++++ webf/lib/src/dom/window.dart | 6 --- 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 integration_tests/snapshots/dom/events/event.ts.31bdc0461.png diff --git a/bridge/core/html/html_anchor_element.d.ts b/bridge/core/html/html_anchor_element.d.ts index fa3f09e8ba..003d441ecb 100644 --- a/bridge/core/html/html_anchor_element.d.ts +++ b/bridge/core/html/html_anchor_element.d.ts @@ -1,6 +1,7 @@ import {Element} from "../dom/element"; +import {HTMLElement} from "./html_element"; -interface HTMLAnchorElement extends Element { +interface HTMLAnchorElement extends HTMLElement { target: DartImpl; accessKey: DartImpl; download: DartImpl; diff --git a/integration_tests/snapshots/dom/events/event.ts.31bdc0461.png b/integration_tests/snapshots/dom/events/event.ts.31bdc0461.png new file mode 100644 index 0000000000000000000000000000000000000000..3a93112cdb87c45474f7187ed9ff5555a9b1ab2d GIT binary patch literal 5292 zcmeHL`CC(G7RFkOtt@pqqm^}@;b|Gi1s9e|1l*}bNCg8DmZ+#GfdqtvB_xs7+A0Ow zq9D6UC2&I$Erdt{ghfdy0wN@l1QOX2NJv;r2xMcvJo8V?59F8R=KJpb&Uw#!-uFEB z&bJ|fwx2kBVr6Azd;04Wp;lHKu31@qaC7rV;Gbs>6BO{ZAvHAcm=(R>X%<|3n0oB= zxy|5{z4`J_R#txxKYilpxr}nv7_q(>XW}jDp0!6-#C_+IoHO$5VWv}(uLCuay}{98 zn=H7GBO9)(4xPIlidK~W7UEdiG@FGkd3{#I7r!4Eea``GhHZTjKY z_Wmmu#z+QLlqbIHwk_7MXcNUH5y#Sog0(vCn#ox#UxUi9ZOtyEmGN}LzIT3D4g>|d z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KHOy=Fsl6zF$_*^Sq^R!&9H8@wYAZ;3{%pTjL`-A z&heW8pe9}<5*LQybf>HFoi$(rNQi+p zEl}wMbu$HRvX~4=)(hxOq)(P+2FWFvn*3#b`YHE-$b!R5U;Al?!zyr&-ifs+^HQ<+ zvYBgAVVMK|hP0QffCSY0yCN_*jPv9*1ASU*US=U2$MB!y0R`}T?8(<=CSBJu_@`J% z&>Lhv;IOf1vgJvtZIu*Vm8(1Ik|A$VQ;u{OxT55h1WW};tX8S4bxnn(!IlCK|lkj?p4`;v@Pag&jHozd$7M6f@H5s!hpek;|yj5 zoFFou-`;+N7R92gxohT9?<8bjr5_=8;9`)>!O5w9XIRbfcbm3YEXac3@MJ+i?0flu z^e)x9WhaekF^2vyC&wrbK1sfnmgmaN($7+0a5tN^GC)NRuxw5f7Xalewh#C<#kk00 z0jt<*fS_d+mdt6$p19+V&vPV+#-H(Alp@UX+=!dY_ncK(nRvJ^3|1iStAMdAP5=bf z!9g^|dC~<>i3SE5qx1lNK&R|=0S?_HB^hx29MA?PfDOi=VxeHN2XVe)+khW#0Lw^= zp&Uw;HEu^`r@Y8CX($0ngAHxaxz!)RRCM62JG}WUuz8?^R2}jxt3IPP1 z23Rey_Fu>mftEkjvUBBXVox+RoCe{Pf~2Lshx`IUKxt#raNMuKeBLYdu+zIx0tt3ofCBl%yToNI-*Kn6N}JUA_HSdU3Z=%3&GkTxl5@cvBMd$F(7OCRbJ~t=N8b#aQ;+JAsW<^%*(g` zQ&(x@*-pq=Tl(am_l|75^|xy`zx}}W({KJa9sfJ$qs?EuwtDoT!}{Vn2zV*w8?1w{4#K)c{y)tL`hY$4j$PbEeFu2sXm$Ez$O-zf3*Y@0C*TWY literal 0 HcmV?d00001 diff --git a/integration_tests/specs/dom/events/event.ts b/integration_tests/specs/dom/events/event.ts index 93397b337c..fd8dc755b2 100644 --- a/integration_tests/specs/dom/events/event.ts +++ b/integration_tests/specs/dom/events/event.ts @@ -786,4 +786,42 @@ describe('Event', () => { el.style.width = '102px'; el2.style.width = '102px'; }); + + it('should works with preventDefault in ` element', async (done) => { + const anchorElement = createElement('a', {}, [createText('')]); + BODY.append(anchorElement); + + anchorElement.addEventListener('click', async (e) => { + e.preventDefault(); + + BODY.append(createText('Nothing happened')); + + await snapshot(); + done(); + }); + + anchorElement.click(); + }); + + it('should satisfy react-router event check', (done) => { + function isModifiedEvent(event: MouseEvent) { + return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey); + } + function shouldProcessLinkClick(event: MouseEvent) { + return event.button === 0 && + // Let browser handle "target=_blank" etc. + !isModifiedEvent(event) // Ignore clicks with modifier keys + ; + } + + const anchorElement = createElement('a', {}, []); + BODY.append(anchorElement); + + anchorElement.addEventListener('click', async (e) => { + expect(shouldProcessLinkClick(e)); + done(); + }); + + anchorElement.click(); + }); }); diff --git a/webf/lib/src/dom/window.dart b/webf/lib/src/dom/window.dart index 09ea128205..c396948804 100644 --- a/webf/lib/src/dom/window.dart +++ b/webf/lib/src/dom/window.dart @@ -142,12 +142,6 @@ class Window extends EventTarget { _watchedViewportElements.clear(); } - @override - void dispose() { - super.dispose(); - _watchedViewportElements.clear(); - } - @override void removeEventListener(String eventType, EventHandler handler, {bool isCapture = false, bool builtInCallback = false}) { super.removeEventListener(eventType, handler, isCapture: isCapture);