Files
open-design/apps/web/tests/first-party-external-link.test.ts
d7151b2b60 feat(analytics): link downloads and first-party browser opens (#5442)
* feat(analytics): attribute desktop downloads

* fix(analytics): initialize attribution routes after HTTP deps

* feat(analytics): bridge first-party browser opens

* feat(analytics): bridge first-party anchor opens

* fix(analytics): make attribution claims idempotent

* fix(analytics): record pending attribution results

* chore(analytics): bind landing attribution KV

* fix(ci): remove landing preview wrangler config override

* fix(landing): resolve download attribution function

* fix(analytics): harden attribution token consumption

* fix(analytics): preserve same-installation claim retries

* fix(analytics): merge recovered attribution retries

* fix(analytics): preserve attributed browser links

* fix(analytics): clear attribution on privacy reset

* fix(analytics): bridge stopped AMR console links

* fix(ci): deploy attribution schema before Pages

* fix(ci): run attribution migrations with Wrangler 4

---------

Co-authored-by: Siri-Ray <2667192167@qq.com>
Co-authored-by: PerishCode <perishcode@gmail.com>
2026-07-14 08:46:04 +00:00

31 lines
1.3 KiB
TypeScript

// @vitest-environment jsdom
import { describe, expect, it, vi } from 'vitest';
import { openFirstPartyExternalLinkFromClick } from '../src/first-party-external-link';
describe('openFirstPartyExternalLinkFromClick', () => {
it('bridges the final URL after a bubbling AMR handler appends attribution parameters', () => {
const opened = vi.fn();
const anchor = document.createElement('a');
anchor.href = 'https://open-design.ai/console';
anchor.addEventListener('click', () => {
const url = new URL(anchor.href);
url.searchParams.set('od_origin', 'open_design');
url.searchParams.set('od_entry_id', 'settings');
url.searchParams.set('od_device_id', 'install-123');
anchor.href = url.toString();
});
document.body.append(anchor);
const listener = (event: MouseEvent) => openFirstPartyExternalLinkFromClick(event, opened);
document.addEventListener('click', listener);
const event = new MouseEvent('click', { bubbles: true, cancelable: true });
anchor.dispatchEvent(event);
document.removeEventListener('click', listener);
expect(event.defaultPrevented).toBe(true);
expect(opened).toHaveBeenCalledWith(
'https://open-design.ai/console?od_origin=open_design&od_entry_id=settings&od_device_id=install-123',
);
});
});