Add About Shakespeare page

This commit is contained in:
Alex Gleason committed 2025-09-19 19:49:29 -05:00
1 parent efbec14d24
commit f67d6dbfc5
7 files changed
+901 -2

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
import { TestApp } from '@/test/TestApp';
import { AboutSettings } from './AboutSettings';
// Mock fetch
global.fetch = vi.fn();
describe('AboutSettings', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('renders about settings page with project information', () => {
render(
<TestApp>
<AboutSettings />
</TestApp>
);
expect(screen.getByText('About Shakespeare')).toBeInTheDocument();
expect(screen.getByText(/Information about Shakespeare/)).toBeInTheDocument();
expect(screen.getByText('Source Code')).toBeInTheDocument();
expect(screen.getByText('View on GitLab')).toBeInTheDocument();
});
it('fetches and displays license text', async () => {
const mockLicense = 'MIT License\n\nCopyright (c) 2024 Shakespeare';
const mockFetch = global.fetch as ReturnType<typeof vi.fn>;
mockFetch.mockResolvedValueOnce({
ok: true,
text: () => Promise.resolve(mockLicense),
} as Response);
render(
<TestApp>
<AboutSettings />
</TestApp>
);
// Initially shows loading
expect(screen.getByText('Loading license...')).toBeInTheDocument();
// Wait for license to load
await waitFor(() => {
expect(screen.getByText(/MIT License/)).toBeInTheDocument();
expect(screen.getByText(/Copyright \(c\) 2024 Shakespeare/)).toBeInTheDocument();
});
// Verify fetch was called with correct URL
expect(global.fetch).toHaveBeenCalledWith('/LICENSE.txt');
});
it('shows error when license fetch fails', async () => {
const mockFetch = global.fetch as ReturnType<typeof vi.fn>;
mockFetch.mockRejectedValueOnce(new Error('Network error'));
render(
<TestApp>
<AboutSettings />
</TestApp>
);
// Wait for error to appear
await waitFor(() => {
expect(screen.getByText(/Failed to load license/)).toBeInTheDocument();
});
});
});
+117
View File
@@ -0,0 +1,117 @@
import { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Info, ExternalLink, Loader2, AlertTriangle } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Alert, AlertDescription } from '@/components/ui/alert';
export function AboutSettings() {
const { t } = useTranslation();
const [license, setLicense] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const fetchLicense = async () => {
try {
setIsLoading(true);
setError(null);
const response = await fetch('/LICENSE.txt');
if (!response.ok) {
throw new Error(`Failed to fetch license: ${response.status} ${response.statusText}`);
}
const licenseText = await response.text();
setLicense(licenseText);
} catch (err) {
console.error('Failed to fetch license:', err);
setError(err instanceof Error ? err.message : 'Failed to fetch license');
} finally {
setIsLoading(false);
}
};
fetchLicense();
}, []);
return (
<div className="p-6 space-y-6">
<div className="space-y-2">
<h1 className="text-2xl font-bold flex items-center gap-3">
<Info className="h-6 w-6 text-primary" />
{t('aboutShakespeare')}
</h1>
<p className="text-muted-foreground">
{t('aboutShakespeareDescription')}
</p>
</div>
<div className="space-y-4">
{/* Project Information */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Info className="h-5 w-5" />
{t('sourceCode')}
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div>
<Button
variant="outline"
asChild
className="w-full sm:w-auto"
>
<a
href="https://gitlab.com/soapbox-pub/act2"
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-2"
>
<ExternalLink className="h-4 w-4" />
{t('viewOnGitLab')}
</a>
</Button>
</div>
</CardContent>
</Card>
{/* License */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Info className="h-5 w-5" />
{t('license')}
</CardTitle>
</CardHeader>
<CardContent>
{isLoading ? (
<div className="flex items-center gap-2 text-muted-foreground py-4">
<Loader2 className="h-4 w-4 animate-spin" />
<span className="text-sm">{t('loadingLicense')}</span>
</div>
) : error ? (
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>
{t('failedToLoadLicense')}: {error}
</AlertDescription>
</Alert>
) : license ? (
<ScrollArea className="h-96 w-full rounded-md border p-4">
<pre className="text-xs font-mono whitespace-pre-wrap break-words">
{license}
</pre>
</ScrollArea>
) : null}
</CardContent>
</Card>
</div>
</div>
);
}
export default AboutSettings;
+8 -1
View File
@@ -1,6 +1,6 @@
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { Bot, GitBranch, Database, Wifi, Settings2 } from 'lucide-react';
import { Bot, GitBranch, Database, Wifi, Settings2, Info } from 'lucide-react';
import { useIsMobile } from '@/hooks/useIsMobile';
interface SettingsItem {
@@ -48,6 +48,13 @@ const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [
icon: Database,
href: '/settings/data',
},
{
id: 'about',
title: t('aboutShakespeare'),
description: t('aboutShakespeareDescription'),
icon: Info,
href: '/settings/about',
},
];
export function Settings() {