Files
tessera-ctl/apps/web/src/components/settings/desktop-app-settings.test.tsx
T
schalli 4c79874278 feat(web): Einstellungen → Desktop-App zeigt in der App den verbundenen Server
- DesktopAppSettings rendert im Desktop-Client (useIsDesktopClient) einen Block "Verbunden mit: {origin}" plus Hinweis auf "Server-Adresse ändern…" im Infobereich-Menü; im Browser bleibt der Block weg
- Neue i18n-Schlüssel settings.desktop.connectedTo/changeHint in de.json und en.json
- Test 4 (Cookie tessera_desktop=1) und Test 5 (ohne Cookie) ergänzt; RED zuerst (Test 4 schlug auf der Zielbehauptung fehl), dann GREEN
- Alle 431 Web-Tests und type-check grün

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 14:52:47 +02:00

132 lines
4.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { act, cleanup, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { DESKTOP_COOKIE_NAME } from '@/lib/desktop-client';
import { DesktopAppSettings } from './desktop-app-settings';
/**
* desktop-app-settings.test — Einstellungsseite "Desktop-App" (18-03).
* next-intl-Mock nach dem Muster in widget-settings-panel.test.tsx
* (de.json-gestuetzt), `@/lib/desktop` gemockt.
*/
vi.mock('next-intl', async () => {
const messages = (await import('@/messages/de.json')).default as Record<string, unknown>;
const lookup = (path: string): string | undefined =>
path.split('.').reduce<unknown>((o, k) => (o && typeof o === 'object' ? (o as any)[k] : undefined), messages) as
| string
| undefined;
return {
useTranslations:
(ns?: string) =>
(key: string, values?: Record<string, unknown>) => {
const raw = lookup(ns ? `${ns}.${key}` : key) ?? key;
return values ? raw.replace(/\{(\w+)\}/g, (_: string, n: string) => String(values[n] ?? '')) : raw;
},
useLocale: () => 'de',
};
});
const { loadDesktopLatest } = vi.hoisted(() => ({ loadDesktopLatest: vi.fn() }));
vi.mock('@/lib/desktop', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/lib/desktop')>();
return {
...actual,
loadDesktopLatest,
};
});
function clearDesktopCookie() {
document.cookie = `${DESKTOP_COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
}
afterEach(() => {
cleanup();
vi.clearAllMocks();
clearDesktopCookie();
});
const windowsFile = {
name: 'Tessera-Setup-1.1.0.exe',
size: 6123456,
sha256: 'x',
url: '/desktop/download/windows',
};
const linuxFile = {
name: 'Tessera-1.1.0.AppImage',
size: 106461688,
sha256: 'y',
url: '/desktop/download/linux',
};
describe('DesktopAppSettings (18-03)', () => {
it('Test 1 (beide Plattformen): Version, zwei Links, Dateiname und Groesse', async () => {
loadDesktopLatest.mockResolvedValue({
version: '1.1.0',
channel: 'live',
commit: 'abc1234',
buildTime: 'x',
files: { windows: windowsFile, linux: linuxFile },
});
render(<DesktopAppSettings />);
expect(await screen.findByText('Aktuelle Version: 1.1.0')).toBeInTheDocument();
const windowsLink = screen.getByTestId('desktop-download-windows');
expect(windowsLink).toHaveAttribute('href', 'http://localhost:3001/desktop/download/windows');
const linuxLink = screen.getByTestId('desktop-download-linux');
expect(linuxLink).toHaveAttribute('href', 'http://localhost:3001/desktop/download/linux');
expect(screen.getByText('Tessera-Setup-1.1.0.exe · 5,8 MB')).toBeInTheDocument();
expect(screen.getByText('Tessera-1.1.0.AppImage · 101,5 MB')).toBeInTheDocument();
});
it('Test 2 (Beta-Kanal): Hinweis mit Commit', async () => {
loadDesktopLatest.mockResolvedValue({
version: '1.1.0',
channel: 'beta',
commit: 'abc1234',
buildTime: 'x',
files: { windows: windowsFile, linux: linuxFile },
});
render(<DesktopAppSettings />);
expect(await screen.findByText('Beta-Ausgabe, Stand abc1234')).toBeInTheDocument();
});
it('Test 3 (keine Pakete): Hinweistext statt Knoepfe, Saetze bleiben', async () => {
loadDesktopLatest.mockResolvedValue(null);
render(<DesktopAppSettings />);
expect(
await screen.findByText('Auf diesem Server sind derzeit keine Desktop-Pakete hinterlegt.'),
).toBeInTheDocument();
expect(screen.queryByTestId('desktop-download-windows')).toBeNull();
expect(screen.queryByTestId('desktop-download-linux')).toBeNull();
expect(
screen.getByText(
'Die Desktop-App öffnet Tessera in einem eigenen Fenster – ohne Browser, mit Symbol im Infobereich der Taskleiste.',
),
).toBeInTheDocument();
});
it('Test 4 (im Desktop-Client): zeigt verbundenen Server und Änderungshinweis', async () => {
document.cookie = `${DESKTOP_COOKIE_NAME}=1; path=/`;
loadDesktopLatest.mockResolvedValue(null);
render(<DesktopAppSettings />);
expect(await screen.findByText('Verbunden mit: http://localhost:3000')).toBeInTheDocument();
expect(
screen.getByText('Ändern über das Tessera-Symbol im Infobereich → „Server-Adresse ändern…“'),
).toBeInTheDocument();
expect(screen.getByTestId('desktop-connected')).toBeInTheDocument();
});
it('Test 5 (im Browser): kein Block ohne Desktop-Cookie', async () => {
loadDesktopLatest.mockResolvedValue(null);
render(<DesktopAppSettings />);
await act(async () => {});
expect(screen.queryByTestId('desktop-connected')).toBeNull();
});
});