Skip to content

Commit

Permalink
test: add test specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Nov 12, 2024
1 parent ba0512b commit 45796d5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bridge/core/html/html_anchor_element.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Element} from "../dom/element";
import {HTMLElement} from "./html_element";

interface HTMLAnchorElement extends Element {
interface HTMLAnchorElement extends HTMLElement {
target: DartImpl<string>;
accessKey: DartImpl<string>;
download: DartImpl<string>;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions integration_tests/specs/dom/events/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,42 @@ describe('Event', () => {
el.style.width = '102px';
el2.style.width = '102px';
});

it('should works with preventDefault in `<a /> 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();
});
});
6 changes: 0 additions & 6 deletions webf/lib/src/dom/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 45796d5

Please sign in to comment.