Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/components/AddUserModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Key, Mail, Shield, User } from 'lucide-react';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Modal } from './Modal';
import { ModalInput } from './ModalInput';
Expand All @@ -26,6 +26,16 @@ export function AddUserModal({ isOpen, onClose, onSave }: AddUserModalProps) {
const [password, setPassword] = useState('');
const [role, setRole] = useState('user');

useEffect(() => {
if (!isOpen) {
setName('');
setUsername('');
setEmail('');
setPassword('');
setRole('user');
}
}, [isOpen]);
Comment thread
arturict marked this conversation as resolved.
Outdated

const handleSave = () => {
onSave({
name,
Expand Down
26 changes: 26 additions & 0 deletions tests/e2e/users.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect, test } from './fixtures';

test.describe('User management', () => {
test('clears the add user form after creating a user', async ({ authenticatedPage: page }) => {
await page.goto('/dashboard/users');
await page.getByRole('button', { name: 'Add User' }).click();

const modal = page.getByRole('heading', { name: 'Add User' }).locator('../..');
const inputs = modal.locator('input');
await inputs.nth(0).fill('Second User');
await inputs.nth(1).fill('seconduser');
await inputs.nth(2).fill('second@example.com');
await inputs.nth(3).fill('SecondPassword123!');
Comment thread
arturict marked this conversation as resolved.
Outdated
await modal.locator('select').selectOption('admin');
await modal.getByRole('button', { name: 'Add User' }).click();

await expect(modal).toBeHidden();
await page.getByRole('button', { name: 'Add User' }).click();

await expect(inputs.nth(0)).toHaveValue('');
await expect(inputs.nth(1)).toHaveValue('');
await expect(inputs.nth(2)).toHaveValue('');
await expect(inputs.nth(3)).toHaveValue('');
await expect(modal.locator('select')).toHaveValue('user');
});
});