]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
00d09e3b4d3cf549a76956b38c8cdbe33c119f05
[ceph-ci.git] /
1 import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
2 import { FormControl, FormsModule } from '@angular/forms';
3
4 import { NgbDatepickerModule, NgbTimepickerModule } from '@ng-bootstrap/ng-bootstrap';
5
6 import { configureTestBed } from '~/testing/unit-test-helper';
7 import { DateTimePickerComponent } from './date-time-picker.component';
8
9 describe('DateTimePickerComponent', () => {
10   let component: DateTimePickerComponent;
11   let fixture: ComponentFixture<DateTimePickerComponent>;
12
13   configureTestBed({
14     declarations: [DateTimePickerComponent],
15     imports: [NgbDatepickerModule, NgbTimepickerModule, FormsModule]
16   });
17
18   beforeEach(() => {
19     spyOn(Date, 'now').and.returnValue(new Date('2022-02-22T00:00:00.00'));
20     fixture = TestBed.createComponent(DateTimePickerComponent);
21     component = fixture.componentInstance;
22   });
23
24   it('should create with correct datetime', fakeAsync(() => {
25     component.control = new FormControl('2022-02-26 00:00:00');
26     fixture.detectChanges();
27     tick();
28     expect(component).toBeTruthy();
29     expect(component.control.value).toBe('2022-02-26 00:00:00');
30   }));
31
32   it('should update control value if datetime is not valid', fakeAsync(() => {
33     component.control = new FormControl('not valid');
34     fixture.detectChanges();
35     tick();
36     expect(component.control.value).toBe('2022-02-22 00:00:00');
37   }));
38
39   it('should init with only date enabled', () => {
40     component.control = new FormControl();
41     component.hasTime = false;
42     fixture.detectChanges();
43     expect(component.format).toBe('YYYY-MM-DD');
44   });
45
46   it('should init with time enabled', () => {
47     component.control = new FormControl();
48     component.hasSeconds = false;
49     fixture.detectChanges();
50     expect(component.format).toBe('YYYY-MM-DD HH:mm');
51   });
52
53   it('should init with seconds enabled', () => {
54     component.control = new FormControl();
55     fixture.detectChanges();
56     expect(component.format).toBe('YYYY-MM-DD HH:mm:ss');
57   });
58 });