Gebruikerslijst: verlopen uitnodiging tonen, Beheerder mag uitnodiging intrekken, neutrale tekst bij ongeldige link
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { renderApp, mockAuthenticated } from '@/test/utils';
|
||||
import { server } from '@/mocks/server';
|
||||
import { API_BASE } from '@/features/auth/mocks/fixtures';
|
||||
import { API_BASE, makeAuthResponse, mockUser } from '@/features/auth/mocks/fixtures';
|
||||
import { getMockUsers } from '@/features/users/mocks/handlers';
|
||||
import { _resetSetupStatusCache } from '@/router';
|
||||
|
||||
@@ -57,6 +57,63 @@ describe('UsersPage', () => {
|
||||
expect(screen.getByTestId(`user-copy-link-${pendingUser.id}`)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('lets the Owner delete a pending invitation', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/users');
|
||||
|
||||
await screen.findByTestId('users-table');
|
||||
const pendingUser = getMockUsers().find((u) => u.invitationPending)!;
|
||||
await userEvent.click(screen.getByTestId(`user-actions-${pendingUser.id}`));
|
||||
|
||||
expect(screen.getByTestId(`user-delete-${pendingUser.id}`)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('lets an Administrator withdraw a pending invitation for a User, but not delete accounts', async () => {
|
||||
server.use(
|
||||
http.post(`${API_BASE}/api/v1/auth/refresh`, () =>
|
||||
HttpResponse.json(makeAuthResponse({ user: { ...mockUser, role: 'Administrator', name: 'Test Admin' } })),
|
||||
),
|
||||
);
|
||||
renderApp('/users');
|
||||
|
||||
await screen.findByTestId('users-table');
|
||||
const pendingUser = getMockUsers().find((u) => u.invitationPending)!;
|
||||
await userEvent.click(screen.getByTestId(`user-actions-${pendingUser.id}`));
|
||||
expect(screen.getByTestId(`user-delete-${pendingUser.id}`)).toBeInTheDocument();
|
||||
await userEvent.keyboard('{Escape}');
|
||||
|
||||
const account = getMockUsers().find((u) => !u.invitationPending && u.role === 'Administrator')!;
|
||||
expect(screen.queryByTestId(`user-delete-${account.id}`)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('lists an expired invitation as expired, removable, without a copy-link action', async () => {
|
||||
mockAuthenticated();
|
||||
server.use(
|
||||
http.get(USERS_URL, () =>
|
||||
HttpResponse.json([
|
||||
{
|
||||
id: '44444444-4444-4444-4444-444444444444',
|
||||
email: 'late@example.com',
|
||||
name: 'late@example.com',
|
||||
role: 'User',
|
||||
isActive: true,
|
||||
createdAt: '2026-01-01T00:00:00.000Z',
|
||||
invitationPending: true,
|
||||
invitationExpired: true,
|
||||
inviteLink: null,
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
renderApp('/users');
|
||||
|
||||
const row = await screen.findByTestId('user-row-44444444-4444-4444-4444-444444444444');
|
||||
expect(within(row).getByText('Invitation expired')).toBeInTheDocument();
|
||||
await userEvent.click(screen.getByTestId('user-actions-44444444-4444-4444-4444-444444444444'));
|
||||
expect(screen.getByTestId('user-delete-44444444-4444-4444-4444-444444444444')).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('user-copy-link-44444444-4444-4444-4444-444444444444')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows an error message when the API fails', async () => {
|
||||
mockAuthenticated();
|
||||
server.use(http.get(USERS_URL, () => HttpResponse.json({}, { status: 500 })));
|
||||
|
||||
@@ -49,6 +49,7 @@ function statusBadgeVariant(user: UserListItem) {
|
||||
}
|
||||
|
||||
function statusLabel(user: UserListItem, t: (key: string) => string) {
|
||||
if (user.invitationPending && user.invitationExpired) return t('users.status.inviteExpired');
|
||||
if (user.invitationPending) return t('users.status.pendingInvite');
|
||||
if (!user.isActive) return t('users.status.inactive');
|
||||
return t('users.status.active');
|
||||
@@ -93,10 +94,14 @@ export function UsersPage() {
|
||||
const canToggleActive = (user: UserListItem) =>
|
||||
isOwnerAction(user) && !user.invitationPending;
|
||||
|
||||
const canDelete = (user: UserListItem) => isOwnerAction(user);
|
||||
// An Administrator may withdraw an open invitation for a plain User (the same reach as assigning
|
||||
// that role); removing accounts stays with the Owner.
|
||||
const canDelete = (user: UserListItem) =>
|
||||
isOwnerAction(user) ||
|
||||
(currentUser?.role === 'Administrator' && user.invitationPending && user.role === 'User');
|
||||
|
||||
const hasAnyActions = (user: UserListItem) =>
|
||||
user.invitationPending ||
|
||||
Boolean(user.invitationPending) ||
|
||||
availableRolesFor(user).length > 0 ||
|
||||
canToggleActive(user) ||
|
||||
canDelete(user);
|
||||
@@ -270,7 +275,7 @@ export function UsersPage() {
|
||||
{t('users.table.actions')}
|
||||
</DropdownMenuLabel>
|
||||
|
||||
{user.invitationPending && (
|
||||
{user.invitationPending && user.inviteLink && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
|
||||
@@ -4,6 +4,8 @@ export interface UserListItem extends User {
|
||||
createdAt: string;
|
||||
invitationPending: boolean;
|
||||
inviteLink: string | null;
|
||||
/** Pending invitation whose link has expired: still listed so it can be removed. */
|
||||
invitationExpired?: boolean;
|
||||
}
|
||||
|
||||
export interface InviteUserPayload {
|
||||
|
||||
Reference in New Issue
Block a user