feat(telegram): native dialogs for confirms and deep-link notices
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 56s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m19s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 56s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m19s
Inside the Mini App, route the destructive confirmations (resign, block, unfriend) through Telegram's native showConfirm, and present the deep-link info modals (stale invite, welcome-on-redeem) as a native showPopup whose button opens the bot chat. Outside Telegram, or on a client predating the dialogs, the existing in-app Modal is used unchanged; offline also keeps the modal so the action retains its disabled state. Adds showConfirm/showPopup wrappers to telegram.ts and a pure popup-params builder (nativedialogs.ts) with unit tests; the deep-link modal components choose native vs in-app via an effect gated on insideTelegram + dialog availability.
This commit is contained in:
@@ -10,6 +10,9 @@ import {
|
||||
telegramThemeParams,
|
||||
telegramSafeAreaInset,
|
||||
telegramShowSettingsButton,
|
||||
telegramDialogsAvailable,
|
||||
telegramShowConfirm,
|
||||
telegramShowPopup,
|
||||
} from './telegram';
|
||||
|
||||
function stubWebApp(initData: string, startParam?: string) {
|
||||
@@ -96,6 +99,38 @@ describe('telegramShowSettingsButton', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('native dialogs', () => {
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
it('telegramDialogsAvailable reflects showPopup presence', () => {
|
||||
expect(telegramDialogsAvailable()).toBe(false);
|
||||
vi.stubGlobal('window', { Telegram: { WebApp: { showPopup: () => {} } } });
|
||||
expect(telegramDialogsAvailable()).toBe(true);
|
||||
});
|
||||
|
||||
it('telegramShowConfirm resolves the user choice inside Telegram', async () => {
|
||||
vi.stubGlobal('window', {
|
||||
Telegram: { WebApp: { showConfirm: (_m: string, cb: (ok: boolean) => void) => cb(true) } },
|
||||
});
|
||||
await expect(telegramShowConfirm('Sure?')).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('telegramShowConfirm resolves false without the SDK dialog', async () => {
|
||||
await expect(telegramShowConfirm('Sure?')).resolves.toBe(false);
|
||||
});
|
||||
|
||||
it('telegramShowPopup resolves the pressed button id', async () => {
|
||||
vi.stubGlobal('window', {
|
||||
Telegram: { WebApp: { showPopup: (_p: unknown, cb: (id: string) => void) => cb('bot') } },
|
||||
});
|
||||
await expect(telegramShowPopup({ message: 'Hi' })).resolves.toBe('bot');
|
||||
});
|
||||
|
||||
it('telegramShowPopup resolves null without the SDK', async () => {
|
||||
await expect(telegramShowPopup({ message: 'Hi' })).resolves.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('routeExternalLinkInTelegram', () => {
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user