feat(ui): route all in-app external links through Telegram openLink
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 49s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 59s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 49s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 59s
Extend the openLink routing from the dictionary lookup to every external
link shown inside the Mini App, so none triggers the WebView's 'open this
link?' confirmation. A shared onExternalLinkClick handler resolves the anchor
via closest() (so it also works delegated on {@html} content), backed by a
pure routeExternalLinkInTelegram decision: only inside Telegram, only an
external http(s) target=_blank link, excluding same-origin/in-app and t.me
links (t.me keeps openTelegramLink). Applied to the word-check lookup, the
About rules link, the Feedback operator-reply links, and the feature-gated
announcement banner.
Outside Telegram every anchor keeps its native target=_blank.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
insideTelegram,
|
||||
routeExternalLinkInTelegram,
|
||||
telegramClosingConfirmation,
|
||||
telegramLaunch,
|
||||
telegramOpenExternalLink,
|
||||
@@ -121,3 +122,36 @@ describe('telegramOpenExternalLink', () => {
|
||||
expect(telegramOpenExternalLink('https://x.io')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('routeExternalLinkInTelegram', () => {
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
function stubInside(openLink = vi.fn(), origin = 'https://app.example') {
|
||||
vi.stubGlobal('window', { Telegram: { WebApp: { initData: 'query_id=abc', openLink } } });
|
||||
vi.stubGlobal('location', { href: origin + '/', origin });
|
||||
return openLink;
|
||||
}
|
||||
|
||||
it('routes an external http(s) _blank link through openLink inside Telegram', () => {
|
||||
const openLink = stubInside();
|
||||
expect(routeExternalLinkInTelegram({ href: 'https://gramota.ru/poisk?query=кот', target: '_blank' })).toBe(true);
|
||||
expect(openLink).toHaveBeenCalledWith('https://gramota.ru/poisk?query=кот');
|
||||
});
|
||||
|
||||
it('leaves a t.me link to the native handler (openTelegramLink owns those)', () => {
|
||||
const openLink = stubInside();
|
||||
expect(routeExternalLinkInTelegram({ href: 'https://t.me/some_bot', target: '_blank' })).toBe(false);
|
||||
expect(openLink).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('leaves same-origin and non-_blank links to in-app navigation', () => {
|
||||
const openLink = stubInside(vi.fn(), 'https://app.example');
|
||||
expect(routeExternalLinkInTelegram({ href: 'https://app.example/lobby', target: '_blank' })).toBe(false);
|
||||
expect(routeExternalLinkInTelegram({ href: 'https://gramota.ru', target: '' })).toBe(false);
|
||||
expect(openLink).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does nothing outside Telegram (the anchor opens natively)', () => {
|
||||
expect(routeExternalLinkInTelegram({ href: 'https://x.io', target: '_blank' })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user