Skip to content

Commit 9ea739c

Browse files
committed
frontend/PasswordComponent: ensure proper validation styling and attributes
1 parent 42b7557 commit 9ea739c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

frontend/src/components/PasswordComponent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export function PasswordComponent(props: PasswordComponentProps) {
2828
type={showPassword ? "text" : "password"}
2929
onChange={handleChange}
3030
value={props.value}
31-
isInvalid={props.isInvalid} />
31+
isInvalid={props.isInvalid}
32+
required
33+
minLength={8} />
3234
<Button
3335
variant="outline-primary"
3436
onClick={(e: Event) => {

frontend/src/components/__tests__/PasswordComponent.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeAll, describe, expect, it, vi } from 'vitest';
2-
import { render, screen, fireEvent } from '@testing-library/preact';
2+
import { render, screen, fireEvent, waitFor } from '@testing-library/preact';
33
import userEvent from '@testing-library/user-event';
44

55
let PasswordComponent: any;
@@ -40,12 +40,14 @@ describe('PasswordComponent', () => {
4040
expect(handleChange).toHaveBeenLastCalledWith('Secret123!');
4141
});
4242

43-
it('shows invalid state and feedback when provided', () => {
43+
it('shows invalid state and feedback when provided', async () => {
4444
const handleChange = vi.fn();
4545
render(<PasswordComponent onChange={handleChange} isInvalid invalidMessage="Invalid password" />);
4646

4747
const input = screen.getByTestId('password-input');
48-
expect(input).toHaveClass('invalid');
48+
await waitFor(() => {
49+
expect(input).toHaveClass('invalid');
50+
})
4951

5052
const feedback = screen.getByTestId('invalid-feedback');
5153
expect(feedback).toHaveTextContent('Invalid password');

0 commit comments

Comments
 (0)