import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { DatePicker } from '../../src/components/DatePicker';
describe('DatePicker', () => {
it('supports datetime-local type and change callback', () => {
const onChange = vi.fn();
render();
const input = screen.getByLabelText('Schedule') as HTMLInputElement;
expect(input.type).toBe('datetime-local');
fireEvent.change(input, { target: { value: '2031-05-20T14:30' } });
expect(onChange).toHaveBeenCalledTimes(1);
});
it('supports date type and disabled state', () => {
render(
{}}
disabled
/>,
);
const input = screen.getByLabelText('Publish date') as HTMLInputElement;
expect(input.type).toBe('date');
expect(input).toBeDisabled();
});
it('renders right icon and error message', () => {
const { container } = render(
{}}
rightIcon={R}
error="Invalid date"
inputClassName="custom-input"
/>,
);
const input = container.querySelector('input');
expect(input).toBeInstanceOf(HTMLInputElement);
expect(screen.getByTestId('right-icon')).toBeInTheDocument();
expect(input).toHaveClass('pr-10');
expect(input).toHaveClass('custom-input');
expect(screen.getByText('Invalid date')).toBeInTheDocument();
});
it('supports inline layout', () => {
const { container } = render(
{}} layout="inline" />,
);
expect(container.querySelector('label')).toHaveClass('inline-flex');
expect(container.querySelector('label > div')).not.toHaveClass('mt-1');
});
});