feat(web): Desktop-Client per Cookie erkennen — Download-Links und Browser-Kontextmenü in der App aus

- withDesktopCookie in middleware.ts setzt tessera_desktop=1 auf JEDER
  Antwort (Fruehausstieg, Redirects, next()), wenn ?desktop=1 anliegt
- desktop-client.ts: isDesktopClient() liest das Cookie, useIsDesktopClient()
  kapselt es hydration-sicher per useEffect
- DesktopDownloadLinks fragt /desktop/latest im Desktop-Client gar nicht
  erst an und rendert nichts
- DesktopContextMenuGuard unterdrueckt das WebView2-Kontextmenue ausserhalb
  von Eingabefeldern/contenteditable, in layout.tsx eingebunden
- middleware.test.ts (neu), desktop-client.test.ts (neu),
  desktop-context-menu-guard.test.tsx (neu), Test 4 in
  desktop-download-links.test.tsx — alle 417 Web-Tests und type-check gruen

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-17 12:38:13 +02:00
parent 5bdabf558b
commit d9b94bd259
9 changed files with 346 additions and 8 deletions
+52
View File
@@ -0,0 +1,52 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { DESKTOP_COOKIE_NAME, isDesktopClient, useIsDesktopClient } from './desktop-client';
/**
* desktop-client.test — Gegenstueck zur Middleware (260917-h2s): liest das
* Cookie `tessera_desktop`, das die Middleware auf jede Antwort setzt, wenn
* der Desktop-Client `?desktop=1` an seine erste Navigation anhaengt.
*/
function clearCookie() {
document.cookie = `${DESKTOP_COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
}
afterEach(() => {
clearCookie();
});
describe('isDesktopClient', () => {
it('ohne Cookie: false', () => {
expect(isDesktopClient()).toBe(false);
});
it('mit tessera_desktop=1: true', () => {
document.cookie = `${DESKTOP_COOKIE_NAME}=1; path=/`;
expect(isDesktopClient()).toBe(true);
});
it('mit tessera_desktop=0: false', () => {
document.cookie = `${DESKTOP_COOKIE_NAME}=0; path=/`;
expect(isDesktopClient()).toBe(false);
});
it('ohne document: false', () => {
vi.stubGlobal('document', undefined);
expect(isDesktopClient()).toBe(false);
vi.unstubAllGlobals();
});
});
describe('useIsDesktopClient', () => {
it('Cookie gesetzt: liefert nach dem Effekt true', async () => {
document.cookie = `${DESKTOP_COOKIE_NAME}=1; path=/`;
const { result } = renderHook(() => useIsDesktopClient());
await waitFor(() => expect(result.current).toBe(true));
});
it('ohne Cookie: bleibt false', async () => {
const { result } = renderHook(() => useIsDesktopClient());
await act(async () => {});
expect(result.current).toBe(false);
});
});