Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase coverage for TimePicker #17639

Merged
Merged
Changes from all commits
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
33 changes: 33 additions & 0 deletions packages/react/src/components/TimePicker/TimePicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,39 @@ describe('TimePicker', () => {
render(<TimePicker id="time-picker" placeholder="🧸" />);
expect(screen.getByPlaceholderText('🧸')).toBeInTheDocument();
});

it('should call onBlur when not disabled or readOnly', () => {
const onBlur = jest.fn();
render(<TimePicker id="time-picker" onBlur={onBlur} />);
const input = screen.getByRole('textbox');

fireEvent.blur(input);
expect(onBlur).toHaveBeenCalled();
});

it('should not call onBlur when disabled', () => {
const onBlur = jest.fn();
render(<TimePicker id="time-picker" onBlur={onBlur} disabled />);
const input = screen.getByRole('textbox');

fireEvent.blur(input);
expect(onBlur).not.toHaveBeenCalled();
});

it('should update value and prevValue when value changes', () => {
const { rerender } = render(
<TimePicker id="time-picker" value="10:00" />
);

// Initial render
expect(screen.getByRole('textbox')).toHaveValue('10:00');

// Rerender with a new value
rerender(<TimePicker id="time-picker" value="11:00" />);

// Check if the value is updated
expect(screen.getByRole('textbox')).toHaveValue('11:00');
});
});

describe('label', () => {
Expand Down
Loading