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

[#12588] Add unit tests to datepicker component #12592

Merged
merged 3 commits into from
Sep 26, 2023
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
21 changes: 20 additions & 1 deletion src/web/app/components/datepicker/datepicker.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { NgbDatepickerModule } from '@ng-bootstrap/ng-bootstrap';
import { By } from '@angular/platform-browser';
import { NgbInputDatepicker, NgbDatepickerModule } from '@ng-bootstrap/ng-bootstrap';
import { DateFormat } from 'src/web/types/datetime-const';
import { DatepickerComponent } from './datepicker.component';

describe('DatepickerComponent', () => {
Expand All @@ -27,4 +29,21 @@ describe('DatepickerComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should emit the date for changeDate', () => {
const changeDateSpy = jest.spyOn(component.dateChangeCallback, 'emit');
const date : DateFormat = { year: 2023, month: 10, day: 12 };
component.changeDate(date);
expect(changeDateSpy).toHaveBeenCalledWith(date);
});

it('the datepicker should navigate to today\'s date for selectTodayDate', () => {
const datepicker = fixture.debugElement.query(By.directive(NgbInputDatepicker)).injector.get(NgbInputDatepicker);
const todayDate = component.calendar.getToday();
const selectTodayDateSpy = jest.spyOn(component.dateChangeCallback, 'emit');
const datePickerNavigateSpy = jest.spyOn(datepicker, 'navigateTo');
component.selectTodayDate(datepicker);
expect(selectTodayDateSpy).toHaveBeenCalledWith(todayDate);
expect(datePickerNavigateSpy).toHaveBeenCalledWith(todayDate);
});
});
Loading