file re-org
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 53s

This commit is contained in:
2025-11-25 11:37:41 -08:00
parent 4b5fe4f8df
commit 8968813ee0
71 changed files with 1678 additions and 246 deletions

View File

@@ -1,75 +0,0 @@
// src/components/PasswordInput.test.tsx
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { PasswordInput } from './PasswordInput';
// Mock the child PasswordStrengthIndicator component to isolate the test
vi.mock('./PasswordStrengthIndicator', () => ({
PasswordStrengthIndicator: ({ password }: { password?: string }) => (
<div data-testid="strength-indicator">{`Strength for: ${password}`}</div>
),
}));
describe('PasswordInput', () => {
it('should render as a password input by default', () => {
render(<PasswordInput />);
const input = screen.getByRole('textbox'); // It's a textbox role even with type password
expect(input).toHaveAttribute('type', 'password');
});
it('should toggle input type between password and text when the eye icon is clicked', () => {
render(<PasswordInput />);
const input = screen.getByRole('textbox');
const toggleButton = screen.getByRole('button', { name: /show password/i });
// Initial state
expect(input).toHaveAttribute('type', 'password');
// Click to show
fireEvent.click(toggleButton);
expect(input).toHaveAttribute('type', 'text');
expect(toggleButton).toHaveAttribute('aria-label', 'Hide password');
// Click to hide again
fireEvent.click(toggleButton);
expect(input).toHaveAttribute('type', 'password');
expect(toggleButton).toHaveAttribute('aria-label', 'Show password');
});
it('should pass through standard input attributes', () => {
const handleChange = vi.fn();
render(
<PasswordInput
value="test"
onChange={handleChange}
placeholder="Enter password"
className="extra-class"
/>
);
const input = screen.getByPlaceholderText('Enter password');
expect(input).toHaveValue('test');
expect(input).toHaveClass('extra-class');
fireEvent.change(input, { target: { value: 'new value' } });
expect(handleChange).toHaveBeenCalledTimes(1);
});
it('should not show strength indicator by default', () => {
render(<PasswordInput value="some-password" />);
expect(screen.queryByTestId('strength-indicator')).not.toBeInTheDocument();
});
it('should show strength indicator when showStrength is true and there is a value', () => {
render(<PasswordInput value="some-password" showStrength />);
const indicator = screen.getByTestId('strength-indicator');
expect(indicator).toBeInTheDocument();
expect(indicator).toHaveTextContent('Strength for: some-password');
});
it('should not show strength indicator when showStrength is true but value is empty', () => {
render(<PasswordInput value="" showStrength />);
expect(screen.queryByTestId('strength-indicator')).not.toBeInTheDocument();
});
});