Restructures frontend to a feature-based folder layout
Continuous Integration / config (pull_request) Successful in 11s
Continuous Integration / changes (pull_request) Successful in 21s
Continuous Integration / backend-build (pull_request) Skipped
Continuous Integration / backend-test (pull_request) Skipped
Continuous Integration / vulnerability-scan (pull_request) Skipped
Continuous Integration / frontend-prepare (pull_request) Successful in 1m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m12s
Continuous Integration / frontend-test (pull_request) Successful in 4m42s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 6m51s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / config (pull_request) Successful in 11s
Continuous Integration / changes (pull_request) Successful in 21s
Continuous Integration / backend-build (pull_request) Skipped
Continuous Integration / backend-test (pull_request) Skipped
Continuous Integration / vulnerability-scan (pull_request) Skipped
Continuous Integration / frontend-prepare (pull_request) Successful in 1m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m12s
Continuous Integration / frontend-test (pull_request) Successful in 4m42s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 6m51s
Continuous Integration / deploy-test (pull_request) Skipped
Groups auth, setup, invitation, profile, users, cms, availability and system code (services/hooks, components, schemas, mocks, pages) under src/features/<name> instead of splitting by technical layer (api/, components/, lib/schemas/, mocks/, pages/). Renames the old connection-oriented `api` layer to `services` per feature, and splits the monolithic api/types.ts into per-feature types.ts files (with ProblemDetails/ApiResult merged into lib/api-client.ts as shared infra). Layout-agnostic code (ui primitives, app shell, i18n, test utils, lib) stays at the top level. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
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 '@/features/auth/mocks/fixtures';
|
||||
import { _resetSetupStatusCache } from '@/router';
|
||||
|
||||
beforeEach(() => {
|
||||
_resetSetupStatusCache();
|
||||
});
|
||||
|
||||
describe('SettingsPage', () => {
|
||||
it('renders the page title', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
expect(await screen.findByTestId('settings-title', {}, { timeout: 10000 })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the current availability status badge', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
expect(await screen.findByTestId('availability-badge', {}, { timeout: 10000 })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders all three availability mode buttons', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
await screen.findByTestId('availability-mode-selector', {}, { timeout: 10000 });
|
||||
expect(screen.getByTestId('mode-option-Available')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('mode-option-Maintenance')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('mode-option-NotAvailable')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('selecting a mode highlights that mode button', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
await screen.findByTestId('availability-mode-selector', {}, { timeout: 10000 });
|
||||
const maintenanceBtn = screen.getByTestId('mode-option-Maintenance');
|
||||
await userEvent.click(maintenanceBtn);
|
||||
|
||||
expect(maintenanceBtn.className).toContain('bg-primary');
|
||||
});
|
||||
|
||||
it('saves availability and shows success toast', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
await screen.findByTestId('availability-save-button', {}, { timeout: 10000 });
|
||||
await userEvent.click(screen.getByTestId('availability-save-button'));
|
||||
|
||||
expect(await screen.findByText(/availability updated/i, {}, { timeout: 10000 })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows error toast when save fails', async () => {
|
||||
server.use(
|
||||
http.post(`${API_BASE}/api/v1/Availability/admin/status`, () =>
|
||||
HttpResponse.json({ title: 'Error' }, { status: 500 }),
|
||||
),
|
||||
);
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
await screen.findByTestId('availability-save-button', {}, { timeout: 10000 });
|
||||
await userEvent.click(screen.getByTestId('availability-save-button'));
|
||||
|
||||
expect(await screen.findByText(/something went wrong/i, {}, { timeout: 10000 })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('disables the availability controls and shows a banner when master-controlled', async () => {
|
||||
server.use(
|
||||
http.get(`${API_BASE}/api/v1/Availability/status`, () =>
|
||||
HttpResponse.json({
|
||||
status: 'NotAvailable',
|
||||
checkedAt: new Date().toISOString(),
|
||||
message: 'Uitgeschakeld door master',
|
||||
isMasterControlled: true,
|
||||
}),
|
||||
),
|
||||
);
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
expect(await screen.findByTestId('availability-master-controlled-banner', {}, { timeout: 10000 })).toBeInTheDocument();
|
||||
expect(screen.getByTestId('mode-option-Available')).toBeDisabled();
|
||||
expect(screen.getByTestId('mode-option-Maintenance')).toBeDisabled();
|
||||
expect(screen.getByTestId('mode-option-NotAvailable')).toBeDisabled();
|
||||
expect(screen.getByTestId('availability-reason-input')).toBeDisabled();
|
||||
expect(screen.getByTestId('availability-save-button')).toBeDisabled();
|
||||
});
|
||||
|
||||
it('does not show the master-controlled banner when not master-controlled', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
await screen.findByTestId('availability-save-button', {}, { timeout: 10000 });
|
||||
expect(screen.queryByTestId('availability-master-controlled-banner')).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId('availability-save-button')).not.toBeDisabled();
|
||||
});
|
||||
|
||||
it('shows a master-controlled error toast on a 409 conflict from the server', async () => {
|
||||
server.use(
|
||||
http.post(`${API_BASE}/api/v1/Availability/admin/status`, () =>
|
||||
HttpResponse.json({ title: 'Conflict' }, { status: 409 }),
|
||||
),
|
||||
);
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
await screen.findByTestId('availability-save-button', {}, { timeout: 10000 });
|
||||
await userEvent.click(screen.getByTestId('availability-save-button'));
|
||||
|
||||
expect(await screen.findByText(/master cms controls this status/i, {}, { timeout: 10000 })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders all placeholder sections', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/settings');
|
||||
|
||||
await screen.findByTestId('settings-title', {}, { timeout: 10000 });
|
||||
expect(screen.getByTestId('placeholder-settings.modules.title')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('placeholder-settings.systemConfig.title')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('placeholder-settings.branding.title')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('redirects unauthenticated users to login', async () => {
|
||||
mockGuest();
|
||||
renderApp('/settings');
|
||||
expect(await screen.findByTestId('login-form-submit-button')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,164 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { toast } from 'sonner';
|
||||
import { Lock } from 'lucide-react';
|
||||
import { useAvailabilityStatus, useUpdateAvailability } from '@/features/availability/services/useAvailability';
|
||||
import { AvailabilityStatusBadge } from '@/features/availability/components/AvailabilityStatusBadge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { ProblemDetailsError } from '@/lib/api-client';
|
||||
import type { AvailabilityStatus } from '@/features/availability/services/types';
|
||||
|
||||
function PlaceholderCard({ titleKey, comingSoonKey }: { titleKey: string; comingSoonKey: string }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Card className="opacity-60">
|
||||
<CardHeader className="flex flex-row items-center gap-2">
|
||||
<Lock className="size-4 text-muted-foreground" />
|
||||
<CardTitle className="text-base">{t(titleKey)}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground" data-testid={`placeholder-${titleKey}`}>
|
||||
{t(comingSoonKey)}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function SettingsPage() {
|
||||
const { t } = useTranslation();
|
||||
const { data: availability, isLoading } = useAvailabilityStatus();
|
||||
const updateAvailability = useUpdateAvailability();
|
||||
|
||||
const [selectedMode, setSelectedMode] = useState<AvailabilityStatus>('Available');
|
||||
const [reason, setReason] = useState('');
|
||||
|
||||
// Adjusts local edit state when the fetched availability changes, without an Effect
|
||||
// (https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes).
|
||||
const [syncedAvailability, setSyncedAvailability] = useState(availability);
|
||||
if (availability !== syncedAvailability) {
|
||||
setSyncedAvailability(availability);
|
||||
if (availability) {
|
||||
setSelectedMode(availability.status);
|
||||
setReason(availability.message ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
const isMasterControlled = availability?.isMasterControlled ?? false;
|
||||
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
await updateAvailability.mutateAsync({ newStatus: selectedMode, reason });
|
||||
toast.success(t('settings.availability.saveSuccess'));
|
||||
} catch (err) {
|
||||
if (err instanceof ProblemDetailsError && err.status === 409) {
|
||||
toast.error(t('settings.availability.masterControlledSaveError'));
|
||||
} else {
|
||||
toast.error(t('errors.generic'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const modes: AvailabilityStatus[] = ['Available', 'Maintenance', 'NotAvailable'];
|
||||
|
||||
return (
|
||||
<div className="space-y-6 max-w-xl">
|
||||
<h1 className="text-2xl font-semibold" data-testid="settings-title">
|
||||
{t('settings.title')}
|
||||
</h1>
|
||||
|
||||
{/* Availability section */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('settings.availability.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{isLoading ? (
|
||||
<p className="text-sm text-muted-foreground">{t('common.loading')}</p>
|
||||
) : availability ? (
|
||||
<AvailabilityStatusBadge
|
||||
status={availability.status}
|
||||
message={availability.message}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{isMasterControlled && (
|
||||
<div
|
||||
data-testid="availability-master-controlled-banner"
|
||||
className="flex items-start gap-2 rounded-md border border-amber-400/50 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:bg-amber-950 dark:text-amber-200"
|
||||
>
|
||||
<Lock className="size-4 mt-0.5 shrink-0" />
|
||||
<div>
|
||||
<p className="font-medium">{t('settings.availability.masterControlledTitle')}</p>
|
||||
<p>{t('settings.availability.masterControlled')}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>{t('settings.availability.mode')}</Label>
|
||||
<div className="flex gap-2 flex-wrap" data-testid="availability-mode-selector">
|
||||
{modes.map((mode) => (
|
||||
<button
|
||||
key={mode}
|
||||
type="button"
|
||||
onClick={() => setSelectedMode(mode)}
|
||||
disabled={isMasterControlled}
|
||||
data-testid={`mode-option-${mode}`}
|
||||
className={`rounded-full border px-4 py-1.5 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${
|
||||
selectedMode === mode
|
||||
? 'border-primary bg-primary text-primary-foreground'
|
||||
: 'border-input bg-background hover:bg-accent'
|
||||
}`}
|
||||
>
|
||||
{t(`settings.availability.modes.${mode}`)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="availability-reason">
|
||||
{t('settings.availability.reason')}
|
||||
</Label>
|
||||
<textarea
|
||||
id="availability-reason"
|
||||
rows={2}
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
disabled={isMasterControlled}
|
||||
data-testid="availability-reason-input"
|
||||
className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
|
||||
placeholder={t('settings.availability.reason')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
onClick={handleSave}
|
||||
disabled={updateAvailability.isPending || isMasterControlled}
|
||||
data-testid="availability-save-button"
|
||||
>
|
||||
{updateAvailability.isPending
|
||||
? t('settings.availability.saving')
|
||||
: t('settings.availability.save')}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<PlaceholderCard
|
||||
titleKey="settings.modules.title"
|
||||
comingSoonKey="settings.modules.comingSoon"
|
||||
/>
|
||||
<PlaceholderCard
|
||||
titleKey="settings.systemConfig.title"
|
||||
comingSoonKey="settings.systemConfig.comingSoon"
|
||||
/>
|
||||
<PlaceholderCard
|
||||
titleKey="settings.branding.title"
|
||||
comingSoonKey="settings.branding.comingSoon"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user