From 4312ae47a260d237e284dc9d2c60e65add6c7ed5 Mon Sep 17 00:00:00 2001 From: Somya Bansal <77123777+somya-05@users.noreply.github.com> Date: Fri, 18 Oct 2024 00:04:53 +0530 Subject: [PATCH] test: increase coverage for TimePicker (#17639) --- .../components/TimePicker/TimePicker-test.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/react/src/components/TimePicker/TimePicker-test.js b/packages/react/src/components/TimePicker/TimePicker-test.js index 8844e9ffa172..eaf36abaf409 100644 --- a/packages/react/src/components/TimePicker/TimePicker-test.js +++ b/packages/react/src/components/TimePicker/TimePicker-test.js @@ -90,6 +90,39 @@ describe('TimePicker', () => { render(); expect(screen.getByPlaceholderText('🧸')).toBeInTheDocument(); }); + + it('should call onBlur when not disabled or readOnly', () => { + const onBlur = jest.fn(); + render(); + const input = screen.getByRole('textbox'); + + fireEvent.blur(input); + expect(onBlur).toHaveBeenCalled(); + }); + + it('should not call onBlur when disabled', () => { + const onBlur = jest.fn(); + render(); + const input = screen.getByRole('textbox'); + + fireEvent.blur(input); + expect(onBlur).not.toHaveBeenCalled(); + }); + + it('should update value and prevValue when value changes', () => { + const { rerender } = render( + + ); + + // Initial render + expect(screen.getByRole('textbox')).toHaveValue('10:00'); + + // Rerender with a new value + rerender(); + + // Check if the value is updated + expect(screen.getByRole('textbox')).toHaveValue('11:00'); + }); }); describe('label', () => {