Adds frontend for cms page

This commit is contained in:
2026-06-30 23:23:50 +02:00
parent c156107cb1
commit 488ab821a7
38 changed files with 2047 additions and 39 deletions
+53 -2
View File
@@ -1,19 +1,70 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { renderApp, mockAuthenticated, mockGuest } from '@/test/utils';
import { server } from '@/mocks/server';
import { API_BASE } from '@/mocks/auth/fixtures';
import { resetMockCmsInstances } from '@/mocks/cms/handlers';
import { _resetSetupStatusCache } from '@/router';
beforeEach(() => {
_resetSetupStatusCache();
resetMockCmsInstances();
});
const CMS_URL = `${API_BASE}/api/v1/CmsInstances`;
describe('CmsPage', () => {
it('renders the CMS page title and placeholder', async () => {
it('renders the page title and Add button', async () => {
mockAuthenticated();
renderApp('/cms');
expect(await screen.findByTestId('cms-title', {}, { timeout: 5000 })).toBeInTheDocument();
expect(screen.getByTestId('cms-placeholder')).toBeInTheDocument();
expect(screen.getByTestId('cms-add-button')).toBeInTheDocument();
});
it('renders list of CMS instances from seed data', async () => {
mockAuthenticated();
renderApp('/cms');
const rows = await screen.findAllByTestId('cms-instance-row', {}, { timeout: 5000 });
expect(rows.length).toBe(2);
});
it('renders empty state when no instances exist', async () => {
mockAuthenticated();
server.use(http.get(CMS_URL, () => HttpResponse.json([])));
renderApp('/cms');
expect(await screen.findByTestId('cms-empty-state', {}, { timeout: 5000 })).toBeInTheDocument();
expect(screen.getByTestId('cms-empty-add-button')).toBeInTheDocument();
});
it('opens AddCmsInstanceDialog when Add button is clicked', async () => {
mockAuthenticated();
renderApp('/cms');
await screen.findByTestId('cms-add-button', {}, { timeout: 5000 });
await userEvent.click(screen.getByTestId('cms-add-button'));
expect(await screen.findByTestId('add-cms-name')).toBeInTheDocument();
});
it('adds a CMS instance successfully', async () => {
mockAuthenticated();
renderApp('/cms');
await screen.findByTestId('cms-add-button', {}, { timeout: 5000 });
await userEvent.click(screen.getByTestId('cms-add-button'));
await userEvent.type(screen.getByTestId('add-cms-name'), 'New CMS');
await userEvent.type(screen.getByTestId('add-cms-url'), 'http://new.example.com');
await userEvent.type(screen.getByTestId('add-cms-apikey-input'), 'secret-key');
await userEvent.click(screen.getByTestId('add-cms-submit'));
const rows = await screen.findAllByTestId('cms-instance-row', {}, { timeout: 5000 });
expect(rows.length).toBe(3);
});
it('redirects unauthenticated users to login', async () => {
+63 -8
View File
@@ -1,17 +1,72 @@
import { useState } from 'react';
import { LayoutGrid } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Button } from '@/components/ui/button';
import { CmsInstanceList } from '@/components/cms/CmsInstanceList';
import { AddCmsInstanceDialog } from '@/components/cms/AddCmsInstanceDialog';
import { SetStatusDialog } from '@/components/cms/SetStatusDialog';
import { useCmsInstances } from '@/api/useCmsInstances';
import type { CmsInstance } from '@/api/types';
export function CmsPage() {
const { t } = useTranslation();
const [addDialogOpen, setAddDialogOpen] = useState(false);
const [statusTarget, setStatusTarget] = useState<CmsInstance | null>(null);
const { data: instances, isPending, isError } = useCmsInstances();
return (
<div className="flex flex-col items-center justify-center py-16 text-center space-y-4">
<LayoutGrid className="size-12 text-muted-foreground" />
<h1 className="text-2xl font-semibold" data-testid="cms-title">
{t('cms.title')}
</h1>
<p className="text-muted-foreground max-w-sm" data-testid="cms-placeholder">
{t('cms.description')}
</p>
<div className="space-y-4 p-4">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-semibold" data-testid="cms-title">
{t('cms.title')}
</h1>
<Button
onClick={() => setAddDialogOpen(true)}
data-testid="cms-add-button"
>
{t('cms.addButton')}
</Button>
</div>
{isPending && (
<p className="text-sm text-muted-foreground">{t('common.loading')}</p>
)}
{isError && (
<p className="text-sm text-destructive">{t('errors.generic')}</p>
)}
{!isPending && !isError && instances?.length === 0 && (
<div
className="flex flex-col items-center justify-center py-16 text-center space-y-4"
data-testid="cms-empty-state"
>
<LayoutGrid className="size-12 text-muted-foreground" />
<h2 className="text-xl font-semibold">{t('cms.emptyState.heading')}</h2>
<p className="text-muted-foreground max-w-sm">{t('cms.emptyState.description')}</p>
<Button onClick={() => setAddDialogOpen(true)} data-testid="cms-empty-add-button">
{t('cms.addButton')}
</Button>
</div>
)}
{!isPending && !isError && instances && instances.length > 0 && (
<CmsInstanceList
instances={instances}
onSetStatus={(instance) => setStatusTarget(instance)}
/>
)}
<AddCmsInstanceDialog
open={addDialogOpen}
onOpenChange={setAddDialogOpen}
/>
<SetStatusDialog
instance={statusTarget}
open={statusTarget !== null}
onOpenChange={(open) => { if (!open) setStatusTarget(null); }}
/>
</div>
);
}