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
@@ -1,4 +1,4 @@
import { cleanup, render, screen } from '@testing-library/react';
import { act, cleanup, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { DesktopDownloadLinks } from './desktop-download-links';
@@ -35,9 +35,14 @@ vi.mock('@/lib/desktop', async (importOriginal) => {
};
});
function clearDesktopCookie() {
document.cookie = 'tessera_desktop=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
}
afterEach(() => {
cleanup();
vi.clearAllMocks();
clearDesktopCookie();
});
const windowsFile = {
@@ -94,4 +99,19 @@ describe('DesktopDownloadLinks (18-03)', () => {
expect(linuxLink.closest('a')).toHaveAttribute('href', 'http://localhost:3001/desktop/download/linux');
expect(screen.queryByText('Linux-Version')).not.toBeInTheDocument();
});
it('Test 4 (im Desktop-Client): rendert nichts und fragt /desktop/latest gar nicht erst an', async () => {
document.cookie = 'tessera_desktop=1; path=/';
loadDesktopLatest.mockResolvedValue({
version: '1.1.0',
channel: 'beta',
commit: 'abc1234',
buildTime: 'x',
files: { windows: windowsFile, linux: linuxFile },
});
const { container } = render(<DesktopDownloadLinks />);
await act(async () => {});
expect(loadDesktopLatest).not.toHaveBeenCalled();
expect(container.firstChild).toBeNull();
});
});