From ac7dbb862848f5d4a32b8039d1abbc46e180ff80 Mon Sep 17 00:00:00 2001 From: Sinchana Date: Thu, 21 Sep 2023 15:16:22 +0530 Subject: [PATCH] #918 - Added test cases --- .../go-datepicker.component.spec.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/projects/go-lib/src/lib/components/go-datepicker/go-datepicker.component.spec.ts b/projects/go-lib/src/lib/components/go-datepicker/go-datepicker.component.spec.ts index de6550147..ab1c19599 100644 --- a/projects/go-lib/src/lib/components/go-datepicker/go-datepicker.component.spec.ts +++ b/projects/go-lib/src/lib/components/go-datepicker/go-datepicker.component.spec.ts @@ -14,6 +14,7 @@ import { GoFormErrorsModule } from '../go-form-errors/go-form-errors.module'; describe('GoDatepickerComponent', () => { let component: GoDatepickerComponent; let fixture: ComponentFixture; + let inputElement: HTMLInputElement; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -41,6 +42,7 @@ describe('GoDatepickerComponent', () => { fixture = TestBed.createComponent(GoDatepickerComponent); component = fixture.componentInstance; component.control = new FormControl(''); + inputElement = fixture.nativeElement.querySelector("input"); }); it('should create', () => { @@ -246,4 +248,22 @@ describe('GoDatepickerComponent', () => { }); }); + describe("onInputCloseCalendar", () => { + it("close the calendar when the user interacts with the date field by typing inside it. ", () => { + component.goCalendar.openCalendar(new Date()); + + component.onInputCloseCalendar(); + + expect(component.goCalendar.isOpen).toBe(false); + }); + + it("should call onInputCloseCalendar() when input event is emitted.", () => { + const onInputCloseCalendarSpy = spyOn(component, "onInputCloseCalendar"); + + inputElement.dispatchEvent(new Event("input")); + + expect(onInputCloseCalendarSpy).toHaveBeenCalled(); + }); + }); + });