Files
solelog/apps/worker/src/screens/Account.test.tsx
Bas van Rossem 1631c1698d feat(worker): add logout + replace admin-only settings with Account screen
The Instellingen tab was activity management, which Phase 2 made admin-only —
workers saw add/edit/delete controls that all 403. Replace it with an Account
tab showing the signed-in name/email (via /api/me) and an Uitloggen button
(wires the existing AuthContext signOut). Activity management belongs to the
Phase 3 admin app, so the worker client drops the Settings screen and its
now-unused activity-mutation hooks (useActivities read stays).

Products affected: SoleLog worker client (apps/worker).
2026-06-17 18:23:42 +02:00

55 lines
1.6 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import Account from './Account';
import { AuthProvider } from '../auth/AuthContext';
import { apiFetch } from '../lib/api';
import { clearToken, getToken, setToken } from '../lib/auth-storage';
// Mock the network layer so no real requests are made.
vi.mock('../lib/api', () => ({
apiFetch: vi.fn(),
}));
const mockedApiFetch = vi.mocked(apiFetch);
function renderAccount() {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(
<QueryClientProvider client={queryClient}>
<AuthProvider>
<Account />
</AuthProvider>
</QueryClientProvider>
);
}
describe('Account', () => {
beforeEach(() => {
mockedApiFetch.mockReset();
mockedApiFetch.mockResolvedValue({
user: { id: 'u1', email: 'worker@solelog.local', name: 'Test Werker' },
});
});
afterEach(() => {
clearToken();
vi.clearAllMocks();
});
it('shows the signed-in user name and email', async () => {
renderAccount();
expect(await screen.findByText('Test Werker')).toBeInTheDocument();
expect(screen.getByText('worker@solelog.local')).toBeInTheDocument();
});
it('logs out: clicking Uitloggen clears the token', async () => {
setToken('tok');
const user = userEvent.setup();
renderAccount();
await user.click(screen.getByRole('button', { name: 'Uitloggen' }));
expect(getToken()).toBeNull();
});
});