fix(ui): copy GCG to clipboard on Android in-app WebViews
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 57s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m16s
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 57s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m16s
On-device diagnostics from Android Telegram and VK confirmed both expose no navigator.share AND no navigator.canShare, so the export fell to a Blob <a download> that those WebViews silently ignore — nothing happened. pickGcgDelivery is now a 3-way decision: Web Share where available (iOS), a clipboard copy in an Android in-app WebView (Telegram/VK: no share, dead download), else a desktop Blob download. shareOrDownloadGcg reports the outcome so the game shows a "GCG copied" toast; the copy is VKWebAppCopyText inside VK (which also covers the desktop VK iframe, where navigator.clipboard is blocked) and navigator.clipboard otherwise. Unit tests cover the 3-way choice and the copy/failed outcomes; new i18n key game.gcgCopied (en+ru); docs ARCHITECTURE/FUNCTIONAL(+ru)/UI_DESIGN/TESTING.
This commit is contained in:
+35
-13
@@ -7,26 +7,31 @@ const file = {} as File;
|
||||
const gcg: GcgExport = { gameId: 'g1', filename: 'game.gcg', content: '#title game' };
|
||||
|
||||
describe('pickGcgDelivery', () => {
|
||||
it('shares when the platform can share files', () => {
|
||||
expect(pickGcgDelivery({ canShare: () => true, share: async () => {} }, file)).toBe('share');
|
||||
const canShareNav = { canShare: () => true, share: async () => {} };
|
||||
const noShareNav = { canShare: () => false, share: async () => {} };
|
||||
|
||||
it('shares when the platform can share files, even in an in-app webview (iOS)', () => {
|
||||
expect(pickGcgDelivery(canShareNav, file, false)).toBe('share');
|
||||
expect(pickGcgDelivery(canShareNav, file, true)).toBe('share');
|
||||
});
|
||||
|
||||
it('downloads when the platform cannot share files', () => {
|
||||
expect(pickGcgDelivery({ canShare: () => false, share: async () => {} }, file)).toBe('download');
|
||||
it('copies in an in-app webview that cannot share files (Android Telegram/VK: no share, dead download)', () => {
|
||||
expect(pickGcgDelivery(noShareNav, file, true)).toBe('copy');
|
||||
expect(pickGcgDelivery(undefined, file, true)).toBe('copy');
|
||||
expect(pickGcgDelivery({ canShare: () => true } as never, file, true)).toBe('copy');
|
||||
});
|
||||
|
||||
it('downloads when there is no navigator', () => {
|
||||
expect(pickGcgDelivery(undefined, file)).toBe('download');
|
||||
});
|
||||
|
||||
it('downloads when the Web Share API is incomplete', () => {
|
||||
expect(pickGcgDelivery({ canShare: () => true } as never, file)).toBe('download');
|
||||
it('downloads on a plain browser without Web Share (desktop)', () => {
|
||||
expect(pickGcgDelivery(noShareNav, file, false)).toBe('download');
|
||||
expect(pickGcgDelivery(undefined, file, false)).toBe('download');
|
||||
});
|
||||
});
|
||||
|
||||
describe('shareOrDownloadGcg', () => {
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
const noCopy = async () => false;
|
||||
|
||||
function stubDownloadEnv(canShare: boolean, share: () => Promise<void>) {
|
||||
const anchor = { href: '', download: '', click: vi.fn(), remove: vi.fn() };
|
||||
const createElement = vi.fn(() => anchor);
|
||||
@@ -45,20 +50,37 @@ describe('shareOrDownloadGcg', () => {
|
||||
const share = vi.fn().mockRejectedValue(new DOMException('cancelled', 'AbortError'));
|
||||
const { createElement } = stubDownloadEnv(true, share);
|
||||
|
||||
await shareOrDownloadGcg(gcg);
|
||||
expect(await shareOrDownloadGcg(gcg, false, noCopy)).toBe('shared');
|
||||
|
||||
expect(share).toHaveBeenCalledOnce();
|
||||
expect(createElement).not.toHaveBeenCalled(); // no download anchor → no webview navigation
|
||||
});
|
||||
|
||||
it('downloads via an anchor when the platform cannot share files', async () => {
|
||||
it('downloads via an anchor on a desktop browser that cannot share files', async () => {
|
||||
const { anchor, createElement } = stubDownloadEnv(false, vi.fn());
|
||||
|
||||
await shareOrDownloadGcg(gcg);
|
||||
expect(await shareOrDownloadGcg(gcg, false, noCopy)).toBe('downloaded');
|
||||
|
||||
expect(createElement).toHaveBeenCalledWith('a');
|
||||
expect(anchor.click).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('copies to the clipboard in an in-app webview that cannot share files (no dead Blob download)', async () => {
|
||||
// Android Telegram/VK expose no Web Share AND ignore <a download>, so the export must copy the
|
||||
// GCG text instead of silently issuing an anchor click that does nothing.
|
||||
const copy = vi.fn().mockResolvedValue(true);
|
||||
const { createElement } = stubDownloadEnv(false, vi.fn());
|
||||
|
||||
expect(await shareOrDownloadGcg(gcg, true, copy)).toBe('copied');
|
||||
|
||||
expect(copy).toHaveBeenCalledWith(gcg.content);
|
||||
expect(createElement).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('reports failure when the in-app clipboard copy fails', async () => {
|
||||
stubDownloadEnv(false, vi.fn());
|
||||
expect(await shareOrDownloadGcg(gcg, true, async () => false)).toBe('failed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('pickTextShare', () => {
|
||||
|
||||
Reference in New Issue
Block a user